fix(@embark/utils): Fix proxy crash with unknown function

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)
```
This commit is contained in:
emizzle 2019-03-19 13:20:20 +11:00 committed by Iuri Matias
parent 30e5af5038
commit d03481eea2
1 changed files with 3 additions and 3 deletions

View File

@ -55,11 +55,11 @@ export function getAddressToContract(contractsList: Contract[], addressToContrac
export function getTransactionParams(contract: AddressToContract, transactionInput: string): object { export function getTransactionParams(contract: AddressToContract, transactionInput: string): object {
const func = contract.functions[transactionInput.substring(0, 10)]; 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 = ""; 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) => { func.abi.inputs.forEach((input) => {
const quote = input.type.indexOf("int") === -1 ? '"' : ""; const quote = input.type.indexOf("int") === -1 ? '"' : "";
paramString += quote + decodedParameters[input.name] + quote + ", "; paramString += quote + decodedParameters[input.name] + quote + ", ";