Esempio n. 1
0
 def getBlockByNumber(self, num, _includeTransactions=True):
     """
     get block according to number
     """
     cmd = "getBlockByNumber"
     number = common.check_int_range(num)
     includeTransactions = common.check_and_trans_to_bool(_includeTransactions)
     params = [self.groupid, hex(number), includeTransactions]
     return self.common_request(cmd, params)
Esempio n. 2
0
    def init(self):
        try:
            self.blockLimit = 500
            # check chainID
            common.check_int_range(client_config.groupid, BcosClient.max_group_id)
            # check group id
            common.check_int_range(client_config.fiscoChainId, BcosClient.max_chain_id)
            # check protocol
            if client_config.client_protocol.lower() not in BcosClient.protocol_list:
                raise BcosException("invalid configuration, must be: {}".
                                    format(''.join(BcosClient.protocol_list)))

            self.fiscoChainId = client_config.fiscoChainId
            self.groupid = client_config.groupid

            if client_config.client_protocol == client_config.PROTOCOL_RPC \
                    and client_config.remote_rpcurl is not None:
                self.rpc = utils.rpc.HTTPProvider(client_config.remote_rpcurl)
                self.rpc.logger = self.logger

            if client_config.client_protocol == client_config.PROTOCOL_CHANNEL:
                if os.path.exists(client_config.channel_node_cert) is False:
                    raise BcosException("{} not found!".format(client_config.channel_node_cert))
                if os.path.exists(client_config.channel_node_key) is False:
                    raise BcosException("{} not found!".format(client_config.channel_node_key))

                self.channel_handler = ChannelHandler()
                self.channel_handler.logger = self.logger
                self.channel_handler.initTLSContext(client_config.channel_ca,
                                                    client_config.channel_node_cert,
                                                    client_config.channel_node_key
                                                    )
                self.channel_handler.start_channel(
                    client_config.channel_host, client_config.channel_port)
                blockNumber = self.getBlockNumber()
                self.channel_handler.setBlockNumber(blockNumber)
                self.channel_handler.getBlockNumber(self.groupid)

            self.logger.info("using protocol " + client_config.client_protocol)
            return self.getinfo()
        except Exception as e:
            raise BcosException("init bcosclient failed, reason: {}".format(e))
Esempio n. 3
0
 def getTransactionByBlockNumberAndIndex(self, num, index):
     cmd = "getTransactionByBlockNumberAndIndex"
     common.check_int_range(num)
     common.check_int_range(index)
     params = [self.groupid, hex(num), hex(index)]
     return self.common_request(cmd, params)
Esempio n. 4
0
 def getTransactionByBlockHashAndIndex(self, hash, index):
     cmd = "getTransactionByBlockHashAndIndex"
     common.check_hash(hash)
     common.check_int_range(index)
     params = [self.groupid, hash, hex(index)]
     return self.common_request(cmd, params)
Esempio n. 5
0
 def getBlockHashByNumber(self, num):
     cmd = "getBlockHashByNumber"
     common.check_int_range(num)
     params = [self.groupid, hex(num)]
     return self.common_request(cmd, params)