def get_block(self, value): """ If param is height, 1. Returns block information by block height 2. Delegates to icx_getBlockByHeight RPC method Or block hash, 1. Returns block information by block hash 2. Delegates to icx_getBlockByHash RPC method Or string value same as `latest`, 1. Returns the last block information 2. Delegates to icx_getLastBlock RPC method :param value: Integer of a block height or hash of a block prefixed with '0x' or `latest` :return result: Block data """ # by height if is_block_height(value): params = {'height': add_0x_prefix(hex(value))} result = self.__provider.make_request('icx_getBlockByHeight', params) # by hash elif is_hex_block_hash(value): params = {'hash': value} result = self.__provider.make_request('icx_getBlockByHash', params) # by value elif is_predefined_block_value(value): result = self.__provider.make_request('icx_getLastBlock') else: raise DataTypeException("It's unrecognized block reference:{0!r}.".format(value)) return result
def get_block(self, value: Union[int, str], full_response: bool = False) -> dict: """ If param is height, 1. Returns block information by block height 2. Delegates to icx_getBlockByHeight RPC method Or block hash, 1. Returns block information by block hash 2. Delegates to icx_getBlockByHash RPC method Or string value same as `latest`, 1. Returns the last block information 2. Delegates to icx_getLastBlock RPC method :param value: Integer of a block height or hash of a block prefixed with '0x' or `latest` :param full_response: Boolean to check whether get naive dict or refined data from server :return result: Block data """ # by height if is_block_height(value): params = {'height': add_0x_prefix(hex(value))} result = self.__provider.make_request('icx_getBlockByHeight', params, full_response) # by hash elif is_hex_block_hash(value): params = {'hash': value} result = self.__provider.make_request('icx_getBlockByHash', params, full_response) # by value elif is_predefined_block_value(value): result = self.__provider.make_request('icx_getLastBlock', full_response=full_response) else: raise DataTypeException( "It's unrecognized block reference:{0!r}.".format(value)) if not full_response: convert_block(result) return result
def get_block(self, value: Union[int, str], full_response: bool = False, block_version: str = DEFAULT_BLOCK_VERSION) -> dict: """ If param is height, 1. Returns block information by block height 2-1. Delegates to icx_getBlockByHeight RPC method (When Block Version is 0.1a) 2-2. Delegates to icx_getBlock RPC method (When Block Version is 0.3) Or block hash, 1. Returns block information by block hash 2-1. Delegates to icx_getBlockByHash RPC method (When Block Version is 0.1a) 2-2. Delegates to icx_getBlock RPC method (When Block Version is 0.3) Or string value same as `latest`, 1. Returns the last block information 2-1. Delegates to icx_getLastBlock RPC method (When Block Version is 0.1a) 2-2. Delegates to icx_getBlock RPC method (When Block Version is 0.3) :param value: Integer of a block height or hash of a block prefixed with '0x' or `latest` :param full_response: Boolean to check whether get naive dict or refined data from server :param block_version: returning block format version :return result: Block data """ # Nested method of returning right name of API method def return_infos_by_block_version(_prev_method: str) -> Tuple[str, Any, bool]: """ Returns API method name, block template, bool of full print by block version :param _prev_method: previous API methods. For instance, icx_getBlockByHeight, icx_getBlockByHash and icx_getLastBlock :return: method name, block template, bool of full print """ new_method = "icx_getBlock" if block_version == self.DEFAULT_BLOCK_VERSION: return _prev_method, BLOCK_0_1a, False else: return new_method, BLOCK_0_3, True # by height if is_block_height(value): params = {'height': add_0x_prefix(hex(value))} prev_method = 'icx_getBlockByHeight' # by hash elif is_hex_block_hash(value): params = {'hash': value} prev_method = 'icx_getBlockByHash' # last block elif is_predefined_block_value(value): params = None prev_method = 'icx_getLastBlock' else: raise DataTypeException("It's unrecognized block reference:{0!r}.".format(value)) method, block_template, full_print = return_infos_by_block_version(prev_method) result = self.__provider.make_request(method, params, full_response) if not full_response: block_template = get_block_template_to_convert_transactions_for_genesis(result, block_template) result = convert(result, block_template, full_print) return result