Skip to content

Commit

Permalink
Refactor RPC getAccounts usage
Browse files Browse the repository at this point in the history
The `getAccounts` function is defined and used in two different places
in the RPC pipeline: `RPCMethodMiddleware.ts` and
`web3-provider-engine`. The second one has been removed, so now all
usage is in `RPCMethodMiddleware.ts`.

`getAccounts` is passed into `web3-provider-engine` and used in the
`HookedWalletSubprovider`: https://github.com/MetaMask/web3-provider-engine/blob/cf612f898002833c36730d23972fe4c4dd483c76/subproviders/hooked-wallet.js

It is used in these methods:
* `eth_coinbase`
* `eth_accounts`
* `parity_defaultAccount`

It's also called to validate the sender, for the following methods:
* `eth_signTypedData`
* `eth_signTypedData_v3`
* `eth_signTypedData_v4`
* `encryption_public_key`
* `eth_decryptMessage`
* `personal_sign`
* `eth_sign`
* `eth_signTransaction`
* `eth_sendTransaction`

Of these methods, most of them are intercepted in
`RPCMethodMiddleware.ts`, so the requests never make it to
`web3-provider-engine`.

These three methods will make their way there: `parity_defaultAccount`,
`encryption_public_key`, and `eth_decryptMessage`. The decryption-
related messages rely on constructor parameters that mobile does not
pass in, so those always throw an error. The only method this hook is
used for in practice is `parity_defaultAccount`.

The `parity_defaultAccount` method was added to
`RPCMethodMiddleware.ts, so now that method won't make it to
`web3-provider-engine` either. Functionally it is the same as
`eth_coinbase`, so the same implementation has been used.

This relates to #5513
  • Loading branch information
Gudahtt committed Mar 29, 2023
1 parent edfe239 commit c0ac2a6
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 15 deletions.
15 changes: 0 additions & 15 deletions app/core/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,21 +134,6 @@ class Engine {
}
},
},
getAccounts: (
end: (arg0: null, arg1: any[]) => void,
payload: { hostname: string | number },
) => {
const { approvedHosts } = store.getState();
const isEnabled = approvedHosts[payload.hostname];
const { KeyringController } = this.context;
const isUnlocked = KeyringController.isUnlocked();
const selectedAddress =
this.context.PreferencesController.state.selectedAddress;
end(
null,
isUnlocked && isEnabled && selectedAddress ? [selectedAddress] : [],
);
},
};
const assetsContractController = new AssetsContractController({
onPreferencesStateChange: (listener) =>
Expand Down
1 change: 1 addition & 0 deletions app/core/RPCMethods/RPCMethodMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ export const getRpcMethodMiddleware = ({
},
eth_accounts: getEthAccounts,
eth_coinbase: getEthAccounts,
parity_defaultAccount: getEthAccounts,
eth_sendTransaction: async () => {
checkTabActive();
return RPCMethods.eth_sendTransaction({
Expand Down

0 comments on commit c0ac2a6

Please sign in to comment.