diff options
author | Amir Bandeali <abandeali1@gmail.com> | 2018-02-09 09:09:34 +0800 |
---|---|---|
committer | Amir Bandeali <abandeali1@gmail.com> | 2018-04-21 04:56:16 +0800 |
commit | 7201a74aeaa6b646e97d7c9c2c4cc979ace5f4f7 (patch) | |
tree | f0cd69fbe346bc6e7fcd8cb1a4f010e8d4513804 /packages/contracts/src/utils/multi_sig_wrapper.ts | |
parent | 9e2f8bead9a51a4c30b77781ae3b39bed31c36ee (diff) | |
download | dexon-0x-contracts-7201a74aeaa6b646e97d7c9c2c4cc979ace5f4f7.tar.gz dexon-0x-contracts-7201a74aeaa6b646e97d7c9c2c4cc979ace5f4f7.tar.zst dexon-0x-contracts-7201a74aeaa6b646e97d7c9c2c4cc979ace5f4f7.zip |
Move utils dir into src
Diffstat (limited to 'packages/contracts/src/utils/multi_sig_wrapper.ts')
-rw-r--r-- | packages/contracts/src/utils/multi_sig_wrapper.ts | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/packages/contracts/src/utils/multi_sig_wrapper.ts b/packages/contracts/src/utils/multi_sig_wrapper.ts new file mode 100644 index 000000000..84fed7944 --- /dev/null +++ b/packages/contracts/src/utils/multi_sig_wrapper.ts @@ -0,0 +1,43 @@ +import { AbiDefinition, MethodAbi } from '@0xproject/types'; +import { BigNumber } from '@0xproject/utils'; +import ABI = require('ethereumjs-abi'); +import ethUtil = require('ethereumjs-util'); +import * as _ from 'lodash'; +import * as Web3 from 'web3'; + +import { MultiSigWalletContract } from '../contract_wrappers/generated/multi_sig_wallet'; + +import { TransactionDataParams } from './types'; + +export class MultiSigWrapper { + private _multiSig: MultiSigWalletContract; + public static encodeFnArgs(name: string, abi: AbiDefinition[], args: any[]) { + const abiEntity = _.find(abi, { name }) as 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(''); + } + constructor(multiSigContract: MultiSigWalletContract) { + this._multiSig = multiSigContract; + } + public async submitTransactionAsync( + destination: string, + from: string, + dataParams: TransactionDataParams, + value: BigNumber = new BigNumber(0), + ) { + const { name, abi, args = [] } = dataParams; + const encoded = MultiSigWrapper.encodeFnArgs(name, abi, args); + return this._multiSig.submitTransaction.sendTransactionAsync(destination, value, encoded, { + from, + }); + } +} |