Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

Commit

Permalink
RPC upgrade to pyevm v0.2.0-alpha.43
Browse files Browse the repository at this point in the history
  • Loading branch information
carver committed May 20, 2019
1 parent 45866bd commit 7f2d617
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions trinity/rpc/modules/eth.py
Expand Up @@ -87,12 +87,13 @@ async def get_header(chain: BaseAsyncChain, at_block: Union[str, int]) -> BlockH
return at_header


async def account_db_at_block(chain: BaseAsyncChain,
at_block: Union[str, int],
read_only: bool=True) ->BaseAccountDB:
async def state_at_block(
chain: BaseAsyncChain,
at_block: Union[str, int],
read_only: bool=True) ->BaseAccountDB:
at_header = await get_header(chain, at_block)
vm = chain.get_vm(at_header)
return vm.state.account_db
return vm.state


async def get_block_at_number(chain: BaseAsyncChain, at_block: Union[str, int]) -> BaseBlock:
Expand Down Expand Up @@ -120,7 +121,7 @@ def dict_to_spoof_transaction(
nonce = txn_dict['nonce']
else:
vm = chain.get_vm(header)
nonce = vm.state.account_db.get_nonce(sender)
nonce = vm.state.get_nonce(sender)

gas_price = txn_dict.get('gasPrice', 0)
gas = txn_dict.get('gas', header.gas_limit)
Expand Down Expand Up @@ -177,8 +178,8 @@ async def gasPrice(self) -> str:

@format_params(decode_hex, to_int_if_hex)
async def getBalance(self, address: Address, at_block: Union[str, int]) -> str:
account_db = await account_db_at_block(self.chain, at_block)
balance = account_db.get_balance(address)
state = await state_at_block(self.chain, at_block)
balance = state.get_balance(address)

return hex(balance)

Expand Down Expand Up @@ -208,17 +209,17 @@ async def getBlockTransactionCountByNumber(self, at_block: Union[str, int]) -> s

@format_params(decode_hex, to_int_if_hex)
async def getCode(self, address: Address, at_block: Union[str, int]) -> str:
account_db = await account_db_at_block(self.chain, at_block)
code = account_db.get_code(address)
state = await state_at_block(self.chain, at_block)
code = state.get_code(address)
return encode_hex(code)

@format_params(decode_hex, to_int_if_hex, to_int_if_hex)
async def getStorageAt(self, address: Address, position: int, at_block: Union[str, int]) -> str:
if not is_integer(position) or position < 0:
raise TypeError("Position of storage must be a whole number, but was: %r" % position)

account_db = await account_db_at_block(self.chain, at_block)
stored_val = account_db.get_storage(address, position)
state = await state_at_block(self.chain, at_block)
stored_val = state.get_storage(address, position)
return encode_hex(int_to_big_endian(stored_val))

@format_params(decode_hex, to_int_if_hex)
Expand All @@ -239,8 +240,8 @@ async def getTransactionByBlockNumberAndIndex(self,

@format_params(decode_hex, to_int_if_hex)
async def getTransactionCount(self, address: Address, at_block: Union[str, int]) -> str:
account_db = await account_db_at_block(self.chain, at_block)
nonce = account_db.get_nonce(address)
state = await state_at_block(self.chain, at_block)
nonce = state.get_nonce(address)
return hex(nonce)

@format_params(decode_hex)
Expand Down

0 comments on commit 7f2d617

Please sign in to comment.