def enquireAddress(accountAddress): try: assert (len(accountAddress) == 58) account_info = algo_client.account_info(accountAddress) print(account_info) logging.info( "..@dev Enquire account.. \nAccount information: {}\n".format( account_info)) except Exception as err: msg = "Address is invalid. \n Length must be 58\n" logging.info( "..@dev Enquire account Error.. \nError getting account information: {}Message: {}\n" .format(msg, err))
def resolve(self, bankrIdentifier, skey): # Check if Leafbank holding Bankers' asset prior to opt-in assetId = getAssetIdv2(transaction_executor) account_info_pk = algo_client.account_info(bankrIdentifier) holding = None idx = 0 print(account_info_pk) for assetinfo in account_info_pk['assets']: scrutinized_asset = assetinfo[idx] idx = idx + 1 if assetId == scrutinized_asset['asset-id']: holding = True msg = "This address has opted in for ISA, ID {}".format(assetId) logging.info("Message: {}".format(msg)) logging.captureWarnings(True) break if not holding: # Use the AssetTransferTxn class to transfer assets and opt-in txn = AssetTransferTxn( sender=bankrIdentifier, sp=params, receiver=bankrIdentifier, amt=0, index=assetId ) # Sign the transaction # Firstly, convert mnemonics to private key--. sk = mnemonic.to_private_key(seed) sendTrxn = txn.sign(sk) # Submit transaction to the network txid = algo_client.send_transaction(sendTrxn, headers={'content-type': 'application/x-binary'}) message = "Transaction was signed with: {}.".format(txid) wait = wait_for_confirmation(txid) time.sleep(2) hasOptedIn = bool(wait is not None) if hasOptedIn: self.hasResolve = True print(assetId) # Now check the asset holding for that account. # This should now show a holding with 0 balance. assetHolding = print_asset_holding(bankrIdentifier, assetId) logging.info("...##Asset Transfer... \nLeaf Bank address: {}.\nMessage: {}\nHas Opted in: {}\nOperation: {}\nHoldings: {}\n".format( bankrIdentifier, message, hasOptedIn, Bankers.resolve.__name__, assetHolding )) return hasOptedIn
def print_asset_holding(accountAddr, assetid): # note: if you have an indexer instance available it is easier to just use this # response = myindexer.accounts(asset_id = assetid) # then loop thru the accounts returned and match the account you are looking for account_info = algo_client.account_info(accountAddr) idx = 0 for my_account_info in account_info['assets']: scrutinized_asset = account_info['assets'][idx] idx = idx + 1 if scrutinized_asset['asset-id'] == assetid: asset_id = scrutinized_asset['asset-id'] data_json = json.dumps(scrutinized_asset, indent=4) logging.info( "...##Asset holding... \nAddress: {}.\n Asset ID: {}\nData in Json: {}\nOperation: {}\n" .format(accountAddr, asset_id, data_json, print_asset_holding.__name__)) return data_json else: active = False return "You do not own any of the Bank's asset"
def print_created_asset(bankAddr, assetid): # note: if you have an indexer instance available it is easier to just use this # response = myindexer.accounts(asset_id = assetid) # then use 'account_info['created-assets'][0] to get info on the created asset account_info = algo_client.account_info(bankAddr) idx = 0 for my_account_info in account_info['created-assets']: scrutinized_asset = account_info['created-assets'][idx] idx = idx + 1 if scrutinized_asset['index'] == assetid: asset_id = scrutinized_asset['index'] data_json = json.dumps(my_account_info['params'], indent=4) logging.info("...##Asset holding... \nAddress: {}.\n Asset ID: {}\nData in Json: {}\nOperation: {}\n".format( bankAddr, asset_id, data_json, print_created_asset.__name__ )) return data_json else: active = False return "Asset does not exist"
def getAssetIdv2(sourceAddr): # Get account info of asset creator account_info = algo_client.account_info(sourceAddr) _Id = account_info["assets"][0]["asset-id"] return _Id