Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

Add async option for send-tx command #1532

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/cli/src/bin/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return this.option('--async-tx', 'avoid waiting for tx gets mined');
return this.option('--async-tx', 'do not wait for the transaction to be mined');

};
1 change: 1 addition & 0 deletions packages/cli/src/commands/send-tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const register: (program: any) => any = program =>
'--gas <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);
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/scripts/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ export interface SendTxParams extends MethodParams, Network {
proxyAddress: string;
value?: string;
gas?: string;
asyncTx: boolean;
}

export interface CompileParams {
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/src/scripts/send-tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ export default async function sendTx({
network,
txParams,
networkFile,
asyncTx,
}: Partial<SendTxParams>): Promise<void | never> {
if (!proxyAddress) throw Error('A contract address must be specified.');
if (!methodName) throw Error('A method name must be specified.');
if (value) txParams = { value, ...txParams };
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;
}