Skip to content

Commit

Permalink
Add status check and query
Browse files Browse the repository at this point in the history
Signed-off-by: kamilsa <[email protected]>
  • Loading branch information
kamilsa committed Dec 27, 2017
1 parent e4e4952 commit 522c08e
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions example/python/tx-example.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import block_pb2
import endpoint_pb2
import endpoint_pb2_grpc
import queries_pb2
import grpc

txbuilder = iroha.ModelTransactionBuilder()
Expand All @@ -14,21 +15,16 @@

me_kp = crypto.convertFromExisting("407e57f50ca48969b08ba948171bb2435e035d82cec417e18e4a38f5fb113f83", "1d7e0a32ee0affeb4d22acd73c2c6fb6bd58e266c8c2ce4fa0ffe3dd6a253ffb")

# print(me_kp.publicKey().hex())

peer_kp = crypto.generateKeypair()
signatory_kp = crypto.generateKeypair()
account_kp = crypto.generateKeypair()
current_time = int(round(time.time() * 1000)) - 10**5
startCounter = 1
creator = "admin@test"
# signatory = "fyodor@iroha"


# build transaction
tx = txbuilder.creatorAccountId(creator) \
.createdTime(current_time) \
.createDomain("ru", "user").build()
.createDomain("ru", "user") \
.createAsset("dollar", "ru", 2).build()

tx_blob = protoTxHelper.signAndAddSignature(tx, me_kp).blob()

Expand All @@ -48,13 +44,38 @@
print("Hash in hex", tx.hash().hex())
tx_hash = tx.hash().blob()
tx_hash = ''.join(map(chr, tx_hash))
# print "Tx hash is", tx_hash

request = endpoint_pb2.TxStatusRequest()
request.tx_hash = tx_hash

response = stub.Status(request)
status = endpoint_pb2.TxStatus.Name(response.tx_status)
print"Status of transaction is:", status

if status != "COMMITTED":
print "Your transaction wasn't committed"
exit()

query = queryBuilder.creatorAccountId(creator) \
.createdTime(current_time) \
.getAssetInfo("dollar#ru") \
.build()
query_blob = protoQueryHelper.signAndAddSignature(query, me_kp).blob()

proto_query = queries_pb2.Query()
proto_query.ParseFromString(''.join(map(chr, query_blob)))

query_stub = endpoint_pb2_grpc.QueryServiceStub(channel)
query_response = query_stub.Find(proto_query)

if not query_response.HasField("asset_response"):
print("Query response error")
exit(0)
else:
print "Query responsed with asset response"

print(response.tx_status)
asset_info = query_response.asset_response.asset
print"Asset Id =", asset_info.asset_id
print"Precision =", asset_info.precision

print("done!")

0 comments on commit 522c08e

Please sign in to comment.