aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/src/utils/multi_sig_wrapper.ts
diff options
context:
space:
mode:
authorAmir Bandeali <abandeali1@gmail.com>2018-05-25 08:24:52 +0800
committerGitHub <noreply@github.com>2018-05-25 08:24:52 +0800
commit654698b20880398eded74342c8030a6009938103 (patch)
tree0c206bee801971372866051b08b1710a05eb431a /packages/contracts/src/utils/multi_sig_wrapper.ts
parent895a9093aa5f204f9f7ad0fedb2934a8b6c40b17 (diff)
parent237ebb07161c46fa85ca778a1c2ff60f63611bd7 (diff)
downloaddexon-0x-contracts-654698b20880398eded74342c8030a6009938103.tar
dexon-0x-contracts-654698b20880398eded74342c8030a6009938103.tar.gz
dexon-0x-contracts-654698b20880398eded74342c8030a6009938103.tar.bz2
dexon-0x-contracts-654698b20880398eded74342c8030a6009938103.tar.lz
dexon-0x-contracts-654698b20880398eded74342c8030a6009938103.tar.xz
dexon-0x-contracts-654698b20880398eded74342c8030a6009938103.tar.zst
dexon-0x-contracts-654698b20880398eded74342c8030a6009938103.zip
Merge pull request #571 from 0xProject/feature/contracts/proxyOwner
Update MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress
Diffstat (limited to 'packages/contracts/src/utils/multi_sig_wrapper.ts')
-rw-r--r--packages/contracts/src/utils/multi_sig_wrapper.ts66
1 files changed, 40 insertions, 26 deletions
diff --git a/packages/contracts/src/utils/multi_sig_wrapper.ts b/packages/contracts/src/utils/multi_sig_wrapper.ts
index 41a1dd8d9..5c73cdf5a 100644
--- a/packages/contracts/src/utils/multi_sig_wrapper.ts
+++ b/packages/contracts/src/utils/multi_sig_wrapper.ts
@@ -1,43 +1,57 @@
-import { AbiDefinition, MethodAbi } from '@0xproject/types';
+import { Provider, TransactionReceiptWithDecodedLogs } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
-import ABI = require('ethereumjs-abi');
-import ethUtil = require('ethereumjs-util');
+import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as _ from 'lodash';
-import * as Web3 from 'web3';
+import { AssetProxyOwnerContract } from '../contract_wrappers/generated/asset_proxy_owner';
import { MultiSigWalletContract } from '../contract_wrappers/generated/multi_sig_wallet';
-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 _web3Wrapper: Web3Wrapper;
+ constructor(multiSigContract: MultiSigWalletContract, provider: Provider) {
this._multiSig = multiSigContract;
+ this._web3Wrapper = new Web3Wrapper(provider);
}
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._getTxWithDecodedMultiSigLogsAsync(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._getTxWithDecodedMultiSigLogsAsync(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._getTxWithDecodedMultiSigLogsAsync(txHash);
+ return tx;
+ }
+ public async executeRemoveAuthorizedAddressAsync(
+ txId: BigNumber,
+ from: string,
+ ): Promise<TransactionReceiptWithDecodedLogs> {
+ const txHash = await (this
+ ._multiSig as AssetProxyOwnerContract).executeRemoveAuthorizedAddress.sendTransactionAsync(txId, { from });
+ const tx = await this._getTxWithDecodedMultiSigLogsAsync(txHash);
+ return tx;
+ }
+ private async _getTxWithDecodedMultiSigLogsAsync(txHash: string): Promise<TransactionReceiptWithDecodedLogs> {
+ const tx = await this._web3Wrapper.awaitTransactionMinedAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS);
+ tx.logs = _.filter(tx.logs, log => log.address === this._multiSig.address);
+ tx.logs = _.map(tx.logs, log => logDecoder.decodeLogOrThrow(log));
+ return tx;
}
}