Skip to content

Commit

Permalink
Fixed off by one error in contract action params interpretation.
Browse files Browse the repository at this point in the history
  • Loading branch information
thekevinbrown committed Apr 16, 2019
1 parent aed9a42 commit be3a69c
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/contracts/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,27 +48,33 @@ 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
} got ${arguments.length}.`
);
}

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];
}

// 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(
Expand Down

0 comments on commit be3a69c

Please sign in to comment.