-
Notifications
You must be signed in to change notification settings - Fork 327
/
Copy pathindex.ts
162 lines (149 loc) · 6.63 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import { Fr } from '@aztec/circuits.js';
import { type DebugLogger, type LogFn } from '@aztec/foundation/log';
import { type Command } from 'commander';
import {
LOCALHOST,
logJson,
makePxeOption,
parseAztecAddress,
parseEthereumAddress,
parseField,
parseFieldFromHexString,
parseOptionalAztecAddress,
parseOptionalInteger,
parseOptionalLogId,
parseOptionalTxHash,
parsePublicKey,
pxeOption,
} from '../../utils/commands.js';
export function injectCommands(program: Command, log: LogFn, debugLogger: DebugLogger) {
program
.command('add-contract')
.description(
'Adds an existing contract to the PXE. This is useful if you have deployed a contract outside of the PXE and want to use it with the PXE.',
)
.requiredOption(
'-c, --contract-artifact <fileLocation>',
"A compiled Aztec.nr contract's ABI in JSON format or name of a contract ABI exported by @aztec/noir-contracts.js",
)
.requiredOption('-ca, --contract-address <address>', 'Aztec address of the contract.', parseAztecAddress)
.requiredOption('--init-hash <init hash>', 'Initialization hash', parseFieldFromHexString)
.option('--salt <salt>', 'Optional deployment salt', parseFieldFromHexString)
.option('-p, --public-key <public key>', 'Optional public key for this contract', parsePublicKey)
.option('--portal-address <address>', 'Optional address to a portal contract on L1', parseEthereumAddress)
.option('--deployer-address <address>', 'Optional address of the contract deployer', parseAztecAddress)
.addOption(pxeOption)
.action(async options => {
const { addContract } = await import('./add_contract.js');
await addContract(
options.rpcUrl,
options.contractArtifact,
options.contractAddress,
options.initHash,
options.salt ?? Fr.ZERO,
options.publicKey,
options.deployerAddress,
debugLogger,
log,
);
});
program
.command('get-block')
.description('Gets info for a given block or latest.')
.argument('[blockNumber]', 'Block height', parseOptionalInteger)
.option('-f, --follow', 'Keep polling for new blocks')
.addOption(pxeOption)
.action(async (blockNumber, options) => {
const { getBlock } = await import('./get_block.js');
await getBlock(options.rpcUrl, blockNumber, options.follow, debugLogger, log);
});
program
.command('get-contract-data')
.description('Gets information about the Aztec contract deployed at the specified address.')
.argument('<contractAddress>', 'Aztec address of the contract.', parseAztecAddress)
.addOption(pxeOption)
.option('-b, --include-bytecode <boolean>', "Include the contract's public function bytecode, if any.", false)
.action(async (contractAddress, options) => {
const { getContractData } = await import('./get_contract_data.js');
await getContractData(options.rpcUrl, contractAddress, options.includeBytecode, debugLogger, log);
});
program
.command('get-logs')
.description('Gets all the unencrypted logs from an intersection of all the filter params.')
.option('-tx, --tx-hash <txHash>', 'A transaction hash to get the receipt for.', parseOptionalTxHash)
.option(
'-fb, --from-block <blockNum>',
'Initial block number for getting logs (defaults to 1).',
parseOptionalInteger,
)
.option('-tb, --to-block <blockNum>', 'Up to which block to fetch logs (defaults to latest).', parseOptionalInteger)
.option('-al --after-log <logId>', 'ID of a log after which to fetch the logs.', parseOptionalLogId)
.option('-ca, --contract-address <address>', 'Contract address to filter logs by.', parseOptionalAztecAddress)
.addOption(pxeOption)
.option('--follow', 'If set, will keep polling for new logs until interrupted.')
.action(async ({ txHash, fromBlock, toBlock, afterLog, contractAddress, rpcUrl, follow }) => {
const { getLogs } = await import('./get_logs.js');
await getLogs(txHash, fromBlock, toBlock, afterLog, contractAddress, rpcUrl, follow, debugLogger, log);
});
program
.command('get-accounts')
.description('Gets all the Aztec accounts stored in the PXE.')
.addOption(pxeOption)
.option('--json', 'Emit output as json')
.action(async (options: any) => {
const { getAccounts } = await import('./get_accounts.js');
await getAccounts(options.rpcUrl, options.json, debugLogger, log, logJson(log));
});
program
.command('get-account')
.description('Gets an account given its Aztec address.')
.argument('<address>', 'The Aztec address to get account for', parseAztecAddress)
.addOption(pxeOption)
.action(async (address, options) => {
const { getAccount } = await import('./get_account.js');
await getAccount(address, options.rpcUrl, debugLogger, log);
});
program
.command('block-number')
.description('Gets the current Aztec L2 block number.')
.addOption(pxeOption)
.action(async (options: any) => {
const { blockNumber } = await import('./block_number.js');
await blockNumber(options.rpcUrl, debugLogger, log);
});
program
.command('get-l1-to-l2-message-witness')
.description('Gets a L1 to L2 message witness.')
.requiredOption('-ca, --contract-address <address>', 'Aztec address of the contract.', parseAztecAddress)
.requiredOption('--message-hash <messageHash>', 'The L1 to L2 message hash.', parseField)
.requiredOption('--secret <secret>', 'The secret used to claim the L1 to L2 message', parseField)
.addOption(pxeOption)
.action(async ({ contractAddress, messageHash, secret, rpcUrl }) => {
const { getL1ToL2MessageWitness } = await import('./get_l1_to_l2_message_witness.js');
await getL1ToL2MessageWitness(rpcUrl, contractAddress, messageHash, secret, debugLogger, log);
});
program
.command('get-node-info')
.description('Gets the information of an Aztec node from a PXE or directly from an Aztec node.')
.option('--node-url <string>', 'URL of the node.', `http://${LOCALHOST}:8080`)
.addOption(makePxeOption(false))
.action(async options => {
const { getNodeInfo } = await import('./get_node_info.js');
let url: string;
if (options.nodeUrl) {
url = options.nodeUrl;
} else {
url = options.rpcUrl;
}
await getNodeInfo(url, !options.nodeUrl, debugLogger, log);
});
program
.command('get-pxe-info')
.description('Gets the information of a PXE at a URL.')
.addOption(pxeOption)
.action(async options => {
const { getPXEInfo } = await import('./get_pxe_info.js');
await getPXEInfo(options.rpcUrl, debugLogger, log);
});
return program;
}