diff options
author | Amir Bandeali <abandeali1@gmail.com> | 2018-05-21 11:10:04 +0800 |
---|---|---|
committer | Amir Bandeali <abandeali1@gmail.com> | 2018-05-25 06:39:19 +0800 |
commit | cc44f5f75d8a1152be9fd49491a9c194cfa2b285 (patch) | |
tree | bc81508208592e98eb41e20bc13080f0cec5991c /packages/contracts/src/utils | |
parent | 23df5cc201b3494c39389ac4cb4de346d7cbbd00 (diff) | |
download | dexon-sol-tools-cc44f5f75d8a1152be9fd49491a9c194cfa2b285.tar dexon-sol-tools-cc44f5f75d8a1152be9fd49491a9c194cfa2b285.tar.gz dexon-sol-tools-cc44f5f75d8a1152be9fd49491a9c194cfa2b285.tar.bz2 dexon-sol-tools-cc44f5f75d8a1152be9fd49491a9c194cfa2b285.tar.lz dexon-sol-tools-cc44f5f75d8a1152be9fd49491a9c194cfa2b285.tar.xz dexon-sol-tools-cc44f5f75d8a1152be9fd49491a9c194cfa2b285.tar.zst dexon-sol-tools-cc44f5f75d8a1152be9fd49491a9c194cfa2b285.zip |
Update multisig tests and utils
Diffstat (limited to 'packages/contracts/src/utils')
-rw-r--r-- | packages/contracts/src/utils/multi_sig_wrapper.ts | 68 |
1 files changed, 43 insertions, 25 deletions
diff --git a/packages/contracts/src/utils/multi_sig_wrapper.ts b/packages/contracts/src/utils/multi_sig_wrapper.ts index 41a1dd8d9..9a2b26d77 100644 --- a/packages/contracts/src/utils/multi_sig_wrapper.ts +++ b/packages/contracts/src/utils/multi_sig_wrapper.ts @@ -1,43 +1,61 @@ -import { AbiDefinition, MethodAbi } from '@0xproject/types'; +import { TransactionReceiptWithDecodedLogs, ZeroEx } from '0x.js'; 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 { MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressContract } from '../contract_wrappers/generated/multi_sig_wallet_with_time_lock_except_remove_authorized_address'; -import { TransactionDataParams } from './types'; +import { constants } from './constants'; +import { LogDecoder } from './log_decoder'; export class MultiSigWrapper { private _multiSig: MultiSigWalletContract; - public static encodeFnArgs(name: string, abi: AbiDefinition[], args: any[]): string { - 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) { + private _logDecoder: LogDecoder = new LogDecoder(constants.TESTRPC_NETWORK_ID); + private _zeroEx: ZeroEx; + constructor(multiSigContract: MultiSigWalletContract, zeroEx: ZeroEx) { this._multiSig = multiSigContract; + this._zeroEx = zeroEx; } public async submitTransactionAsync( destination: string, + data: string, from: string, - dataParams: TransactionDataParams, - value: BigNumber = new BigNumber(0), - ): Promise<string> { - const { name, abi, args = [] } = dataParams; - const encoded = MultiSigWrapper.encodeFnArgs(name, abi, args); - return this._multiSig.submitTransaction.sendTransactionAsync(destination, value, encoded, { + opts: { value?: BigNumber } = {}, + ): Promise<TransactionReceiptWithDecodedLogs> { + const value = _.isUndefined(opts.value) ? new BigNumber(0) : opts.value; + const txHash = await this._multiSig.submitTransaction.sendTransactionAsync(destination, value, data, { from, }); + const tx = await this._getTxWithDecodedMultiSigLogs(txHash); + return tx; + } + public async confirmTransactionAsync(txId: BigNumber, from: string): Promise<TransactionReceiptWithDecodedLogs> { + const txHash = await this._multiSig.confirmTransaction.sendTransactionAsync(txId, { from }); + const tx = await this._getTxWithDecodedMultiSigLogs(txHash); + return tx; + } + public async executeTransactionAsync(txId: BigNumber, from: string): Promise<TransactionReceiptWithDecodedLogs> { + const txHash = await this._multiSig.executeTransaction.sendTransactionAsync(txId, { from }); + const tx = await this._getTxWithDecodedMultiSigLogs(txHash); + return tx; + } + public async executeRemoveAuthorizedAddressAsync( + txId: BigNumber, + from: string, + ): Promise<TransactionReceiptWithDecodedLogs> { + const txHash = await (this + ._multiSig as MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressContract).executeRemoveAuthorizedAddress.sendTransactionAsync( + txId, + { from }, + ); + const tx = await this._getTxWithDecodedMultiSigLogs(txHash); + return tx; + } + private async _getTxWithDecodedMultiSigLogs(txHash: string) { + const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash); + tx.logs = _.filter(tx.logs, log => log.address === this._multiSig.address); + tx.logs = _.map(tx.logs, log => this._logDecoder.decodeLogOrThrow(log)); + return tx; } } |