def trace_filter(self, from_block=None, to_block=None, from_addresses=None, to_addresses=None): """ https://github.com/ethcore/parity/wiki/JSONRPC-trace-module#trace_filter TESTED """ params = {} if from_block is not None: from_block = validate_block(from_block) params['fromBlock'] = from_block if to_block is not None: to_block = validate_block(to_block) params['toBlock'] = to_block if from_addresses is not None: if not isinstance(from_addresses, list): from_addresses = [from_addresses] params['fromAddress'] = from_addresses if to_addresses is not None: if not isinstance(to_addresses, list): to_addresses = [to_addresses] params['toAddress'] = to_addresses return self.call('trace_filter', [params])
def eth_call(self, to_address, from_address=None, gas=None, gas_price=None, value=None, data=None, default_block=BLOCK_TAG_LATEST): """ https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_call NEEDS TESTING """ default_block = validate_block(default_block) obj = {} obj['to'] = to_address if from_address is not None: obj['from'] = from_address if gas is not None: obj['gas'] = hex(gas) if gas_price is not None: obj['gasPrice'] = clean_hex(gas_price) if value is not None: obj['value'] = value if data is not None: obj['data'] = data return self.call('eth_call', [obj, default_block])
def eth_getStorageAt(self, address=None, position=0, block=BLOCK_TAG_LATEST): """ Returns the value from a storage position at a given address. :param address: 20 Bytes - address to check for balance. :type address: str :param address: (optionnal) integer of the position in the storage. default is 0 :type address: int :param block: (optionnal) integer block number, or the string "latest", "earliest" or "pending" :type block: int or str :return: the value at this storage position. :rtype: str :Example: >>> explorer = EthereumExplorerRPC() >>> explorer.eth_getStorageAt("0x295a70b2de5e3953354a6a8344e616ed314d7251", 0, "latest") '0x0000000000000000000000000000000000000000000000000000000000000000' .. seealso:: https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getstorageat .. todo:: TESTED """ block = validate_block(block) return self.call('eth_getStorageAt', [address, hex(position), block])
def eth_getBalance(self, address=None, block=BLOCK_TAG_LATEST): """ Returns the balance of the account of given address. :param address: 20 Bytes - address to check for balance. :type address: str :param block: (optionnal) integer block number, or the string "latest", "earliest" or "pending" :type block: int or str :return: integer of the current balance in wei. :rtype: int :Example: >>> explorer = EthereumExplorerRPC() >>> explorer.eth_getBalance("0x956b6B7454884b734B29A8115F045a95179ea00C") 17410594678300000000 .. seealso:: https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getbalance .. todo:: TESTED """ address = address or self.eth_coinbase() block = validate_block(block) v = hex_to_dec(self.call('eth_getBalance', [address, block])) return (v if v else 0)
def trace_block(self, block=BLOCK_TAG_LATEST): """ https://wiki.parity.io/JSONRPC https://github.com/ethcore/parity/wiki/JSONRPC-trace-module#trace_block NEEDS TESTING """ block = validate_block(block) return self.call('trace_block', [block])
def eth_getUncleCountByBlockNumber(self, block=BLOCK_TAG_LATEST): """ Returns the number of uncles in a block from a block matching the given block number. :param block: (optionnal) integer block number, or the string "latest", "earliest" or "pending" :type block: int or str :return: integer of the number of uncles in this block. :rtype: int :Example: >>> explorer = EthereumExplorerRPC() >>> explorer.eth_getUncleCountByBlockNumber(5100196) 0 .. seealso:: https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getunclecountbyblocknumber .. todo:: TESTED """ block = validate_block(block) return hex_to_dec(self.call('eth_getUncleCountByBlockNumber', [block]))
def eth_getTransactionByBlockNumberAndIndex(self, block=BLOCK_TAG_LATEST, index=0): """ Returns information about a transaction by block number and transaction index position. :param block: (optionnal) integer block number, or the string "latest", "earliest" or "pending" :type block: int or str :param index: (optionnal) integer of the transaction index position. :type index: int :return: A transaction object, or null when no transaction was found :rtype: dict :Example: >>> explorer = EthereumExplorerRPC() >>> explorer.eth_getTransactionByBlockNumberAndIndex(5100196, 1) {'blockHash': '0x98a548cbd0cd385f46c9bf28c16bc36dc6ec27207617e236f527716e617ae91b', 'blockNumber': '0x4dd2a4', 'from': '0xb01cb49fe0d6d6e47edf3a072d15dfe73155331c', 'gas': '0x5208', 'gasPrice': '0xe33e22200', 'hash': '0xf02ffa405bae96e62a9e36fbd781362ca378ec62353d5e2bd0585868d3deaf61', 'input': '0x', 'nonce': '0x1908f', 'r': '0xcad900a5060ba9bb646a7f6965f98e945d71a19b3e30ff53d03b9797c6153d07', 's': '0x53b11a48758fc383df878a9b5468c83b033f5036b124b16dbb0a5167aee7fc4f', 'to': '0x26cd018553871f2e887986bc24c68a0ce622bb8f', 'transactionIndex': '0x1', 'v': '0x25', 'value': '0x1bc16d674ec80000'} .. seealso:: :method:`eth_getTransactionByHash` https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_gettransactionbyblocknumberandindex .. todo:: TESTED """ block = validate_block(block) return self.call('eth_getTransactionByBlockNumberAndIndex', [block, hex(index)])
def eth_getUncleByBlockNumberAndIndex(self, block=BLOCK_TAG_LATEST, index=0): """ Returns information about a uncle of a block by number and uncle index position. :param block: (optionnal) integer block number, or the string "latest", "earliest" or "pending" :type block: int or str :param index: (optionnal) the uncle's index position. :type index: int :return: A block object, or null when no block was found :rtype: dict .. note:: An uncle doesn't contain individual transactions. .. seealso:: https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getunclebyblocknumberandindex .. todo:: NOT TESTED """ block = validate_block(block) return self.call('eth_getUncleByBlockNumberAndIndex', [block, hex(index)])
def eth_getBlockByNumber(self, block=BLOCK_TAG_LATEST, tx_objects=True): """ Returns information about a block by hash. :param block: (optionnal) integer block number, or the string "latest", "earliest" or "pending" :type block: int or str :param tx_objects: (optionnal) If true it returns the full transaction objects, if false only the hashes of the transactions. :type tx_objects: Boolean :return: A block object, or null when no block was found :rtype: dict :Example: >>> explorer = EthereumExplorerRPC() >>> explorer.eth_getBlockByNumber(5100196) {'difficulty': '0xaa41aea7beb9e', 'extraData': '0x6e616e6f706f6f6c2e6f7267', 'gasLimit': '0x7a121d', 'gasUsed': '0x614398', 'hash': '0x98a548cbd0cd385f46c9bf28c16bc36dc6ec27207617e236f527716e617ae91b', 'logsBloom': '0x000001052440040410040000008006000020000002a11000308045410029410802804801080040c00880000002010c0201804010100900b0000001000240000010800040080044910000010c0000204a041140220008000040000040808800404020802226400018144000400484880012000408000401400000211000c000e2040000209000040080c00000c000890080001090008000001000000102000100002400082240104010400000420080041004050a1080c0042000000000080ac000000802020400001009088021040230000000249208020621000022001820180500200000820002600004888840810420200080100400080000ac0004100000', 'miner': '0x52bc44d5378309ee2abf1539bf71de1b7d7be3b5', 'mixHash': '0xa79e0692e7056ea2af26a78a1ed42ac7f3049eb322041c073e5d5a08f6c7e053', 'nonce': '0x6677371ca8459875', 'number': '0x4dd2a4', [...] 'totalDifficulty': '0x8b344e12294352eee8', 'transactions': [{ [...] 'value': '0x0'}], 'transactionsRoot': '0x184cd24c9f45c66ff3846c48fb63e24094aa5909cabfd38211c1d8209128cbc0', 'uncles': []} .. seealso:: https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getblockbynumber .. todo:: TESTED """ block = validate_block(block) return self.call('eth_getBlockByNumber', [block, tx_objects])
def eth_getCode(self, address, default_block=BLOCK_TAG_LATEST): """ Returns code at a given address. :param address: 20 Bytes - address. :type address: str :param block: (optionnal) integer block number, or the string "latest", "earliest" or "pending" :type block: int or str :return: the code from the given address. :rtype: hex str :Example: >>> explorer = EthereumExplorerRPC() >>> explorer.eth_getCode("0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413") '0x6060604052361561020e5760e060020a6000350463013cf08b[...]62f93160ef3e563' .. seealso:: https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getcode .. todo:: TESTED """ default_block = validate_block(default_block) return self.call('eth_getCode', [address, default_block])
def eth_getTransactionCount(self, address, block=BLOCK_TAG_LATEST): """ Returns the number of transactions sent from an address. :param address: 20 Bytes - address. :type address: str :param block: (optionnal) integer block number, or the string "latest", "earliest" or "pending" :type block: int or str :return: integer of the number of transactions send from this address. :rtype: int :Example: >>> explorer = EthereumExplorerRPC() >>> explorer.eth_getTransactionCount("0x956b6B7454884b734B29A8115F045a95179ea00C") 12891 .. seealso:: https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_gettransactioncount .. todo:: TESTED """ block = validate_block(block) return hex_to_dec( self.call('eth_getTransactionCount', [address, block]))