def print_status_streaming(tx): # Create status request print("Hash of the transaction: ", tx.hash().hex()) tx_hash = tx.hash().blob() # Check python version if sys.version_info[0] == 2: tx_hash = ''.join(map(chr, tx_hash)) else: tx_hash = bytes(tx_hash) # Create request request = endpoint_pb2.TxStatusRequest() request.tx_hash = tx_hash # Create connection to Iroha channel = grpc.insecure_channel('127.0.0.1:50051') stub = endpoint_pb2_grpc.CommandServiceStub(channel) # Send request response = stub.StatusStream(request) for status in response: print("Status of transaction:") print(status)
def get_status(tx): # Create status request print("Hash of the transaction: ", tx.hash().hex()) tx_hash = tx.hash().blob() if sys.version_info[0] == 2: tx_hash = ''.join(map(chr, tx_hash)) else: tx_hash = bytes(tx_hash) request = endpoint_pb2.TxStatusRequest() request.tx_hash = tx_hash channel = grpc.insecure_channel('127.0.0.1:50051') stub = endpoint_pb2_grpc.CommandServiceStub(channel) 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(1)
def get_tx_status(tx, address='127.0.0.1:50051'): """ Get status of the transaction :param tx: iroha transaction :param address: ip address and iroha port :return: status of tx transaction """ # Create status request print("Hash of the transaction: ", tx.hash().hex()) tx_hash = tx.hash().blob() if sys.version_info[0] == 2: tx_hash = ''.join(map(chr, tx_hash)) else: tx_hash = bytes(tx_hash) request = endpoint_pb2.TxStatusRequest() request.tx_hash = tx_hash # channel = grpc.insecure_channel(address) stub = endpoint_pb2_grpc.CommandServiceStub(channel) response = stub.Status(request) status = endpoint_pb2.TxStatus.Name(response.tx_status) return status
def send_formed_tx(proto_tx, address='127.0.0.1:50051'): # l_r["Payload"] = l_r["payload"] # del l_r["payload"] # proto_tx = json_format.Parse(l_r, endpoint_pb2.Transaction, ignore_unknown_fields=False) # proto_tx = block_pb2.Transaction() # proto_tx.ParseFromJson(l_r) channel = grpc.insecure_channel(address) stub = endpoint_pb2_grpc.CommandServiceStub(channel) stub.Torii(proto_tx)
def send_tx(tx, key_pair): tx_blob = proto_tx_helper.signAndAddSignature(tx, key_pair).blob() proto_tx = block_pb2.Transaction() if sys.version_info[0] == 2: tmp = ''.join(map(chr, tx_blob)) else: tmp = bytes(tx_blob) proto_tx.ParseFromString(tmp) channel = grpc.insecure_channel('127.0.0.1:50051') stub = endpoint_pb2_grpc.CommandServiceStub(channel) stub.Torii(proto_tx)
# build transaction tx = tx_builder.creatorAccountId(creator) \ .txCounter(start_tx_counter) \ .createdTime(current_time) \ .createDomain("ru", "user") \ .createAsset("dollar", "ru", 2).build() tx_blob = proto_tx_helper.signAndAddSignature(tx, me_kp).blob() # create proto object and send to iroha proto_tx = block_pb2.Transaction() proto_tx.ParseFromString(''.join(map(chr, tx_blob))) channel = grpc.insecure_channel('127.0.0.1:50051') stub = endpoint_pb2_grpc.CommandServiceStub(channel) stub.Torii(proto_tx) time.sleep(5) # create status request print("Hash of the transaction: ", tx.hash().hex()) tx_hash = tx.hash().blob() tx_hash = ''.join(map(chr, tx_hash)) request = endpoint_pb2.TxStatusRequest() request.tx_hash = tx_hash response = stub.Status(request) status = endpoint_pb2.TxStatus.Name(response.tx_status)