* Handle a `eth_sendTransaction` request. * * @param args - Named arguments. * @param args.hostname - The hostname associated with this request. * @param args.req - The JSON-RPC request. * @param args.res - The JSON-RPC response. * @param args.sendTransaction - A function that requests approva
({
hostname,
req,
res,
sendTransaction,
validateAccountAndChainId,
}: {
hostname: string;
req: JsonRpcRequest<unknown> & { method: 'eth_sendTransaction' };
res: PendingJsonRpcResponse<unknown>;
sendTransaction: TransactionController['addTransaction'];
validateAccountAndChainId: (args: {
from: string;
chainId?: number;
}) => Promise<void>;
})
| 59 | * used in the transaction. |
| 60 | */ |
| 61 | async function eth_sendTransaction({ |
| 62 | hostname, |
| 63 | req, |
| 64 | res, |
| 65 | sendTransaction, |
| 66 | validateAccountAndChainId, |
| 67 | }: { |
| 68 | hostname: string; |
| 69 | req: JsonRpcRequest<unknown> & { method: 'eth_sendTransaction' }; |
| 70 | res: PendingJsonRpcResponse<unknown>; |
| 71 | sendTransaction: TransactionController['addTransaction']; |
| 72 | validateAccountAndChainId: (args: { |
| 73 | from: string; |
| 74 | chainId?: number; |
| 75 | }) => Promise<void>; |
| 76 | }) { |
| 77 | if ( |
| 78 | !Array.isArray(req.params) && |
| 79 | !(isObject(req.params) && hasProperty(req.params, 0)) |
| 80 | ) { |
| 81 | throw rpcErrors.invalidParams({ |
| 82 | message: `Invalid parameters: expected an array`, |
| 83 | }); |
| 84 | } |
| 85 | const transactionParameters = req.params[0]; |
| 86 | if (!isObject(transactionParameters)) { |
| 87 | throw rpcErrors.invalidParams({ |
| 88 | message: `Invalid parameters: expected the first parameter to be an object`, |
| 89 | }); |
| 90 | } |
| 91 | await validateAccountAndChainId({ |
| 92 | from: req.params[0].from, |
| 93 | chainId: req.params[0].chainId, |
| 94 | }); |
| 95 | |
| 96 | const { result, transactionMeta } = await sendTransaction(req.params[0], { |
| 97 | deviceConfirmedOn: WalletDevice.MM_MOBILE, |
| 98 | origin: hostname, |
| 99 | }); |
| 100 | |
| 101 | ppomUtil.validateRequest(req, transactionMeta?.id); |
| 102 | |
| 103 | res.result = await result; |
| 104 | } |
| 105 | |
| 106 | export default eth_sendTransaction; |
no test coverage detected