def send_query(query, key_pair): query_blob = proto_query_helper.signAndAddSignature(query, key_pair).blob() proto_query = queries_pb2.Query() if sys.version_info[0] == 2: tmp = ''.join(map(chr, query_blob)) else: tmp = bytes(query_blob) proto_query.ParseFromString(tmp) channel = grpc.insecure_channel('127.0.0.1:50051') query_stub = endpoint_pb2_grpc.QueryServiceStub(channel) query_response = query_stub.Find(proto_query) return query_response
def get_blocks(): query = blocks_query_builder.creatorAccountId(creator)\ .createdTime(current_time)\ .queryCounter(1) \ .build() query_blob = iroha.ModelProtoBlocksQuery(query).signAndAddSignature( key_pair).finish().blob() proto_query = queries_pb2.BlocksQuery() if sys.version_info[0] == 2: tmp = ''.join(map(chr, query_blob)) else: tmp = bytes(query_blob) proto_query.ParseFromString(tmp) channel = grpc.insecure_channel('127.0.0.1:50051') query_stub = endpoint_pb2_grpc.QueryServiceStub(channel) query_response = query_stub.FetchCommits(proto_query) for block in query_response: print("block:") print(block)
def send_query(query, key_pair, address='127.0.0.1:50051'): """ Send query to iroha address :param query: to send :param key_pair: for signatures :param address: iroha address :return: query response """ query_blob = proto_query_helper.signAndAddSignature(query, key_pair).blob() proto_query = queries_pb2.Query() if sys.version_info[0] == 2: tmp = ''.join(map(chr, query_blob)) else: tmp = bytes(query_blob) proto_query.ParseFromString(tmp) channel = grpc.insecure_channel(address) query_stub = endpoint_pb2_grpc.QueryServiceStub(channel) query_response = query_stub.Find(proto_query) return MessageToJson(query_response)
print("Status of transaction is:", status) if status != "COMMITTED": print("Your transaction wasn't committed") exit(1) query = query_builder.creatorAccountId(creator) \ .createdTime(current_time) \ .queryCounter(start_query_counter) \ .getAssetInfo("dollar#ru") \ .build() query_blob = proto_query_helper.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(1) else: print("Query responded with asset response") asset_info = query_response.asset_response.asset print("Asset Id =", asset_info.asset_id) print("Precision =", asset_info.precision) print("done!")