def test_call_hello(self): address = self.contracts["hello"] contract = Contract.load_from_address(address) print(contract) print(contract.status) pprint(contract.state) contract.account = self.account resp = contract.call(gas_price=1000000000, method="contrAddr", params=[]) print(resp) pprint(contract.last_receipt) assert contract.last_receipt["success"] assert contract.last_receipt["event_logs"][0]["params"][0]["vname"] == "addr" assert contract.last_receipt["event_logs"][0]["params"][0]["value"] == contract.address0x resp = contract.call(gas_price=1000000000, method="setHello", params=[Contract.value_dict("msg", "String", "hi contract.")]) print(resp) pprint(contract.last_receipt) assert contract.last_receipt["success"] assert contract.last_receipt["event_logs"][0]["params"][0]["vname"] == "code" assert contract.last_receipt["event_logs"][0]["params"][0]["type"] == "Int32" assert contract.last_receipt["event_logs"][0]["params"][0]["value"] == "2" resp = contract.call(gas_price=1000000000, method="getHello", params=[]) print(resp) pprint(contract.last_receipt) assert contract.last_receipt["success"] assert contract.last_receipt["event_logs"][0]["_eventname"] == "getHello()" assert contract.last_receipt["event_logs"][0]["params"][0]["vname"] == "msg" assert contract.last_receipt["event_logs"][0]["params"][0]["type"] == "String" assert contract.last_receipt["event_logs"][0]["params"][0]["value"] == "hi contract."
def tiat_create_txns(contract, src_acc, dest_accs, amount): # Clear any cached sessions. This is needed to ensure multiple processes # don't try to reuse the same TCP connection, which would lead to havoc LocalNet = chain.BlockChain(API_ENDPOINT, version=1, network_id=0) chain.set_active_chain(LocalNet) src_acc = Account(private_key=src_acc.private_key) contract = Contract.load_from_address(contract.address, load_state=False) txn_info_list = [] contract.account = src_acc src_addr = src_acc.bech32_address orig_nonce = nonces.get(src_addr, src_acc.get_nonce()) for dest_acc in dest_accs: try: dest = dest_acc.address0x txn_info = contract.call( method="Transfer", params=[ Contract.value_dict("to", "ByStr20", dest), Contract.value_dict("tokens", "Uint128", str(amount)) ], nonce=new_nonce(src_acc), confirm=False) txn_info_list.append(txn_info) print(json.dumps(src_acc.last_params), file=sys.stderr) print("Created {} transactions".format(len(txn_info_list))) except Exception as e: print("Could not send from {} to {}: {}".format( src_acc.address0x, dest, e)) nonce_now = nonces.get(src_addr, src_acc.get_nonce()) # print("{}: created {} transactions; nonce went from {} to {}".format(src_acc.bech32_address, len(txn_info_list), orig_nonce, nonce_now)) return txn_info_list, src_acc, nonce_now
def test_call_other_account(self): address = self.contracts["hello"] contract = Contract.load_from_address(address) print(contract) print(contract.status) account2 = Account(private_key="d0b47febbef2bd0c4a4ee04aa20b60d61eb02635e8df5e7fd62409a2b1f5ddf8") print("Account2 balance", account2.get_balance()) contract.account = account2 resp = contract.call(gas_price=1000000000, method="setHello", params=[ Contract.value_dict("msg", "String", "hello from another account") ]) print(resp) pprint(contract.last_receipt) assert contract.last_receipt["success"] assert contract.last_receipt["event_logs"][0]["params"][0]["vname"] == "code" assert contract.last_receipt["event_logs"][0]["params"][0]["value"] == "1" resp = contract.call(gas_price=1000000000, method="getHello", params=[]) print(resp) pprint(contract.last_receipt) assert contract.last_receipt["success"] assert contract.last_receipt["event_logs"][0]["_eventname"] == "getHello()" assert contract.last_receipt["event_logs"][0]["params"][0]["vname"] == "msg" assert contract.last_receipt["event_logs"][0]["params"][0]["type"] == "String" assert contract.last_receipt["event_logs"][0]["params"][0]["value"] == "hi contract."
def test_call_hello(self): contract = Contract.load_from_address("45dca9586598c8af78b191eaa28daf2b0a0b4f43") print(contract) print(contract.status) print(contract.code) pprint(contract.init) pprint(contract.state) contract.account = self.account resp = contract.call(method="contrAddr", params=[]) print(resp) pprint(contract.last_receipt) assert contract.last_receipt["success"] assert contract.last_receipt["event_logs"][0]["params"][0]["vname"] == "addr" assert contract.last_receipt["event_logs"][0]["params"][0]["value"] == contract.address0x resp = contract.call(method="setHello", params=[Contract.value_dict("msg", "String", "hi contract.")]) print(resp) pprint(contract.last_receipt) assert contract.last_receipt["success"] assert contract.last_receipt["event_logs"][0]["params"][0]["vname"] == "code" assert contract.last_receipt["event_logs"][0]["params"][0]["type"] == "Int32" assert contract.last_receipt["event_logs"][0]["params"][0]["value"] == "2" resp = contract.call(method="getHello", params=[]) print(resp) pprint(contract.last_receipt) assert contract.last_receipt["success"] assert contract.last_receipt["event_logs"][0]["_eventname"] == "getHello()" assert contract.last_receipt["event_logs"][0]["params"][0]["vname"] == "msg" assert contract.last_receipt["event_logs"][0]["params"][0]["type"] == "String" assert contract.last_receipt["event_logs"][0]["params"][0]["value"] == "hi contract."
def test_from_address_test(self): address = self.contracts["test"] contract = Contract.load_from_address(address, load_state=True) print(contract) pprint(contract.get_state(get_code=True, get_init=False)) print(contract.status) print(contract.code) pprint(contract.init) pprint(contract.state)
def test_from_address_test(self): address = "2d3195fbfbe0442556c9613e539a0b62a64f2402" contract = Contract.load_from_address(address, load_state=True) print(contract) pprint(contract.get_state(get_code=True, get_init=True)) print(contract.status) print(contract.code) pprint(contract.init) pprint(contract.state)
def test_from_address_hello(self): address = "45dca9586598c8af78b191eaa28daf2b0a0b4f43" contract = Contract.load_from_address(address, load_state=True) print(contract) pprint(contract.get_state(get_code=True, get_init=True)) print(contract.status) print(contract.code) pprint(contract.init) pprint(contract.state)
def withdraw(config, gas_price, gas_limit, contract): ''' This function will generate a transaction to transfer the token from TEE accoount to the worker's account. ''' cfg = _parse_config(config) # set the active chain local_chain = BlockChain(cfg["baseChainServer"], int(cfg["baseChainversion"]), int(cfg["baseChainID"])) chain.set_active_chain(local_chain) KMSConnector.rpcserver = cfg["baseChainServer"] KMSConnector.version = cfg["baseChainversion"] KMSConnector.networkid = cfg["baseChainID"] KMSConnector.host = str(cfg["KMS_HOST"]) KMSConnector.port = int(cfg["KMS_PORT"]) contract_addr = cfg[contract] contract = Contract.load_from_address(contract_addr) account = Account(private_key=cfg["oracleSK"]) contract.account = account resp = contract.call(method="get_reward_balance", params=[ Contract.value_dict( 'oracle_owner_address', 'ByStr20', zilkey.normalise_address( cfg['oracleAddress']).lower()) ], gas_price=gas_price, gas_limit=gas_limit) if (resp is not None) and (not resp['receipt']['success']): print("Network error") else: if (resp['receipt']['event_logs'][0]['params'][0]['value']['arguments'] == []) or (resp['receipt']['event_logs'][0]['params'][0] ['value']['arguments'] == ['0']): print("No money") else: money = int(resp['receipt']['event_logs'][0]['params'][0]['value'] ['arguments'][0]) / 1000000000000.0 print("Have money: " + str(money)) kms = KMSConnector() if kms.withdraw( zilkey.normalise_address(cfg['oracleAddress'].lower()), money, cfg[contract]) == "success": print("Withdraw submit success") time.sleep(300) print("Withdraw success") elif kms.withdraw( zilkey.normalise_address(cfg['oracleAddress'].lower()), money, cfg[contract]) is None: print("KMS server has no response") else: print("Withdraw submit fail")
def deploy_execution_script(exprs): contract_addr = "zil1mejpsqd5cw589xyq3llzvrk0nvetm9v0l5kcn7" contract = Contract.load_from_address(contract_addr) contract.account = account resp = contract.call(method="deployScript", params=[ Contract.value_dict('exprs', "String", exprs)], priority=True) if resp['receipt']['success']: event_logs = resp['receipt']['event_logs'] if event_logs[0]['_eventname'] == 'Script Deploy': print("Script committed successfully, the script id is " + event_logs[0]['params'][1]['value']) else: print("Commit fail, please see the event log") pprint(event_logs) else: print("Commit fail") pprint(resp)
def test_call(self): address = self.contracts["test"] contract = Contract.load_from_address(address) print(contract) contract.get_state(get_init=True, get_code=False) print(contract.status) pprint(contract.init) pprint(contract.state) contract.account = self.account resp = contract.call(gas_price=1000000000, method="getMessage", params=[]) print(resp) pprint(contract.last_receipt) assert contract.last_receipt["success"] assert contract.last_receipt["event_logs"][0]["params"][0]["vname"] == "msg" assert contract.last_receipt["event_logs"][0]["params"][0]["value"] == "Test Message"
def register_to_process(self, sk, request_id): account = Account(private_key=sk) contract = Contract.load_from_address(self.contract_addr) contract.account = account resp = contract.call(method="register_to_process", params=[ Contract.value_dict("verify_request_id", "Uint32", request_id) ], amount=DEFAULT_REGISTER_STAKE) if not resp: return False if resp['receipt']['success']: if "event_logs" in resp['receipt']: event_logs = resp['receipt']["event_logs"] for event_log in event_logs: if event_log['_eventname'] == 'register success': return True return False
def test_call(self): contract = Contract.load_from_address("2d3195fbfbe0442556c9613e539a0b62a64f2402") print(contract) contract.get_state(get_init=True, get_code=True) print(contract.status) print(contract.code) pprint(contract.init) pprint(contract.state) contract.account = self.account resp = contract.call(method="getMessage", params=[]) print(resp) pprint(contract.last_receipt) assert contract.last_receipt["success"] assert contract.last_receipt["event_logs"][0]["params"][0]["vname"] == "msg" assert contract.last_receipt["event_logs"][0]["params"][0]["value"] == "Test Message"
def test_web_api(): # request contract address contract_addr = "zil16awfafxs789g8nthnm5s9p4l8vnxs5zpfr3upr" contract = Contract.load_from_address(contract_addr) contract.account = account print("Waiting for the request published on chain...") resp = contract.call(method="request", params=[], amount=25, priority=True) if resp['receipt']['success']: event_logs = resp['receipt']['event_logs'] if event_logs[0]['_eventname'] == 'request': print("Request committed successfully, waiting the response...") get_response_event(contract_addr) else: print("Commit fail, please see the event log") pprint(event_logs) else: print("Commit fail") pprint(resp)
def test_trading_pairs(): # request contract address contract_addr = "zil14mkwtfdu7myp0a2wwxd6jv4y0j2k8sj45g4zj9" contract = Contract.load_from_address(contract_addr) contract.account = account print("Waiting for the request published on chain...") resp = contract.call(method="request", params=[], amount=25, priority=True) if resp['receipt']['success']: event_logs = resp['receipt']['event_logs'] if event_logs[0]['_eventname'] == 'request': print("Request committed successfully, waiting the response...") get_response_event(contract_addr) else: print("Commit fail, please see the event log") pprint(event_logs) else: print("Commit fail") pprint(resp)
def test_cross_chain_txn(): # request contract address contract_addr = "zil1usddye6wam5ewygqk9ywm6054ruvjghsdkzh0f" contract = Contract.load_from_address(contract_addr) contract.account = account print("Waiting for the request published on chain...") resp = contract.call(method="request", params=[], amount=15, priority=True) if resp['receipt']['success']: event_logs = resp['receipt']['event_logs'] if event_logs[0]['_eventname'] == 'request': print("Request committed successfully, waiting the response...") get_response_event(contract_addr) else: print("Commit fail, please see the event log") pprint(event_logs) else: print("Commit fail") pprint(resp)
def test_executor(): # request contract address contract_addr = "zil1phx2r986z4hr3rcpk0ztnxfaqvw4je5e2ek2w8" contract = Contract.load_from_address(contract_addr) contract.account = account print("Waiting for the request published on chain...") resp = contract.call(method="request", params=[], amount=25, priority=True) if resp['receipt']['success']: event_logs = resp['receipt']['event_logs'] if event_logs[0]['_eventname'] == 'request': print("Request committed successfully, waiting the response...") get_response_event(contract_addr) else: print("Commit fail, please see the event log") pprint(event_logs) else: print("Commit fail") pprint(resp)
def test_cross_chain_info(): # request contract address contract_addr = "zil1wazvqe0pl3qwnd7hcjw6yqaqy7say2a4qkhkzj" contract = Contract.load_from_address(contract_addr) contract.account = account print("Waiting for the request published on chain...") resp = contract.call(method="request", params=[], amount=25, priority=True) if resp['receipt']['success']: event_logs = resp['receipt']['event_logs'] if event_logs[0]['_eventname'] == 'request': print("Request committed successfully, waiting the response...") get_response_event(contract_addr) else: print("Commit fail, please see the event log") pprint(event_logs) else: print("Commit fail") pprint(resp)
def contract_create_txns(contract, src_accs, method): # Clear any cached sessions. This is needed to ensure multiple processes # don't try to reuse the same TCP connection, which would lead to havoc LocalNet = chain.BlockChain(API_ENDPOINT, version=1, network_id=0) chain.set_active_chain(LocalNet) contract = Contract.load_from_address(contract.address, load_state=False) txn_info_list = [] for src_acc in src_accs: contract.account = src_acc src_addr = src_acc.bech32_address try: txn_info = None if method == 'registerOwnership': txn_info = contract.call(method="registerOwnership", params=[ Contract.value_dict( "ipfs_cid", "String", src_addr) ], nonce=1, confirm=False) elif method == 'configureResolver': label = src_addr txn_info = contract.call( method="configureResolver", params=[ Contract.value_dict("recordOwner", "ByStr20", src_acc.address0x), Contract.value_dict("node", "ByStr32", parentLabelToNode(rootNode, label)), Contract.value_dict("resolver", "ByStr20", src_acc.address0x) ], nonce=1, confirm=False) txn_info_list.append(txn_info) print(json.dumps(src_acc.last_params), file=sys.stderr) print("Created {} transactions".format(len(txn_info_list))) except Exception as e: print("Crowdfund exception: {}".format(e)) # nonce_now = nonces.get(src_addr, src_acc.get_nonce()) return txn_info_list, src_acc, None
def nft_create_txns(contract, src_acc, dest_accs, type='mint'): # Clear any cached sessions. This is needed to ensure multiple processes # don't try to reuse the same TCP connection, which would lead to havoc LocalNet = chain.BlockChain(API_ENDPOINT, version=1, network_id=0) chain.set_active_chain(LocalNet) src_acc = Account(private_key=src_acc.private_key) contract = Contract.load_from_address(contract.address, load_state=False) txn_info_list = [] contract.account = src_acc src_addr = src_acc.bech32_address for dest_acc in dest_accs: try: src = src_acc.address0x dest = dest_acc.address0x txn_info = None if type == 'mint': txn_info = contract.call( method="mint", params=[ Contract.value_dict("to", "ByStr20", dest), Contract.value_dict("tokenId", "Uint256", get_token_id(dest)) ], nonce=1, confirm=False) elif type == 'transfer': txn_info = contract.call( method="transfer", params=[ Contract.value_dict("tokenOwner", "ByStr20", src), Contract.value_dict("to", "ByStr20", dest), Contract.value_dict("tokenId", "Uint256", get_token_id(src)) ], nonce=1, confirm=False) txn_info_list.append(txn_info) print(json.dumps(src_acc.last_params), file=sys.stderr) print("Created {} transactions".format(len(txn_info_list))) except Exception as e: print("Could not send from {} to {}: {}".format( src_acc.address0x, dest, e)) return txn_info_list, src_acc, None
def contract_create_multidest_txns(contract, src_acc, dest_accs, method): # Clear any cached sessions. This is needed to ensure multiple processes # don't try to reuse the same TCP connection, which would lead to havoc LocalNet = chain.BlockChain(API_ENDPOINT, version=1, network_id=0) chain.set_active_chain(LocalNet) src_acc = Account(private_key=src_acc.private_key) contract = Contract.load_from_address(contract.address, load_state=False) txn_info_list = [] contract.account = src_acc src_addr = src_acc.bech32_address for dest_acc in dest_accs: try: dest = dest_acc.address0x txn_info = None if method == 'bestow': label = dest_acc.bech32_address txn_info = contract.call( method="bestow", params=[ Contract.value_dict("node", "ByStr32", parentLabelToNode(rootNode, label)), Contract.value_dict("label", "String", label), Contract.value_dict("owner", "ByStr20", dest), Contract.value_dict( "resolver", "ByStr20", "0x0000000000000000000000000000000000000000") ], nonce=1, confirm=False) txn_info_list.append(txn_info) print(json.dumps(src_acc.last_params), file=sys.stderr) print("Created {} transactions".format(len(txn_info_list))) except Exception as e: print("Could not send from {} to {}: {}".format( src_acc.address0x, dest, e)) return txn_info_list, src_acc, None
def crowd_create_txns(contract, src_accs, amount): # Clear any cached sessions. This is needed to ensure multiple processes # don't try to reuse the same TCP connection, which would lead to havoc LocalNet = chain.BlockChain(API_ENDPOINT, version=1, network_id=0) chain.set_active_chain(LocalNet) contract = Contract.load_from_address(contract.address, load_state=False) txn_info_list = [] for src_acc in src_accs: contract.account = src_acc src_addr = src_acc.bech32_address try: txn_info = contract.call(method="Donate", params=[], zils=amount, nonce=1, confirm=False) txn_info_list.append(txn_info) print(json.dumps(src_acc.last_params), file=sys.stderr) print("Created {} transactions".format(len(txn_info_list))) except Exception as e: print("Crowdfund exception: {}".format(e)) # nonce_now = nonces.get(src_addr, src_acc.get_nonce()) return txn_info_list, src_acc, None
def __init__(self, account): # Set mainnet chain.set_active_chain(chain.MainNet) # Set contract _addr = "zil1hgg7k77vpgpwj3av7q7vv5dl4uvunmqqjzpv2w" self.contract = Contract.load_from_address(_addr, load_state=True) # Set account self.contract.account = account # Set Zilliqa API self.api = ZilliqaAPI("https://api.zilliqa.com/") # Load Zilgraph JSON fp_json = open("zilgraph.json") self.tokens = json.load(fp_json)["tokens"] # Setup dictionaries self.token = {} self.decimals = {"zil": 12} for tok in self.tokens: self.token[tok] = Account(address=self.tokens[tok]["addr"]) self.decimals[tok] = self.tokens[tok]["decimals"]
from pyzil.zilliqa import chain from pyzil.account import Account from pyzil.contract import Contract from pyzil.zilliqa.api import ZilliqaAPI chain.set_active_chain(chain.TestNet) # user account account = Account( private_key= "919457fa2d81c0b7f1f1918683b1ff6b459c444aefec494c92f34d746ebb6b73") balance = account.get_balance() print("{}: {}".format(account, balance)) contract_addr = "zil1cfq4we3nmf2t7687qjvdwlz89qw2gzy700qwff" contract = Contract.load_from_address(contract_addr) contract.account = account def new_swap_request_test(swap_chain, initial_money, swap_money, target_addr, swap_chain_initial_addr, swap_chain_target_addr): resp = contract.call(method="request_swap", params=[ Contract.value_dict("swap_chain", "String", swap_chain), Contract.value_dict("initial_money", "Uint128", str(initial_money)), Contract.value_dict("swap_money", "Uint128", str(swap_money)), Contract.value_dict("target_addr", "ByStr20", target_addr),
def get_contract(self, contract_addr): contract = Contract.load_from_address(contract_addr) contract.get_state() pprint(contract.state) return contract
def main_run(): # # # Dry run # funded_accounts = 1 # level = 1 # level_bal = {level: int(genesis.get_balance())} # prev_batch_size = 1 # num_levels = math.ceil(math.log(NUM_ACCOUNTS, ACC_BATCH_SIZE)) # while funded_accounts < NUM_ACCOUNTS: # batch_size = min(ACC_BATCH_SIZE ** level, NUM_ACCOUNTS - funded_accounts) # amount_to_transfer = math.ceil(1.1 * NUM_ACCOUNTS * ACC_MIN_BALANCE) if level == 1 else (level_bal[level] - ACC_MIN_BALANCE)/ batch_size # print("{} accounts at level {}".format(batch_size, level + 1)) # for l, bal in level_bal.items(): # print("Level {} balance: {} ZILs".format(l, bal)) # total_to_transfer = amount_to_transfer * batch_size # print("Transferring {} ZILs ({}x balance) from each account account @L{} to accounts @L{}".format(total_to_transfer, total_to_transfer/level_bal[level], level, level + 1)) # level_bal[level + 1] = amount_to_transfer # level += 1 # prev_batch_size = batch_size # funded_accounts += batch_size # print("----------------") # exit(0) # Simple distribution from genesis to accounts # print(genesis.get_nonce()) # batch_accs = [] # for _ in range(NUM_ACCOUNTS): # acc = gen_account() # batch_accs.append(acc) # nativet = inter_account_transactions( [ genesis ], batch_accs, zils=ACC_MIN_BALANCE) # exit(0) # token = deploy_contract(genesis, # "fungible.scilla", [ # Contract.value_dict("owner", "ByStr20", genesis.address0x), # # Contract.value_dict("_sharding_input", "String", # # "{\"transitions\" : [\"Transfer\", \"TransferFrom\", \"Mint\"], \"weak_reads\": [\"Transfer:balances[_sender]\", \"TransferFrom:balances[from]\"]}"), # Contract.value_dict("init_supply", "Uint128", "1000000000000000000000000000000000"), # Contract.value_dict("decimals", "Uint32", "0"), # Contract.value_dict("name", "String", "Megabux"), # Contract.value_dict("symbol", "String", "MGBX"), # Contract.value_dict("default_operators", "List ByStr20", "[]")]) # exit(0) # Transfers between accounts # token = Contract.load_from_address("0xf3a8bc908694DDd2d92c86317827a8A55476a700", load_state=False) # batch_accs = [] # for _ in range(NUM_ACCOUNTS): # acc = gen_account() # batch_accs.append(acc) # tokent = token_inter_account_transactions(token, batch_accs, batch_accs, amount=100) # crowd = deploy_contract(genesis, "CrowdFunding.scilla", [ # Contract.value_dict("owner", "ByStr20", genesis.address0x), # Contract.value_dict("max_block", "BNum", "1000"), # Contract.value_dict("goal", "Uint128", "5000")]) # pprint(crowd.get_state()) # nonfung = deploy_contract(genesis, "nonfungible-rewritten.scilla", [ # Contract.value_dict("_sharding_input", "String", # "{\"transitions\" : [\"mint\", \"transfer\"]}"), # Contract.value_dict("contractOwner", "ByStr20", genesis.address0x), # Contract.value_dict("name", "String", "CryptoKatz"), # Contract.value_dict("symbol", "String", "KATZ"), # ]) # pprint(nonfung.get_state()) # proof = deploy_contract(genesis, "ProofIPFS.scilla", [ # Contract.value_dict("_sharding_input", "String", # "{\"transitions\" : [\"registerOwnership\"]}"), # Contract.value_dict("owner", "ByStr20", genesis.address0x), # ]) # pprint(proof.get_state()) # registry = deploy_contract(genesis, "registry-rewritten.scilla", [ # Contract.value_dict("_sharding_input", "String", # "{\"transitions\" : [\"configureResolver\", \"bestow\"]}"), # Contract.value_dict("initialOwner", "ByStr20", genesis.address0x), # Contract.value_dict("rootNode", "ByStr32", "0x0000000000000000000000000000000000000000000000000000000000000000"), # ]) # pprint(registry.get_state()) # exit(0) # crowd = Contract.load_from_address("0xe1e16bf479a754f8b1010e6f908bdd5c98f8ff6f", load_state=False) # nonfung = Contract.load_from_address("0x25f8fb3dcd66ef086fb69c27c9b7b01c88a7c28d", load_state=False) # proof = Contract.load_from_address("0x555395974120a87b73dbc367a01e3f8a9de790f6", load_state=False) registry = Contract.load_from_address( "0xf4661d40eadcaab4d7547df30a04344558d8e15c", load_state=False) batch_accs = [] for _ in range(NUM_ACCOUNTS): acc = gen_account() batch_accs.append(acc) contract_multidest_transactions(registry, [genesis], batch_accs, 'bestow') print("XXXXX", file=sys.stderr, flush=True) contract_transactions(registry, batch_accs, 'configureResolver') # print("XXXXX", file=sys.stderr, flush=True) # nft_transactions(nonfung, [genesis], batch_accs, type='mint') # print("XXXXX", file=sys.stderr, flush=True) # nft_transactions(nonfung, batch_accs, batch_accs, type='transfer') exit(0) # Fancy distribution funded_accounts = 1 accounts = [genesis] prev_batch = accounts # Keep representative account for each level to check balance level = 1 level_acc = {level: genesis} while funded_accounts < NUM_ACCOUNTS: # Aim to increase with every batch, until we hit the desired NUM_ACCOUNTS batch_size = min(max(ACC_BATCH_SIZE, len(prev_batch)**100), NUM_ACCOUNTS - funded_accounts) acc = level_acc[level] # amount_to_transfer = math.ceil(1.1 * NUM_ACCOUNTS * ACC_MIN_BALANCE) if level == 1 else (acc.get_balance() - ACC_MIN_BALANCE) / batch_size tokens_to_transfer = math.ceil( 1.1 * NUM_ACCOUNTS * TOKEN_MIN_BALANCE) if level == 1 else ( int(token.get_state()["balances"][acc.address0x]) - TOKEN_MIN_BALANCE) // batch_size tx_batch = [] batch_accs = [] for _ in range(batch_size): acc = gen_account() batch_accs.append(acc) for l, acc in level_acc.items(): print("Level {} balance: {} ZILs, {} MGBX".format( l, acc.get_balance(), token.get_state()["balances"][acc.address0x])) # print("Transferring {} ZILs and {} MGBX from each of {} account(s) @L{} to each of {} account(s) @L{}".format(amount_to_transfer, tokens_to_transfer, len(prev_batch), level, len(batch_accs), level + 1)) # nativet = inter_account_transactions(prev_batch, batch_accs, zils=amount_to_transfer) tokent = token_inter_account_transactions(token, prev_batch, batch_accs, amount=tokens_to_transfer) prev_batch = batch_accs accounts.extend(batch_accs) funded_accounts += len(batch_accs) level += 1 level_acc[level] = batch_accs[0] # tx_batch.extend(nativet) tx_batch.extend(tokent) wait_for_txs(tx_batch) print("Total accounts funded: {}".format(funded_accounts))
def gzil_balance(self): gzil_contract = Contract.load_from_address( self.token["gzil"].bech32_address, load_state=True) balance = float(gzil_contract.state['balances'][ self.contract.account.address0x]) * 1e-15 return balance