diff options
author | Amir Bandeali <abandeali1@gmail.com> | 2017-11-30 14:02:43 +0800 |
---|---|---|
committer | Amir Bandeali <abandeali1@gmail.com> | 2017-11-30 23:10:18 +0800 |
commit | 4b3e0383235ca4ca0127f24c2e05543bb45a56bb (patch) | |
tree | 7a9c1888f99b1121826b09ca28185565ed47cd50 /packages/contracts/util/multi_sig_wrapper.ts | |
parent | c57190dead41846809effb8823bd4e486ca72512 (diff) | |
download | dexon-0x-contracts-4b3e0383235ca4ca0127f24c2e05543bb45a56bb.tar.gz dexon-0x-contracts-4b3e0383235ca4ca0127f24c2e05543bb45a56bb.tar.zst dexon-0x-contracts-4b3e0383235ca4ca0127f24c2e05543bb45a56bb.zip |
Add contracts to packages, fix most linting errors
Diffstat (limited to 'packages/contracts/util/multi_sig_wrapper.ts')
-rw-r--r-- | packages/contracts/util/multi_sig_wrapper.ts | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/packages/contracts/util/multi_sig_wrapper.ts b/packages/contracts/util/multi_sig_wrapper.ts new file mode 100644 index 000000000..7c13dae97 --- /dev/null +++ b/packages/contracts/util/multi_sig_wrapper.ts @@ -0,0 +1,34 @@ +import ABI = require('ethereumjs-abi'); +import ethUtil = require('ethereumjs-util'); +import * as _ from 'lodash'; +import * as Web3 from 'web3'; + +import {ContractInstance, TransactionDataParams} from './types'; + +export class MultiSigWrapper { + private multiSig: ContractInstance; + constructor(multiSigContractInstance: ContractInstance) { + this.multiSig = multiSigContractInstance; + } + public async submitTransactionAsync(destination: string, from: string, + dataParams: TransactionDataParams, + value: number = 0) { + const {name, abi, args = []} = dataParams; + const encoded = this.encodeFnArgs(name, abi, args); + return this.multiSig.submitTransaction(destination, value, encoded, {from}); + } + public encodeFnArgs(name: string, abi: Web3.AbiDefinition[], args: any[]) { + const abiEntity = _.find(abi, {name}) as Web3.MethodAbi; + if (_.isUndefined(abiEntity)) { + throw new Error(`Did not find abi entry for name: ${name}`); + } + const types = _.map(abiEntity.inputs, input => input.type); + const funcSig = ethUtil.bufferToHex(ABI.methodID(name, types)); + const argsData = _.map(args, arg => { + const target = _.isBoolean(arg) ? +arg : arg; + const targetBuff = ethUtil.toBuffer(target); + return ethUtil.setLengthLeft(targetBuff, 32).toString('hex'); + }); + return funcSig + argsData.join(''); + } +} |