def get_block(self, block_hash="", block_height=-1,
                  block_data_filter="prev_block_hash, height, block_hash",
                  tx_data_filter="tx_hash"):

        response = self.__stub_to_peer_service.GetBlock(
            loopchain_pb2.GetBlockRequest(
                block_hash=block_hash,
                block_height=block_height,
                block_data_filter=block_data_filter,
                tx_data_filter=tx_data_filter))

        return response
    def get_block(self, channel: str, block_hash: str= "", block_height: int=-1):
        block_data_filter = "prev_block_hash, height, block_hash, merkle_tree_root_hash," \
                            " time_stamp, peer_id, signature"
        tx_data_filter = "icx_origin_data"

        response = self.call("GetBlock",
                             loopchain_pb2.GetBlockRequest(
                                  block_hash=block_hash,
                                  block_height=block_height,
                                  block_data_filter=block_data_filter,
                                  tx_data_filter=tx_data_filter,
                                  channel=channel),
                             self.REST_GRPC_TIMEOUT)

        return response
Exemple #3
0
    def get_block(self,
                  block_hash="",
                  block_height=-1,
                  block_data_filter="prev_block_hash, height, block_hash",
                  tx_data_filter="tx_hash",
                  channel=conf.LOOPCHAIN_DEFAULT_CHANNEL):

        response = self.__stub_to_peer_service.GetBlock(
            loopchain_pb2.GetBlockRequest(block_hash=block_hash,
                                          block_height=block_height,
                                          block_data_filter=block_data_filter,
                                          tx_data_filter=tx_data_filter,
                                          channel=channel),
            self.REST_GRPC_TIMEOUT)

        return response
Exemple #4
0
def menu4_6(params):
    print("Print all [Block - hash], (tx - hash)")
    peer_stub = params[0]

    response = peer_stub.GetLastBlockHash(
        loopchain_pb2.CommonRequest(request=""), conf.GRPC_TIMEOUT)
    print("\nlast block hash: " + str(response.block_hash) + "\n")

    block_hash = response.block_hash
    total_tx = 0
    total_height = -1

    while block_hash is not None:
        response = peer_stub.GetBlock(
            loopchain_pb2.GetBlockRequest(block_hash=block_hash,
                                          block_data_filter="prev_block_hash, "
                                          "height, block_hash",
                                          tx_data_filter="tx_hash"))
        # print("[block: " + str(response) + "]")
        if len(response.block_data_json) > 0:
            block_data = json.loads(response.block_data_json)
            print("[block height: " + str(block_data["height"]) + ", hash: " +
                  str(block_data["block_hash"]) + "]")

            if len(response.tx_data_json) == 1:
                tx_data = json.loads(response.tx_data_json[0])
                print("has tx: " + str(tx_data["tx_hash"]))
            else:
                print("has tx: " + str(len(response.tx_data_json)))

            total_height += 1
            total_tx += len(response.tx_data_json)
            block_hash = block_data["prev_block_hash"]
            if int(block_data["height"]) == 0:
                block_hash = None
        else:
            block_hash = None

    print("\nblock chain height: " + str(total_height) + ", total tx: " +
          str(total_tx))

    menu4(peer_stub)
Exemple #5
0
    def get_block(self,
                  channel: str,
                  block_hash: str = "",
                  block_height: int = -1):
        block_data_filter = "prev_block_hash, height, block_hash, merkle_tree_root_hash," \
                            " time_stamp, peer_id, signature"
        if conf.CHANNEL_OPTION[channel]['send_tx_type'] == conf.SendTxType.icx:
            tx_data_filter = "icx_origin_data"
        else:
            tx_data_filter = "tx_hash, timestamp, data_string, peer_id"

        response = self.call(
            "GetBlock",
            loopchain_pb2.GetBlockRequest(block_hash=block_hash,
                                          block_height=block_height,
                                          block_data_filter=block_data_filter,
                                          tx_data_filter=tx_data_filter,
                                          channel=channel),
            self.REST_GRPC_TIMEOUT)

        return response