From d03481eea2df9ada6571b7e05f29491153b39147 Mon Sep 17 00:00:00 2001 From: emizzle Date: Tue, 19 Mar 2019 13:20:20 +1100 Subject: [PATCH] fix(@embark/utils): Fix proxy crash with unknown function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If a transaction is sent and the proxy is enabled, but the function hash (identified in the data of the transaction) is not recognized as a function of the contract (ie does not match a function hash in the contract’s ABI), then embark would crash. The fix was to introduce error handling in `transactionUtils.getTransactionParams` that defaults the contract name and params to `UNKNOWN`. This can be replicated by 1. Clone https://github.com/mortimr/ethvtx_embark 2. `embark run` the dapp 3. Connect with Metamask 4. Ensure you have enough funds 5. In the “Tx calls” bubble, enter a new value, then click “Set Value”. 6. When the Metamask dialog appears, the error should have already happened. The console shows: ``` embark/src/lib/utils/transactionUtils.ts:58 const functionName = func.functionName; ^ TypeError: Cannot read property 'functionName' of undefined at functionName (/Users/mortimr/Horyus/ethvtx_embark/node_modules/embark/src/lib/utils/transactionUtils.ts:58:29) at ConsoleListener.getTransactionParams [as _onIpcLogRequest] (/Users/mortimr/Horyus/ethvtx_embark/node_modules/embark/src/lib/modules/console_listener/index.js:102:41) at _onIpcLogRequest (/Users/mortimr/Horyus/ethvtx_embark/node_modules/embark/src/lib/modules/console_listener/index.js:76:12) at Server._done (/Users/mortimr/Horyus/ethvtx_embark/node_modules/embark/src/lib/core/ipc.js:81:7) at Server.emit (/Users/mortimr/Horyus/ethvtx_embark/node_modules/event-pubsub/es5.js:74:21) at Server.gotData (/Users/mortimr/Horyus/ethvtx_embark/node_modules/node-ipc/dao/socketServer.js:194:14) at Socket.emit (events.js:189:13) at Socket.EventEmitter.emit (domain.js:441:20) at addChunk (_stream_readable.js:284:12) at readableAddChunk (_stream_readable.js:261:13) at Socket.Readable.push (_stream_readable.js:220:10) at Pipe.onStreamRead [as onread] (internal/stream_base_commons.js:94:17) ``` --- packages/embark/src/lib/utils/transactionUtils.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/embark/src/lib/utils/transactionUtils.ts b/packages/embark/src/lib/utils/transactionUtils.ts index 43e9540e3..f8965e855 100644 --- a/packages/embark/src/lib/utils/transactionUtils.ts +++ b/packages/embark/src/lib/utils/transactionUtils.ts @@ -55,11 +55,11 @@ export function getAddressToContract(contractsList: Contract[], addressToContrac export function getTransactionParams(contract: AddressToContract, transactionInput: string): object { const func = contract.functions[transactionInput.substring(0, 10)]; - const functionName = func.functionName; + const functionName = func ? func.functionName : "UNKNOWN"; - const decodedParameters = utils.decodeParams(func.abi.inputs, transactionInput.substring(10)); let paramString = ""; - if (func.abi.inputs) { + if (func && func.abi && func.abi.inputs) { + const decodedParameters = utils.decodeParams(func.abi.inputs, transactionInput.substring(10)); func.abi.inputs.forEach((input) => { const quote = input.type.indexOf("int") === -1 ? '"' : ""; paramString += quote + decodedParameters[input.name] + quote + ", ";