Collector code example
1 min
import sys
import time
from Collector import CollectorConfig, CollectorType
from ApiClient import ApiClient
def build_config():
config = CollectorConfig.Config(CollectorType.CollectorType(0), "[email protected]", "11", "myCollector", 1709211262)
config.addCollectorAddress(1, "0xadF6bc922e6f10FE6b4147AE4b41b52E669d94a7")
config.addCurrencyLimits("ETH", "0.5", )
config.addNetworkLimits("ETH", 10000000000000000000, None)
return config
def wait_for_collector_to_finish(api_user, collector_id: str, time_to_wait: int = 2000):
index = None
for i, collector in enumerate(api_user.getCollectors()['FunctionData']['Collectors']):
if collector['Config']['CollectorId'] == collector_id:
index = i
timeout = time.time() + time_to_wait
while time.time() < timeout:
api_run_id = api_user.getCollectors()['FunctionData']['Collectors'][index]['RunId']
if not api_run_id:
return True
time.sleep(10)
return False
if __name__ == "__main__":
# PLEASE DO NOT COMMIT YOUR TESTING CHANGES BELOW THIS LINE
path_to_example_qr = "example_qr.txt"
if len(sys.argv) == 2:
path_to_example_qr = sys.argv[1]
HOT_IP_ADDRESS = "3.255.11.149"
api_user = ApiClient.fromQr(path_to_example_qr, HOT_IP_ADDRESS)
api_user.generateNewAccessToken()
# create wallets
# for i in range(1,5):
# api_user.createManyWallets(["wallet_id_" + str(i)],["Tx24"], 1, ["ETH"], False)
# fund adresses if needed
# wallets = api_user.getWalletsBalances(1, ["wallet_id_1","wallet_id_2","wallet_id_3","wallet_id_4"], True)["FunctionData"]
# # fund addresses
# for wallet in wallets["WalletsBalance"]:
# for balance in wallet["Balances"]:
# if balance["Coin"] == "ETH":
# api_user.sendTransaction(3, "ETH", [(balance["Address"], "100000000000000")], "1000000000", 21000,
# max_priority_fee="1000000000")
config = build_config()
# need to do only in the first time we add collector
# api_user.addCollector(config)
response = api_user.startCollector(config)
if wait_for_collector_to_finish(api_user, config.collector_id, 4000):
api_user.getWalletsBalances(1, ["wallet_id_1","wallet_id_2","wallet_id_3","wallet_id_4"], True)