From 1ad395cf86b2006c09bdae814607c2baf9790b91 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 4 Sep 2017 18:14:48 +0200 Subject: Make the functions immidiately return txHash instead of awaiting for a transaction to be mined --- src/0x.ts | 1 - 1 file changed, 1 deletion(-) (limited to 'src/0x.ts') diff --git a/src/0x.ts b/src/0x.ts index ba222f2c9..3cf672a1b 100644 --- a/src/0x.ts +++ b/src/0x.ts @@ -3,7 +3,6 @@ import * as BigNumber from 'bignumber.js'; import {SchemaValidator, schemas} from '0x-json-schemas'; import {bigNumberConfigs} from './bignumber_config'; import * as ethUtil from 'ethereumjs-util'; -import contract = require('truffle-contract'); import findVersions = require('find-versions'); import compareVersions = require('compare-versions'); import {Web3Wrapper} from './web3_wrapper'; -- cgit v1.2.3 From c9e490bdaec53e3a93b5da8daaaf0b1d87d9de76 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 4 Sep 2017 19:08:14 +0200 Subject: Implement zeroEx.awaitTransactionMined --- src/0x.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/0x.ts') diff --git a/src/0x.ts b/src/0x.ts index 3cf672a1b..e92c92e1f 100644 --- a/src/0x.ts +++ b/src/0x.ts @@ -1,5 +1,6 @@ import * as _ from 'lodash'; import * as BigNumber from 'bignumber.js'; +import * as Web3 from 'web3'; import {SchemaValidator, schemas} from '0x-json-schemas'; import {bigNumberConfigs} from './bignumber_config'; import * as ethUtil from 'ethereumjs-util'; @@ -248,4 +249,17 @@ export class ZeroEx { throw new Error(ZeroExError.InvalidSignature); } + public async awaitTransactionMined(txHash: string, + pollingIntervalMs: number = 500): Promise { + const txReceiptPromise = new Promise((resolve: (receipt: Web3.TransactionReceipt) => void, reject) => { + const intervalId = setInterval(async () => { + const transactionReceipt = await this._web3Wrapper.getTransactionReceiptAsync(txHash); + if (!_.isNull(transactionReceipt)) { + clearInterval(intervalId); + resolve(transactionReceipt); + } + }, pollingIntervalMs); + }); + return txReceiptPromise; + } } -- cgit v1.2.3 From 2b547f94a44dfed029b5559b743344d5998fa3bc Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 5 Sep 2017 10:07:16 +0200 Subject: Change non-exhange contracts to also return txHash --- src/0x.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/0x.ts') diff --git a/src/0x.ts b/src/0x.ts index e92c92e1f..4a1d605a2 100644 --- a/src/0x.ts +++ b/src/0x.ts @@ -249,8 +249,8 @@ export class ZeroEx { throw new Error(ZeroExError.InvalidSignature); } - public async awaitTransactionMined(txHash: string, - pollingIntervalMs: number = 500): Promise { + public async awaitTransactionMinedAsync(txHash: string, + pollingIntervalMs: number = 500): Promise { const txReceiptPromise = new Promise((resolve: (receipt: Web3.TransactionReceipt) => void, reject) => { const intervalId = setInterval(async () => { const transactionReceipt = await this._web3Wrapper.getTransactionReceiptAsync(txHash); -- cgit v1.2.3 From 96d2a55effa6666c1b8d90594ca5607dcc1bce8e Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 5 Sep 2017 10:29:51 +0200 Subject: Add TransationReceipt as a public exported type --- src/0x.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/0x.ts') diff --git a/src/0x.ts b/src/0x.ts index 4a1d605a2..86976c4ab 100644 --- a/src/0x.ts +++ b/src/0x.ts @@ -16,7 +16,7 @@ import {TokenRegistryWrapper} from './contract_wrappers/token_registry_wrapper'; import {EtherTokenWrapper} from './contract_wrappers/ether_token_wrapper'; import {TokenWrapper} from './contract_wrappers/token_wrapper'; import {TokenTransferProxyWrapper} from './contract_wrappers/token_transfer_proxy_wrapper'; -import {ECSignature, ZeroExError, Order, SignedOrder, Web3Provider, ZeroExConfig} from './types'; +import {ECSignature, ZeroExError, Order, SignedOrder, Web3Provider, ZeroExConfig, TransactionReceipt} from './types'; // Customize our BigNumber instances bigNumberConfigs.configure(); @@ -249,9 +249,15 @@ export class ZeroEx { throw new Error(ZeroExError.InvalidSignature); } + /** + * Waits for transaction to be mined and returns the transaction receipt + * @param txHash Transaction hash + * @param pollingIntervalMs How often (in ms) should we check if the transaction is mined. + * @return Web3.TransactionReceipt + */ public async awaitTransactionMinedAsync(txHash: string, - pollingIntervalMs: number = 500): Promise { - const txReceiptPromise = new Promise((resolve: (receipt: Web3.TransactionReceipt) => void, reject) => { + pollingIntervalMs: number = 500): Promise { + const txReceiptPromise = new Promise((resolve: (receipt: TransactionReceipt) => void, reject) => { const intervalId = setInterval(async () => { const transactionReceipt = await this._web3Wrapper.getTransactionReceiptAsync(txHash); if (!_.isNull(transactionReceipt)) { -- cgit v1.2.3 From a12df1c73a97b3ba18ab53c1b25be39b837f6240 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 5 Sep 2017 11:38:28 +0200 Subject: Fix gasPrice regression --- src/0x.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/0x.ts') diff --git a/src/0x.ts b/src/0x.ts index 86976c4ab..fd7d9b5a5 100644 --- a/src/0x.ts +++ b/src/0x.ts @@ -170,13 +170,16 @@ export class ZeroEx { // We re-assign the send method so that Web3@1.0 providers work with 0x.js (provider as any).sendAsync = (provider as any).send; } - this._web3Wrapper = new Web3Wrapper(provider); const gasPrice = _.isUndefined(config) ? undefined : config.gasPrice; - this.token = new TokenWrapper(this._web3Wrapper, gasPrice); - this.proxy = new TokenTransferProxyWrapper(this._web3Wrapper, gasPrice); - this.exchange = new ExchangeWrapper(this._web3Wrapper, this.token, gasPrice); - this.tokenRegistry = new TokenRegistryWrapper(this._web3Wrapper, gasPrice); - this.etherToken = new EtherTokenWrapper(this._web3Wrapper, this.token, gasPrice); + const defaults = { + gasPrice, + }; + this._web3Wrapper = new Web3Wrapper(provider, defaults); + this.token = new TokenWrapper(this._web3Wrapper); + this.proxy = new TokenTransferProxyWrapper(this._web3Wrapper); + this.exchange = new ExchangeWrapper(this._web3Wrapper, this.token); + this.tokenRegistry = new TokenRegistryWrapper(this._web3Wrapper); + this.etherToken = new EtherTokenWrapper(this._web3Wrapper, this.token); } /** * Sets a new web3 provider for 0x.js. Updating the provider will stop all -- cgit v1.2.3 From f6a945dfe4844d243ef67042b33e9ade2fc60308 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 5 Sep 2017 12:52:00 +0200 Subject: Fix the comment at awaitTransactionMinedAsync --- src/0x.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/0x.ts') diff --git a/src/0x.ts b/src/0x.ts index fd7d9b5a5..e1ba796c8 100644 --- a/src/0x.ts +++ b/src/0x.ts @@ -253,10 +253,10 @@ export class ZeroEx { throw new Error(ZeroExError.InvalidSignature); } /** - * Waits for transaction to be mined and returns the transaction receipt + * Waits for a transaction to be mined and returns the transaction receipt. * @param txHash Transaction hash * @param pollingIntervalMs How often (in ms) should we check if the transaction is mined. - * @return Web3.TransactionReceipt + * @return TransactionReceipt */ public async awaitTransactionMinedAsync(txHash: string, pollingIntervalMs: number = 500): Promise { -- cgit v1.2.3 From b5c6c9196290314a875f89b88178b1be4b0db7d0 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 5 Sep 2017 12:52:44 +0200 Subject: Increase the default polling interval to 1000 --- src/0x.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/0x.ts') diff --git a/src/0x.ts b/src/0x.ts index e1ba796c8..209b2704d 100644 --- a/src/0x.ts +++ b/src/0x.ts @@ -259,7 +259,7 @@ export class ZeroEx { * @return TransactionReceipt */ public async awaitTransactionMinedAsync(txHash: string, - pollingIntervalMs: number = 500): Promise { + pollingIntervalMs: number = 1000): Promise { const txReceiptPromise = new Promise((resolve: (receipt: TransactionReceipt) => void, reject) => { const intervalId = setInterval(async () => { const transactionReceipt = await this._web3Wrapper.getTransactionReceiptAsync(txHash); -- cgit v1.2.3 From a7b2131db77b72379f0d57eaff694d5a925191cd Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 5 Sep 2017 18:45:20 +0200 Subject: Decode logs args in awaitTransactionMinedAsync --- src/0x.ts | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) (limited to 'src/0x.ts') diff --git a/src/0x.ts b/src/0x.ts index 209b2704d..d88683c3d 100644 --- a/src/0x.ts +++ b/src/0x.ts @@ -1,6 +1,7 @@ import * as _ from 'lodash'; import * as BigNumber from 'bignumber.js'; import * as Web3 from 'web3'; +import * as abiDecoder from 'abi-decoder'; import {SchemaValidator, schemas} from '0x-json-schemas'; import {bigNumberConfigs} from './bignumber_config'; import * as ethUtil from 'ethereumjs-util'; @@ -11,12 +12,24 @@ import {constants} from './utils/constants'; import {utils} from './utils/utils'; import {signatureUtils} from './utils/signature_utils'; import {assert} from './utils/assert'; +import {artifacts} from './artifacts'; import {ExchangeWrapper} from './contract_wrappers/exchange_wrapper'; import {TokenRegistryWrapper} from './contract_wrappers/token_registry_wrapper'; import {EtherTokenWrapper} from './contract_wrappers/ether_token_wrapper'; import {TokenWrapper} from './contract_wrappers/token_wrapper'; import {TokenTransferProxyWrapper} from './contract_wrappers/token_transfer_proxy_wrapper'; -import {ECSignature, ZeroExError, Order, SignedOrder, Web3Provider, ZeroExConfig, TransactionReceipt} from './types'; +import { + ECSignature, + ZeroExError, + Order, + SignedOrder, + Web3Provider, + ZeroExConfig, + TransactionReceipt, + DecodedLogArgs, + TransactionReceiptWithDecodedLogs, + LogWithDecodedArgs, +} from './types'; // Customize our BigNumber instances bigNumberConfigs.configure(); @@ -170,6 +183,7 @@ export class ZeroEx { // We re-assign the send method so that Web3@1.0 providers work with 0x.js (provider as any).sendAsync = (provider as any).send; } + this._registerArtifactsWithinABIDecoder(); const gasPrice = _.isUndefined(config) ? undefined : config.gasPrice; const defaults = { gasPrice, @@ -264,11 +278,34 @@ export class ZeroEx { const intervalId = setInterval(async () => { const transactionReceipt = await this._web3Wrapper.getTransactionReceiptAsync(txHash); if (!_.isNull(transactionReceipt)) { - clearInterval(intervalId); - resolve(transactionReceipt); + clearInterval(intervalId); + const logsWithDecodedArgs = _.map(transactionReceipt.logs, (log: Web3.LogEntry) => { + const decodedLog = abiDecoder.decodeLogs([log])[0]; + const decodedArgs = decodedLog.events; + const args: DecodedLogArgs = {}; + _.forEach(decodedArgs, arg => { + args[arg.name] = arg.value; + }); + const logWithDecodedArgs: LogWithDecodedArgs = { + ...log, + args, + event: decodedLog.name, + }; + return logWithDecodedArgs; + }); + const transactionReceiptWithDecodedLogArgs: TransactionReceiptWithDecodedLogs = { + ...transactionReceipt, + logs: logsWithDecodedArgs, + }; + resolve(transactionReceiptWithDecodedLogArgs); } }, pollingIntervalMs); }); return txReceiptPromise; } + private _registerArtifactsWithinABIDecoder(): void { + for (const artifact of _.values(artifacts)) { + abiDecoder.addABI(artifact.abi); + } + } } -- cgit v1.2.3 From 2f97ddb7279a95ffb93ae6bbdfa77618a7f41fe1 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 5 Sep 2017 18:50:22 +0200 Subject: Fix the return types and export the required public types --- src/0x.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/0x.ts') diff --git a/src/0x.ts b/src/0x.ts index d88683c3d..0af164b1e 100644 --- a/src/0x.ts +++ b/src/0x.ts @@ -270,11 +270,12 @@ export class ZeroEx { * Waits for a transaction to be mined and returns the transaction receipt. * @param txHash Transaction hash * @param pollingIntervalMs How often (in ms) should we check if the transaction is mined. - * @return TransactionReceipt + * @return Transaction receipt with decoded log args. */ - public async awaitTransactionMinedAsync(txHash: string, - pollingIntervalMs: number = 1000): Promise { - const txReceiptPromise = new Promise((resolve: (receipt: TransactionReceipt) => void, reject) => { + public async awaitTransactionMinedAsync( + txHash: string, pollingIntervalMs: number = 1000): Promise { + const txReceiptPromise = new Promise( + (resolve: (receipt: TransactionReceiptWithDecodedLogs) => void, reject) => { const intervalId = setInterval(async () => { const transactionReceipt = await this._web3Wrapper.getTransactionReceiptAsync(txHash); if (!_.isNull(transactionReceipt)) { -- cgit v1.2.3