def alice_creates_exchange_batch(): alice_tx = iroha.transaction([ iroha.command('TransferAsset', src_account_id='alice@test', dest_account_id='bob@test', asset_id='bitcoin#test', amount='1') ], creator_account='alice@test', quorum=2) bob_tx = iroha.transaction( [ iroha.command('TransferAsset', src_account_id='bob@test', dest_account_id='alice@test', asset_id='dogecoin#test', amount='2') ], creator_account='bob@test' # we intentionally omit here bob's quorum, since alice is the originator of the exchange and in general case # alice does not know bob's quorum. # bob knowing own quorum in case of accept should sign the tx using all the number of missing keys at once ) iroha.batch(alice_tx, bob_tx, atomic=True) # sign transactions only after batch meta creation ic.sign_transaction(alice_tx, *alice_private_keys) send_batch_and_print_status(alice_tx, bob_tx)
def add_coin_to_admin(): """ Add 1000.00 units of 'coin#domain' to 'admin@test' """ tx = iroha.transaction([ iroha.command('AddAssetQuantity', asset_id='coin#domain', amount='1000.00') ]) IrohaCrypto.sign_transaction(tx, admin_private_key) send_transaction_and_print_status(tx)
def create_account_userone(): """ Create account 'userone@domain' """ tx = iroha.transaction([ iroha.command('CreateAccount', account_name='userone', domain_id='domain', public_key=user_public_key) ]) IrohaCrypto.sign_transaction(tx, admin_private_key) send_transaction_and_print_status(tx)
def set_age_to_userone(): """ Set age to userone@domain by admin@test """ tx = iroha.transaction([ iroha.command('SetAccountDetail', account_id='userone@domain', key='age', value='18') ]) IrohaCrypto.sign_transaction(tx, admin_private_key) send_transaction_and_print_status(tx)
def userone_grants_to_admin_set_account_detail_permission(): """ Make admin@test able to set detail to userone@domain """ tx = iroha.transaction([ iroha.command('GrantPermission', account_id='admin@test', permission=can_set_my_account_detail) ], creator_account='userone@domain') IrohaCrypto.sign_transaction(tx, user_private_key) send_transaction_and_print_status(tx)
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 transfer_coin_from_admin_to_userone(): """ Transfer 2.00 'coin#domain' from 'admin@test' to 'userone@domain' """ tx = iroha.transaction([ iroha.command('TransferAsset', src_account_id='admin@test', dest_account_id='userone@domain', asset_id='coin#domain', description='init top up', amount='2.00') ]) IrohaCrypto.sign_transaction(tx, admin_private_key) send_transaction_and_print_status(tx)
def send_tx(self): iroha = Iroha('admin@test') admin_private_key = 'f101537e319568c765b2cc89698325604991dca57b9716b58016b253506cab70' tx = iroha.transaction([ iroha.command('TransferAsset', src_account_id='admin@test', dest_account_id='test@test', asset_id='coin#test', amount='0.01', description=HOSTNAME) ]) ic.sign_transaction(tx, admin_private_key) self.client.send_tx(tx)
def add_keys_and_set_quorum(): alice_iroha = Iroha('alice@test') alice_cmds = [ alice_iroha.command('AddSignatory', account_id='alice@test', public_key=ic.hex_key_to_bytes(alice_public_keys[1])), alice_iroha.command('SetAccountQuorum', account_id='alice@test', quorum=2) ] alice_tx = alice_iroha.transaction(alice_cmds) ic.sign_transaction(alice_tx, alice_private_keys[0]) send_transaction_and_print_status(alice_tx) bob_iroha = Iroha('bob@test') bob_cmds = [ bob_iroha.command('AddSignatory', account_id='bob@test', public_key=ic.hex_key_to_bytes(bob_public_keys[1])), bob_iroha.command('SetAccountQuorum', account_id='bob@test', quorum=2) ] bob_tx = bob_iroha.transaction(bob_cmds) ic.sign_transaction(bob_tx, bob_private_keys[0]) send_transaction_and_print_status(bob_tx)
def create_users(): global iroha init_cmds = [ iroha.command('CreateAsset', asset_name='bitcoin', domain_id='test', precision=2), iroha.command('CreateAsset', asset_name='dogecoin', domain_id='test', precision=2), iroha.command('AddAssetQuantity', asset_id='bitcoin#test', amount='100000'), iroha.command('AddAssetQuantity', asset_id='dogecoin#test', amount='20000'), iroha.command('CreateAccount', account_name='alice', domain_id='test', public_key=ic.hex_key_to_bytes(alice_public_keys[0])), iroha.command('CreateAccount', account_name='bob', domain_id='test', public_key=ic.hex_key_to_bytes(bob_public_keys[0])), iroha.command('TransferAsset', src_account_id='admin@test', dest_account_id='alice@test', asset_id='bitcoin#test', description='init top up', amount='100000'), iroha.command('TransferAsset', src_account_id='admin@test', dest_account_id='bob@test', asset_id='dogecoin#test', description='init doge', amount='20000') ] init_tx = iroha.transaction(init_cmds) ic.sign_transaction(init_tx, admin_private_key) send_transaction_and_print_status(init_tx)
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)
def create_domain_and_asset(): """ Creates domain 'domain' and asset 'coin#domain' with precision 2 """ commands = [ iroha.command('CreateDomain', domain_id='domain', default_role='user'), iroha.command('CreateAsset', asset_name='coin', domain_id='domain', precision=2) ] tx = IrohaCrypto.sign_transaction(iroha.transaction(commands), admin_private_key) send_transaction_and_print_status(tx)