我正在使用 Etherscan API 将传入交易获取到各种不同的以太坊合约(目前在 Kovan 测试网上)。我试图回顾 12 秒,并将它找到的任何事务作为电报消息发送到 python 中。然而,它获得了时间戳,但永远不会意识到存在时差,甚至永远不会开始加载 TG 消息。任何人都可以帮忙吗?我的代码:
if filecontents != None:
cont = True
while cont:
chatIdFile = open("chatID.botdata", "r")
filecontents = chatIdFile.read()
chatIdFile.close()
if filecontents != None:
cont = True
chatId = filecontents
else:
cont = False
contractsFile = open("contracts.json", "r")
contractsJson = contractsFile.read()
contractsFile.close()
contractsObject = json.loads(contractsJson)
del contractsObject["placeholder-DONOTREMOVE"]
for address in contractsObject:
address = contractsObject[address]
url = "https://api-kovan.etherscan.io/api?module=account&action=txlist&address=" + address['Address'] + "&apikey=" + ETH_API
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36"}
print("Try" + address['Address'])
response = requests.request("get", url, headers=headers)
responseToProc = response.json()
responseToProc = json.dumps(responseToProc)
responseToProc = json.loads(responseToProc)
responseToProc = responseToProc['result']
for row in responseToProc:
dt = datetime.datetime.now()
utc_timestamp = round(dt.timestamp())
if row['to'] == address['Address'].lower() or row['to'] == "":
if int(row['timeStamp']) >= (int(utc_timestamp) - 12):
print("Ran TimeStamp")
#Send the Message
try:
if int(row['value']) == 0:
text = "Contract:" + address['Name'] + " Received a contract interaction. No Ethereum was sent to the contract, however. Check the transaction for more info: \n https://kovan.etherscan.io/tx/" + row['hash']
else:
text = "Contract: " + address['Name'] + " received: " + str(int(row['value']) / 1000000000000000000) + " ETH. See the transaction at: \n https://kovan.etherscan.io/tx/" + row['hash']
except NameError:
if int(row['value']) == 0:
text = "Contract:" + address['Address'] + " Received a contract interaction. No Ethereum was sent to the contract, however. Check the transaction for more info: \n https://kovan.etherscan.io/tx/" + row['hash']
else:
text = "Contract: " + address['Address'] + " received: " + str(int(row['value']) / 1000000000000000000) + " ETH. See the transaction at: \n https://kovan.etherscan.io/tx/" + row['hash']
headers = {"User-agent": " Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36"}
payload = {
"text": text,
"chat_id": chatId,
"reply_to_message_id": 0,
"allow_sending_without_reply": True,
}
response = requests.request("post", url2, headers=headers, data=payload)
print(response.json())
time.sleep(0.5)
time.sleep(8)