You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
766 B
27 lines
766 B
7 years ago
|
const ethjsABI = require('ethjs-abi');
|
||
6 years ago
|
const { ethSendTransaction } = require('./web3');
|
||
7 years ago
|
|
||
7 years ago
|
function findMethod (abi, name, args) {
|
||
7 years ago
|
for (let i = 0; i < abi.length; i++) {
|
||
6 years ago
|
const methodArgs = abi[i].inputs.map(input => input.type).join(',');
|
||
7 years ago
|
if ((abi[i].name === name) && (methodArgs === args)) {
|
||
|
return abi[i];
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
6 years ago
|
async function transaction (target, name, argsTypes, argsValues, opts) {
|
||
7 years ago
|
const abiMethod = findMethod(target.abi, name, argsTypes);
|
||
|
const encodedData = ethjsABI.encodeMethod(abiMethod, argsValues);
|
||
|
return target.sendTransaction(Object.assign({ data: encodedData }, opts));
|
||
|
}
|
||
7 years ago
|
|
||
6 years ago
|
function ether (from, to, value) {
|
||
|
return ethSendTransaction({ from, to, value, gasPrice: 0 });
|
||
6 years ago
|
}
|
||
6 years ago
|
|
||
7 years ago
|
module.exports = {
|
||
6 years ago
|
ether,
|
||
|
transaction,
|
||
7 years ago
|
};
|