@aztec-labs/cli 6.0.0-nightly.20260829
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.
- package/README.md +23 -0
- package/dest/cmds/aztec_node/block_number.d.ts +3 -0
- package/dest/cmds/aztec_node/block_number.d.ts.map +1 -0
- package/dest/cmds/aztec_node/block_number.js +10 -0
- package/dest/cmds/aztec_node/get_block.d.ts +3 -0
- package/dest/cmds/aztec_node/get_block.d.ts.map +1 -0
- package/dest/cmds/aztec_node/get_block.js +10 -0
- package/dest/cmds/aztec_node/get_current_min_fee.d.ts +3 -0
- package/dest/cmds/aztec_node/get_current_min_fee.d.ts.map +1 -0
- package/dest/cmds/aztec_node/get_current_min_fee.js +7 -0
- package/dest/cmds/aztec_node/get_l1_to_l2_message_witness.d.ts +5 -0
- package/dest/cmds/aztec_node/get_l1_to_l2_message_witness.d.ts.map +1 -0
- package/dest/cmds/aztec_node/get_l1_to_l2_message_witness.js +12 -0
- package/dest/cmds/aztec_node/get_logs.d.ts +33 -0
- package/dest/cmds/aztec_node/get_logs.d.ts.map +1 -0
- package/dest/cmds/aztec_node/get_logs.js +61 -0
- package/dest/cmds/aztec_node/get_node_info.d.ts +3 -0
- package/dest/cmds/aztec_node/get_node_info.d.ts.map +1 -0
- package/dest/cmds/aztec_node/get_node_info.js +58 -0
- package/dest/cmds/aztec_node/index.d.ts +4 -0
- package/dest/cmds/aztec_node/index.d.ts.map +1 -0
- package/dest/cmds/aztec_node/index.js +38 -0
- package/dest/cmds/infrastructure/index.d.ts +4 -0
- package/dest/cmds/infrastructure/index.d.ts.map +1 -0
- package/dest/cmds/infrastructure/index.js +22 -0
- package/dest/cmds/infrastructure/sequencers.d.ts +12 -0
- package/dest/cmds/infrastructure/sequencers.d.ts.map +1 -0
- package/dest/cmds/infrastructure/sequencers.js +113 -0
- package/dest/cmds/infrastructure/setup_l2_contract.d.ts +3 -0
- package/dest/cmds/infrastructure/setup_l2_contract.d.ts.map +1 -0
- package/dest/cmds/infrastructure/setup_l2_contract.js +35 -0
- package/dest/cmds/l1/advance_epoch.d.ts +3 -0
- package/dest/cmds/l1/advance_epoch.d.ts.map +1 -0
- package/dest/cmds/l1/advance_epoch.js +12 -0
- package/dest/cmds/l1/assume_proven_through.d.ts +4 -0
- package/dest/cmds/l1/assume_proven_through.d.ts.map +1 -0
- package/dest/cmds/l1/assume_proven_through.js +12 -0
- package/dest/cmds/l1/compute_genesis_values.d.ts +4 -0
- package/dest/cmds/l1/compute_genesis_values.d.ts.map +1 -0
- package/dest/cmds/l1/compute_genesis_values.js +17 -0
- package/dest/cmds/l1/create_l1_account.d.ts +3 -0
- package/dest/cmds/l1/create_l1_account.d.ts.map +1 -0
- package/dest/cmds/l1/create_l1_account.js +15 -0
- package/dest/cmds/l1/deploy_l1_contracts_cmd.d.ts +4 -0
- package/dest/cmds/l1/deploy_l1_contracts_cmd.d.ts.map +1 -0
- package/dest/cmds/l1/deploy_l1_contracts_cmd.js +80 -0
- package/dest/cmds/l1/deploy_new_rollup.d.ts +5 -0
- package/dest/cmds/l1/deploy_new_rollup.d.ts.map +1 -0
- package/dest/cmds/l1/deploy_new_rollup.js +26 -0
- package/dest/cmds/l1/get_l1_addresses.d.ts +4 -0
- package/dest/cmds/l1/get_l1_addresses.d.ts.map +1 -0
- package/dest/cmds/l1/get_l1_addresses.js +21 -0
- package/dest/cmds/l1/get_l1_balance.d.ts +4 -0
- package/dest/cmds/l1/get_l1_balance.d.ts.map +1 -0
- package/dest/cmds/l1/get_l1_balance.js +35 -0
- package/dest/cmds/l1/governance_utils.d.ts +50 -0
- package/dest/cmds/l1/governance_utils.d.ts.map +1 -0
- package/dest/cmds/l1/governance_utils.js +87 -0
- package/dest/cmds/l1/index.d.ts +4 -0
- package/dest/cmds/l1/index.d.ts.map +1 -0
- package/dest/cmds/l1/index.js +201 -0
- package/dest/cmds/l1/prover_stats.d.ts +14 -0
- package/dest/cmds/l1/prover_stats.d.ts.map +1 -0
- package/dest/cmds/l1/prover_stats.js +147 -0
- package/dest/cmds/l1/trigger_seed_snapshot.d.ts +6 -0
- package/dest/cmds/l1/trigger_seed_snapshot.d.ts.map +1 -0
- package/dest/cmds/l1/trigger_seed_snapshot.js +20 -0
- package/dest/cmds/l1/update_l1_validators.d.ts +45 -0
- package/dest/cmds/l1/update_l1_validators.d.ts.map +1 -0
- package/dest/cmds/l1/update_l1_validators.js +280 -0
- package/dest/cmds/misc/generate_bootnode_enr.d.ts +3 -0
- package/dest/cmds/misc/generate_bootnode_enr.d.ts.map +1 -0
- package/dest/cmds/misc/generate_bootnode_enr.js +5 -0
- package/dest/cmds/misc/generate_p2p_private_key.d.ts +3 -0
- package/dest/cmds/misc/generate_p2p_private_key.d.ts.map +1 -0
- package/dest/cmds/misc/generate_p2p_private_key.js +7 -0
- package/dest/cmds/misc/generate_secret_key.d.ts +5 -0
- package/dest/cmds/misc/generate_secret_key.d.ts.map +1 -0
- package/dest/cmds/misc/generate_secret_key.js +6 -0
- package/dest/cmds/misc/index.d.ts +4 -0
- package/dest/cmds/misc/index.d.ts.map +1 -0
- package/dest/cmds/misc/index.js +32 -0
- package/dest/cmds/misc/update/common.d.ts +17 -0
- package/dest/cmds/misc/update/common.d.ts.map +1 -0
- package/dest/cmds/misc/update/common.js +3 -0
- package/dest/cmds/misc/update/github.d.ts +3 -0
- package/dest/cmds/misc/update/github.d.ts.map +1 -0
- package/dest/cmds/misc/update/github.js +2 -0
- package/dest/cmds/misc/update/noir.d.ts +10 -0
- package/dest/cmds/misc/update/noir.d.ts.map +1 -0
- package/dest/cmds/misc/update/noir.js +45 -0
- package/dest/cmds/misc/update/npm.d.ts +34 -0
- package/dest/cmds/misc/update/npm.d.ts.map +1 -0
- package/dest/cmds/misc/update/npm.js +123 -0
- package/dest/cmds/misc/update/utils.d.ts +14 -0
- package/dest/cmds/misc/update/utils.d.ts.map +1 -0
- package/dest/cmds/misc/update/utils.js +38 -0
- package/dest/cmds/misc/update.d.ts +3 -0
- package/dest/cmds/misc/update.d.ts.map +1 -0
- package/dest/cmds/misc/update.js +51 -0
- package/dest/cmds/validator_keys/add.d.ts +5 -0
- package/dest/cmds/validator_keys/add.d.ts.map +1 -0
- package/dest/cmds/validator_keys/add.js +83 -0
- package/dest/cmds/validator_keys/eth_json_v3_worker.d.ts +2 -0
- package/dest/cmds/validator_keys/eth_json_v3_worker.d.ts.map +1 -0
- package/dest/cmds/validator_keys/eth_json_v3_worker.js +27 -0
- package/dest/cmds/validator_keys/generate_bls_keypair.d.ts +12 -0
- package/dest/cmds/validator_keys/generate_bls_keypair.d.ts.map +1 -0
- package/dest/cmds/validator_keys/generate_bls_keypair.js +27 -0
- package/dest/cmds/validator_keys/index.d.ts +4 -0
- package/dest/cmds/validator_keys/index.d.ts.map +1 -0
- package/dest/cmds/validator_keys/index.js +33 -0
- package/dest/cmds/validator_keys/new.d.ts +35 -0
- package/dest/cmds/validator_keys/new.d.ts.map +1 -0
- package/dest/cmds/validator_keys/new.js +220 -0
- package/dest/cmds/validator_keys/set_funding_account.d.ts +14 -0
- package/dest/cmds/validator_keys/set_funding_account.d.ts.map +1 -0
- package/dest/cmds/validator_keys/set_funding_account.js +37 -0
- package/dest/cmds/validator_keys/shared.d.ts +81 -0
- package/dest/cmds/validator_keys/shared.d.ts.map +1 -0
- package/dest/cmds/validator_keys/shared.js +352 -0
- package/dest/cmds/validator_keys/staker.d.ts +38 -0
- package/dest/cmds/validator_keys/staker.d.ts.map +1 -0
- package/dest/cmds/validator_keys/staker.js +210 -0
- package/dest/cmds/validator_keys/utils.d.ts +35 -0
- package/dest/cmds/validator_keys/utils.d.ts.map +1 -0
- package/dest/cmds/validator_keys/utils.js +86 -0
- package/dest/config/cached_fetch.d.ts +27 -0
- package/dest/config/cached_fetch.d.ts.map +1 -0
- package/dest/config/cached_fetch.js +132 -0
- package/dest/config/chain_l2_config.d.ts +19 -0
- package/dest/config/chain_l2_config.d.ts.map +1 -0
- package/dest/config/chain_l2_config.js +60 -0
- package/dest/config/enrich_env.d.ts +4 -0
- package/dest/config/enrich_env.d.ts.map +1 -0
- package/dest/config/enrich_env.js +12 -0
- package/dest/config/generated/networks.d.ts +236 -0
- package/dest/config/generated/networks.d.ts.map +1 -0
- package/dest/config/generated/networks.js +237 -0
- package/dest/config/get_l1_config.d.ts +9 -0
- package/dest/config/get_l1_config.d.ts.map +1 -0
- package/dest/config/get_l1_config.js +24 -0
- package/dest/config/index.d.ts +5 -0
- package/dest/config/index.d.ts.map +1 -0
- package/dest/config/index.js +4 -0
- package/dest/config/network_config.d.ts +22 -0
- package/dest/config/network_config.d.ts.map +1 -0
- package/dest/config/network_config.js +119 -0
- package/dest/utils/aztec.d.ts +56 -0
- package/dest/utils/aztec.d.ts.map +1 -0
- package/dest/utils/aztec.js +161 -0
- package/dest/utils/commands.d.ts +161 -0
- package/dest/utils/commands.d.ts.map +1 -0
- package/dest/utils/commands.js +341 -0
- package/dest/utils/encoding.d.ts +15 -0
- package/dest/utils/encoding.d.ts.map +1 -0
- package/dest/utils/encoding.js +103 -0
- package/dest/utils/github.d.ts +3 -0
- package/dest/utils/github.d.ts.map +1 -0
- package/dest/utils/github.js +2 -0
- package/dest/utils/index.d.ts +6 -0
- package/dest/utils/index.d.ts.map +1 -0
- package/dest/utils/index.js +5 -0
- package/dest/utils/inspect.d.ts +11 -0
- package/dest/utils/inspect.d.ts.map +1 -0
- package/dest/utils/inspect.js +90 -0
- package/dest/utils/setup_contracts.d.ts +3 -0
- package/dest/utils/setup_contracts.d.ts.map +1 -0
- package/dest/utils/setup_contracts.js +16 -0
- package/package.json +141 -0
- package/public_include_metric_prefixes.json +1 -0
- package/src/cmds/aztec_node/block_number.ts +9 -0
- package/src/cmds/aztec_node/get_block.ts +11 -0
- package/src/cmds/aztec_node/get_current_min_fee.ts +9 -0
- package/src/cmds/aztec_node/get_l1_to_l2_message_witness.ts +27 -0
- package/src/cmds/aztec_node/get_logs.ts +100 -0
- package/src/cmds/aztec_node/get_node_info.ts +61 -0
- package/src/cmds/aztec_node/index.ts +91 -0
- package/src/cmds/infrastructure/index.ts +51 -0
- package/src/cmds/infrastructure/sequencers.ts +122 -0
- package/src/cmds/infrastructure/setup_l2_contract.ts +40 -0
- package/src/cmds/l1/advance_epoch.ts +14 -0
- package/src/cmds/l1/assume_proven_through.ts +20 -0
- package/src/cmds/l1/compute_genesis_values.ts +29 -0
- package/src/cmds/l1/create_l1_account.ts +16 -0
- package/src/cmds/l1/deploy_l1_contracts_cmd.ts +105 -0
- package/src/cmds/l1/deploy_new_rollup.ts +65 -0
- package/src/cmds/l1/get_l1_addresses.ts +31 -0
- package/src/cmds/l1/get_l1_balance.ts +44 -0
- package/src/cmds/l1/governance_utils.ts +183 -0
- package/src/cmds/l1/index.ts +499 -0
- package/src/cmds/l1/prover_stats.ts +213 -0
- package/src/cmds/l1/trigger_seed_snapshot.ts +32 -0
- package/src/cmds/l1/update_l1_validators.ts +358 -0
- package/src/cmds/misc/generate_bootnode_enr.ts +13 -0
- package/src/cmds/misc/generate_p2p_private_key.ts +9 -0
- package/src/cmds/misc/generate_secret_key.ts +5 -0
- package/src/cmds/misc/index.ts +67 -0
- package/src/cmds/misc/update/common.ts +16 -0
- package/src/cmds/misc/update/github.ts +2 -0
- package/src/cmds/misc/update/noir.ts +56 -0
- package/src/cmds/misc/update/npm.ts +148 -0
- package/src/cmds/misc/update/utils.ts +49 -0
- package/src/cmds/misc/update.ts +71 -0
- package/src/cmds/validator_keys/add.ts +122 -0
- package/src/cmds/validator_keys/eth_json_v3_worker.ts +30 -0
- package/src/cmds/validator_keys/generate_bls_keypair.ts +33 -0
- package/src/cmds/validator_keys/index.ts +181 -0
- package/src/cmds/validator_keys/new.ts +326 -0
- package/src/cmds/validator_keys/set_funding_account.ts +54 -0
- package/src/cmds/validator_keys/shared.ts +414 -0
- package/src/cmds/validator_keys/staker.ts +300 -0
- package/src/cmds/validator_keys/utils.ts +124 -0
- package/src/config/cached_fetch.ts +154 -0
- package/src/config/chain_l2_config.ts +71 -0
- package/src/config/enrich_env.ts +15 -0
- package/src/config/generated/networks.ts +241 -0
- package/src/config/get_l1_config.ts +31 -0
- package/src/config/index.ts +4 -0
- package/src/config/network_config.ts +150 -0
- package/src/utils/aztec.ts +203 -0
- package/src/utils/commands.ts +434 -0
- package/src/utils/encoding.ts +117 -0
- package/src/utils/github.ts +2 -0
- package/src/utils/index.ts +5 -0
- package/src/utils/inspect.ts +111 -0
- package/src/utils/setup_contracts.ts +19 -0
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
import { Fr } from '@aztec-labs/foundation/curves/bn254';
|
|
2
|
+
import { GrumpkinScalar } from '@aztec-labs/foundation/curves/grumpkin';
|
|
3
|
+
import { EthAddress } from '@aztec-labs/foundation/eth-address';
|
|
4
|
+
import type { LogFn } from '@aztec-labs/foundation/log';
|
|
5
|
+
import type { PXE } from '@aztec-labs/pxe/server';
|
|
6
|
+
import { FunctionSelector } from '@aztec-labs/stdlib/abi/function-selector';
|
|
7
|
+
import { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
|
|
8
|
+
import { PublicKeys } from '@aztec-labs/stdlib/keys';
|
|
9
|
+
import { LogCursor, Tag } from '@aztec-labs/stdlib/logs';
|
|
10
|
+
import { TxHash } from '@aztec-labs/stdlib/tx/tx-hash';
|
|
11
|
+
import { type Command, CommanderError, InvalidArgumentError, Option } from 'commander';
|
|
12
|
+
import { lookup } from 'dns/promises';
|
|
13
|
+
import { rename, writeFile } from 'fs/promises';
|
|
14
|
+
|
|
15
|
+
export { LogCursor };
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* If we can successfully resolve 'host.docker.internal', then we are running in a container, and we should treat
|
|
19
|
+
* localhost as being host.docker.internal.
|
|
20
|
+
*/
|
|
21
|
+
export const getLocalhost = () =>
|
|
22
|
+
lookup('host.docker.internal')
|
|
23
|
+
.then(() => 'host.docker.internal')
|
|
24
|
+
.catch(() => 'localhost');
|
|
25
|
+
|
|
26
|
+
export const LOCALHOST = await getLocalhost();
|
|
27
|
+
export const { ETHEREUM_HOSTS = `http://${LOCALHOST}:8545`, PRIVATE_KEY, MNEMONIC, API_KEY, CLI_VERSION } = process.env;
|
|
28
|
+
|
|
29
|
+
export function addOptions(program: Command, options: Option[]) {
|
|
30
|
+
options.forEach(option => program.addOption(option));
|
|
31
|
+
return program;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const makeNodeOption = (mandatory: boolean) =>
|
|
35
|
+
new Option('-n, --node-url <string>', 'URL of the Aztec node')
|
|
36
|
+
.env('AZTEC_NODE_URL')
|
|
37
|
+
.default(`http://${LOCALHOST}:8080`)
|
|
38
|
+
.makeOptionMandatory(mandatory);
|
|
39
|
+
|
|
40
|
+
export const nodeOption = makeNodeOption(true);
|
|
41
|
+
|
|
42
|
+
export const l1ChainIdOption = new Option('-c, --l1-chain-id <number>', 'Chain ID of the ethereum host')
|
|
43
|
+
.env('L1_CHAIN_ID')
|
|
44
|
+
.default(31337)
|
|
45
|
+
.argParser(value => {
|
|
46
|
+
const parsedValue = Number(value);
|
|
47
|
+
if (isNaN(parsedValue)) {
|
|
48
|
+
throw new Error('Chain ID must be a number.');
|
|
49
|
+
}
|
|
50
|
+
return parsedValue;
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
export const createSigningKeyOption = (
|
|
54
|
+
description: string,
|
|
55
|
+
mandatory: boolean,
|
|
56
|
+
argsParser?: (value: string, previous: GrumpkinScalar) => GrumpkinScalar,
|
|
57
|
+
) =>
|
|
58
|
+
new Option('-sk, --signing-key <string>', description)
|
|
59
|
+
.env('SIGNING_KEY')
|
|
60
|
+
.argParser(argsParser ?? parseSigningKey)
|
|
61
|
+
.makeOptionMandatory(mandatory);
|
|
62
|
+
|
|
63
|
+
export const logJson = (log: LogFn) => (obj: object) => log(JSON.stringify(obj, null, 2));
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Updates a file in place atomically.
|
|
67
|
+
* @param filePath - Path to file
|
|
68
|
+
* @param contents - New contents to write
|
|
69
|
+
*/
|
|
70
|
+
export async function atomicUpdateFile(filePath: string, contents: string) {
|
|
71
|
+
const tmpFilepath = filePath + '.tmp';
|
|
72
|
+
try {
|
|
73
|
+
await writeFile(tmpFilepath, contents, {
|
|
74
|
+
// let's crash if the tmp file already exists
|
|
75
|
+
flag: 'wx',
|
|
76
|
+
});
|
|
77
|
+
await rename(tmpFilepath, filePath);
|
|
78
|
+
} catch (e) {
|
|
79
|
+
if (e instanceof Error && 'code' in e && e.code === 'EEXIST') {
|
|
80
|
+
const commanderError = new CommanderError(
|
|
81
|
+
1,
|
|
82
|
+
e.code,
|
|
83
|
+
`Temporary file already exists: ${tmpFilepath}. Delete this file and try again.`,
|
|
84
|
+
);
|
|
85
|
+
commanderError.nestedError = e.message;
|
|
86
|
+
throw commanderError;
|
|
87
|
+
} else {
|
|
88
|
+
throw e;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Utility to select a TX sender either from user input
|
|
95
|
+
* or from the first account that is found in a PXE instance.
|
|
96
|
+
* @param pxe - The PXE instance that will be checked for an account.
|
|
97
|
+
* @param _from - The user input.
|
|
98
|
+
* @returns An Aztec address. Will throw if one can't be found in either options.
|
|
99
|
+
*/
|
|
100
|
+
export async function getTxSender(pxe: PXE, _from?: string) {
|
|
101
|
+
let from: AztecAddress;
|
|
102
|
+
if (_from) {
|
|
103
|
+
try {
|
|
104
|
+
from = AztecAddress.fromStringUnsafe(_from);
|
|
105
|
+
} catch {
|
|
106
|
+
throw new InvalidArgumentError(`Invalid option 'from' passed: ${_from}`);
|
|
107
|
+
}
|
|
108
|
+
} else {
|
|
109
|
+
const accounts = await pxe.getRegisteredAccounts();
|
|
110
|
+
if (!accounts.length) {
|
|
111
|
+
throw new Error('No accounts found in PXE instance.');
|
|
112
|
+
}
|
|
113
|
+
from = accounts[0].address;
|
|
114
|
+
}
|
|
115
|
+
return from;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Parses and validates a hex string. Removes leading 0x if present, checks for hex validity,
|
|
120
|
+
* and enforces an optional minimum length.
|
|
121
|
+
* @param hex - The hex string to validate.
|
|
122
|
+
* @param minLen - Optional minimum length (in hex characters, after stripping '0x').
|
|
123
|
+
* @returns The normalized hex string (without leading 0x).
|
|
124
|
+
* @throws InvalidArgumentError if the string is not valid hex or does not meet the minimum length.
|
|
125
|
+
*/
|
|
126
|
+
// minLen is now interpreted as the minimum number of bytes (2 hex characters per byte)
|
|
127
|
+
export function parseHex(hex: string, minLen?: number): `0x${string}` {
|
|
128
|
+
const normalized = hex.startsWith('0x') ? hex.slice(2) : hex;
|
|
129
|
+
|
|
130
|
+
if (!/^[0-9a-fA-F]*$/.test(normalized)) {
|
|
131
|
+
throw new InvalidArgumentError('Invalid hex string');
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (minLen !== undefined) {
|
|
135
|
+
const minHexLen = minLen * 2;
|
|
136
|
+
if (normalized.length < minHexLen) {
|
|
137
|
+
throw new InvalidArgumentError(
|
|
138
|
+
`Hex string is too short (length ${normalized.length}), minimum byte length is ${minLen} (hex chars: ${minHexLen})`,
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return `0x${normalized}`;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Removes the leading 0x from a hex string. If no leading 0x is found the string is returned unchanged.
|
|
148
|
+
* @param hex - A hex string
|
|
149
|
+
* @returns A new string with leading 0x removed
|
|
150
|
+
*/
|
|
151
|
+
const stripLeadingHex = (hex: string) => {
|
|
152
|
+
if (hex.length > 2 && hex.startsWith('0x')) {
|
|
153
|
+
return hex.substring(2);
|
|
154
|
+
}
|
|
155
|
+
return hex;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
export function parseBigint(bigint: string): bigint | undefined {
|
|
159
|
+
return bigint ? BigInt(bigint) : undefined;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Parses a hex encoded string to an Fr integer
|
|
164
|
+
* @param str - Hex encoded string
|
|
165
|
+
* @returns A integer
|
|
166
|
+
*/
|
|
167
|
+
export function parseFieldFromHexString(str: string): Fr {
|
|
168
|
+
const hex = stripLeadingHex(str);
|
|
169
|
+
|
|
170
|
+
// ensure it's a hex string
|
|
171
|
+
if (!hex.match(/^[0-9a-f]+$/i)) {
|
|
172
|
+
throw new InvalidArgumentError('Invalid hex string');
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// pad it so that we may read it as a buffer.
|
|
176
|
+
// Buffer needs _exactly_ two hex characters per byte
|
|
177
|
+
const padded = hex.length % 2 === 1 ? '0' + hex : hex;
|
|
178
|
+
let buf = Buffer.from(padded, 'hex');
|
|
179
|
+
if (buf.length > Fr.SIZE_IN_BYTES) {
|
|
180
|
+
buf = buf.subarray(buf.length - Fr.SIZE_IN_BYTES);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const fr = Buffer.alloc(Fr.SIZE_IN_BYTES, 0);
|
|
184
|
+
fr.set(buf, Fr.SIZE_IN_BYTES - buf.length);
|
|
185
|
+
|
|
186
|
+
// finally, turn it into an integer
|
|
187
|
+
return Fr.fromBuffer(fr);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Parses an AztecAddress from a string.
|
|
192
|
+
* @param address - A serialized Aztec address
|
|
193
|
+
* @returns An Aztec address
|
|
194
|
+
* @throws InvalidArgumentError if the input string is not valid.
|
|
195
|
+
*/
|
|
196
|
+
export function parseAztecAddress(address: string): AztecAddress {
|
|
197
|
+
try {
|
|
198
|
+
return AztecAddress.fromStringUnsafe(address);
|
|
199
|
+
} catch {
|
|
200
|
+
throw new InvalidArgumentError(`Invalid Aztec address: ${address}`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Parses an Ethereum address from a string.
|
|
206
|
+
* @param address - A serialized Ethereum address
|
|
207
|
+
* @returns An Ethereum address
|
|
208
|
+
* @throws InvalidArgumentError if the input string is not valid.
|
|
209
|
+
*/
|
|
210
|
+
export function parseEthereumAddress(address: string): EthAddress {
|
|
211
|
+
try {
|
|
212
|
+
return EthAddress.fromString(address);
|
|
213
|
+
} catch {
|
|
214
|
+
throw new InvalidArgumentError(`Invalid Ethereumaddress: ${address}`);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Parses an AztecAddress from a string.
|
|
220
|
+
* @param address - A serialized Aztec address
|
|
221
|
+
* @returns An Aztec address
|
|
222
|
+
* @throws InvalidArgumentError if the input string is not valid.
|
|
223
|
+
*/
|
|
224
|
+
export function parseOptionalAztecAddress(address: string): AztecAddress | undefined {
|
|
225
|
+
if (!address) {
|
|
226
|
+
return undefined;
|
|
227
|
+
}
|
|
228
|
+
return parseAztecAddress(address);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Parses an optional `<blockNumber>-<txIndexWithinBlock>-<logIndexWithinTx>` triple into a {@link LogCursor},
|
|
233
|
+
* used as the `--after-log` argument of `get-logs` to resume pagination strictly after a previously-seen log.
|
|
234
|
+
* Thin wrapper over {@link LogCursor.parseOptional} that surfaces parse errors as commander's
|
|
235
|
+
* {@link InvalidArgumentError}.
|
|
236
|
+
*/
|
|
237
|
+
export function parseOptionalLogCursor(value: string): LogCursor | undefined {
|
|
238
|
+
try {
|
|
239
|
+
return LogCursor.parseOptional(value);
|
|
240
|
+
} catch (err) {
|
|
241
|
+
throw new InvalidArgumentError(err instanceof Error ? err.message : String(err));
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Parses a log tag from a string. Tags are field-element values; we delegate to the {@link parseField} parser.
|
|
247
|
+
*
|
|
248
|
+
* @param tag - A hex string, integer, or boolean string representing the tag.
|
|
249
|
+
* @returns A {@link Tag} wrapping the parsed field.
|
|
250
|
+
*/
|
|
251
|
+
export function parseTag(tag: string): Tag {
|
|
252
|
+
return new Tag(parseField(tag));
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Parses a selector from a string.
|
|
257
|
+
* @param selector - A serialized selector.
|
|
258
|
+
* @returns A selector.
|
|
259
|
+
* @throws InvalidArgumentError if the input string is not valid.
|
|
260
|
+
*/
|
|
261
|
+
export function parseOptionalSelector(selector: string): FunctionSelector | undefined {
|
|
262
|
+
if (!selector) {
|
|
263
|
+
return undefined;
|
|
264
|
+
}
|
|
265
|
+
try {
|
|
266
|
+
return FunctionSelector.fromString(selector);
|
|
267
|
+
} catch {
|
|
268
|
+
throw new InvalidArgumentError(`Invalid selector: ${selector}`);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Parses a string into an integer or returns undefined if the input is falsy.
|
|
274
|
+
*
|
|
275
|
+
* @param value - The string to parse into an integer.
|
|
276
|
+
* @returns The parsed integer, or undefined if the input string is falsy.
|
|
277
|
+
* @throws If the input is not a valid integer.
|
|
278
|
+
*/
|
|
279
|
+
export function parseOptionalInteger(
|
|
280
|
+
value: string,
|
|
281
|
+
min: number = Number.MIN_SAFE_INTEGER,
|
|
282
|
+
max: number = Number.MAX_SAFE_INTEGER,
|
|
283
|
+
): number | undefined {
|
|
284
|
+
if (!value) {
|
|
285
|
+
return undefined;
|
|
286
|
+
}
|
|
287
|
+
const parsed = Number(value);
|
|
288
|
+
if (!Number.isInteger(parsed)) {
|
|
289
|
+
throw new InvalidArgumentError('Invalid integer.');
|
|
290
|
+
}
|
|
291
|
+
if (parsed < min) {
|
|
292
|
+
throw new InvalidArgumentError(`Value must be greater than ${min}.`);
|
|
293
|
+
}
|
|
294
|
+
if (parsed > max) {
|
|
295
|
+
throw new InvalidArgumentError(`Value must be less than ${max}.`);
|
|
296
|
+
}
|
|
297
|
+
return parsed;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Parses a TxHash from a string.
|
|
302
|
+
* @param txHash - A transaction hash
|
|
303
|
+
* @returns A TxHash instance
|
|
304
|
+
* @throws InvalidArgumentError if the input string is not valid.
|
|
305
|
+
*/
|
|
306
|
+
export function parseTxHash(txHash: string): TxHash {
|
|
307
|
+
try {
|
|
308
|
+
return TxHash.fromString(txHash);
|
|
309
|
+
} catch {
|
|
310
|
+
throw new InvalidArgumentError(`Invalid transaction hash: ${txHash}`);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Parses an optional TxHash from a string.
|
|
316
|
+
* Calls parseTxHash internally.
|
|
317
|
+
* @param txHash - A transaction hash
|
|
318
|
+
* @returns A TxHash instance, or undefined if the input string is falsy.
|
|
319
|
+
* @throws InvalidArgumentError if the input string is not valid.
|
|
320
|
+
*/
|
|
321
|
+
export function parseOptionalTxHash(txHash: string): TxHash | undefined {
|
|
322
|
+
if (!txHash) {
|
|
323
|
+
return undefined;
|
|
324
|
+
}
|
|
325
|
+
return parseTxHash(txHash);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Parses a public key from a string.
|
|
330
|
+
* @param publicKey - A public keys object serialised as a string
|
|
331
|
+
* @returns A PublicKeys instance
|
|
332
|
+
* @throws InvalidArgumentError if the input string is not valid.
|
|
333
|
+
*/
|
|
334
|
+
export function parsePublicKey(publicKey: string): PublicKeys | undefined {
|
|
335
|
+
if (!publicKey) {
|
|
336
|
+
return undefined;
|
|
337
|
+
}
|
|
338
|
+
try {
|
|
339
|
+
return PublicKeys.fromString(publicKey);
|
|
340
|
+
} catch {
|
|
341
|
+
throw new InvalidArgumentError(`Invalid public key: ${publicKey}`);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Parses a partial address from a string.
|
|
347
|
+
* @param address - A partial address
|
|
348
|
+
* @returns A Fr instance
|
|
349
|
+
* @throws InvalidArgumentError if the input string is not valid.
|
|
350
|
+
*/
|
|
351
|
+
export function parsePartialAddress(address: string): Fr {
|
|
352
|
+
try {
|
|
353
|
+
return Fr.fromHexString(address);
|
|
354
|
+
} catch {
|
|
355
|
+
throw new InvalidArgumentError(`Invalid partial address: ${address}`);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Parses an account signing key from a string.
|
|
361
|
+
* @param signingKey - A string
|
|
362
|
+
* @returns A signing key
|
|
363
|
+
* @throws InvalidArgumentError if the input string is not valid.
|
|
364
|
+
*/
|
|
365
|
+
export function parseSigningKey(signingKey: string): GrumpkinScalar {
|
|
366
|
+
try {
|
|
367
|
+
return GrumpkinScalar.fromHexString(signingKey);
|
|
368
|
+
} catch {
|
|
369
|
+
throw new InvalidArgumentError(`Invalid signing key: ${signingKey}`);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* Parses a field from a string.
|
|
375
|
+
* @param field - A string representing the field.
|
|
376
|
+
* @returns A field.
|
|
377
|
+
* @throws InvalidArgumentError if the input string is not valid.
|
|
378
|
+
*/
|
|
379
|
+
export function parseField(field: string): Fr {
|
|
380
|
+
try {
|
|
381
|
+
const isHex = field.startsWith('0x') || field.match(new RegExp(`^[0-9a-f]{${Fr.SIZE_IN_BYTES * 2}}$`, 'i'));
|
|
382
|
+
if (isHex) {
|
|
383
|
+
return Fr.fromHexString(field);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
if (['true', 'false'].includes(field)) {
|
|
387
|
+
return new Fr(field === 'true');
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
const isNumber = +field || field === '0';
|
|
391
|
+
if (isNumber) {
|
|
392
|
+
return new Fr(BigInt(field));
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
const isBigInt = field.endsWith('n');
|
|
396
|
+
if (isBigInt) {
|
|
397
|
+
return new Fr(BigInt(field.replace(/n$/, '')));
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
return new Fr(BigInt(field));
|
|
401
|
+
} catch {
|
|
402
|
+
throw new InvalidArgumentError(`Invalid field: ${field}`);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* Parses an array of strings to Frs.
|
|
408
|
+
* @param fields - An array of strings representing the fields.
|
|
409
|
+
* @returns An array of Frs.
|
|
410
|
+
*/
|
|
411
|
+
export function parseFields(fields: string[]): Fr[] {
|
|
412
|
+
return fields.map(parseField);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Pretty prints an object as JSON
|
|
417
|
+
* @param data - The object to stringify
|
|
418
|
+
* @returns A JSON string
|
|
419
|
+
*/
|
|
420
|
+
export function prettyPrintJSON(data: Record<string, any>): string {
|
|
421
|
+
return JSON.stringify(
|
|
422
|
+
data,
|
|
423
|
+
(_key, val) => {
|
|
424
|
+
if (typeof val === 'bigint') {
|
|
425
|
+
return String(val);
|
|
426
|
+
} else if (val && typeof val === 'object' && 'toBuffer' in val) {
|
|
427
|
+
return '0x' + val.toBuffer().toString('hex');
|
|
428
|
+
} else {
|
|
429
|
+
return val;
|
|
430
|
+
}
|
|
431
|
+
},
|
|
432
|
+
2,
|
|
433
|
+
);
|
|
434
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { Fr } from '@aztec-labs/foundation/curves/bn254';
|
|
2
|
+
import type { ABIParameter, AbiType, StructType } from '@aztec-labs/stdlib/abi';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Parses a hex string into an ABI struct type.
|
|
6
|
+
* @param str - The encoded hex string.
|
|
7
|
+
* @param abiType - The ABI Struct type.
|
|
8
|
+
* @returns An object in the ABI struct type's format.
|
|
9
|
+
*/
|
|
10
|
+
export function parseStructString(str: string, abiType: StructType) {
|
|
11
|
+
// Assign string bytes to struct fields.
|
|
12
|
+
const buf = Buffer.from(str.replace(/^0x/i, ''), 'hex');
|
|
13
|
+
const struct: any = {};
|
|
14
|
+
let byteIndex = 0;
|
|
15
|
+
let argIndex = 0;
|
|
16
|
+
while (byteIndex < buf.length) {
|
|
17
|
+
const { name } = abiType.fields[argIndex];
|
|
18
|
+
struct[name] = Fr.fromBuffer(buf.subarray(byteIndex, byteIndex + 32));
|
|
19
|
+
byteIndex += 32;
|
|
20
|
+
argIndex += 1;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return struct;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Helper function to encode CLI string args to an appropriate JS type.
|
|
28
|
+
* @param arg - The CLI argument.
|
|
29
|
+
* @param abiType - The type as described by the contract's ABI.
|
|
30
|
+
* @returns The encoded argument.
|
|
31
|
+
*/
|
|
32
|
+
function encodeArg(arg: string, abiType: AbiType, name: string): any {
|
|
33
|
+
const { kind } = abiType;
|
|
34
|
+
if (kind === 'field' || kind === 'integer') {
|
|
35
|
+
let res: bigint;
|
|
36
|
+
try {
|
|
37
|
+
res = BigInt(arg);
|
|
38
|
+
} catch {
|
|
39
|
+
throw new Error(
|
|
40
|
+
`Invalid value passed for ${name}. Could not parse ${arg} as a${kind === 'integer' ? 'n' : ''} ${kind}.`,
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
return res;
|
|
44
|
+
} else if (kind === 'boolean') {
|
|
45
|
+
if (arg === 'true') {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
if (arg === 'false') {
|
|
49
|
+
return false;
|
|
50
|
+
} else {
|
|
51
|
+
throw Error(`Invalid boolean value passed for ${name}: ${arg}.`);
|
|
52
|
+
}
|
|
53
|
+
} else if (kind === 'string') {
|
|
54
|
+
return arg;
|
|
55
|
+
} else if (kind === 'array') {
|
|
56
|
+
let arr;
|
|
57
|
+
const res = [];
|
|
58
|
+
try {
|
|
59
|
+
arr = JSON.parse(arg);
|
|
60
|
+
} catch {
|
|
61
|
+
throw new Error(`Unable to parse arg ${arg} as array for ${name} parameter`);
|
|
62
|
+
}
|
|
63
|
+
if (!Array.isArray(arr)) {
|
|
64
|
+
throw Error(`Invalid argument ${arg} passed for array parameter ${name}.`);
|
|
65
|
+
}
|
|
66
|
+
if (arr.length !== abiType.length) {
|
|
67
|
+
throw Error(`Invalid array length passed for ${name}. Expected ${abiType.length}, received ${arr.length}.`);
|
|
68
|
+
}
|
|
69
|
+
for (let i = 0; i < abiType.length; i += 1) {
|
|
70
|
+
res.push(encodeArg(arr[i], abiType.type, name));
|
|
71
|
+
}
|
|
72
|
+
return res;
|
|
73
|
+
} else if (kind === 'struct') {
|
|
74
|
+
// check if input is encoded long string
|
|
75
|
+
if (arg.startsWith('0x')) {
|
|
76
|
+
return parseStructString(arg, abiType);
|
|
77
|
+
}
|
|
78
|
+
let obj;
|
|
79
|
+
try {
|
|
80
|
+
obj = JSON.parse(arg);
|
|
81
|
+
} catch {
|
|
82
|
+
throw new Error(`Unable to parse arg ${arg} as struct`);
|
|
83
|
+
}
|
|
84
|
+
if (Array.isArray(obj)) {
|
|
85
|
+
throw Error(`Array passed for arg ${name}. Expected a struct.`);
|
|
86
|
+
}
|
|
87
|
+
const res: any = {};
|
|
88
|
+
for (const field of abiType.fields) {
|
|
89
|
+
// Remove field name from list as it's present
|
|
90
|
+
const arg = obj[field.name];
|
|
91
|
+
if (!arg) {
|
|
92
|
+
throw Error(`Expected field ${field.name} not found in struct ${name}.`);
|
|
93
|
+
}
|
|
94
|
+
res[field.name] = encodeArg(obj[field.name], field.type, field.name);
|
|
95
|
+
}
|
|
96
|
+
return res;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Tries to encode function args to their equivalent TS type.
|
|
102
|
+
* @param args - An array of function's / constructor's args.
|
|
103
|
+
* @returns The encoded array.
|
|
104
|
+
*/
|
|
105
|
+
export function encodeArgs(args: any[], params: ABIParameter[]) {
|
|
106
|
+
if (args.length !== params.length) {
|
|
107
|
+
throw new Error(
|
|
108
|
+
`Invalid args provided.\nExpected args: [${params
|
|
109
|
+
.map(param => param.name + ': ' + param.type.kind)
|
|
110
|
+
.join(', ')}]\nReceived args: ${args.join(', ')}`,
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
return args.map((arg: any, index) => {
|
|
114
|
+
const { type, name } = params[index];
|
|
115
|
+
return encodeArg(arg, type, name);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { BlockNumber } from '@aztec-labs/foundation/branded-types';
|
|
2
|
+
import type { LogFn } from '@aztec-labs/foundation/log';
|
|
3
|
+
import type { AztecNode } from '@aztec-labs/stdlib/interfaces/client';
|
|
4
|
+
import type { TxHash } from '@aztec-labs/stdlib/tx';
|
|
5
|
+
|
|
6
|
+
export async function inspectBlock(
|
|
7
|
+
aztecNode: AztecNode,
|
|
8
|
+
blockNumber: BlockNumber,
|
|
9
|
+
log: LogFn,
|
|
10
|
+
opts: { showTxs?: boolean } = {},
|
|
11
|
+
) {
|
|
12
|
+
const block = await aztecNode.getBlock(blockNumber, { includeTransactions: opts.showTxs });
|
|
13
|
+
if (!block) {
|
|
14
|
+
log(`No block found for block number ${blockNumber}`);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
log(`Block ${blockNumber} (${block.hash.toString()})`);
|
|
19
|
+
log(` Total fees: ${block.header.totalFees.toBigInt()}`);
|
|
20
|
+
log(` Total mana used: ${block.header.totalManaUsed.toBigInt()}`);
|
|
21
|
+
log(
|
|
22
|
+
` Fee per gas unit: DA=${block.header.globalVariables.gasFees.feePerDaGas} L2=${block.header.globalVariables.gasFees.feePerL2Gas}`,
|
|
23
|
+
);
|
|
24
|
+
log(` Coinbase: ${block.header.globalVariables.coinbase}`);
|
|
25
|
+
log(` Fee recipient: ${block.header.globalVariables.feeRecipient}`);
|
|
26
|
+
log(` Timestamp: ${new Date(Number(block.header.globalVariables.timestamp) * 500)}`);
|
|
27
|
+
if (opts.showTxs && block.body) {
|
|
28
|
+
log(``);
|
|
29
|
+
for (const txHash of block.body.txEffects.map(tx => tx.txHash)) {
|
|
30
|
+
await inspectTx(aztecNode, txHash, log, { includeBlockInfo: false });
|
|
31
|
+
}
|
|
32
|
+
} else if (block.body) {
|
|
33
|
+
log(` Transactions: ${block.body.txEffects.length}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export async function inspectTx(
|
|
38
|
+
aztecNode: AztecNode,
|
|
39
|
+
txHash: TxHash,
|
|
40
|
+
log: LogFn,
|
|
41
|
+
opts: { includeBlockInfo?: boolean } = {},
|
|
42
|
+
) {
|
|
43
|
+
const receipt = await aztecNode.getTxReceipt(txHash, { includeTxEffect: true });
|
|
44
|
+
// Base tx data
|
|
45
|
+
log(`Tx ${txHash.toString()}`);
|
|
46
|
+
log(` Status: ${receipt.status}`);
|
|
47
|
+
if (receipt.executionResult) {
|
|
48
|
+
log(` Execution result: ${receipt.executionResult}`);
|
|
49
|
+
}
|
|
50
|
+
if (receipt.error) {
|
|
51
|
+
log(` Error: ${receipt.error}`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (!receipt.isMined() || !receipt.txEffect) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const effects = receipt.txEffect;
|
|
59
|
+
|
|
60
|
+
if (opts.includeBlockInfo) {
|
|
61
|
+
log(` Block: ${receipt.blockNumber} (${receipt.blockHash?.toString()})`);
|
|
62
|
+
}
|
|
63
|
+
if (receipt.transactionFee) {
|
|
64
|
+
log(` Fee: ${receipt.transactionFee.toString()}`);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Public logs
|
|
68
|
+
const publicLogs = effects.publicLogs;
|
|
69
|
+
if (publicLogs.length > 0) {
|
|
70
|
+
log(' Logs:');
|
|
71
|
+
for (const publicLog of publicLogs) {
|
|
72
|
+
log(` ${publicLog.toHumanReadable()}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Public data writes
|
|
77
|
+
const writes = effects.publicDataWrites;
|
|
78
|
+
if (writes.length > 0) {
|
|
79
|
+
log(' Public data writes:');
|
|
80
|
+
for (const write of writes) {
|
|
81
|
+
log(` Leaf ${write.leafSlot.toString()} = ${write.value.toString()}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Created notes
|
|
86
|
+
const notes = effects.noteHashes;
|
|
87
|
+
if (notes.length > 0) {
|
|
88
|
+
log(' Created notes:');
|
|
89
|
+
log(` Total: ${notes.length}`);
|
|
90
|
+
for (const note of notes) {
|
|
91
|
+
log(` Note hash: ${note.toShortString()}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Created nullifiers
|
|
96
|
+
const nullifiers = effects.nullifiers;
|
|
97
|
+
if (nullifiers.length > 0) {
|
|
98
|
+
log(' Created nullifiers:');
|
|
99
|
+
for (const nullifier of nullifiers) {
|
|
100
|
+
log(` Nullifier: ${nullifier.toShortString()}`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// L2 to L1 messages
|
|
105
|
+
if (effects.l2ToL1Msgs.length > 0) {
|
|
106
|
+
log(` L2 to L1 messages:`);
|
|
107
|
+
for (const msg of effects.l2ToL1Msgs) {
|
|
108
|
+
log(` ${msg.toString()}`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { AztecAddress } from '@aztec-labs/aztec.js/addresses';
|
|
2
|
+
import { getContractInstanceFromInstantiationParams } from '@aztec-labs/aztec.js/contracts';
|
|
3
|
+
import { Fr } from '@aztec-labs/aztec.js/fields';
|
|
4
|
+
import { SPONSORED_FPC_SALT } from '@aztec-labs/constants';
|
|
5
|
+
|
|
6
|
+
async function getSponsoredFPCContract() {
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
8
|
+
// @ts-ignore - Importing noir-contracts.js even in devDeps results in a circular dependency error. Need to ignore because this line doesn't cause an error in a dev environment
|
|
9
|
+
const { SponsoredFPCContract } = await import('@aztec-labs/noir-contracts.js/SponsoredFPC');
|
|
10
|
+
return SponsoredFPCContract;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export async function getSponsoredFPCAddress(): Promise<AztecAddress> {
|
|
14
|
+
const SponsoredFPCContract = await getSponsoredFPCContract();
|
|
15
|
+
const sponsoredFPCInstance = await getContractInstanceFromInstantiationParams(SponsoredFPCContract.artifact, {
|
|
16
|
+
salt: new Fr(SPONSORED_FPC_SALT),
|
|
17
|
+
});
|
|
18
|
+
return sponsoredFPCInstance.address;
|
|
19
|
+
}
|