Skip to content

Commit

Permalink
modify rpcStataManager getAccount (#3345)
Browse files Browse the repository at this point in the history
* modify rpcStataManager getAccount

* fix type error

* Update mock provider response for getProof on non-existent account to mirror infura

* Update nonexistent account check to compare bytes

---------

Co-authored-by: acolytec3 <[email protected]>
  • Loading branch information
rodrigoherrerai and acolytec3 authored Apr 12, 2024
1 parent 6eccff7 commit 7d960df
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
16 changes: 8 additions & 8 deletions packages/statemanager/src/rpcStateManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,8 @@ export class RPCStateManager implements EVMStateManagerInterface {
}

/**
* Gets the code corresponding to the provided `address`.
* @param address - Address to get the `account` for
* @returns {Promise<Uint8Array>} - Resolves with the code corresponding to the provided address.
* Returns an empty `Uint8Array` if the account has no associated code.
* Gets the account associated with `address` or `undefined` if account does not exist
* @param address - Address of the `account` to get
*/
async getAccount(address: Address): Promise<Account | undefined> {
const elem = this._accountCache?.get(address)
Expand All @@ -265,11 +263,13 @@ export class RPCStateManager implements EVMStateManagerInterface {
: undefined
}

const rlp = (await this.getAccountFromProvider(address)).serialize()
const accountFromProvider = await this.getAccountFromProvider(address)
const account =
equalsBytes(rlp, KECCAK256_RLP_EMPTY_ACCOUNT) === false
? Account.fromRlpSerializedAccount(rlp)
: undefined
equalsBytes(accountFromProvider.codeHash, new Uint8Array(32).fill(0)) ||
equalsBytes(accountFromProvider.serialize(), KECCAK256_RLP_EMPTY_ACCOUNT)
? undefined
: Account.fromRlpSerializedAccount(accountFromProvider.serialize())

this._accountCache?.put(address, account)

return account
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ const getProofValues = async (params: [address: string, _: [], blockTag: bigint
return {
address,
balance: '0x0',
codeHash: '0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470',
codeHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
nonce: '0x0',
storageHash: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
storageHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
storageProof: [],
}
}
Expand Down

0 comments on commit 7d960df

Please sign in to comment.