Skip to content

Commit

Permalink
fix(contract): override object when invoking a function
Browse files Browse the repository at this point in the history
  • Loading branch information
MilGard91 committed Apr 7, 2022
1 parent ec52f61 commit c605151
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/contract/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,18 @@ function buildCall(contract: Contract, functionAbi: FunctionAbi): AsyncContractF
*/
function buildInvoke(contract: Contract, functionAbi: FunctionAbi): AsyncContractFunction {
return async function (...args: Array<any>): Promise<any> {
return contract.invoke(functionAbi.name, args);
const { inputs } = functionAbi;
const inputsLength = inputs.reduce((acc, input) => {
if (!/_len$/.test(input.name)) {
return acc + 1;
}
return acc;
}, 0);
const options = {};
if (inputsLength + 1 === args.length && typeof args[args.length - 1] === 'object') {
Object.assign(options, args.pop());
}
return contract.invoke(functionAbi.name, args, options);
};
}

Expand Down

0 comments on commit c605151

Please sign in to comment.