def get_blocks(): """ Subscribe to blocks stream from the network :return: """ query = iroha.blocks_query() IrohaCrypto.sign_query(query, admin_private_key) for block in net.send_blocks_stream_query(query): print('The next block arrived:', block)
def get_userone_details(): """ Get all the kv-storage entries for userone@domain """ query = iroha.query('GetAccountDetail', account_id='userone@domain') IrohaCrypto.sign_query(query, admin_private_key) response = net.send_query(query) data = response.account_detail_response print('Account id = {}, details = {}'.format('userone@domain', data.detail))
def get_account_assets(): """ List all the assets of userone@domain """ query = iroha.query('GetAccountAssets', account_id='userone@domain') IrohaCrypto.sign_query(query, admin_private_key) response = net.send_query(query) data = response.account_assets_response.account_assets for asset in data: print('Asset id = {}, balance = {}'.format(asset.asset_id, asset.balance))
def get_coin_info(): """ Get asset info for coin#domain :return: """ query = iroha.query('GetAssetInfo', asset_id='coin#domain') IrohaCrypto.sign_query(query, admin_private_key) response = net.send_query(query) data = response.asset_response.asset print('Asset id = {}, precision = {}'.format(data.asset_id, data.precision))
def check_no_pending_txs(): print(' ~~~ No pending txs expected:') print( net.send_query( ic.sign_query( iroha.query('GetPendingTransactions', creator_account='bob@test'), bob_private_keys[0]))) print(' ~~~')
def bob_accepts_exchange_request(): global net q = ic.sign_query( Iroha('bob@test').query('GetPendingTransactions'), bob_private_keys[0] ) pending_transactions = net.send_query(q) for tx in pending_transactions.transactions_response.transactions: if tx.payload.reduced_payload.creator_account_id == 'alice@test': del tx.signatures[:] # we need do this temporarily, otherwise accept will not reach MST engine else: ic.sign_transaction(tx, *bob_private_keys) send_batch_and_print_status(*pending_transactions.transactions_response.transactions)
def bob_declines_exchange_request(): print(""" IT IS EXPECTED HERE THAT THE BATCH WILL FAIL STATEFUL VALIDATION """) global net q = ic.sign_query( Iroha('bob@test').query('GetPendingTransactions'), bob_private_keys[0] ) pending_transactions = net.send_query(q) for tx in pending_transactions.transactions_response.transactions: if tx.payload.reduced_payload.creator_account_id == 'alice@test': del tx.signatures[:] # we need do this temporarily, otherwise accept will not reach MST engine else: ic.sign_transaction(tx, *alice_private_keys) # intentionally alice keys were used to fail bob's txs # zeroes as private keys are also acceptable send_batch_and_print_status(*pending_transactions.transactions_response.transactions)