Exemplo n.º 1
0
 def test_converter_blocks(self):
     """
     Test with different sample blocks which are made from JSON RPC API V2 or V3
     and with the genesis block.
     """
     for block in self.blocks:
         convert_block(block)
         self.assertTrue(validate_block(block))
Exemplo n.º 2
0
    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
Exemplo n.º 3
0
    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))

        convert_block(result)
        return result