Spaces:
Sleeping
Sleeping
Commit
·
5c33ba8
1
Parent(s):
04beda8
Update app.py
Browse files
app.py
CHANGED
@@ -46,8 +46,11 @@ def sha256(input_string):
|
|
46 |
|
47 |
|
48 |
# 发送自己到自己 0ETH 的交易
|
49 |
-
def send_transaction(w3, account_address, private_key, chain_id,
|
50 |
try:
|
|
|
|
|
|
|
51 |
# 设置交易的相关信息
|
52 |
tx = {
|
53 |
'chainId': chain_id, # 网络 ID
|
@@ -64,11 +67,11 @@ def send_transaction(w3, account_address, private_key, chain_id, gas_price, inpu
|
|
64 |
# 发送签名后的交易并获取交易哈希
|
65 |
tx_hash = w3.eth.send_raw_transaction(signed_tx.rawTransaction)
|
66 |
# 打印结果信息
|
67 |
-
st.toast(f'{
|
68 |
# 返回铭文还有交易哈希
|
69 |
return input_data, tx_hash.hex()
|
70 |
except Exception as e:
|
71 |
-
st.toast(f'
|
72 |
time.sleep(1) # 延迟1秒后继续运行代码
|
73 |
return None, None
|
74 |
|
@@ -144,12 +147,12 @@ if approved_use:
|
|
144 |
if not validate_input(f'{input_data}'):
|
145 |
st.warning("**请注意**:通常代币铭文文本里不能包含空格、换行符,而且所有的字母都必须为小写。")
|
146 |
|
147 |
-
|
148 |
# 每次交易成功后暂停 3 秒
|
149 |
-
if
|
150 |
-
|
151 |
else:
|
152 |
-
|
153 |
|
154 |
# 点击发送交易开始
|
155 |
if st.button(f'开始**发送交易**'):
|
@@ -158,19 +161,15 @@ if approved_use:
|
|
158 |
for the_id in range(token_amount):
|
159 |
# 使用当前账户发送交易,获取当前账户的 nonce
|
160 |
address, key = accounts[current_account_index]
|
161 |
-
# 获取 gas
|
162 |
-
gas_price = w3.eth.gas_price
|
163 |
-
# 这里是未开检查后直接发送交易
|
164 |
# 使用 current_nonce 发送交易
|
165 |
-
data, tx_hash = send_transaction(w3, address, key, 137,
|
166 |
# 记录最后输出的结果
|
167 |
transaction_results.append(f"Transaction Hash: https://polygonscan.com/tx/{tx_hash}")
|
168 |
# 交易成功后,手动增加 nonce 值
|
169 |
-
nonces[address] += 1
|
170 |
# 更新当前账户索引,确保索引始终在账户列表的范围内
|
171 |
current_account_index = (current_account_index + 1) % len(accounts)
|
172 |
# 暂停 3 秒
|
173 |
-
if
|
174 |
time.sleep(0.5) # 暂停三秒
|
175 |
st.toast(f'所有任务已经完成。', icon='🎉')
|
176 |
# 庆祝动画
|
|
|
46 |
|
47 |
|
48 |
# 发送自己到自己 0ETH 的交易
|
49 |
+
def send_transaction(w3, account_address, private_key, chain_id, input_data, the_id):
|
50 |
try:
|
51 |
+
gas_price = w3.eth.gas_price
|
52 |
+
# 自动获取最新的 nonce
|
53 |
+
current_nonce = w3.eth.get_transaction_count(account_address)
|
54 |
# 设置交易的相关信息
|
55 |
tx = {
|
56 |
'chainId': chain_id, # 网络 ID
|
|
|
67 |
# 发送签名后的交易并获取交易哈希
|
68 |
tx_hash = w3.eth.send_raw_transaction(signed_tx.rawTransaction)
|
69 |
# 打印结果信息
|
70 |
+
st.toast(f'{the_id}', icon='✅')
|
71 |
# 返回铭文还有交易哈希
|
72 |
return input_data, tx_hash.hex()
|
73 |
except Exception as e:
|
74 |
+
st.toast(f'{the_id}', icon='❌')
|
75 |
time.sleep(1) # 延迟1秒后继续运行代码
|
76 |
return None, None
|
77 |
|
|
|
147 |
if not validate_input(f'{input_data}'):
|
148 |
st.warning("**请注意**:通常代币铭文文本里不能包含空格、换行符,而且所有的字母都必须为小写。")
|
149 |
|
150 |
+
sleep_05s = st.toggle('每次完成交易后暂停 0.5 秒')
|
151 |
# 每次交易成功后暂停 3 秒
|
152 |
+
if sleep_05s:
|
153 |
+
sleep_05s = True
|
154 |
else:
|
155 |
+
sleep_05s = False
|
156 |
|
157 |
# 点击发送交易开始
|
158 |
if st.button(f'开始**发送交易**'):
|
|
|
161 |
for the_id in range(token_amount):
|
162 |
# 使用当前账户发送交易,获取当前账户的 nonce
|
163 |
address, key = accounts[current_account_index]
|
|
|
|
|
|
|
164 |
# 使用 current_nonce 发送交易
|
165 |
+
data, tx_hash = send_transaction(w3, address, key, 137, input_data, the_id)
|
166 |
# 记录最后输出的结果
|
167 |
transaction_results.append(f"Transaction Hash: https://polygonscan.com/tx/{tx_hash}")
|
168 |
# 交易成功后,手动增加 nonce 值
|
|
|
169 |
# 更新当前账户索引,确保索引始终在账户列表的范围内
|
170 |
current_account_index = (current_account_index + 1) % len(accounts)
|
171 |
# 暂停 3 秒
|
172 |
+
if sleep_05s:
|
173 |
time.sleep(0.5) # 暂停三秒
|
174 |
st.toast(f'所有任务已经完成。', icon='🎉')
|
175 |
# 庆祝动画
|