|
1 | 1 | import { Fr, computeSecretHash, fileURLToPath } from '@aztec/aztec.js';
|
| 2 | +import { LOCALHOST } from '@aztec/cli/cli-utils'; |
2 | 3 | import { type LogFn, createConsoleLogger, createDebugLogger } from '@aztec/foundation/log';
|
3 | 4 | import { AztecLmdbStore } from '@aztec/kv-store/lmdb';
|
| 5 | +import { type PXEService } from '@aztec/pxe'; |
4 | 6 |
|
5 |
| -import { Argument, Command } from 'commander'; |
| 7 | +import { Argument, Command, Option } from 'commander'; |
6 | 8 | import { readFileSync } from 'fs';
|
7 |
| -import { dirname, resolve } from 'path'; |
| 9 | +import { dirname, join, resolve } from 'path'; |
8 | 10 |
|
9 | 11 | import { injectCommands } from '../cmds/index.js';
|
10 | 12 | import { Aliases, WalletDB } from '../storage/wallet_db.js';
|
11 | 13 | import { createAliasOption } from '../utils/options/index.js';
|
| 14 | +import { PXEWrapper } from '../utils/pxe_wrapper.js'; |
12 | 15 |
|
13 | 16 | const userLog = createConsoleLogger();
|
14 | 17 | const debugLogger = createDebugLogger('aztec:wallet');
|
@@ -66,18 +69,39 @@ async function main() {
|
66 | 69 | const walletVersion: string = JSON.parse(readFileSync(packageJsonPath).toString()).version;
|
67 | 70 |
|
68 | 71 | const db = WalletDB.getInstance();
|
| 72 | + const pxeWrapper = new PXEWrapper(); |
69 | 73 |
|
70 | 74 | const program = new Command('wallet');
|
71 | 75 | program
|
72 | 76 | .description('Aztec wallet')
|
73 | 77 | .version(walletVersion)
|
74 | 78 | .option('-d, --data-dir <string>', 'Storage directory for wallet data', WALLET_DATA_DIRECTORY)
|
75 |
| - .hook('preSubcommand', command => { |
76 |
| - const dataDir = command.optsWithGlobals().dataDir; |
| 79 | + .addOption( |
| 80 | + new Option('--remote-pxe', 'Connect to an external PXE RPC server, instead of the local one') |
| 81 | + .env('REMOTE_PXE') |
| 82 | + .default(false) |
| 83 | + .conflicts('rpc-url'), |
| 84 | + ) |
| 85 | + .addOption( |
| 86 | + new Option('-n, --node-url <string>', 'URL of the Aztec node to connect to') |
| 87 | + .env('AZTEC_NODE_URL') |
| 88 | + .default(`http://${LOCALHOST}:8080`), |
| 89 | + ) |
| 90 | + .hook('preSubcommand', async command => { |
| 91 | + const { dataDir, remotePxe, nodeUrl } = command.optsWithGlobals(); |
| 92 | + if (!remotePxe) { |
| 93 | + debugLogger.info('Using local PXE service'); |
| 94 | + await pxeWrapper.init(nodeUrl, join(dataDir, 'pxe')); |
| 95 | + } |
77 | 96 | db.init(AztecLmdbStore.open(dataDir));
|
| 97 | + }) |
| 98 | + .hook('postAction', async () => { |
| 99 | + if (pxeWrapper.getPXE()) { |
| 100 | + await (pxeWrapper.getPXE() as PXEService).stop(); |
| 101 | + } |
78 | 102 | });
|
79 | 103 |
|
80 |
| - injectCommands(program, userLog, debugLogger, db); |
| 104 | + injectCommands(program, userLog, debugLogger, db, pxeWrapper); |
81 | 105 | injectInternalCommands(program, userLog, db);
|
82 | 106 | await program.parseAsync(process.argv);
|
83 | 107 | }
|
|
0 commit comments