-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
107 lines (87 loc) · 3.37 KB
/
main.py
File metadata and controls
107 lines (87 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import logging
import os
import sys
import time
import random
import json
import requests
from web3 import Web3
from eth_account import Account
from chains import chains
from create_wallet import create_wallet
from config import rpcs, verifiers
FDC_HUB_ADDRESS = "0xc25c749DC27Efb1864Cb3DADa8845B7687eB2d44"
FDC_REQUEST_FEE_CONFIGURATIONS = "0x259852Ae6d5085bDc0650D3887825f7b76F0c4fe"
DURATION = 30 # seconds between attestations
CHAIN_ID = 14
FDC_HUB_ABI = [
{
"inputs": [{"internalType": "bytes", "name": "_data", "type": "bytes"}],
"name": "requestAttestation",
"outputs": [],
"stateMutability": "payable",
"type": "function",
}
]
FDC_REQUEST_FEE_CONFIGURATIONS_ABI = [
{
"inputs": [{"internalType": "bytes", "name": "_data", "type": "bytes"}],
"name": "getRequestFee",
"outputs": [{"internalType": "uint256", "name": "_fee", "type": "uint256"}],
"stateMutability": "view",
"type": "function",
}
]
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s")
w3 = Web3(Web3.HTTPProvider(os.getenv("FLARE_RPC_URL")))
def main_loop(account):
fdc_hub_contract = w3.eth.contract(address=FDC_HUB_ADDRESS, abi=FDC_HUB_ABI)
fdc_request_fee_configurations_contract = w3.eth.contract(
address=FDC_REQUEST_FEE_CONFIGURATIONS, abi=FDC_REQUEST_FEE_CONFIGURATIONS_ABI
)
available_chains = ["btc"]
while True:
try:
selected_chain = random.choice(available_chains)
logging.info(f"Getting random request from {selected_chain}")
abi_bytes = chains[selected_chain].get_abi_bytes(
rpcs[selected_chain], verifiers[selected_chain]
)
print(f"Attestation request data: {abi_bytes}")
att_request_fee = (
fdc_request_fee_configurations_contract.functions.getRequestFee(
abi_bytes
).call()
)
logging.info(f"FDC Request Fee: {att_request_fee}")
nonce = w3.eth.get_transaction_count(account.address)
gas_price = w3.eth.gas_price
tx = fdc_hub_contract.functions.requestAttestation(
abi_bytes
).build_transaction(
{
"from": account.address,
"nonce": nonce,
"gasPrice": gas_price,
"value": att_request_fee,
"chainId": CHAIN_ID,
}
)
tx["gas"] = w3.eth.estimate_gas(tx)
signed = account.sign_transaction(tx)
tx_hash = w3.eth.send_raw_transaction(signed.raw_transaction)
logging.info(f"Sent attestation tx, hash: {tx_hash.hex()}")
receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
status = receipt.status == 1
logging.info(f"Tx receipt status: {'SUCCESS' if status else 'FAILURE'}")
except Exception as e:
logging.exception("Error in main loop:", exc_info=e)
logging.info(f"Sleeping for {DURATION}s\n")
time.sleep(DURATION)
if __name__ == "__main__":
if not os.path.exists("./disposable_wallet.json"):
create_wallet()
with open("./disposable_wallet.json", "r") as wallet_info:
acct = json.load(wallet_info)
print(acct)
main_loop(Account.from_key(acct["private_key"]))