Exemplo n.º 1
0
    def eth_getLogs(self, fromBlock=None, toBlock=None, address=None, topics=None, validate_block_number=True):
        """validate_block_number (default True), if True will also check the node's
        current blockNumber and make sure it is not lower than either the fromBlock
        or toBlock arguments"""

        kwargs = {}
        if fromBlock:
            kwargs['fromBlock'] = validate_block_param(fromBlock)
        if toBlock:
            kwargs['toBlock'] = validate_block_param(toBlock)
        if address:
            kwargs['address'] = validate_hex_int(address)
        if topics:
            # validate topics
            if not isinstance(topics, list):
                raise TypeError("topics must be an array of DATA")
            for topic in topics:
                if isinstance(topic, list):
                    if not all(validate_hex_int(t, 32) for t in topic if t is not None):
                        raise TypeError("topics must be an array of DATA")
                else:
                    if topic is not None and not validate_hex_int(topic):
                        raise TypeError("topics must be an array of DATA")
            kwargs['topics'] = topics

        if validate_block_number and (fromBlock or toBlock):
            return self._eth_getLogs_with_block_number_validation(kwargs)
        else:
            return self._fetch("eth_getLogs", [kwargs])
Exemplo n.º 2
0
    def eth_newFilter(self, *, fromBlock=None, toBlock=None, address=None, topics=None):

        kwargs = {}
        if fromBlock:
            kwargs['fromBlock'] = validate_block_param(fromBlock)
        if toBlock:
            kwargs['toBlock'] = validate_block_param(toBlock)
        if address:
            kwargs['address'] = validate_hex_int(address)
        if topics:
            if not isinstance(topics, list):
                raise TypeError("topics must be an array of DATA")
            kwargs['topics'] = [None if i is None else validate_hex_int(i, 32) for i in topics]

        return self._fetch("eth_newFilter", [kwargs])
Exemplo n.º 3
0
    def eth_estimateGas(self, source_address, target_address, **kwargs):

        source_address = validate_hex_int(source_address)
        hexkwargs = {"from": source_address}

        if target_address:
            target_address = validate_hex_int(target_address)
            hexkwargs["to"] = target_address

        for k, value in kwargs.items():
            if k == 'gasprice' or k == 'gas_price':
                k = 'gasPrice'
            hexkwargs[k] = validate_hex_int(value)
        if 'value' not in hexkwargs:
            hexkwargs['value'] = "0x0"
        return self._fetch("eth_estimateGas", [hexkwargs], parse_int)
Exemplo n.º 4
0
    def eth_call(self, *, to_address, from_address=None, gas=None, gasprice=None, value=None, data=None, block="latest", result_processor=None):

        to_address = validate_hex_int(to_address)
        block = validate_block_param(block)

        callobj = {"to": to_address}
        if from_address:
            callobj['from'] = validate_hex_int(from_address)
        if gas:
            callobj['gas'] = validate_hex_int(gas)
        if gasprice:
            callobj['gasPrice'] = validate_hex_int(gasprice)
        if value:
            callobj['value'] = validate_hex_int(value)
        if data:
            callobj['data'] = validate_hex_int(data)

        return self._fetch("eth_call", [callobj, block], result_processor)
Exemplo n.º 5
0
    def eth_getCode(self, address, block="latest"):

        address = validate_hex_int(address)
        block = validate_block_param(block)
        return self._fetch("eth_getCode", [address, block])
Exemplo n.º 6
0
    def eth_getTransactionByHash(self, tx):

        tx = validate_hex_int(tx)
        return self._fetch("eth_getTransactionByHash", [tx])
Exemplo n.º 7
0
    def eth_getTransactionReceipt(self, tx):

        tx = validate_hex_int(tx)
        return self._fetch("eth_getTransactionReceipt", [tx])
Exemplo n.º 8
0
 def eth_sendRawTransaction(self, tx):
     tx = validate_hex_int(tx)
     return self._fetch("eth_sendRawTransaction", [tx])
Exemplo n.º 9
0
    def eth_getTransactionCount(self, address, block="latest"):

        address = validate_hex_int(address)
        block = validate_block_param(block)

        return self._fetch("eth_getTransactionCount", [address, block], parse_int)