Ejemplo n.º 1
0
def EventEmitter(stub, initHeight):
    data_parser = DatatypeParser()
    try:
        client = BcosClient()
        lastHeight = initHeight
        while 1:
            currHeight = client.getBlockNumber()
            if currHeight > lastHeight:
                for height in range(lastHeight + 1, currHeight + 1):
                    result = client.getBlockByNumber(
                        height, _includeTransactions=False)
                for hash in result["transactions"]:
                    receipt = client.getTransactionReceipt(hash)
                    logs = data_parser.parse_event_logs(receipt["logs"])
                    for log in logs:
                        print(log)
                        if log["eventname"] == "Task1Finished":
                            stub.PublishMessage(
                                gateway_pb2.PublishMessageRequest(
                                    name="task1",
                                    correlationKey="task1",
                                    variables=json.dumps(
                                        {"contract": receipt["to"]})))
                        elif log["eventname"] == "Task2Finished":
                            stub.PublishMessage(
                                gateway_pb2.PublishMessageRequest(
                                    name="task2",
                                    correlationKey=receipt["to"]))
    except BcosException as e:
        print("execute demo_transaction failed for: {}".format(e))
    except BcosError as e:
        print("execute demo_transaction failed for: {}".format(e))
Ejemplo n.º 2
0
     "getTransactionByBlockHashAndIndex",
     client.getTransactionByBlockHashAndIndex(
         "0xe7588bf4ee5a6fb5aae9bdcc2c4f3c58cf7a789b15a4daa6617ed594b5ba3951",
         0))
 print(
     "\n>>---------------------------------------------------------------------"
 )
 print("getTransactionByBlockNumberAndIndex",
       client.getTransactionByBlockNumberAndIndex(50, 0))
 print(
     "\n>>---------------------------------------------------------------------"
 )
 print(
     "getTransactionReceipt",
     client.getTransactionReceipt(
         "0x41fa9a0ce36d486ee2bf6d2219b68b44ca300ec7aeb07f8f2aa9c225655d2b61"
     ))
 print(
     "\n>>---------------------------------------------------------------------"
 )
 print("getPendingTransactions", client.getPendingTransactions())
 print(
     "\n>>---------------------------------------------------------------------"
 )
 print("getPendingTxSize", client.getPendingTxSize())
 print(
     "\n>>---------------------------------------------------------------------"
 )
 print("getCode",
       client.getCode("0x83592a3cf1af302612756b8687c8dc7935c0ad1d"))
 print(
Ejemplo n.º 3
0
    print("getBlockHashByNumber", blockhash)
    print("\n>>---------------------------------------------------------------------")
    block = client.getBlockByHash(blockhash)
    print("getBlockByHash", block)
    if isinstance(block, dict) and "transactions" in block.keys():
        txhash = block['transactions'][0]["hash"]
        print("\n>>---------------------------------------------------------------------")
        print("getTransactionByHash", client.getTransactionByHash(txhash))
        print("\n>>---------------------------------------------------------------------")
        print("getTransactionByBlockHashAndIndex",
              client.getTransactionByBlockHashAndIndex(blockhash, 0))
        print("\n>>---------------------------------------------------------------------")
        print("getTransactionByBlockNumberAndIndex",
              client.getTransactionByBlockNumberAndIndex(1, 0))
        print("\n>>---------------------------------------------------------------------")
        print("getTransactionReceipt", client.getTransactionReceipt(txhash))
        print("\n>>---------------------------------------------------------------------")
    print("getPendingTransactions", client.getPendingTransactions())
    print("\n>>---------------------------------------------------------------------")
    print("getPendingTxSize", client.getPendingTxSize())
    print("\n>>---------------------------------------------------------------------")
    print("getCode", client.getCode("0x83592a3cf1af302612756b8687c8dc7935c0ad1d"))
    print("\n>>---------------------------------------------------------------------")
    print("getTotalTransactionCount", client.getTotalTransactionCount())
    print("\n>>---------------------------------------------------------------------")
    print("getSystemConfigByKey", client.getSystemConfigByKey("tx_count_limit"))
    print("\n>>---------------------------------------------------------------------")

    print("getPbftView", int(client.getPbftView(), 16))
    print("\n>>---------------------------------------------------------------------")
    print("getSealerList", client.getSealerList())
Ejemplo n.º 4
0
     print(
         "getTransactionByBlockHashAndIndex",
         json.dumps(client.getTransactionByBlockHashAndIndex(blockhash, 0)),
     )
     print(
         "\n>>---------------------------------------------------------------------"
     )
     print(
         "getTransactionByBlockNumberAndIndex",
         client.getTransactionByBlockNumberAndIndex(1, 0),
     )
     print(
         "\n>>---------------------------------------------------------------------"
     )
     print("getTransactionReceipt",
           json.dumps(client.getTransactionReceipt(txhash)))
     print(
         "\n>>---------------------------------------------------------------------"
     )
 print("getPendingTransactions", client.getPendingTransactions())
 print(
     "\n>>---------------------------------------------------------------------"
 )
 print("getPendingTxSize", client.getPendingTxSize())
 print(
     "\n>>---------------------------------------------------------------------"
 )
 print("getTotalTransactionCount", client.getTotalTransactionCount())
 print(
     "\n>>---------------------------------------------------------------------"
 )