generic-caver
Version:
41 lines (36 loc) • 1.06 kB
JavaScript
Object.assign(global, require('ffp-js'));
const findFunctionInABI = (contract, funcSig) => go(
contract._jsonInterface,
filterL(obj =>
obj.name == fnSpliter(funcSig) &&
go(
funcSig,
_ => funcSig.substring(funcSig.indexOf('(')+1, funcSig.length-1).split(','),
callTypes => go(
obj.inputs,
map(a => a.type),
abiTypes => merge(callTypes, abiTypes)
),
filterL(a => a[0] !== a[1]),
take(1),
a => a.length == 0
)
),
take(1),
func => {
if (func.length == 0) throw { message: 'Please check function signature or parameter(length).' }
else return func
}
)
const fnSpliter = fnSignature => go(fnSignature, str => str.substr(0, str.indexOf('(')));
const inputGenerator = (contract, funcSig, params) => go(
findFunctionInABI(contract, funcSig),
first,
fn => fn.inputs,
map(input => params[input.name])
);
module.exports = {
findFunctionInABI,
fnSpliter,
inputGenerator
}