How to execute a query using the Hyperledger Iroha Python library.
Try executing "Get Account Transactions" to get a list of transactions sent by the specified account.
from iroha import Iroha, IrohaCrypto, IrohaGrpc
import iroha_config
net = IrohaGrpc(iroha_config.IROHA_HOST)
iroha = Iroha(iroha_config.ADMIN_ACCOUNT)
admin_priv_key = iroha_config.ADMIN_PRIV_KEY
# Creating a Query
get_block_query = iroha.query(
'GetAccountTransactions',
account_id = 'admin@test',
page_size = 10,
)
# Sign Query
IrohaCrypto.sign_query(get_block_query, iroha_config.ADMIN_PRIV_KEY)
# Send Query
response = net.send_query(get_block_query)
print(response)
Iroha's host name and private key are set in iroha_config.
The points are the following three. -Use "iroha.query" to create a query. (Update system uses "iroha.command") -Use "sign_query" for signature. (Update system uses "sign_transaction") -Use "send_query" to send a query. (Update system uses "send_tx")
I was able to get the information of the transaction sent by the specified account. I set page_size to 10, but I didn't put much data on the blockchain, so I was able to get only 3 data.
query_hash: "a45f8b59aa211688836bb6567c10baf10e24dfdc9db6c62d3fc8a779200ee136"
transactions_page_response {
transactions {
payload {
reduced_payload {
commands {
create_asset {
asset_name: "samplecoin"
domain_id: "test"
precision: 10
}
}
commands {
add_asset_quantity {
asset_id: "samplecoin#test"
amount: "100000000"
}
}
creator_account_id: "admin@test"
created_time: 1594000825126
quorum: 1
}
}
signatures {
public_key: "313a07e6384776ed95447710d15e59148473ccfc052a681317a72a69f2a49910"
signature: "042b25c8096ca4bfcaca54d05c3d862498f38ddc612b0255138cc74044005d0475467176ef84672fd79b93714e8263e22aa867e7f8e22cf7eba06bb0e63e0b02"
}
}
transactions {
payload {
reduced_payload {
commands {
transfer_asset {
src_account_id: "admin@test"
dest_account_id: "test@test"
asset_id: "samplecoin#test"
description: "test"
amount: "10000"
}
}
creator_account_id: "admin@test"
created_time: 1594002435597
quorum: 1
}
}
signatures {
public_key: "313a07e6384776ed95447710d15e59148473ccfc052a681317a72a69f2a49910"
signature: "f147a7e1c1604a3172efa91e4604fd4bfff728fe0d8d4c644e7d3a0d65ee4f3d2436ad9a26bc9777b0de514f120ed6b4d83a5410cbc097a281a5a588702d4d06"
}
}
transactions {
payload {
reduced_payload {
commands {
create_account {
account_name: "iroha"
domain_id: "test"
public_key: "efdc215eab6dd2c4435d370da73e4b88350e1fed9d39afed503fcbee985fce1f"
}
}
creator_account_id: "admin@test"
created_time: 1594016319157
quorum: 1
}
}
signatures {
public_key: "313a07e6384776ed95447710d15e59148473ccfc052a681317a72a69f2a49910"
signature: "429bf3ae70b60d31ab3fc3c15fa11cb8155b6a824f831652c1c46068feaeb866846b8048e0959cbcbeed532423f050e77d2fe192ea90d0827a6f1489bf67ec0a"
}
}
all_transactions_size: 3
}
・ [Hyperledger Iroha] Notes on how to use Python SDK -[Hyperledger Iroha] Create an account using Python library
I tried using the Iroha library. Other queries will work if you change the name of the query to be executed or change the parameters.
As long as you look at the Iroha query, you can easily get "who" and "what", but It seems that there is no query that tells "for which asset", "who", and "what".
Recommended Posts