In @0x/base-contract
: Expose txHashPromise
in PromiseWithTransactionHash
.
In `@0x/abi-gen-templates`: Update `awaitTransactionSuccessAsync()` partial to expose `txHashPromise`.
This commit is contained in:
parent
4d493eeebd
commit
fddad131a2
@ -25,7 +25,7 @@ public {{this.tsName}} = {
|
|||||||
const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults);
|
const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults);
|
||||||
return txHash;
|
return txHash;
|
||||||
},
|
},
|
||||||
async awaitTransactionSuccessAsync(
|
awaitTransactionSuccessAsync(
|
||||||
{{> typed_params inputs=inputs}}
|
{{> typed_params inputs=inputs}}
|
||||||
{{#this.payable}}
|
{{#this.payable}}
|
||||||
txData?: Partial<TxDataPayable> | number,
|
txData?: Partial<TxDataPayable> | number,
|
||||||
@ -36,26 +36,30 @@ public {{this.tsName}} = {
|
|||||||
pollingIntervalMs?: number,
|
pollingIntervalMs?: number,
|
||||||
timeoutMs?: number,
|
timeoutMs?: number,
|
||||||
): PromiseWithTransactionHash<TransactionReceiptWithDecodedLogs> {
|
): PromiseWithTransactionHash<TransactionReceiptWithDecodedLogs> {
|
||||||
// `txData` is optional, so it might be set to `pollingIntervalMs`.
|
// `txData` may be omitted on its own, so it might be set to `pollingIntervalMs`.
|
||||||
if (typeof(txData) === 'number') {
|
if (typeof(txData) === 'number') {
|
||||||
pollingIntervalMs = txData;
|
pollingIntervalMs = txData;
|
||||||
timeoutMs = pollingIntervalMs;
|
timeoutMs = pollingIntervalMs;
|
||||||
txData = {};
|
txData = {};
|
||||||
}
|
}
|
||||||
|
//
|
||||||
const self = this as any as {{contractName}}Contract;
|
const self = this as any as {{contractName}}Contract;
|
||||||
{{#if inputs}}
|
{{#if inputs}}
|
||||||
const txHash = await self.{{this.tsName}}.sendTransactionAsync({{> params input=inputs}}, txData);
|
const txHashPromise = self.{{this.tsName}}.sendTransactionAsync({{> params input=inputs}}, txData);
|
||||||
{{else}}
|
{{else}}
|
||||||
const txHash = await self.{{this.tsName}}.sendTransactionAsync(txData);
|
const txHashPromise = self.{{this.tsName}}.sendTransactionAsync(txData);
|
||||||
{{/if}}
|
{{/if}}
|
||||||
// tslint:disable-next-line: no-unnecessary-type-assertion
|
return new PromiseWithTransactionHash<TransactionReceiptWithDecodedLogs>(
|
||||||
const receiptPromise = self._web3Wrapper.awaitTransactionSuccessAsync(
|
txHashPromise,
|
||||||
txHash,
|
(async (): Promise<TransactionReceiptWithDecodedLogs> => {
|
||||||
|
// When the transaction hash resolves, wait for it to be mined.
|
||||||
|
return self._web3Wrapper.awaitTransactionSuccessAsync(
|
||||||
|
await txHashPromise,
|
||||||
pollingIntervalMs,
|
pollingIntervalMs,
|
||||||
timeoutMs,
|
timeoutMs,
|
||||||
) as any as PromiseWithTransactionHash<TransactionReceiptWithDecodedLogs>;
|
);
|
||||||
receiptPromise.txHash = txHash;
|
})(),
|
||||||
return receiptPromise;
|
);
|
||||||
},
|
},
|
||||||
async estimateGasAsync(
|
async estimateGasAsync(
|
||||||
{{> typed_params inputs=inputs}}
|
{{> typed_params inputs=inputs}}
|
||||||
|
@ -26,14 +26,16 @@ export interface AbiEncoderByFunctionSignature {
|
|||||||
* Not used by BaseContract, but generated contracts will return it in
|
* Not used by BaseContract, but generated contracts will return it in
|
||||||
* `awaitTransactionSuccessAsync()`.
|
* `awaitTransactionSuccessAsync()`.
|
||||||
* Maybe there's a better place for this.
|
* Maybe there's a better place for this.
|
||||||
* If you're wondering why this class is not simpler, it's to get around
|
|
||||||
* Typescript/ES5 transpiling issues.
|
|
||||||
*/
|
*/
|
||||||
export class PromiseWithTransactionHash<T> implements PromiseLike<T> {
|
export class PromiseWithTransactionHash<T> implements PromiseLike<T> {
|
||||||
public txHash: string = '';
|
public readonly txHashPromise: Promise<string>;
|
||||||
private readonly _promise: Promise<T>;
|
private readonly _promise: Promise<T>;
|
||||||
constructor(handler: (resolve: (value?: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void) {
|
constructor(
|
||||||
this._promise = new Promise(handler);
|
txHashPromise: Promise<string>,
|
||||||
|
promise: Promise<T>,
|
||||||
|
) {
|
||||||
|
this.txHashPromise = txHashPromise;
|
||||||
|
this._promise = promise;
|
||||||
}
|
}
|
||||||
public then<TResult>(
|
public then<TResult>(
|
||||||
onFulfilled?: (v: T) => TResult | PromiseLike<TResult>,
|
onFulfilled?: (v: T) => TResult | PromiseLike<TResult>,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user