From be3a69c3b818dd80c77dc4d81379a8f0b125eebf Mon Sep 17 00:00:00 2001 From: Kevin Brown Date: Tue, 16 Apr 2019 15:43:49 +1000 Subject: [PATCH] Fixed off by one error in contract action params interpretation. --- src/contracts/contract.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/contracts/contract.ts b/src/contracts/contract.ts index d679470..d12e9f4 100644 --- a/src/contracts/contract.ts +++ b/src/contracts/contract.ts @@ -48,10 +48,7 @@ export class Contract implements EOSJSContract { const data: { [key: string]: any } = {}; // Copy the params across for the call. - if ( - arguments.length != action.fields.length && - arguments.length + 1 != action.fields.length - ) { + if (arguments.length < action.fields.length) { throw new Error( `Insufficient arguments supplied to ${action.name}. Expected ${ action.fields.length @@ -59,6 +56,14 @@ export class Contract implements EOSJSContract { ); } + if (arguments.length > action.fields.length + 1) { + throw new Error( + `Too many arguments supplied to ${action.name}. Expected ${action.fields.length} got ${ + arguments.length + }.` + ); + } + for (let i = 0; i < action.fields.length; i++) { data[action.fields[i].name] = arguments[i]; } @@ -66,9 +71,10 @@ export class Contract implements EOSJSContract { // Who are we acting as? // We default to sending transactions from the contract account. let authorization = account; + const options = arguments[action.fields.length]; - if (arguments[action.fields.length] instanceof Account) { - authorization = arguments[action.fields.length]; + if (options && options.from && options.from instanceof Account) { + authorization = options.from; } return EOSManager.transact(