Skip to content

Commit

Permalink
Refactor eth_sendTransaction handler
Browse files Browse the repository at this point in the history
The handler for `eth_sendTransaction` was previously spread between
`RPCMethodMiddleware.ts` and the static middleware of
`web3-provider-engine`. Instead it is all handled in
`RPCMethodMiddleware.ts` now.

This should have no functional impact. It is difficult to trace through
`web3-provider-engine`, but this case is one of the easier ones because
the static middleware is run first, and in this case it will always end
the request.

This relates to #5513
  • Loading branch information
Gudahtt committed Mar 8, 2023
1 parent 65ef08a commit 241ba4e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
22 changes: 0 additions & 22 deletions app/core/Engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import { PreferencesController } from '@metamask/preferences-controller';
import {
Transaction,
TransactionController,
WalletDevice,
} from '@metamask/transaction-controller';
import { GasFeeController } from '@metamask/gas-fee-controller';
import { ApprovalController } from '@metamask/approval-controller';
Expand Down Expand Up @@ -110,27 +109,6 @@ class Engine {

const networkController = new NetworkController(networkControllerOpts);
networkController.providerConfig = {
static: {
eth_sendTransaction: async (
payload: { params: any[], origin: any },
next: any,
end: (arg0: undefined, arg1: undefined) => void,
) => {
const { TransactionController } = this.context;
try {
const hash = await (
await TransactionController.addTransaction(
payload.params[0],
payload.origin,
WalletDevice.MM_MOBILE,
)
).result;
end(undefined, hash);
} catch (error) {
end(error);
}
},
},
getAccounts: (
end: (arg0: null, arg1: any[]) => void,
payload: { hostname: string | number },
Expand Down
13 changes: 12 additions & 1 deletion app/core/RPCMethods/RPCMethodMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ethErrors } from 'eth-json-rpc-errors';
import RPCMethods from './index.js';
import { RPC } from '../../constants/network';
import { NetworksChainId, NetworkType } from '@metamask/controller-utils';
import { WalletDevice } from '@metamask/transaction-controller';
import Networks, {
blockTagParamIndex,
getAllNetworks,
Expand Down Expand Up @@ -330,7 +331,17 @@ export const getRpcMethodMiddleware = ({
chainId: req.params[0].chainId,
checkSelectedAddress: isMMSDK || isWalletConnect,
});
next();

const { TransactionController } = Engine.context;
const hash = await (
await TransactionController.addTransaction(
req.params[0],
hostname,
WalletDevice.MM_MOBILE,
)
).result;

res.result = hash;
},
eth_signTransaction: async () => {
// This is implemented later in our middleware stack – specifically, in
Expand Down

0 comments on commit 241ba4e

Please sign in to comment.