@aztec/cli 0.16.1 → 0.16.3

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 (114) hide show
  1. package/dest/bin/index.js +4 -3
  2. package/dest/cmds/add_contract.d.ts +7 -0
  3. package/dest/cmds/add_contract.d.ts.map +1 -0
  4. package/dest/cmds/add_contract.js +15 -0
  5. package/dest/cmds/add_note.d.ts +8 -0
  6. package/dest/cmds/add_note.d.ts.map +1 -0
  7. package/dest/cmds/add_note.js +13 -0
  8. package/dest/cmds/block_number.d.ts +6 -0
  9. package/dest/cmds/block_number.d.ts.map +1 -0
  10. package/dest/cmds/block_number.js +10 -0
  11. package/dest/cmds/call.d.ts +7 -0
  12. package/dest/cmds/call.d.ts.map +1 -0
  13. package/dest/cmds/call.js +18 -0
  14. package/dest/cmds/check_deploy.d.ts +7 -0
  15. package/dest/cmds/check_deploy.d.ts.map +1 -0
  16. package/dest/cmds/check_deploy.js +16 -0
  17. package/dest/cmds/compute_selector.d.ts +6 -0
  18. package/dest/cmds/compute_selector.d.ts.map +1 -0
  19. package/dest/cmds/compute_selector.js +9 -0
  20. package/dest/cmds/create_account.d.ts +7 -0
  21. package/dest/cmds/create_account.d.ts.map +1 -0
  22. package/dest/cmds/create_account.js +30 -0
  23. package/dest/cmds/deploy.d.ts +7 -0
  24. package/dest/cmds/deploy.d.ts.map +1 -0
  25. package/dest/cmds/deploy.js +58 -0
  26. package/dest/cmds/deploy_l1_contracts.d.ts +6 -0
  27. package/dest/cmds/deploy_l1_contracts.d.ts.map +1 -0
  28. package/dest/cmds/deploy_l1_contracts.js +15 -0
  29. package/dest/cmds/example_contracts.d.ts +6 -0
  30. package/dest/cmds/example_contracts.d.ts.map +1 -0
  31. package/dest/cmds/example_contracts.js +10 -0
  32. package/dest/cmds/generate_p2p_private_key.d.ts +6 -0
  33. package/dest/cmds/generate_p2p_private_key.d.ts.map +1 -0
  34. package/dest/cmds/generate_p2p_private_key.js +11 -0
  35. package/dest/cmds/generate_private_key.d.ts +6 -0
  36. package/dest/cmds/generate_private_key.d.ts.map +1 -0
  37. package/dest/cmds/generate_private_key.js +22 -0
  38. package/dest/cmds/get_account.d.ts +7 -0
  39. package/dest/cmds/get_account.d.ts.map +1 -0
  40. package/dest/cmds/get_account.js +15 -0
  41. package/dest/cmds/get_accounts.d.ts +6 -0
  42. package/dest/cmds/get_accounts.d.ts.map +1 -0
  43. package/dest/cmds/get_accounts.js +18 -0
  44. package/dest/cmds/get_contract_data.d.ts +7 -0
  45. package/dest/cmds/get_contract_data.d.ts.map +1 -0
  46. package/dest/cmds/get_contract_data.js +28 -0
  47. package/dest/cmds/get_logs.d.ts +7 -0
  48. package/dest/cmds/get_logs.d.ts.map +1 -0
  49. package/dest/cmds/get_logs.js +54 -0
  50. package/dest/cmds/get_node_info.d.ts +6 -0
  51. package/dest/cmds/get_node_info.d.ts.map +1 -0
  52. package/dest/cmds/get_node_info.js +15 -0
  53. package/dest/cmds/get_recipient.d.ts +7 -0
  54. package/dest/cmds/get_recipient.d.ts.map +1 -0
  55. package/dest/cmds/get_recipient.js +15 -0
  56. package/dest/cmds/get_recipients.d.ts +6 -0
  57. package/dest/cmds/get_recipients.d.ts.map +1 -0
  58. package/dest/cmds/get_recipients.js +18 -0
  59. package/dest/cmds/get_tx_receipt.d.ts +7 -0
  60. package/dest/cmds/get_tx_receipt.d.ts.map +1 -0
  61. package/dest/cmds/get_tx_receipt.js +16 -0
  62. package/dest/cmds/inspect_contract.d.ts +6 -0
  63. package/dest/cmds/inspect_contract.d.ts.map +1 -0
  64. package/dest/cmds/inspect_contract.js +19 -0
  65. package/dest/cmds/parse_parameter_struct.d.ts +6 -0
  66. package/dest/cmds/parse_parameter_struct.d.ts.map +1 -0
  67. package/dest/cmds/parse_parameter_struct.js +20 -0
  68. package/dest/cmds/register_account.d.ts +7 -0
  69. package/dest/cmds/register_account.d.ts.map +1 -0
  70. package/dest/cmds/register_account.js +13 -0
  71. package/dest/cmds/register_recipient.d.ts +7 -0
  72. package/dest/cmds/register_recipient.d.ts.map +1 -0
  73. package/dest/cmds/register_recipient.js +11 -0
  74. package/dest/cmds/send.d.ts +7 -0
  75. package/dest/cmds/send.d.ts.map +1 -0
  76. package/dest/cmds/send.js +26 -0
  77. package/dest/cmds/unbox.d.ts +6 -0
  78. package/dest/cmds/unbox.d.ts.map +1 -0
  79. package/dest/cmds/unbox.js +9 -0
  80. package/dest/index.d.ts.map +1 -1
  81. package/dest/index.js +65 -312
  82. package/dest/utils.d.ts +9 -5
  83. package/dest/utils.d.ts.map +1 -1
  84. package/dest/utils.js +14 -10
  85. package/package.json +8 -8
  86. package/src/bin/index.ts +4 -2
  87. package/src/cmds/add_contract.ts +27 -0
  88. package/src/cmds/add_note.ts +24 -0
  89. package/src/cmds/block_number.ts +12 -0
  90. package/src/cmds/call.ts +35 -0
  91. package/src/cmds/check_deploy.ts +17 -0
  92. package/src/cmds/compute_selector.ts +10 -0
  93. package/src/cmds/create_account.ts +39 -0
  94. package/src/cmds/deploy.ts +77 -0
  95. package/src/cmds/deploy_l1_contracts.ts +25 -0
  96. package/src/cmds/example_contracts.ts +12 -0
  97. package/src/cmds/generate_p2p_private_key.ts +13 -0
  98. package/src/cmds/generate_private_key.ts +23 -0
  99. package/src/cmds/get_account.ts +18 -0
  100. package/src/cmds/get_accounts.ts +19 -0
  101. package/src/cmds/get_contract_data.ts +39 -0
  102. package/src/cmds/get_logs.ts +71 -0
  103. package/src/cmds/get_node_info.ts +17 -0
  104. package/src/cmds/get_recipient.ts +18 -0
  105. package/src/cmds/get_recipients.ts +19 -0
  106. package/src/cmds/get_tx_receipt.ts +18 -0
  107. package/src/cmds/inspect_contract.ts +29 -0
  108. package/src/cmds/parse_parameter_struct.ts +30 -0
  109. package/src/cmds/register_account.ts +24 -0
  110. package/src/cmds/register_recipient.ts +21 -0
  111. package/src/cmds/send.ts +40 -0
  112. package/src/cmds/unbox.ts +11 -0
  113. package/src/index.ts +97 -358
  114. package/src/utils.ts +28 -22
@@ -0,0 +1,71 @@
1
+ import { AztecAddress, FunctionSelector, LogFilter, LogId, TxHash } from '@aztec/aztec.js';
2
+ import { DebugLogger, LogFn } from '@aztec/foundation/log';
3
+ import { sleep } from '@aztec/foundation/sleep';
4
+
5
+ import { createCompatibleClient } from '../client.js';
6
+
7
+ /**
8
+ *
9
+ */
10
+ export async function getLogs(
11
+ txHash: TxHash,
12
+ fromBlock: number,
13
+ toBlock: number,
14
+ afterLog: LogId,
15
+ contractAddress: AztecAddress,
16
+ selector: FunctionSelector,
17
+ rpcUrl: string,
18
+ follow: boolean,
19
+ debugLogger: DebugLogger,
20
+ log: LogFn,
21
+ ) {
22
+ const pxe = await createCompatibleClient(rpcUrl, debugLogger);
23
+
24
+ if (follow) {
25
+ if (txHash) {
26
+ throw Error('Cannot use --follow with --tx-hash');
27
+ }
28
+ if (toBlock) {
29
+ throw Error('Cannot use --follow with --to-block');
30
+ }
31
+ }
32
+
33
+ const filter: LogFilter = { txHash, fromBlock, toBlock, afterLog, contractAddress, selector };
34
+
35
+ const fetchLogs = async () => {
36
+ const response = await pxe.getUnencryptedLogs(filter);
37
+ const logs = response.logs;
38
+
39
+ if (!logs.length) {
40
+ const filterOptions = Object.entries(filter)
41
+ .filter(([, value]) => value !== undefined)
42
+ .map(([key, value]) => `${key}: ${value}`)
43
+ .join(', ');
44
+ if (!follow) {
45
+ log(`No logs found for filter: {${filterOptions}}`);
46
+ }
47
+ } else {
48
+ if (!follow && !filter.afterLog) {
49
+ log('Logs found: \n');
50
+ }
51
+ logs.forEach(unencryptedLog => log(unencryptedLog.toHumanReadable()));
52
+ // Set the continuation parameter for the following requests
53
+ filter.afterLog = logs[logs.length - 1].id;
54
+ }
55
+ return response.maxLogsHit;
56
+ };
57
+
58
+ if (follow) {
59
+ log('Fetching logs...');
60
+ while (true) {
61
+ const maxLogsHit = await fetchLogs();
62
+ if (!maxLogsHit) {
63
+ await sleep(1000);
64
+ }
65
+ }
66
+ } else {
67
+ while (await fetchLogs()) {
68
+ // Keep fetching logs until we reach the end.
69
+ }
70
+ }
71
+ }
@@ -0,0 +1,17 @@
1
+ import { DebugLogger, LogFn } from '@aztec/foundation/log';
2
+
3
+ import { createCompatibleClient } from '../client.js';
4
+
5
+ /**
6
+ *
7
+ */
8
+ export async function getNodeInfo(rpcUrl: string, debugLogger: DebugLogger, log: LogFn) {
9
+ const client = await createCompatibleClient(rpcUrl, debugLogger);
10
+ const info = await client.getNodeInfo();
11
+ log(`\nNode Info:\n`);
12
+ log(`Sandbox Version: ${info.sandboxVersion}\n`);
13
+ log(`Compatible Nargo Version: ${info.compatibleNargoVersion}\n`);
14
+ log(`Chain Id: ${info.chainId}\n`);
15
+ log(`Protocol Version: ${info.protocolVersion}\n`);
16
+ log(`Rollup Address: ${info.l1ContractAddresses.rollupAddress.toString()}`);
17
+ }
@@ -0,0 +1,18 @@
1
+ import { AztecAddress } from '@aztec/aztec.js';
2
+ import { DebugLogger, LogFn } from '@aztec/foundation/log';
3
+
4
+ import { createCompatibleClient } from '../client.js';
5
+
6
+ /**
7
+ *
8
+ */
9
+ export async function getRecipient(aztecAddress: AztecAddress, rpcUrl: string, debugLogger: DebugLogger, log: LogFn) {
10
+ const client = await createCompatibleClient(rpcUrl, debugLogger);
11
+ const recipient = await client.getRecipient(aztecAddress);
12
+
13
+ if (!recipient) {
14
+ log(`Unknown recipient ${aztecAddress.toString()}`);
15
+ } else {
16
+ log(recipient.toReadableString());
17
+ }
18
+ }
@@ -0,0 +1,19 @@
1
+ import { DebugLogger, LogFn } from '@aztec/foundation/log';
2
+
3
+ import { createCompatibleClient } from '../client.js';
4
+
5
+ /**
6
+ *
7
+ */
8
+ export async function getRecipients(rpcUrl: string, debugLogger: DebugLogger, log: LogFn) {
9
+ const client = await createCompatibleClient(rpcUrl, debugLogger);
10
+ const recipients = await client.getRecipients();
11
+ if (!recipients.length) {
12
+ log('No recipients found.');
13
+ } else {
14
+ log(`Recipients found: \n`);
15
+ for (const recipient of recipients) {
16
+ log(recipient.toReadableString());
17
+ }
18
+ }
19
+ }
@@ -0,0 +1,18 @@
1
+ import { TxHash } from '@aztec/aztec.js';
2
+ import { JsonStringify } from '@aztec/foundation/json-rpc';
3
+ import { DebugLogger, LogFn } from '@aztec/foundation/log';
4
+
5
+ import { createCompatibleClient } from '../client.js';
6
+
7
+ /**
8
+ *
9
+ */
10
+ export async function getTxReceipt(rpcUrl: string, txHash: TxHash, debugLogger: DebugLogger, log: LogFn) {
11
+ const client = await createCompatibleClient(rpcUrl, debugLogger);
12
+ const receipt = await client.getTxReceipt(txHash);
13
+ if (!receipt) {
14
+ log(`No receipt found for transaction hash ${txHash.toString()}`);
15
+ } else {
16
+ log(`\nTransaction receipt: \n${JsonStringify(receipt, true)}\n`);
17
+ }
18
+ }
@@ -0,0 +1,29 @@
1
+ import {
2
+ FunctionSelector,
3
+ decodeFunctionSignature,
4
+ decodeFunctionSignatureWithParameterNames,
5
+ } from '@aztec/foundation/abi';
6
+ import { DebugLogger, LogFn } from '@aztec/foundation/log';
7
+
8
+ import { getContractArtifact } from '../utils.js';
9
+
10
+ /**
11
+ *
12
+ */
13
+ export async function inspectContract(contractArtifactFile: string, debugLogger: DebugLogger, log: LogFn) {
14
+ const contractArtifact = await getContractArtifact(contractArtifactFile, debugLogger);
15
+ const contractFns = contractArtifact.functions.filter(
16
+ f => !f.isInternal && f.name !== 'compute_note_hash_and_nullifier',
17
+ );
18
+ if (contractFns.length === 0) {
19
+ log(`No external functions found for contract ${contractArtifact.name}`);
20
+ }
21
+ for (const fn of contractFns) {
22
+ const signatureWithParameterNames = decodeFunctionSignatureWithParameterNames(fn.name, fn.parameters);
23
+ const signature = decodeFunctionSignature(fn.name, fn.parameters);
24
+ const selector = FunctionSelector.fromSignature(signature);
25
+ log(
26
+ `${fn.functionType} ${signatureWithParameterNames} \n\tfunction signature: ${signature}\n\tselector: ${selector}`,
27
+ );
28
+ }
29
+ }
@@ -0,0 +1,30 @@
1
+ import { StructType } from '@aztec/foundation/abi';
2
+ import { JsonStringify } from '@aztec/foundation/json-rpc';
3
+ import { LogFn } from '@aztec/foundation/log';
4
+
5
+ import { parseStructString } from '../encoding.js';
6
+ import { getContractArtifact } from '../utils.js';
7
+
8
+ /**
9
+ *
10
+ */
11
+ export async function parseParameterStruct(
12
+ encodedString: string,
13
+ contractArtifactPath: string,
14
+ parameterName: string,
15
+ log: LogFn,
16
+ ) {
17
+ const contractArtifact = await getContractArtifact(contractArtifactPath, log);
18
+ const parameterAbitype = contractArtifact.functions
19
+ .map(({ parameters }) => parameters)
20
+ .flat()
21
+ .find(({ name, type }) => name === parameterName && type.kind === 'struct');
22
+
23
+ if (!parameterAbitype) {
24
+ log(`No struct parameter found with name ${parameterName}`);
25
+ return;
26
+ }
27
+
28
+ const data = parseStructString(encodedString, parameterAbitype.type as StructType);
29
+ log(`\nStruct Data: \n${JsonStringify(data, true)}\n`);
30
+ }
@@ -0,0 +1,24 @@
1
+ import { Fq, Fr } from '@aztec/foundation/fields';
2
+ import { DebugLogger, LogFn } from '@aztec/foundation/log';
3
+
4
+ import { createCompatibleClient } from '../client.js';
5
+
6
+ /**
7
+ *
8
+ */
9
+ export async function registerAccount(
10
+ rpcUrl: string,
11
+ privateKey: Fq,
12
+ partialAddress: Fr,
13
+ debugLogger: DebugLogger,
14
+ log: LogFn,
15
+ ) {
16
+ const client = await createCompatibleClient(rpcUrl, debugLogger);
17
+
18
+ const { address, publicKey } = await client.registerAccount(privateKey, partialAddress);
19
+
20
+ log(`\nRegistered account:\n`);
21
+ log(`Address: ${address.toString()}`);
22
+ log(`Public key: ${publicKey.toString()}`);
23
+ log(`Partial address: ${partialAddress.toString()}`);
24
+ }
@@ -0,0 +1,21 @@
1
+ import { AztecAddress, Fr, Point } from '@aztec/aztec.js';
2
+ import { DebugLogger, LogFn } from '@aztec/foundation/log';
3
+ import { CompleteAddress } from '@aztec/types';
4
+
5
+ import { createCompatibleClient } from '../client.js';
6
+
7
+ /**
8
+ *
9
+ */
10
+ export async function registerRecipient(
11
+ aztecAddress: AztecAddress,
12
+ publicKey: Point,
13
+ partialAddress: Fr,
14
+ rpcUrl: string,
15
+ debugLogger: DebugLogger,
16
+ log: LogFn,
17
+ ) {
18
+ const client = await createCompatibleClient(rpcUrl, debugLogger);
19
+ await client.registerRecipient(CompleteAddress.create(aztecAddress, publicKey, partialAddress));
20
+ log(`\nRegistered details for account with address: ${aztecAddress}\n`);
21
+ }
@@ -0,0 +1,40 @@
1
+ import { AztecAddress, Contract, Fq, Fr, getSchnorrAccount } from '@aztec/aztec.js';
2
+ import { DebugLogger, LogFn } from '@aztec/foundation/log';
3
+
4
+ import { createCompatibleClient } from '../client.js';
5
+ import { prepTx } from '../utils.js';
6
+
7
+ /**
8
+ *
9
+ */
10
+ export async function send(
11
+ functionName: string,
12
+ functionArgsIn: any[],
13
+ contractArtifactPath: string,
14
+ contractAddress: AztecAddress,
15
+ privateKey: Fq,
16
+ rpcUrl: string,
17
+ wait: boolean,
18
+ debugLogger: DebugLogger,
19
+ log: LogFn,
20
+ ) {
21
+ const { functionArgs, contractArtifact } = await prepTx(contractArtifactPath, functionName, functionArgsIn, log);
22
+
23
+ const client = await createCompatibleClient(rpcUrl, debugLogger);
24
+ const wallet = await getSchnorrAccount(client, privateKey, privateKey, Fr.ZERO).getWallet();
25
+ const contract = await Contract.at(contractAddress, contractArtifact, wallet);
26
+ const tx = contract.methods[functionName](...functionArgs).send();
27
+ log(`\nTransaction hash: ${(await tx.getTxHash()).toString()}`);
28
+ if (wait) {
29
+ await tx.wait();
30
+
31
+ log('Transaction has been mined');
32
+
33
+ const receipt = await tx.getReceipt();
34
+ log(`Status: ${receipt.status}\n`);
35
+ log(`Block number: ${receipt.blockNumber}`);
36
+ log(`Block hash: ${receipt.blockHash?.toString('hex')}`);
37
+ } else {
38
+ log('Transaction pending. Check status with get-tx-receipt');
39
+ }
40
+ }
@@ -0,0 +1,11 @@
1
+ import { LogFn } from '@aztec/foundation/log';
2
+
3
+ import { unboxContract } from '../unbox.js';
4
+
5
+ /**
6
+ *
7
+ */
8
+ export async function unbox(contractName: string, localDirectory: string | undefined, cliVersion: string, log: LogFn) {
9
+ const unboxTo: string = localDirectory ? localDirectory : contractName;
10
+ await unboxContract(contractName, unboxTo, cliVersion, log);
11
+ }