@aztec/cli 0.1.0-alpha36 → 0.1.0-alpha38
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/.tsbuildinfo +1 -1
- package/README.md +8 -8
- package/dest/bin/index.d.ts +3 -0
- package/dest/bin/index.d.ts.map +1 -0
- package/dest/bin/index.js +17 -0
- package/dest/{cli_encoder.d.ts → encoding.d.ts} +1 -1
- package/dest/encoding.d.ts.map +1 -0
- package/dest/encoding.js +87 -0
- package/dest/index.d.ts +9 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +132 -98
- package/dest/utils.d.ts +1 -1
- package/dest/utils.js +4 -4
- package/package.json +8 -7
- package/src/bin/index.ts +20 -0
- package/src/index.ts +146 -114
- package/src/utils.ts +4 -4
- package/tsconfig.json +3 -0
- package/dest/cli_encoder.d.ts.map +0 -1
- package/dest/cli_encoder.js +0 -87
- /package/src/{cli_encoder.ts → encoding.ts} +0 -0
package/src/index.ts
CHANGED
|
@@ -1,25 +1,29 @@
|
|
|
1
|
-
#!/usr/bin/env -S node --no-warnings
|
|
2
1
|
import {
|
|
3
2
|
AztecAddress,
|
|
4
3
|
Contract,
|
|
5
4
|
ContractDeployer,
|
|
6
5
|
Fr,
|
|
7
6
|
Point,
|
|
8
|
-
createAccounts,
|
|
9
7
|
createAztecRpcClient,
|
|
10
8
|
generatePublicKey,
|
|
11
|
-
|
|
9
|
+
getAccountWallets,
|
|
10
|
+
getSchnorrAccount,
|
|
11
|
+
isContractDeployed,
|
|
12
12
|
} from '@aztec/aztec.js';
|
|
13
13
|
import { StructType } from '@aztec/foundation/abi';
|
|
14
14
|
import { JsonStringify } from '@aztec/foundation/json-rpc';
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
15
|
+
import { DebugLogger, LogFn } from '@aztec/foundation/log';
|
|
16
|
+
import { compileContract } from '@aztec/noir-compiler/cli';
|
|
17
|
+
import { SchnorrAccountContractAbi } from '@aztec/noir-contracts/artifacts';
|
|
18
|
+
import { CompleteAddress, ContractData, L2BlockL2Logs, PrivateKey, TxHash } from '@aztec/types';
|
|
18
19
|
|
|
19
20
|
import { Command } from 'commander';
|
|
21
|
+
import { readFileSync } from 'fs';
|
|
22
|
+
import { dirname, resolve } from 'path';
|
|
23
|
+
import { fileURLToPath } from 'url';
|
|
20
24
|
import { mnemonicToAccount } from 'viem/accounts';
|
|
21
25
|
|
|
22
|
-
import { encodeArgs, parseStructString } from './
|
|
26
|
+
import { encodeArgs, parseStructString } from './encoding.js';
|
|
23
27
|
import {
|
|
24
28
|
deployAztecContracts,
|
|
25
29
|
getAbiFunction,
|
|
@@ -31,8 +35,6 @@ import {
|
|
|
31
35
|
|
|
32
36
|
const accountCreationSalt = Fr.ZERO;
|
|
33
37
|
|
|
34
|
-
const debugLogger = createDebugLogger('aztec:cli');
|
|
35
|
-
const log = createConsoleLogger();
|
|
36
38
|
const stripLeadingHex = (hex: string) => {
|
|
37
39
|
if (hex.length > 2 && hex.startsWith('0x')) {
|
|
38
40
|
return hex.substring(2);
|
|
@@ -40,16 +42,22 @@ const stripLeadingHex = (hex: string) => {
|
|
|
40
42
|
return hex;
|
|
41
43
|
};
|
|
42
44
|
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
program.name('aztec-cli').description('CLI for interacting with Aztec.').version('0.1.0');
|
|
46
|
-
|
|
47
|
-
const { ETHEREUM_HOST, AZTEC_RPC_HOST, PRIVATE_KEY, PUBLIC_KEY, API_KEY } = process.env;
|
|
45
|
+
const { ETHEREUM_HOST, AZTEC_RPC_HOST, PRIVATE_KEY, API_KEY } = process.env;
|
|
48
46
|
|
|
49
47
|
/**
|
|
50
|
-
*
|
|
48
|
+
* Returns commander program that defines the CLI.
|
|
49
|
+
* @param log - Console logger.
|
|
50
|
+
* @param debugLogger - Debug logger.
|
|
51
|
+
* @returns The CLI.
|
|
51
52
|
*/
|
|
52
|
-
|
|
53
|
+
export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
|
|
54
|
+
const program = new Command();
|
|
55
|
+
|
|
56
|
+
const packageJsonPath = resolve(dirname(fileURLToPath(import.meta.url)), '../package.json');
|
|
57
|
+
const version: string = JSON.parse(readFileSync(packageJsonPath).toString()).version;
|
|
58
|
+
|
|
59
|
+
program.name('aztec-cli').description('CLI for interacting with Aztec.').version(version);
|
|
60
|
+
|
|
53
61
|
program
|
|
54
62
|
.command('deploy-l1-contracts')
|
|
55
63
|
.description('Deploys all necessary Ethereum contracts for Aztec.')
|
|
@@ -97,7 +105,7 @@ async function main() {
|
|
|
97
105
|
publicKey = await generatePublicKey(new PrivateKey(key));
|
|
98
106
|
} else {
|
|
99
107
|
const key = PrivateKey.random();
|
|
100
|
-
privKey =
|
|
108
|
+
privKey = key.toString();
|
|
101
109
|
publicKey = await generatePublicKey(key);
|
|
102
110
|
}
|
|
103
111
|
log(`\nPrivate Key: ${privKey}\nPublic Key: ${publicKey.toString()}\n`);
|
|
@@ -105,27 +113,31 @@ async function main() {
|
|
|
105
113
|
|
|
106
114
|
program
|
|
107
115
|
.command('create-account')
|
|
108
|
-
.description(
|
|
116
|
+
.description(
|
|
117
|
+
'Creates an aztec account that can be used for sending transactions. Registers the account on the RPC server and deploys an account contract. Uses a Schnorr single-key account which uses the same key for encryption and authentication (not secure for production usage).',
|
|
118
|
+
)
|
|
119
|
+
.summary('Creates an aztec account that can be used for sending transactions.')
|
|
109
120
|
.option(
|
|
110
121
|
'-k, --private-key <string>',
|
|
111
|
-
'Private
|
|
122
|
+
'Private key for note encryption and transaction signing. Uses random by default.',
|
|
112
123
|
PRIVATE_KEY,
|
|
113
124
|
)
|
|
114
125
|
.option('-u, --rpc-url <string>', 'URL of the Aztec RPC', AZTEC_RPC_HOST || 'http://localhost:8080')
|
|
115
126
|
.action(async options => {
|
|
116
127
|
const client = createAztecRpcClient(options.rpcUrl);
|
|
117
|
-
const privateKey = options.privateKey
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
log(
|
|
128
|
-
|
|
128
|
+
const privateKey = options.privateKey
|
|
129
|
+
? new PrivateKey(Buffer.from(stripLeadingHex(options.privateKey), 'hex'))
|
|
130
|
+
: PrivateKey.random();
|
|
131
|
+
|
|
132
|
+
const account = getSchnorrAccount(client, privateKey, privateKey, accountCreationSalt);
|
|
133
|
+
const wallet = await account.waitDeploy();
|
|
134
|
+
const { address, publicKey, partialAddress } = wallet.getCompleteAddress();
|
|
135
|
+
|
|
136
|
+
log(`\nCreated new account:\n`);
|
|
137
|
+
log(`Address: ${address.toString()}`);
|
|
138
|
+
log(`Public key: ${publicKey.toString()}`);
|
|
139
|
+
if (!options.privateKey) log(`Private key: ${privateKey.toString()}`);
|
|
140
|
+
log(`Partial address: ${partialAddress.toString()}`);
|
|
129
141
|
});
|
|
130
142
|
|
|
131
143
|
program
|
|
@@ -140,40 +152,33 @@ async function main() {
|
|
|
140
152
|
.option('-u, --rpc-url <string>', 'URL of the Aztec RPC', AZTEC_RPC_HOST || 'http://localhost:8080')
|
|
141
153
|
.option(
|
|
142
154
|
'-k, --public-key <string>',
|
|
143
|
-
'
|
|
144
|
-
PUBLIC_KEY,
|
|
155
|
+
'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.',
|
|
145
156
|
)
|
|
157
|
+
.option('-s, --salt <string>', 'Optional deployment salt as a hex string for generating the deployment address.')
|
|
146
158
|
.action(async (options: any) => {
|
|
147
159
|
const contractAbi = await getContractAbi(options.contractAbi, log);
|
|
148
160
|
const constructorAbi = contractAbi.functions.find(({ name }) => name === 'constructor');
|
|
149
161
|
|
|
150
162
|
const client = createAztecRpcClient(options.rpcUrl);
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
} else {
|
|
155
|
-
const accounts = await client.getAccounts();
|
|
156
|
-
if (!accounts) {
|
|
157
|
-
throw new Error('No public key provided or found in Aztec RPC.');
|
|
158
|
-
}
|
|
159
|
-
publicKey = await client.getPublicKey(accounts[0]);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
log(`Using Public Key: ${publicKey.toString()}`);
|
|
163
|
-
|
|
164
|
-
const deployer = new ContractDeployer(contractAbi, client);
|
|
163
|
+
const publicKey = options.publicKey ? Point.fromString(options.publicKey) : undefined;
|
|
164
|
+
const salt = options.salt ? Fr.fromBuffer(Buffer.from(stripLeadingHex(options.salt), 'hex')) : undefined;
|
|
165
|
+
const deployer = new ContractDeployer(contractAbi, client, publicKey);
|
|
165
166
|
|
|
166
167
|
const constructor = getAbiFunction(contractAbi, 'constructor');
|
|
168
|
+
if (!constructor) throw new Error(`Constructor not found in contract ABI`);
|
|
167
169
|
if (constructor.parameters.length !== options.args.length) {
|
|
168
|
-
throw Error(
|
|
169
|
-
`Invalid number of args passed
|
|
170
|
+
throw new Error(
|
|
171
|
+
`Invalid number of args passed (expected ${constructor.parameters.length} but got ${options.args.length})`,
|
|
170
172
|
);
|
|
171
173
|
}
|
|
172
174
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
175
|
+
debugLogger(`Input arguments: ${options.args.map((x: any) => `"${x}"`).join(', ')}`);
|
|
176
|
+
const args = encodeArgs(options.args, constructorAbi!.parameters);
|
|
177
|
+
debugLogger(`Encoded arguments: ${args.join(', ')}`);
|
|
178
|
+
const tx = deployer.deploy(...args).send({ contractAddressSalt: salt });
|
|
179
|
+
debugLogger(`Deploy tx sent with hash ${await tx.getTxHash()}`);
|
|
180
|
+
const deployed = await tx.wait();
|
|
181
|
+
log(`\nContract deployed at ${deployed.contractAddress!.toString()}\n`);
|
|
177
182
|
});
|
|
178
183
|
|
|
179
184
|
program
|
|
@@ -184,13 +189,14 @@ async function main() {
|
|
|
184
189
|
.action(async options => {
|
|
185
190
|
const client = createAztecRpcClient(options.rpcUrl);
|
|
186
191
|
const address = AztecAddress.fromString(options.contractAddress);
|
|
187
|
-
const isDeployed = await
|
|
188
|
-
log(`\
|
|
192
|
+
const isDeployed = await isContractDeployed(client, address);
|
|
193
|
+
if (isDeployed) log(`\nContract found at ${address.toString()}\n`);
|
|
194
|
+
else log(`\nNo contract found at ${address.toString()}\n`);
|
|
189
195
|
});
|
|
190
196
|
|
|
191
197
|
program
|
|
192
198
|
.command('get-tx-receipt')
|
|
193
|
-
.argument('<txHash>', 'A
|
|
199
|
+
.argument('<txHash>', 'A transaction hash to get the receipt for.')
|
|
194
200
|
.description('Gets the receipt for the specified transaction hash.')
|
|
195
201
|
.option('-u, --rpc-url <string>', 'URL of the Aztec RPC', AZTEC_RPC_HOST || 'http://localhost:8080')
|
|
196
202
|
.action(async (_txHash, options) => {
|
|
@@ -198,9 +204,9 @@ async function main() {
|
|
|
198
204
|
const txHash = TxHash.fromString(_txHash);
|
|
199
205
|
const receipt = await client.getTxReceipt(txHash);
|
|
200
206
|
if (!receipt) {
|
|
201
|
-
log(`No receipt found for
|
|
207
|
+
log(`No receipt found for transaction hash ${_txHash}`);
|
|
202
208
|
} else {
|
|
203
|
-
log(`\
|
|
209
|
+
log(`\nTransaction receipt: \n${JsonStringify(receipt, true)}\n`);
|
|
204
210
|
}
|
|
205
211
|
});
|
|
206
212
|
|
|
@@ -213,25 +219,25 @@ async function main() {
|
|
|
213
219
|
.action(async (contractAddress, options) => {
|
|
214
220
|
const client = createAztecRpcClient(options.rpcUrl);
|
|
215
221
|
const address = AztecAddress.fromString(contractAddress);
|
|
216
|
-
const
|
|
217
|
-
? await client.
|
|
218
|
-
: await client.
|
|
222
|
+
const contractDataWithOrWithoutBytecode = options.includeBytecode
|
|
223
|
+
? await client.getContractDataAndBytecode(address)
|
|
224
|
+
: await client.getContractData(address);
|
|
219
225
|
|
|
220
|
-
if (!
|
|
226
|
+
if (!contractDataWithOrWithoutBytecode) {
|
|
221
227
|
log(`No contract data found at ${contractAddress}`);
|
|
222
228
|
return;
|
|
223
229
|
}
|
|
224
230
|
let contractData: ContractData;
|
|
225
231
|
|
|
226
|
-
if ('contractData' in
|
|
227
|
-
contractData =
|
|
232
|
+
if ('contractData' in contractDataWithOrWithoutBytecode) {
|
|
233
|
+
contractData = contractDataWithOrWithoutBytecode.contractData;
|
|
228
234
|
} else {
|
|
229
|
-
contractData =
|
|
235
|
+
contractData = contractDataWithOrWithoutBytecode;
|
|
230
236
|
}
|
|
231
237
|
log(`\nContract Data: \nAddress: ${contractData.contractAddress.toString()}`);
|
|
232
|
-
log(`Portal:
|
|
233
|
-
if ('bytecode' in
|
|
234
|
-
log(`Bytecode: ${
|
|
238
|
+
log(`Portal: ${contractData.portalContractAddress.toString()}`);
|
|
239
|
+
if ('bytecode' in contractDataWithOrWithoutBytecode) {
|
|
240
|
+
log(`Bytecode: ${contractDataWithOrWithoutBytecode.bytecode}`);
|
|
235
241
|
}
|
|
236
242
|
log('\n');
|
|
237
243
|
});
|
|
@@ -239,23 +245,18 @@ async function main() {
|
|
|
239
245
|
program
|
|
240
246
|
.command('get-logs')
|
|
241
247
|
.description('Gets all the unencrypted logs from L2 blocks in the range specified.')
|
|
242
|
-
.
|
|
243
|
-
.
|
|
248
|
+
.option('-f, --from <blockNum>', 'Initial block number for getting logs (defaults to 1).')
|
|
249
|
+
.option('-l, --limit <blockCount>', 'How many blocks to fetch (defaults to 100).')
|
|
244
250
|
.option('-u, --rpc-url <string>', 'URL of the Aztec RPC', AZTEC_RPC_HOST || 'http://localhost:8080')
|
|
245
|
-
.action(async
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
limit = parseInt(_take);
|
|
251
|
-
} catch {
|
|
252
|
-
log(`Invalid integer value(s) passed: ${_from}, ${_take}`);
|
|
253
|
-
return;
|
|
254
|
-
}
|
|
251
|
+
.action(async options => {
|
|
252
|
+
const { from, limit } = options;
|
|
253
|
+
const fromBlock = from ? parseInt(from) : 1;
|
|
254
|
+
const limitCount = limit ? parseInt(limit) : 100;
|
|
255
|
+
|
|
255
256
|
const client = createAztecRpcClient(options.rpcUrl);
|
|
256
|
-
const logs = await client.getUnencryptedLogs(
|
|
257
|
+
const logs = await client.getUnencryptedLogs(fromBlock, limitCount);
|
|
257
258
|
if (!logs.length) {
|
|
258
|
-
log(`No logs found in blocks ${
|
|
259
|
+
log(`No logs found in blocks ${fromBlock} to ${fromBlock + limitCount}`);
|
|
259
260
|
} else {
|
|
260
261
|
log('Logs found: \n');
|
|
261
262
|
L2BlockL2Logs.unrollLogs(logs).forEach(fnLog => log(`${fnLog.toString('ascii')}\n`));
|
|
@@ -263,8 +264,8 @@ async function main() {
|
|
|
263
264
|
});
|
|
264
265
|
|
|
265
266
|
program
|
|
266
|
-
.command('register-
|
|
267
|
-
.description(
|
|
267
|
+
.command('register-recipient')
|
|
268
|
+
.description('Register a recipient in the Aztec RPC.')
|
|
268
269
|
.option('-a, --address <aztecAddress>', "The account's Aztec address.")
|
|
269
270
|
.option('-p, --public-key <publicKey>', 'The account public key.')
|
|
270
271
|
.option('-pa, --partial-address <partialAddress', 'The partially computed address of the account contract.')
|
|
@@ -275,7 +276,7 @@ async function main() {
|
|
|
275
276
|
const publicKey = Point.fromString(options.publicKey);
|
|
276
277
|
const partialAddress = Fr.fromString(options.partialAddress);
|
|
277
278
|
|
|
278
|
-
await client.
|
|
279
|
+
await client.registerRecipient(await CompleteAddress.create(address, publicKey, partialAddress));
|
|
279
280
|
log(`\nRegistered details for Address: ${options.address}\n`);
|
|
280
281
|
});
|
|
281
282
|
|
|
@@ -290,29 +291,60 @@ async function main() {
|
|
|
290
291
|
log('No accounts found.');
|
|
291
292
|
} else {
|
|
292
293
|
log(`Accounts found: \n`);
|
|
293
|
-
for (const
|
|
294
|
-
|
|
295
|
-
log(
|
|
296
|
-
`Address: ${address}\nPublic Key: ${pk.toString()}\nPartial Contract Address: ${partialAddress.toString()}\n`,
|
|
297
|
-
);
|
|
294
|
+
for (const account of accounts) {
|
|
295
|
+
log(account.toReadableString());
|
|
298
296
|
}
|
|
299
297
|
}
|
|
300
298
|
});
|
|
301
299
|
|
|
302
300
|
program
|
|
303
|
-
.command('get-account
|
|
304
|
-
.description(
|
|
305
|
-
.argument('<address>', 'The Aztec address to get
|
|
301
|
+
.command('get-account')
|
|
302
|
+
.description('Gets an account given its Aztec address.')
|
|
303
|
+
.argument('<address>', 'The Aztec address to get account for')
|
|
306
304
|
.option('-u, --rpc-url <string>', 'URL of the Aztec RPC', AZTEC_RPC_HOST || 'http://localhost:8080')
|
|
307
305
|
.action(async (_address, options) => {
|
|
308
306
|
const client = createAztecRpcClient(options.rpcUrl);
|
|
309
307
|
const address = AztecAddress.fromString(_address);
|
|
310
|
-
const
|
|
308
|
+
const account = await client.getAccount(address);
|
|
311
309
|
|
|
312
|
-
if (!
|
|
313
|
-
log(`
|
|
310
|
+
if (!account) {
|
|
311
|
+
log(`Unknown account ${_address}`);
|
|
314
312
|
} else {
|
|
315
|
-
log(
|
|
313
|
+
log(account.toReadableString());
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
program
|
|
318
|
+
.command('get-recipients')
|
|
319
|
+
.description('Gets all the recipients stored in the Aztec RPC.')
|
|
320
|
+
.option('-u, --rpc-url <string>', 'URL of the Aztec RPC', AZTEC_RPC_HOST || 'http://localhost:8080')
|
|
321
|
+
.action(async (options: any) => {
|
|
322
|
+
const client = createAztecRpcClient(options.rpcUrl);
|
|
323
|
+
const recipients = await client.getRecipients();
|
|
324
|
+
if (!recipients.length) {
|
|
325
|
+
log('No recipients found.');
|
|
326
|
+
} else {
|
|
327
|
+
log(`Recipients found: \n`);
|
|
328
|
+
for (const recipient of recipients) {
|
|
329
|
+
log(recipient.toReadableString());
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
program
|
|
335
|
+
.command('get-recipient')
|
|
336
|
+
.description('Gets a recipient given its Aztec address.')
|
|
337
|
+
.argument('<address>', 'The Aztec address to get recipient for')
|
|
338
|
+
.option('-u, --rpc-url <string>', 'URL of the Aztec RPC', AZTEC_RPC_HOST || 'http://localhost:8080')
|
|
339
|
+
.action(async (_address, options) => {
|
|
340
|
+
const client = createAztecRpcClient(options.rpcUrl);
|
|
341
|
+
const address = AztecAddress.fromString(_address);
|
|
342
|
+
const recipient = await client.getRecipient(address);
|
|
343
|
+
|
|
344
|
+
if (!recipient) {
|
|
345
|
+
log(`Unknown recipient ${_address}`);
|
|
346
|
+
} else {
|
|
347
|
+
log(recipient.toReadableString());
|
|
316
348
|
}
|
|
317
349
|
});
|
|
318
350
|
|
|
@@ -346,22 +378,25 @@ async function main() {
|
|
|
346
378
|
);
|
|
347
379
|
}
|
|
348
380
|
|
|
381
|
+
const privateKey = new PrivateKey(Buffer.from(stripLeadingHex(options.privateKey), 'hex'));
|
|
382
|
+
|
|
349
383
|
const client = createAztecRpcClient(options.rpcUrl);
|
|
350
|
-
const wallet = await
|
|
384
|
+
const wallet = await getAccountWallets(
|
|
351
385
|
client,
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
386
|
+
SchnorrAccountContractAbi,
|
|
387
|
+
[privateKey],
|
|
388
|
+
[privateKey],
|
|
389
|
+
[accountCreationSalt],
|
|
355
390
|
);
|
|
356
|
-
const contract = await Contract.
|
|
391
|
+
const contract = await Contract.at(contractAddress, contractAbi, wallet);
|
|
357
392
|
const tx = contract.methods[functionName](...functionArgs).send();
|
|
358
393
|
await tx.isMined();
|
|
359
|
-
log('\
|
|
394
|
+
log('\nTransaction has been mined');
|
|
360
395
|
const receipt = await tx.getReceipt();
|
|
361
|
-
log(`
|
|
362
|
-
log(`
|
|
363
|
-
log(`Block
|
|
364
|
-
log(`
|
|
396
|
+
log(`Transaction hash: ${(await tx.getTxHash()).toString()}`);
|
|
397
|
+
log(`Status: ${receipt.status}\n`);
|
|
398
|
+
log(`Block number: ${receipt.blockNumber}`);
|
|
399
|
+
log(`Block hash: ${receipt.blockHash?.toString('hex')}`);
|
|
365
400
|
});
|
|
366
401
|
|
|
367
402
|
program
|
|
@@ -396,7 +431,7 @@ async function main() {
|
|
|
396
431
|
const client = createAztecRpcClient(options.rpcUrl);
|
|
397
432
|
const from = await getTxSender(client, options.from);
|
|
398
433
|
const result = await client.viewTx(functionName, functionArgs, contractAddress, from);
|
|
399
|
-
log('\nView
|
|
434
|
+
log('\nView result: ', JsonStringify(result, true), '\n');
|
|
400
435
|
});
|
|
401
436
|
|
|
402
437
|
// Helper for users to decode hex strings into structs if needed
|
|
@@ -443,10 +478,7 @@ async function main() {
|
|
|
443
478
|
names.forEach(name => log(name));
|
|
444
479
|
});
|
|
445
480
|
|
|
446
|
-
|
|
447
|
-
}
|
|
481
|
+
compileContract(program, 'compile', log);
|
|
448
482
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
process.exit(1);
|
|
452
|
-
});
|
|
483
|
+
return program;
|
|
484
|
+
}
|
package/src/utils.ts
CHANGED
|
@@ -6,10 +6,10 @@ import { DebugLogger, LogFn } from '@aztec/foundation/log';
|
|
|
6
6
|
import fs from 'fs';
|
|
7
7
|
import { mnemonicToAccount, privateKeyToAccount } from 'viem/accounts';
|
|
8
8
|
|
|
9
|
-
import { encodeArgs } from './
|
|
9
|
+
import { encodeArgs } from './encoding.js';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
* Helper type to dynamically import
|
|
12
|
+
* Helper type to dynamically import contracts.
|
|
13
13
|
*/
|
|
14
14
|
interface ArtifactsType {
|
|
15
15
|
[key: string]: ContractAbi;
|
|
@@ -105,9 +105,9 @@ export async function getTxSender(client: AztecRPC, _from?: string) {
|
|
|
105
105
|
} else {
|
|
106
106
|
const accounts = await client.getAccounts();
|
|
107
107
|
if (!accounts.length) {
|
|
108
|
-
throw new Error('No accounts found in Aztec RPC
|
|
108
|
+
throw new Error('No accounts found in Aztec RPC instance.');
|
|
109
109
|
}
|
|
110
|
-
from = accounts[0];
|
|
110
|
+
from = accounts[0].address;
|
|
111
111
|
}
|
|
112
112
|
return from;
|
|
113
113
|
}
|
package/tsconfig.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cli_encoder.d.ts","sourceRoot":"","sources":["../src/cli_encoder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAW,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAE1E;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,OAcjE;AA8CD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,SAO7D"}
|
package/dest/cli_encoder.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { Fr } from '@aztec/aztec.js';
|
|
2
|
-
/**
|
|
3
|
-
* Parses a hex string into an ABI struct type.
|
|
4
|
-
* @param str - The encoded hex string.
|
|
5
|
-
* @param abiType - The ABI Struct type.
|
|
6
|
-
* @returns An object in the ABI struct type's format.
|
|
7
|
-
*/
|
|
8
|
-
export function parseStructString(str, abiType) {
|
|
9
|
-
// Assing string bytes to struct fields.
|
|
10
|
-
const buf = Buffer.from(str.replace(/^0x/i, ''), 'hex');
|
|
11
|
-
const struct = {};
|
|
12
|
-
let byteIndex = 0;
|
|
13
|
-
let argIndex = 0;
|
|
14
|
-
while (byteIndex < buf.length) {
|
|
15
|
-
const { name } = abiType.fields[argIndex];
|
|
16
|
-
struct[name] = Fr.fromBuffer(buf.subarray(byteIndex, byteIndex + 32));
|
|
17
|
-
byteIndex += 32;
|
|
18
|
-
argIndex += 1;
|
|
19
|
-
}
|
|
20
|
-
return struct;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Helper function to encode CLI string args to an appropriate JS type.
|
|
24
|
-
* @param arg - The CLI argument.
|
|
25
|
-
* @param abiType - The type as described by the contract's ABI.
|
|
26
|
-
* @returns The encoded argument.
|
|
27
|
-
*/
|
|
28
|
-
function encodeArg(arg, abiType) {
|
|
29
|
-
const { kind } = abiType;
|
|
30
|
-
if (kind === 'field' || kind === 'integer') {
|
|
31
|
-
return BigInt(arg);
|
|
32
|
-
}
|
|
33
|
-
else if (kind === 'boolean') {
|
|
34
|
-
if (arg === 'true')
|
|
35
|
-
return true;
|
|
36
|
-
if (arg === 'false')
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
else if (kind === 'array') {
|
|
40
|
-
let arr;
|
|
41
|
-
try {
|
|
42
|
-
arr = JSON.parse(arg);
|
|
43
|
-
if (!Array.isArray(arr))
|
|
44
|
-
throw Error();
|
|
45
|
-
for (let i = 0; i < abiType.length; i += 1) {
|
|
46
|
-
return encodeArg(arg[i], abiType.type);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
catch {
|
|
50
|
-
throw new Error(`Unable to parse arg ${arg} as array`);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
else if (kind === 'struct') {
|
|
54
|
-
// check if input is encoded long string
|
|
55
|
-
if (arg.startsWith('0x')) {
|
|
56
|
-
return parseStructString(arg, abiType);
|
|
57
|
-
}
|
|
58
|
-
let obj;
|
|
59
|
-
try {
|
|
60
|
-
obj = JSON.parse(arg);
|
|
61
|
-
if (Array.isArray(obj))
|
|
62
|
-
throw Error();
|
|
63
|
-
const res = [];
|
|
64
|
-
for (const field of abiType.fields) {
|
|
65
|
-
res.push(encodeArg(obj[field.name], field.type));
|
|
66
|
-
}
|
|
67
|
-
return res;
|
|
68
|
-
}
|
|
69
|
-
catch {
|
|
70
|
-
throw new Error(`Unable to parse arg ${arg} as struct`);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Tries to encode function args to their equivalent TS type.
|
|
76
|
-
* @param args - An array of function's / constructor's args.
|
|
77
|
-
* @returns The encoded array.
|
|
78
|
-
*/
|
|
79
|
-
export function encodeArgs(args, params) {
|
|
80
|
-
return args
|
|
81
|
-
.map((arg, index) => {
|
|
82
|
-
const paramType = params[index].type;
|
|
83
|
-
return encodeArg(arg, paramType);
|
|
84
|
-
})
|
|
85
|
-
.flat();
|
|
86
|
-
}
|
|
87
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2xpX2VuY29kZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvY2xpX2VuY29kZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLGlCQUFpQixDQUFDO0FBR3JDOzs7OztHQUtHO0FBQ0gsTUFBTSxVQUFVLGlCQUFpQixDQUFDLEdBQVcsRUFBRSxPQUFtQjtJQUNoRSx3Q0FBd0M7SUFDeEMsTUFBTSxHQUFHLEdBQUcsTUFBTSxDQUFDLElBQUksQ0FBQyxHQUFHLENBQUMsT0FBTyxDQUFDLE1BQU0sRUFBRSxFQUFFLENBQUMsRUFBRSxLQUFLLENBQUMsQ0FBQztJQUN4RCxNQUFNLE1BQU0sR0FBUSxFQUFFLENBQUM7SUFDdkIsSUFBSSxTQUFTLEdBQUcsQ0FBQyxDQUFDO0lBQ2xCLElBQUksUUFBUSxHQUFHLENBQUMsQ0FBQztJQUNqQixPQUFPLFNBQVMsR0FBRyxHQUFHLENBQUMsTUFBTSxFQUFFO1FBQzdCLE1BQU0sRUFBRSxJQUFJLEVBQUUsR0FBRyxPQUFPLENBQUMsTUFBTSxDQUFDLFFBQVEsQ0FBQyxDQUFDO1FBQzFDLE1BQU0sQ0FBQyxJQUFJLENBQUMsR0FBRyxFQUFFLENBQUMsVUFBVSxDQUFDLEdBQUcsQ0FBQyxRQUFRLENBQUMsU0FBUyxFQUFFLFNBQVMsR0FBRyxFQUFFLENBQUMsQ0FBQyxDQUFDO1FBQ3RFLFNBQVMsSUFBSSxFQUFFLENBQUM7UUFDaEIsUUFBUSxJQUFJLENBQUMsQ0FBQztLQUNmO0lBRUQsT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