142 lines
4.6 KiB
Python
142 lines
4.6 KiB
Python
import random
|
|
import time
|
|
|
|
from loguru import logger
|
|
from peewee import fn
|
|
from web3 import Web3
|
|
|
|
from models.nexus import Nexus
|
|
|
|
|
|
def eth_transfer_proxy(conn_url, from_address, to_address, amount, from_private_key, gas, chain_id, limit_gas_price):
|
|
web3 = Web3(Web3.HTTPProvider(conn_url))
|
|
|
|
try:
|
|
from_address = web3.to_checksum_address(from_address)
|
|
print("to_address:", to_address)
|
|
|
|
balance = web3.from_wei(web3.eth.get_balance(Web3.to_checksum_address(from_address)), 'ether')
|
|
gas_price = web3.eth.gas_price / 10 ** 9
|
|
logger.info(['web_3.eth.gas_price', gas_price, '余额', float(balance)])
|
|
|
|
nonce = web3.eth.get_transaction_count(from_address, 'pending')
|
|
|
|
value_balance = web3.from_wei(web3.eth.get_balance(web3.to_checksum_address(to_address)), 'ether')
|
|
logger.info(f"要转向的账户余额为:{value_balance}")
|
|
|
|
# if value_balance > 0.0001:
|
|
from_balance = web3.from_wei(web3.eth.get_balance(web3.to_checksum_address(from_address)), 'ether')
|
|
logger.info(f"原先账户的余额为:{from_balance}")
|
|
|
|
if gas_price < limit_gas_price:
|
|
# 构建交易
|
|
tx = {
|
|
'nonce': nonce,
|
|
'to': web3.to_checksum_address(to_address),
|
|
'value': web3.to_wei(amount, 'ether'),
|
|
"gasPrice": int(web3.eth.gas_price * 1.1),
|
|
'gas': gas,
|
|
# 'gasPrice': web3_sync.to_wei(gas_price_new, 'gwei'),
|
|
'chainId': chain_id # Sepolia 测试网的链 ID
|
|
|
|
}
|
|
|
|
# 签名交易
|
|
signed_tx = web3.eth.account.sign_transaction(tx, from_private_key)
|
|
# 发送原始交易
|
|
tx_hash = web3.eth.send_raw_transaction(signed_tx.raw_transaction)
|
|
|
|
print(f"交易哈希为 sent for nonce {nonce}, tx hash: {tx_hash.hex()}")
|
|
|
|
else:
|
|
logger.info(f"要转向的账户余额为:{value_balance}")
|
|
time.sleep(2)
|
|
|
|
except Exception as e:
|
|
print(e)
|
|
raise Exception(e)
|
|
|
|
|
|
from tomorrow3 import threads
|
|
|
|
|
|
@threads(100) # 指定线程数为4
|
|
def get_num(i):
|
|
web3 = Web3(Web3.HTTPProvider(conn_url))
|
|
|
|
from_address = web3.to_checksum_address(i.address)
|
|
|
|
balance = web3.from_wei(web3.eth.get_balance(Web3.to_checksum_address(from_address)), 'ether')
|
|
print(i.text, balance)
|
|
|
|
# time.sleep(0.5)
|
|
|
|
i.num = balance
|
|
i.save()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
conn_url = "https://rpc.nexus.xyz/http"
|
|
|
|
# eth_transfer_proxy(
|
|
# conn_url="https://rpc.nexus.xyz/http",
|
|
# from_address="0xf540845c941c779C3b6De4667a15f88F0AbAb212",
|
|
# to_address="0x3e499b15cC500dF22847690A15A7199EC425913B",
|
|
# gas=21000,
|
|
# from_private_key="0x0cc6c1b52c5b12bfd69efa1c51f91fe896456dea6231b6e8c372f633fc985666",
|
|
# amount=10,
|
|
# chain_id=392,
|
|
# proxy="",
|
|
# limit_gas_price=1
|
|
#
|
|
# )
|
|
|
|
for z in range(30):
|
|
|
|
for i in Nexus.select().where(
|
|
Nexus.num > 0,
|
|
Nexus.to_id.is_null(),
|
|
).order_by(fn.RAND()):
|
|
ne_infos = Nexus.select().where(
|
|
Nexus.to_id == i.id,
|
|
).order_by(fn.RAND())
|
|
for ne_info in ne_infos:
|
|
eth_transfer_proxy(
|
|
conn_url="https://rpc.nexus.xyz/http",
|
|
from_address=i.address,
|
|
to_address=ne_info.address,
|
|
gas=21000,
|
|
from_private_key=i.private_key,
|
|
amount=random.random() + random.randint(1, (i.num - 1) // random.randint(10, 20)),
|
|
chain_id=392,
|
|
limit_gas_price=1
|
|
)
|
|
|
|
time.sleep(random.randint(3, 10))
|
|
|
|
for i in Nexus.select():
|
|
get_num(i)
|
|
|
|
time.sleep(random.randint(30, 60))
|
|
|
|
for i in Nexus.select().where(
|
|
Nexus.num > 0,
|
|
Nexus.to_id.is_null(False),
|
|
).order_by(fn.RAND()):
|
|
ne_infos = Nexus.select().where(
|
|
Nexus.id == i.to_id,
|
|
).order_by(fn.RAND())
|
|
for ne_info in ne_infos:
|
|
eth_transfer_proxy(
|
|
conn_url="https://rpc.nexus.xyz/http",
|
|
from_address=i.address,
|
|
to_address=ne_info.address,
|
|
gas=21000,
|
|
from_private_key=i.private_key,
|
|
amount=i.num - 0.01 - random.random(),
|
|
chain_id=392,
|
|
limit_gas_price=1
|
|
)
|
|
|
|
time.sleep(random.randint(3, 10))
|