From bc1194cd7a3e21bdc0058885f7e9798dc8ff189d Mon Sep 17 00:00:00 2001 From: Anton Bukov Date: Thu, 30 Apr 2020 20:19:23 +0300 Subject: [PATCH] Add async option for send-tx command --- packages/cli/src/bin/options.ts | 4 ++++ packages/cli/src/commands/send-tx.ts | 1 + packages/cli/src/scripts/interfaces.ts | 1 + packages/cli/src/scripts/send-tx.ts | 4 +++- 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/bin/options.ts b/packages/cli/src/bin/options.ts index 6d5c10927..8143001b3 100644 --- a/packages/cli/src/bin/options.ts +++ b/packages/cli/src/bin/options.ts @@ -31,3 +31,7 @@ program.Command.prototype.withNonInteractiveOption = function(): Command { program.Command.prototype.withSkipCompileOption = function(): Command { return this.option('--skip-compile', 'skips contract compilation'); }; + +program.Command.prototype.withAsyncOption = function(): Command { + return this.option('--async-tx', 'avoid waiting for tx gets mined'); +}; diff --git a/packages/cli/src/commands/send-tx.ts b/packages/cli/src/commands/send-tx.ts index 4b42dd7c8..c11b8192a 100644 --- a/packages/cli/src/commands/send-tx.ts +++ b/packages/cli/src/commands/send-tx.ts @@ -34,6 +34,7 @@ const register: (program: any) => any = program => '--gas ', `gas limit of the transaction, will default to the limit specified in the configuration file, or use gas estimation if not set`, ) + .withAsyncOption() .withNetworkOptions() .withNonInteractiveOption() .action(action); diff --git a/packages/cli/src/scripts/interfaces.ts b/packages/cli/src/scripts/interfaces.ts index 6d62f5bb1..e82236113 100644 --- a/packages/cli/src/scripts/interfaces.ts +++ b/packages/cli/src/scripts/interfaces.ts @@ -175,6 +175,7 @@ export interface SendTxParams extends MethodParams, Network { proxyAddress: string; value?: string; gas?: string; + asyncTx: boolean; } export interface CompileParams { diff --git a/packages/cli/src/scripts/send-tx.ts b/packages/cli/src/scripts/send-tx.ts index 2af6e0987..71138b129 100644 --- a/packages/cli/src/scripts/send-tx.ts +++ b/packages/cli/src/scripts/send-tx.ts @@ -10,6 +10,7 @@ export default async function sendTx({ network, txParams, networkFile, + asyncTx, }: Partial): Promise { if (!proxyAddress) throw Error('A contract address must be specified.'); if (!methodName) throw Error('A method name must be specified.'); @@ -17,5 +18,6 @@ export default async function sendTx({ if (gas) txParams = { gas, ...txParams }; const controller = new TransactionController(txParams, network, networkFile); - await controller.sendTransaction(proxyAddress, methodName, methodArgs); + const result = controller.sendTransaction(proxyAddress, methodName, methodArgs); + return asyncTx ? result : await result; }