@aztec/cli-wallet 0.0.0-test.1 → 0.0.1-commit.b655e406

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/README.md +30 -0
  2. package/dest/bin/index.js +48 -26
  3. package/dest/cmds/authorize_action.d.ts +3 -2
  4. package/dest/cmds/authorize_action.d.ts.map +1 -1
  5. package/dest/cmds/authorize_action.js +8 -4
  6. package/dest/cmds/bridge_fee_juice.d.ts +2 -2
  7. package/dest/cmds/bridge_fee_juice.d.ts.map +1 -1
  8. package/dest/cmds/bridge_fee_juice.js +8 -7
  9. package/dest/cmds/check_tx.d.ts +4 -2
  10. package/dest/cmds/check_tx.d.ts.map +1 -1
  11. package/dest/cmds/check_tx.js +145 -6
  12. package/dest/cmds/create_account.d.ts +6 -5
  13. package/dest/cmds/create_account.d.ts.map +1 -1
  14. package/dest/cmds/create_account.js +46 -27
  15. package/dest/cmds/create_authwit.d.ts +3 -2
  16. package/dest/cmds/create_authwit.d.ts.map +1 -1
  17. package/dest/cmds/create_authwit.js +5 -5
  18. package/dest/cmds/deploy.d.ts +6 -3
  19. package/dest/cmds/deploy.d.ts.map +1 -1
  20. package/dest/cmds/deploy.js +71 -54
  21. package/dest/cmds/deploy_account.d.ts +5 -7
  22. package/dest/cmds/deploy_account.d.ts.map +1 -1
  23. package/dest/cmds/deploy_account.js +46 -29
  24. package/dest/cmds/import_test_accounts.d.ts +2 -2
  25. package/dest/cmds/import_test_accounts.d.ts.map +1 -1
  26. package/dest/cmds/import_test_accounts.js +6 -9
  27. package/dest/cmds/index.d.ts +2 -2
  28. package/dest/cmds/index.d.ts.map +1 -1
  29. package/dest/cmds/index.js +83 -115
  30. package/dest/cmds/profile.d.ts +8 -0
  31. package/dest/cmds/profile.d.ts.map +1 -0
  32. package/dest/cmds/profile.js +28 -0
  33. package/dest/cmds/register_contract.d.ts +6 -2
  34. package/dest/cmds/register_contract.d.ts.map +1 -1
  35. package/dest/cmds/register_contract.js +20 -7
  36. package/dest/cmds/register_sender.d.ts +3 -2
  37. package/dest/cmds/register_sender.d.ts.map +1 -1
  38. package/dest/cmds/send.d.ts +7 -8
  39. package/dest/cmds/send.d.ts.map +1 -1
  40. package/dest/cmds/send.js +31 -20
  41. package/dest/cmds/simulate.d.ts +6 -2
  42. package/dest/cmds/simulate.d.ts.map +1 -1
  43. package/dest/cmds/simulate.js +25 -19
  44. package/dest/storage/wallet_db.d.ts +4 -16
  45. package/dest/storage/wallet_db.d.ts.map +1 -1
  46. package/dest/storage/wallet_db.js +2 -23
  47. package/dest/utils/authorizations.d.ts +6 -0
  48. package/dest/utils/authorizations.d.ts.map +1 -0
  49. package/dest/utils/authorizations.js +28 -0
  50. package/dest/utils/cli_wallet_and_node_wrapper.d.ts +12 -0
  51. package/dest/utils/cli_wallet_and_node_wrapper.d.ts.map +1 -0
  52. package/dest/utils/cli_wallet_and_node_wrapper.js +25 -0
  53. package/dest/utils/ecdsa.d.ts +0 -2
  54. package/dest/utils/ecdsa.d.ts.map +1 -1
  55. package/dest/utils/options/fees.d.ts +20 -27
  56. package/dest/utils/options/fees.d.ts.map +1 -1
  57. package/dest/utils/options/fees.js +85 -144
  58. package/dest/utils/options/options.d.ts +8 -4
  59. package/dest/utils/options/options.d.ts.map +1 -1
  60. package/dest/utils/options/options.js +26 -14
  61. package/dest/utils/profiling.d.ts +5 -0
  62. package/dest/utils/profiling.d.ts.map +1 -0
  63. package/dest/utils/profiling.js +60 -0
  64. package/dest/utils/wallet.d.ts +35 -0
  65. package/dest/utils/wallet.d.ts.map +1 -0
  66. package/dest/utils/wallet.js +193 -0
  67. package/package.json +24 -20
  68. package/src/bin/index.ts +56 -32
  69. package/src/cmds/authorize_action.ts +15 -4
  70. package/src/cmds/bridge_fee_juice.ts +14 -11
  71. package/src/cmds/check_tx.ts +182 -5
  72. package/src/cmds/create_account.ts +55 -32
  73. package/src/cmds/create_authwit.ts +8 -4
  74. package/src/cmds/deploy.ts +79 -62
  75. package/src/cmds/deploy_account.ts +57 -28
  76. package/src/cmds/import_test_accounts.ts +7 -11
  77. package/src/cmds/index.ts +256 -220
  78. package/src/cmds/profile.ts +48 -0
  79. package/src/cmds/register_contract.ts +28 -5
  80. package/src/cmds/register_sender.ts +3 -2
  81. package/src/cmds/send.ts +31 -17
  82. package/src/cmds/simulate.ts +39 -23
  83. package/src/storage/wallet_db.ts +3 -31
  84. package/src/utils/authorizations.ts +51 -0
  85. package/src/utils/cli_wallet_and_node_wrapper.ts +35 -0
  86. package/src/utils/options/fees.ts +134 -206
  87. package/src/utils/options/options.ts +41 -19
  88. package/src/utils/profiling.ts +158 -0
  89. package/src/utils/wallet.ts +264 -0
  90. package/dest/cmds/add_authwit.d.ts +0 -4
  91. package/dest/cmds/add_authwit.d.ts.map +0 -1
  92. package/dest/cmds/add_authwit.js +0 -4
  93. package/dest/cmds/cancel_tx.d.ts +0 -11
  94. package/dest/cmds/cancel_tx.d.ts.map +0 -1
  95. package/dest/cmds/cancel_tx.js +0 -38
  96. package/dest/utils/accounts.d.ts +0 -11
  97. package/dest/utils/accounts.d.ts.map +0 -1
  98. package/dest/utils/accounts.js +0 -87
  99. package/dest/utils/pxe_wrapper.d.ts +0 -10
  100. package/dest/utils/pxe_wrapper.d.ts.map +0 -1
  101. package/dest/utils/pxe_wrapper.js +0 -21
  102. package/src/cmds/add_authwit.ts +0 -13
  103. package/src/cmds/cancel_tx.ts +0 -62
  104. package/src/utils/accounts.ts +0 -102
  105. package/src/utils/pxe_wrapper.ts +0 -26
@@ -0,0 +1,48 @@
1
+ import type { AztecAddress } from '@aztec/aztec.js/addresses';
2
+ import { AuthWitness } from '@aztec/aztec.js/authorization';
3
+ import { Contract } from '@aztec/aztec.js/contracts';
4
+ import type { AztecNode } from '@aztec/aztec.js/node';
5
+ import { prepTx } from '@aztec/cli/utils';
6
+ import type { LogFn } from '@aztec/foundation/log';
7
+ import { serializePrivateExecutionSteps } from '@aztec/stdlib/kernel';
8
+
9
+ import { promises as fs } from 'fs';
10
+ import path from 'path';
11
+
12
+ import type { CLIFeeArgs } from '../utils/options/fees.js';
13
+ import { printProfileResult } from '../utils/profiling.js';
14
+ import type { CLIWallet } from '../utils/wallet.js';
15
+
16
+ export async function profile(
17
+ wallet: CLIWallet,
18
+ node: AztecNode,
19
+ from: AztecAddress,
20
+ functionName: string,
21
+ functionArgsIn: any[],
22
+ contractArtifactPath: string,
23
+ contractAddress: AztecAddress,
24
+ debugOutputPath: string | undefined,
25
+ feeOpts: CLIFeeArgs,
26
+ authWitnesses: AuthWitness[],
27
+ log: LogFn,
28
+ ) {
29
+ const { functionArgs, contractArtifact } = await prepTx(contractArtifactPath, functionName, functionArgsIn, log);
30
+
31
+ const contract = await Contract.at(contractAddress, contractArtifact, wallet);
32
+ const call = contract.methods[functionName](...functionArgs);
33
+
34
+ const { paymentMethod, gasSettings } = await feeOpts.toUserFeeOptions(node, wallet, from);
35
+ const result = await call.profile({
36
+ fee: { gasSettings, paymentMethod },
37
+ from,
38
+ profileMode: 'full',
39
+ authWitnesses,
40
+ skipProofGeneration: false,
41
+ });
42
+ printProfileResult(result.stats, log, true, result.executionSteps);
43
+ if (debugOutputPath) {
44
+ const ivcInputsPath = path.join(debugOutputPath, 'ivc-inputs.msgpack');
45
+ log(`Debug output written to ${ivcInputsPath}.`);
46
+ await fs.writeFile(ivcInputsPath, serializePrivateExecutionSteps(result.executionSteps));
47
+ }
48
+ }
@@ -1,20 +1,43 @@
1
- import type { AccountWalletWithSecretKey, AztecAddress, AztecNode } from '@aztec/aztec.js';
1
+ import type { AztecAddress } from '@aztec/aztec.js/addresses';
2
+ import { getContractInstanceFromInstantiationParams } from '@aztec/aztec.js/contracts';
3
+ import { Fr } from '@aztec/aztec.js/fields';
4
+ import { PublicKeys } from '@aztec/aztec.js/keys';
5
+ import type { AztecNode } from '@aztec/aztec.js/node';
6
+ import type { Wallet } from '@aztec/aztec.js/wallet';
2
7
  import { getContractArtifact } from '@aztec/cli/cli-utils';
3
8
  import type { LogFn } from '@aztec/foundation/log';
9
+ import { getAllFunctionAbis, getInitializer } from '@aztec/stdlib/abi';
4
10
 
5
11
  export async function registerContract(
6
- wallet: AccountWalletWithSecretKey,
12
+ wallet: Wallet,
7
13
  node: AztecNode,
8
14
  address: AztecAddress,
9
15
  artifactPath: string,
10
16
  log: LogFn,
17
+ initializer?: string,
18
+ publicKeys?: PublicKeys,
19
+ rawArgs?: any[],
20
+ salt?: Fr,
21
+ deployer?: AztecAddress,
11
22
  ) {
12
23
  const contractArtifact = await getContractArtifact(artifactPath, log);
13
- const contractInstance = await node.getContract(address);
24
+ const hasInitializer = getAllFunctionAbis(contractArtifact).some(fn => fn.isInitializer);
25
+ const constructorArtifact = hasInitializer ? getInitializer(contractArtifact, initializer) : undefined;
26
+ let contractInstance = await node.getContract(address);
14
27
  if (!contractInstance) {
15
- throw new Error(`Contract not found at address: ${address}`);
28
+ log(`Contract not found in the node at ${address}. Computing instance locally...`);
29
+ contractInstance = await getContractInstanceFromInstantiationParams(contractArtifact, {
30
+ constructorArtifact,
31
+ publicKeys: publicKeys ?? PublicKeys.default(),
32
+ constructorArgs: rawArgs,
33
+ salt: salt ?? Fr.ZERO,
34
+ deployer,
35
+ });
16
36
  }
17
- await wallet.registerContract({ instance: contractInstance, artifact: contractArtifact });
37
+ if (!contractInstance.address.equals(address)) {
38
+ throw new Error(`Contract address mismatch: expected ${address}, got ${contractInstance.address}`);
39
+ }
40
+ await wallet.registerContract(contractInstance, contractArtifact);
18
41
  log(`Contract registered: at ${contractInstance.address}`);
19
42
  return contractInstance;
20
43
  }
@@ -1,7 +1,8 @@
1
- import type { AccountWalletWithSecretKey, AztecAddress } from '@aztec/aztec.js';
1
+ import { AztecAddress } from '@aztec/aztec.js/addresses';
2
+ import type { Wallet } from '@aztec/aztec.js/wallet';
2
3
  import type { LogFn } from '@aztec/foundation/log';
3
4
 
4
- export async function registerSender(wallet: AccountWalletWithSecretKey, address: AztecAddress, log: LogFn) {
5
+ export async function registerSender(wallet: Wallet, address: AztecAddress, log: LogFn) {
5
6
  await wallet.registerSender(address);
6
7
  log(`Sender registered: ${address}`);
7
8
  }
package/src/cmds/send.ts CHANGED
@@ -1,19 +1,28 @@
1
- import { type AccountWalletWithSecretKey, type AztecAddress, Contract, Fr } from '@aztec/aztec.js';
1
+ import type { AztecAddress } from '@aztec/aztec.js/addresses';
2
+ import { AuthWitness } from '@aztec/aztec.js/authorization';
3
+ import { Contract, type SendInteractionOptions } from '@aztec/aztec.js/contracts';
4
+ import type { AztecNode } from '@aztec/aztec.js/node';
2
5
  import { prepTx } from '@aztec/cli/utils';
3
6
  import type { LogFn } from '@aztec/foundation/log';
4
- import { GasSettings } from '@aztec/stdlib/gas';
5
7
 
6
- import { type IFeeOpts, printGasEstimates } from '../utils/options/fees.js';
8
+ import { DEFAULT_TX_TIMEOUT_S } from '../utils/cli_wallet_and_node_wrapper.js';
9
+ import { CLIFeeArgs } from '../utils/options/fees.js';
10
+ import { printProfileResult } from '../utils/profiling.js';
11
+ import type { CLIWallet } from '../utils/wallet.js';
7
12
 
8
13
  export async function send(
9
- wallet: AccountWalletWithSecretKey,
14
+ wallet: CLIWallet,
15
+ node: AztecNode,
16
+ from: AztecAddress,
10
17
  functionName: string,
11
18
  functionArgsIn: any[],
12
19
  contractArtifactPath: string,
13
20
  contractAddress: AztecAddress,
14
21
  wait: boolean,
15
22
  cancellable: boolean,
16
- feeOpts: IFeeOpts,
23
+ feeOpts: CLIFeeArgs,
24
+ authWitnesses: AuthWitness[],
25
+ verbose: boolean,
17
26
  log: LogFn,
18
27
  ) {
19
28
  const { functionArgs, contractArtifact } = await prepTx(contractArtifactPath, functionName, functionArgsIn, log);
@@ -21,20 +30,32 @@ export async function send(
21
30
  const contract = await Contract.at(contractAddress, contractArtifact, wallet);
22
31
  const call = contract.methods[functionName](...functionArgs);
23
32
 
24
- const gasLimits = await call.estimateGas({ ...(await feeOpts.toSendOpts(wallet)) });
25
- printGasEstimates(feeOpts, gasLimits, log);
33
+ const { paymentMethod, gasSettings } = await feeOpts.toUserFeeOptions(node, wallet, from);
34
+ const sendOptions: SendInteractionOptions = {
35
+ fee: { paymentMethod, gasSettings },
36
+ from,
37
+ authWitnesses,
38
+ };
39
+
40
+ const { estimatedGas, stats } = await call.simulate({
41
+ ...sendOptions,
42
+ fee: { ...sendOptions.fee, estimateGas: true },
43
+ });
26
44
 
27
45
  if (feeOpts.estimateOnly) {
28
46
  return;
29
47
  }
30
48
 
31
- const nonce = Fr.random();
32
- const tx = call.send({ ...(await feeOpts.toSendOpts(wallet)), nonce, cancellable });
49
+ const tx = call.send({ ...sendOptions, fee: { ...sendOptions.fee, gasSettings: estimatedGas } });
50
+ if (verbose) {
51
+ printProfileResult(stats!, log);
52
+ }
53
+
33
54
  const txHash = await tx.getTxHash();
34
55
  log(`\nTransaction hash: ${txHash.toString()}`);
35
56
  if (wait) {
36
57
  try {
37
- await tx.wait();
58
+ await tx.wait({ timeout: DEFAULT_TX_TIMEOUT_S });
38
59
 
39
60
  log('Transaction has been mined');
40
61
 
@@ -49,14 +70,7 @@ export async function send(
49
70
  } else {
50
71
  log('Transaction pending. Check status with check-tx');
51
72
  }
52
- const gasSettings = GasSettings.from({
53
- ...feeOpts.gasSettings,
54
- ...gasLimits,
55
- });
56
73
  return {
57
74
  txHash,
58
- nonce,
59
- cancellable,
60
- gasSettings,
61
75
  };
62
76
  }
@@ -1,42 +1,58 @@
1
- import { type AccountWalletWithSecretKey, type AztecAddress, Contract, type ProfileResult } from '@aztec/aztec.js';
1
+ import type { AztecAddress } from '@aztec/aztec.js/addresses';
2
+ import { AuthWitness } from '@aztec/aztec.js/authorization';
3
+ import { Contract } from '@aztec/aztec.js/contracts';
4
+ import type { AztecNode } from '@aztec/aztec.js/node';
2
5
  import { prepTx } from '@aztec/cli/utils';
3
6
  import type { LogFn } from '@aztec/foundation/log';
4
7
 
5
8
  import { format } from 'util';
6
9
 
7
- function printProfileResult(result: ProfileResult, log: LogFn) {
8
- log(format('\nSimulation result:'));
9
- log(format('Return value:', JSON.stringify(result.returnValues, null, 2)));
10
-
11
- log(format('\nGate count per circuit:'));
12
- let acc = 0;
13
- result.gateCounts.forEach(r => {
14
- acc += r.gateCount;
15
- log(format(' ', r.circuitName.padEnd(50), 'Gates:', r.gateCount.toLocaleString(), '\tAcc:', acc.toLocaleString()));
16
- });
17
-
18
- log(format('\nTotal gates:', acc.toLocaleString()));
19
- }
10
+ import { printAuthorizations } from '../utils/authorizations.js';
11
+ import type { CLIFeeArgs } from '../utils/options/fees.js';
12
+ import { printProfileResult } from '../utils/profiling.js';
13
+ import type { CLIWallet } from '../utils/wallet.js';
20
14
 
21
15
  export async function simulate(
22
- wallet: AccountWalletWithSecretKey,
16
+ wallet: CLIWallet,
17
+ node: AztecNode,
18
+ from: AztecAddress,
23
19
  functionName: string,
24
20
  functionArgsIn: any[],
25
21
  contractArtifactPath: string,
26
22
  contractAddress: AztecAddress,
27
- profile: boolean,
23
+ feeOpts: CLIFeeArgs,
24
+ authWitnesses: AuthWitness[],
25
+ verbose: boolean,
28
26
  log: LogFn,
29
27
  ) {
30
28
  const { functionArgs, contractArtifact } = await prepTx(contractArtifactPath, functionName, functionArgsIn, log);
31
29
 
32
30
  const contract = await Contract.at(contractAddress, contractArtifact, wallet);
33
31
  const call = contract.methods[functionName](...functionArgs);
34
-
35
- if (profile) {
36
- const result = await call.simulateWithProfile();
37
- printProfileResult(result, log);
38
- } else {
39
- const result = await call.simulate();
40
- log(format('\nSimulation result: ', result, '\n'));
32
+ const { paymentMethod, gasSettings } = await feeOpts.toUserFeeOptions(node, wallet, from);
33
+ const simulationResult = await call.simulate({
34
+ fee: { paymentMethod, gasSettings },
35
+ from,
36
+ authWitnesses,
37
+ includeMetadata: true,
38
+ });
39
+ if (verbose) {
40
+ await printAuthorizations(
41
+ simulationResult.offchainEffects!,
42
+ async (address: AztecAddress) => {
43
+ const metadata = await wallet.getContractMetadata(address);
44
+ if (!metadata.contractInstance) {
45
+ return undefined;
46
+ }
47
+ const classMetadata = await wallet.getContractClassMetadata(
48
+ metadata.contractInstance.currentContractClassId,
49
+ true,
50
+ );
51
+ return classMetadata.artifact;
52
+ },
53
+ log,
54
+ );
55
+ printProfileResult(simulationResult.stats!, log);
41
56
  }
57
+ log(format('\nSimulation result: ', simulationResult.result, '\n'));
42
58
  }
@@ -3,11 +3,10 @@ import type { LogFn } from '@aztec/foundation/log';
3
3
  import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
4
4
  import type { AuthWitness } from '@aztec/stdlib/auth-witness';
5
5
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
6
- import { GasSettings } from '@aztec/stdlib/gas';
7
6
  import type { TxHash } from '@aztec/stdlib/tx';
8
7
 
9
- import type { AccountType } from '../utils/accounts.js';
10
8
  import { extractECDSAPublicKeyFromBase64String } from '../utils/ecdsa.js';
9
+ import type { AccountType } from '../utils/wallet.js';
11
10
 
12
11
  export const Aliases = ['accounts', 'contracts', 'artifacts', 'secrets', 'transactions', 'authwits'] as const;
13
12
  export type AliasType = (typeof Aliases)[number];
@@ -16,7 +15,6 @@ export class WalletDB {
16
15
  #accounts!: AztecAsyncMap<string, Buffer>;
17
16
  #aliases!: AztecAsyncMap<string, Buffer>;
18
17
  #bridgedFeeJuice!: AztecAsyncMap<string, Buffer>;
19
- #transactions!: AztecAsyncMap<string, Buffer>;
20
18
 
21
19
  private static instance: WalletDB;
22
20
 
@@ -34,7 +32,6 @@ export class WalletDB {
34
32
  this.#accounts = store.openMap('accounts');
35
33
  this.#aliases = store.openMap('aliases');
36
34
  this.#bridgedFeeJuice = store.openMap('bridgedFeeJuice');
37
- this.#transactions = store.openMap('transactions');
38
35
 
39
36
  await this.refreshAliasCache();
40
37
  }
@@ -125,45 +122,20 @@ export class WalletDB {
125
122
  await this.refreshAliasCache();
126
123
  }
127
124
 
128
- async storeTx(
129
- {
130
- txHash,
131
- nonce,
132
- cancellable,
133
- gasSettings,
134
- }: { txHash: TxHash; nonce: Fr; cancellable: boolean; gasSettings: GasSettings },
135
- log: LogFn,
136
- alias?: string,
137
- ) {
125
+ async storeTx({ txHash }: { txHash: TxHash }, log: LogFn, alias?: string) {
138
126
  if (alias) {
139
127
  await this.#aliases.set(`transactions:${alias}`, Buffer.from(txHash.toString()));
140
128
  }
141
- await this.#transactions.set(`${txHash.toString()}:nonce`, nonce.toBuffer());
142
- await this.#transactions.set(`${txHash.toString()}:cancellable`, Buffer.from(cancellable ? 'true' : 'false'));
143
- await this.#transactions.set(`${txHash.toString()}:gasSettings`, gasSettings.toBuffer());
144
129
  await this.#aliases.set(`transactions:last`, Buffer.from(txHash.toString()));
145
130
  log(`Transaction hash stored in database with alias${alias ? `es last & ${alias}` : ' last'}`);
146
131
 
147
132
  await this.refreshAliasCache();
148
133
  }
149
134
 
150
- async retrieveTxData(txHash: TxHash) {
151
- const nonceBuffer = await this.#transactions.getAsync(`${txHash.toString()}:nonce`);
152
- if (!nonceBuffer) {
153
- throw new Error(
154
- `Could not find ${txHash.toString()}:nonce. Transaction with hash "${txHash.toString()}" does not exist on this wallet.`,
155
- );
156
- }
157
- const nonce = Fr.fromBuffer(nonceBuffer);
158
- const cancellable = (await this.#transactions.getAsync(`${txHash.toString()}:cancellable`))!.toString() === 'true';
159
- const gasBuffer = (await this.#transactions.getAsync(`${txHash.toString()}:gasSettings`))!;
160
- return { txHash, nonce, cancellable, gasSettings: GasSettings.fromBuffer(gasBuffer) };
161
- }
162
-
163
135
  tryRetrieveAlias(arg: string) {
164
136
  try {
165
137
  return this.retrieveAliasFromCache(arg);
166
- } catch (e) {
138
+ } catch {
167
139
  return arg;
168
140
  }
169
141
  }
@@ -0,0 +1,51 @@
1
+ import type { ContractArtifact } from '@aztec/aztec.js/abi';
2
+ import type { AztecAddress } from '@aztec/aztec.js/addresses';
3
+ import { CallAuthorizationRequest } from '@aztec/aztec.js/authorization';
4
+ import type { LogFn } from '@aztec/foundation/log';
5
+ import { type AbiDecoded, decodeFromAbi, getFunctionArtifact } from '@aztec/stdlib/abi';
6
+ import type { OffchainEffect } from '@aztec/stdlib/tx';
7
+
8
+ import { format } from 'util';
9
+
10
+ export async function printAuthorizations(
11
+ offchainEffects: OffchainEffect[],
12
+ artifactRetriever: (address: AztecAddress) => Promise<ContractArtifact | undefined>,
13
+ log: LogFn,
14
+ ) {
15
+ log(format('\nAuthorizations requested by the tx:\n'));
16
+ const callAuthorizationSelector = await CallAuthorizationRequest.getSelector();
17
+ const callAuthorizationEffects = offchainEffects.filter(effect =>
18
+ effect.data[0].equals(callAuthorizationSelector.toField()),
19
+ );
20
+ for (const callAuthorizationEffect of callAuthorizationEffects) {
21
+ const callAuthorizationRequest = await CallAuthorizationRequest.fromFields(callAuthorizationEffect.data);
22
+ const artifact = await artifactRetriever(callAuthorizationEffect.contractAddress);
23
+ if (!artifact) {
24
+ log(format(' -', `Call authorization. Inner hash: ${callAuthorizationRequest.innerHash.toString()}\n`));
25
+ log(format(' ', `Contract: unknown@${callAuthorizationEffect.contractAddress}`));
26
+ log(
27
+ format(
28
+ ' ',
29
+ `${callAuthorizationRequest.functionSelector.toString()}(\n${callAuthorizationRequest.args.map(arg => ` ${arg.toString()}`).join(',\n')}\n )`,
30
+ ),
31
+ );
32
+ } else {
33
+ const functionAbi = await getFunctionArtifact(artifact, callAuthorizationRequest.functionSelector);
34
+ const callData = decodeFromAbi(
35
+ functionAbi.parameters.map(param => param.type),
36
+ callAuthorizationRequest.args,
37
+ ) as AbiDecoded[];
38
+ const parameters = functionAbi.parameters.map((param, i) => ({ name: param.name, value: callData[i] }));
39
+ log(format(' -', `Call authorization. Inner hash: ${callAuthorizationRequest.innerHash.toString()}`));
40
+ log(format(' ', `Contract: ${artifact.name}@${callAuthorizationEffect.contractAddress}`));
41
+ log(
42
+ format(
43
+ ' ',
44
+ /* eslint-disable-next-line @typescript-eslint/no-base-to-string */
45
+ `${functionAbi.name}(\n${parameters.map(p => ` ${p.name}: ${p.value}`).join(',\n')}\n )`,
46
+ ),
47
+ );
48
+ }
49
+ log(`\n`);
50
+ }
51
+ }
@@ -0,0 +1,35 @@
1
+ import type { AztecNode } from '@aztec/stdlib/interfaces/client';
2
+
3
+ import { CLIWallet } from './wallet.js';
4
+
5
+ export const DEFAULT_TX_TIMEOUT_S = 180;
6
+
7
+ /*
8
+ * Wrapper class for CLIWallet and AztecNode, avoids initialization issues due to closures when providing CLIWallet
9
+ * and AztecNode to injected commander.js commands
10
+ */
11
+ export class CliWalletAndNodeWrapper {
12
+ private _wallet: CLIWallet | undefined;
13
+ private _node: AztecNode | undefined;
14
+
15
+ constructor() {}
16
+
17
+ get wallet() {
18
+ if (!this._wallet) {
19
+ throw new Error('Wallet not initialized while it should have been initialized in preSubcommand');
20
+ }
21
+ return this._wallet;
22
+ }
23
+
24
+ get node() {
25
+ if (!this._node) {
26
+ throw new Error('Node not initialized while it should have been initialized in preSubcommand');
27
+ }
28
+ return this._node;
29
+ }
30
+
31
+ setNodeAndWallet(node: AztecNode, wallet: CLIWallet) {
32
+ this._node = node;
33
+ this._wallet = wallet;
34
+ }
35
+ }