@aztec/cli 0.1.0-alpha37 → 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 +121 -87
- 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 +134 -105
- 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,26 +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,
|
|
12
11
|
isContractDeployed,
|
|
13
12
|
} from '@aztec/aztec.js';
|
|
14
13
|
import { StructType } from '@aztec/foundation/abi';
|
|
15
14
|
import { JsonStringify } from '@aztec/foundation/json-rpc';
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
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';
|
|
19
19
|
|
|
20
20
|
import { Command } from 'commander';
|
|
21
|
+
import { readFileSync } from 'fs';
|
|
22
|
+
import { dirname, resolve } from 'path';
|
|
23
|
+
import { fileURLToPath } from 'url';
|
|
21
24
|
import { mnemonicToAccount } from 'viem/accounts';
|
|
22
25
|
|
|
23
|
-
import { encodeArgs, parseStructString } from './
|
|
26
|
+
import { encodeArgs, parseStructString } from './encoding.js';
|
|
24
27
|
import {
|
|
25
28
|
deployAztecContracts,
|
|
26
29
|
getAbiFunction,
|
|
@@ -32,8 +35,6 @@ import {
|
|
|
32
35
|
|
|
33
36
|
const accountCreationSalt = Fr.ZERO;
|
|
34
37
|
|
|
35
|
-
const debugLogger = createDebugLogger('aztec:cli');
|
|
36
|
-
const log = createConsoleLogger();
|
|
37
38
|
const stripLeadingHex = (hex: string) => {
|
|
38
39
|
if (hex.length > 2 && hex.startsWith('0x')) {
|
|
39
40
|
return hex.substring(2);
|
|
@@ -41,16 +42,22 @@ const stripLeadingHex = (hex: string) => {
|
|
|
41
42
|
return hex;
|
|
42
43
|
};
|
|
43
44
|
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
program.name('aztec-cli').description('CLI for interacting with Aztec.').version('0.1.0');
|
|
47
|
-
|
|
48
|
-
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;
|
|
49
46
|
|
|
50
47
|
/**
|
|
51
|
-
*
|
|
48
|
+
* Returns commander program that defines the CLI.
|
|
49
|
+
* @param log - Console logger.
|
|
50
|
+
* @param debugLogger - Debug logger.
|
|
51
|
+
* @returns The CLI.
|
|
52
52
|
*/
|
|
53
|
-
|
|
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
|
+
|
|
54
61
|
program
|
|
55
62
|
.command('deploy-l1-contracts')
|
|
56
63
|
.description('Deploys all necessary Ethereum contracts for Aztec.')
|
|
@@ -98,7 +105,7 @@ async function main() {
|
|
|
98
105
|
publicKey = await generatePublicKey(new PrivateKey(key));
|
|
99
106
|
} else {
|
|
100
107
|
const key = PrivateKey.random();
|
|
101
|
-
privKey =
|
|
108
|
+
privKey = key.toString();
|
|
102
109
|
publicKey = await generatePublicKey(key);
|
|
103
110
|
}
|
|
104
111
|
log(`\nPrivate Key: ${privKey}\nPublic Key: ${publicKey.toString()}\n`);
|
|
@@ -106,31 +113,31 @@ async function main() {
|
|
|
106
113
|
|
|
107
114
|
program
|
|
108
115
|
.command('create-account')
|
|
109
|
-
.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.')
|
|
110
120
|
.option(
|
|
111
121
|
'-k, --private-key <string>',
|
|
112
|
-
'Private
|
|
122
|
+
'Private key for note encryption and transaction signing. Uses random by default.',
|
|
113
123
|
PRIVATE_KEY,
|
|
114
124
|
)
|
|
115
125
|
.option('-u, --rpc-url <string>', 'URL of the Aztec RPC', AZTEC_RPC_HOST || 'http://localhost:8080')
|
|
116
126
|
.action(async options => {
|
|
117
127
|
const client = createAztecRpcClient(options.rpcUrl);
|
|
118
|
-
const privateKey = options.privateKey
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
);
|
|
130
|
-
log(
|
|
131
|
-
accounts.map((acc, i) =>
|
|
132
|
-
log(`\nAddress: ${acc.toString()}\nPublic Key: ${pubKeysAndPartialAddresses[i][0].toString()}\n`),
|
|
133
|
-
);
|
|
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()}`);
|
|
134
141
|
});
|
|
135
142
|
|
|
136
143
|
program
|
|
@@ -145,40 +152,33 @@ async function main() {
|
|
|
145
152
|
.option('-u, --rpc-url <string>', 'URL of the Aztec RPC', AZTEC_RPC_HOST || 'http://localhost:8080')
|
|
146
153
|
.option(
|
|
147
154
|
'-k, --public-key <string>',
|
|
148
|
-
'
|
|
149
|
-
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.',
|
|
150
156
|
)
|
|
157
|
+
.option('-s, --salt <string>', 'Optional deployment salt as a hex string for generating the deployment address.')
|
|
151
158
|
.action(async (options: any) => {
|
|
152
159
|
const contractAbi = await getContractAbi(options.contractAbi, log);
|
|
153
160
|
const constructorAbi = contractAbi.functions.find(({ name }) => name === 'constructor');
|
|
154
161
|
|
|
155
162
|
const client = createAztecRpcClient(options.rpcUrl);
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
} else {
|
|
160
|
-
const accounts = await client.getAccounts();
|
|
161
|
-
if (!accounts) {
|
|
162
|
-
throw new Error('No public key provided or found in Aztec RPC.');
|
|
163
|
-
}
|
|
164
|
-
publicKey = (await client.getPublicKeyAndPartialAddress(accounts[0]))[0];
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
log(`Using Public Key: ${publicKey.toString()}`);
|
|
168
|
-
|
|
169
|
-
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);
|
|
170
166
|
|
|
171
167
|
const constructor = getAbiFunction(contractAbi, 'constructor');
|
|
168
|
+
if (!constructor) throw new Error(`Constructor not found in contract ABI`);
|
|
172
169
|
if (constructor.parameters.length !== options.args.length) {
|
|
173
|
-
throw Error(
|
|
174
|
-
`Invalid number of args passed
|
|
170
|
+
throw new Error(
|
|
171
|
+
`Invalid number of args passed (expected ${constructor.parameters.length} but got ${options.args.length})`,
|
|
175
172
|
);
|
|
176
173
|
}
|
|
177
174
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
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`);
|
|
182
182
|
});
|
|
183
183
|
|
|
184
184
|
program
|
|
@@ -190,12 +190,13 @@ async function main() {
|
|
|
190
190
|
const client = createAztecRpcClient(options.rpcUrl);
|
|
191
191
|
const address = AztecAddress.fromString(options.contractAddress);
|
|
192
192
|
const isDeployed = await isContractDeployed(client, address);
|
|
193
|
-
log(`\
|
|
193
|
+
if (isDeployed) log(`\nContract found at ${address.toString()}\n`);
|
|
194
|
+
else log(`\nNo contract found at ${address.toString()}\n`);
|
|
194
195
|
});
|
|
195
196
|
|
|
196
197
|
program
|
|
197
198
|
.command('get-tx-receipt')
|
|
198
|
-
.argument('<txHash>', 'A
|
|
199
|
+
.argument('<txHash>', 'A transaction hash to get the receipt for.')
|
|
199
200
|
.description('Gets the receipt for the specified transaction hash.')
|
|
200
201
|
.option('-u, --rpc-url <string>', 'URL of the Aztec RPC', AZTEC_RPC_HOST || 'http://localhost:8080')
|
|
201
202
|
.action(async (_txHash, options) => {
|
|
@@ -203,9 +204,9 @@ async function main() {
|
|
|
203
204
|
const txHash = TxHash.fromString(_txHash);
|
|
204
205
|
const receipt = await client.getTxReceipt(txHash);
|
|
205
206
|
if (!receipt) {
|
|
206
|
-
log(`No receipt found for
|
|
207
|
+
log(`No receipt found for transaction hash ${_txHash}`);
|
|
207
208
|
} else {
|
|
208
|
-
log(`\
|
|
209
|
+
log(`\nTransaction receipt: \n${JsonStringify(receipt, true)}\n`);
|
|
209
210
|
}
|
|
210
211
|
});
|
|
211
212
|
|
|
@@ -234,7 +235,7 @@ async function main() {
|
|
|
234
235
|
contractData = contractDataWithOrWithoutBytecode;
|
|
235
236
|
}
|
|
236
237
|
log(`\nContract Data: \nAddress: ${contractData.contractAddress.toString()}`);
|
|
237
|
-
log(`Portal:
|
|
238
|
+
log(`Portal: ${contractData.portalContractAddress.toString()}`);
|
|
238
239
|
if ('bytecode' in contractDataWithOrWithoutBytecode) {
|
|
239
240
|
log(`Bytecode: ${contractDataWithOrWithoutBytecode.bytecode}`);
|
|
240
241
|
}
|
|
@@ -244,23 +245,18 @@ async function main() {
|
|
|
244
245
|
program
|
|
245
246
|
.command('get-logs')
|
|
246
247
|
.description('Gets all the unencrypted logs from L2 blocks in the range specified.')
|
|
247
|
-
.
|
|
248
|
-
.
|
|
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).')
|
|
249
250
|
.option('-u, --rpc-url <string>', 'URL of the Aztec RPC', AZTEC_RPC_HOST || 'http://localhost:8080')
|
|
250
|
-
.action(async
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
limit = parseInt(_take);
|
|
256
|
-
} catch {
|
|
257
|
-
log(`Invalid integer value(s) passed: ${_from}, ${_take}`);
|
|
258
|
-
return;
|
|
259
|
-
}
|
|
251
|
+
.action(async options => {
|
|
252
|
+
const { from, limit } = options;
|
|
253
|
+
const fromBlock = from ? parseInt(from) : 1;
|
|
254
|
+
const limitCount = limit ? parseInt(limit) : 100;
|
|
255
|
+
|
|
260
256
|
const client = createAztecRpcClient(options.rpcUrl);
|
|
261
|
-
const logs = await client.getUnencryptedLogs(
|
|
257
|
+
const logs = await client.getUnencryptedLogs(fromBlock, limitCount);
|
|
262
258
|
if (!logs.length) {
|
|
263
|
-
log(`No logs found in blocks ${
|
|
259
|
+
log(`No logs found in blocks ${fromBlock} to ${fromBlock + limitCount}`);
|
|
264
260
|
} else {
|
|
265
261
|
log('Logs found: \n');
|
|
266
262
|
L2BlockL2Logs.unrollLogs(logs).forEach(fnLog => log(`${fnLog.toString('ascii')}\n`));
|
|
@@ -268,8 +264,8 @@ async function main() {
|
|
|
268
264
|
});
|
|
269
265
|
|
|
270
266
|
program
|
|
271
|
-
.command('register-
|
|
272
|
-
.description(
|
|
267
|
+
.command('register-recipient')
|
|
268
|
+
.description('Register a recipient in the Aztec RPC.')
|
|
273
269
|
.option('-a, --address <aztecAddress>', "The account's Aztec address.")
|
|
274
270
|
.option('-p, --public-key <publicKey>', 'The account public key.')
|
|
275
271
|
.option('-pa, --partial-address <partialAddress', 'The partially computed address of the account contract.')
|
|
@@ -280,7 +276,7 @@ async function main() {
|
|
|
280
276
|
const publicKey = Point.fromString(options.publicKey);
|
|
281
277
|
const partialAddress = Fr.fromString(options.partialAddress);
|
|
282
278
|
|
|
283
|
-
await client.
|
|
279
|
+
await client.registerRecipient(await CompleteAddress.create(address, publicKey, partialAddress));
|
|
284
280
|
log(`\nRegistered details for Address: ${options.address}\n`);
|
|
285
281
|
});
|
|
286
282
|
|
|
@@ -295,27 +291,60 @@ async function main() {
|
|
|
295
291
|
log('No accounts found.');
|
|
296
292
|
} else {
|
|
297
293
|
log(`Accounts found: \n`);
|
|
298
|
-
for (const
|
|
299
|
-
|
|
300
|
-
log(`Address: ${address}\nPublic Key: ${pk.toString()}\nPartial Address: ${partialAddress.toString()}\n`);
|
|
294
|
+
for (const account of accounts) {
|
|
295
|
+
log(account.toReadableString());
|
|
301
296
|
}
|
|
302
297
|
}
|
|
303
298
|
});
|
|
304
299
|
|
|
305
300
|
program
|
|
306
|
-
.command('get-account
|
|
307
|
-
.description(
|
|
308
|
-
.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')
|
|
309
304
|
.option('-u, --rpc-url <string>', 'URL of the Aztec RPC', AZTEC_RPC_HOST || 'http://localhost:8080')
|
|
310
305
|
.action(async (_address, options) => {
|
|
311
306
|
const client = createAztecRpcClient(options.rpcUrl);
|
|
312
307
|
const address = AztecAddress.fromString(_address);
|
|
313
|
-
const
|
|
308
|
+
const account = await client.getAccount(address);
|
|
314
309
|
|
|
315
|
-
if (!
|
|
310
|
+
if (!account) {
|
|
316
311
|
log(`Unknown account ${_address}`);
|
|
317
312
|
} else {
|
|
318
|
-
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());
|
|
319
348
|
}
|
|
320
349
|
});
|
|
321
350
|
|
|
@@ -349,22 +378,25 @@ async function main() {
|
|
|
349
378
|
);
|
|
350
379
|
}
|
|
351
380
|
|
|
381
|
+
const privateKey = new PrivateKey(Buffer.from(stripLeadingHex(options.privateKey), 'hex'));
|
|
382
|
+
|
|
352
383
|
const client = createAztecRpcClient(options.rpcUrl);
|
|
353
|
-
const wallet = await
|
|
384
|
+
const wallet = await getAccountWallets(
|
|
354
385
|
client,
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
386
|
+
SchnorrAccountContractAbi,
|
|
387
|
+
[privateKey],
|
|
388
|
+
[privateKey],
|
|
389
|
+
[accountCreationSalt],
|
|
358
390
|
);
|
|
359
|
-
const contract = await Contract.
|
|
391
|
+
const contract = await Contract.at(contractAddress, contractAbi, wallet);
|
|
360
392
|
const tx = contract.methods[functionName](...functionArgs).send();
|
|
361
393
|
await tx.isMined();
|
|
362
|
-
log('\
|
|
394
|
+
log('\nTransaction has been mined');
|
|
363
395
|
const receipt = await tx.getReceipt();
|
|
364
|
-
log(`
|
|
365
|
-
log(`
|
|
366
|
-
log(`Block
|
|
367
|
-
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')}`);
|
|
368
400
|
});
|
|
369
401
|
|
|
370
402
|
program
|
|
@@ -399,7 +431,7 @@ async function main() {
|
|
|
399
431
|
const client = createAztecRpcClient(options.rpcUrl);
|
|
400
432
|
const from = await getTxSender(client, options.from);
|
|
401
433
|
const result = await client.viewTx(functionName, functionArgs, contractAddress, from);
|
|
402
|
-
log('\nView
|
|
434
|
+
log('\nView result: ', JsonStringify(result, true), '\n');
|
|
403
435
|
});
|
|
404
436
|
|
|
405
437
|
// Helper for users to decode hex strings into structs if needed
|
|
@@ -446,10 +478,7 @@ async function main() {
|
|
|
446
478
|
names.forEach(name => log(name));
|
|
447
479
|
});
|
|
448
480
|
|
|
449
|
-
|
|
450
|
-
}
|
|
481
|
+
compileContract(program, 'compile', log);
|
|
451
482
|
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
process.exit(1);
|
|
455
|
-
});
|
|
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2xpX2VuY29kZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvY2xpX2VuY29kZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLGlCQUFpQixDQUFDO0FBR3JDOzs7OztHQUtHO0FBQ0gsTUFBTSxVQUFVLGlCQUFpQixDQUFDLEdBQVcsRUFBRSxPQUFtQjtJQUNoRSx3Q0FBd0M7SUFDeEMsTUFBTSxHQUFHLEdBQUcsTUFBTSxDQUFDLElBQUksQ0FBQyxHQUFHLENBQUMsT0FBTyxDQUFDLE1BQU0sRUFBRSxFQUFFLENBQUMsRUFBRSxLQUFL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