Skip to content

Commit

Permalink
feat: add --no-wait flag to deploy/send commands
Browse files Browse the repository at this point in the history
  • Loading branch information
alexghr committed Sep 25, 2023
1 parent 714c727 commit ac6eff3
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions yarn-project/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
'Optional encryption public key for this address. Set this value only if this contract is expected to receive private notes, which will be encrypted using this public key.',
)
.option('-s, --salt <string>', 'Optional deployment salt as a hex string for generating the deployment address.')
// negatable boolean flag. Passing `--no-wait` will set `options.wait` to false.
// https://github.com/tj/commander.js#other-option-types-negatable-boolean-and-booleanvalue
.option('--no-wait', 'Skip waiting for the contract to be deployed. Print the hash of deployment transaction')
.action(async (abiPath, options: any) => {
const contractAbi = await getContractAbi(abiPath, log);
const constructorAbi = contractAbi.functions.find(({ name }) => name === 'constructor');
Expand All @@ -177,9 +180,14 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
const args = encodeArgs(options.args, constructorAbi!.parameters);
debugLogger(`Encoded arguments: ${args.join(', ')}`);
const tx = deployer.deploy(...args).send({ contractAddressSalt: salt });
debugLogger(`Deploy tx sent with hash ${await tx.getTxHash()}`);
const deployed = await tx.wait();
log(`\nContract deployed at ${deployed.contractAddress!.toString()}\n`);
const txHash = await tx.getTxHash();
debugLogger(`Deploy tx sent with hash ${txHash}`);
if (options.wait) {
const deployed = await tx.wait();
log(`\nContract deployed at ${deployed.contractAddress!.toString()}\n`);
} else {
log(`\nDeployment transaction hash: ${txHash}\n`);
}
});

program
Expand Down Expand Up @@ -361,7 +369,7 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
.requiredOption('-ca, --contract-address <address>', 'Aztec address of the contract.')
.option('-k, --private-key <string>', "The sender's private key.", PRIVATE_KEY)
.option('-u, --rpc-url <string>', 'URL of the Aztec RPC', AZTEC_RPC_HOST || 'http://localhost:8080')

.option('--no-wait', 'Print transaction hash without waiting for it to be mined')
.action(async (functionName, options) => {
const { contractAddress, functionArgs, contractAbi } = await prepTx(
options.contractAbi,
Expand All @@ -377,13 +385,19 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
const wallet = await getSchnorrAccount(client, privateKey, privateKey, accountCreationSalt).getWallet();
const contract = await Contract.at(contractAddress, contractAbi, wallet);
const tx = contract.methods[functionName](...functionArgs).send();
await tx.wait();
log('\nTransaction has been mined');
const receipt = await tx.getReceipt();
log(`Transaction hash: ${(await tx.getTxHash()).toString()}`);
log(`Status: ${receipt.status}\n`);
log(`Block number: ${receipt.blockNumber}`);
log(`Block hash: ${receipt.blockHash?.toString('hex')}`);
if (options.wait) {
await tx.wait();

log('Transaction has been mined');

const receipt = await tx.getReceipt();
log(`Status: ${receipt.status}\n`);
log(`Block number: ${receipt.blockNumber}`);
log(`Block hash: ${receipt.blockHash?.toString('hex')}`);
} else {
log('\nTransaction pending. Check status with get-tx-receipt');
}
});

program
Expand Down

0 comments on commit ac6eff3

Please sign in to comment.