From b086c52110e5bc79a3d8eccbc2bc50cd68b3dc9b Mon Sep 17 00:00:00 2001 From: just-mitch <68168980+just-mitch@users.noreply.github.com> Date: Mon, 16 Dec 2024 15:49:13 -0500 Subject: [PATCH] feat: json output for get_node_info (#10771) Need this to (easily) update the network joiner script. --- .../cli/src/cmds/pxe/get_node_info.ts | 79 +++++++++++++------ yarn-project/cli/src/cmds/pxe/index.ts | 3 +- 2 files changed, 59 insertions(+), 23 deletions(-) diff --git a/yarn-project/cli/src/cmds/pxe/get_node_info.ts b/yarn-project/cli/src/cmds/pxe/get_node_info.ts index d2972b9f1e6..329b2428297 100644 --- a/yarn-project/cli/src/cmds/pxe/get_node_info.ts +++ b/yarn-project/cli/src/cmds/pxe/get_node_info.ts @@ -1,7 +1,14 @@ import { type AztecNode, type PXE, createAztecNodeClient, createCompatibleClient } from '@aztec/aztec.js'; import { type LogFn, type Logger } from '@aztec/foundation/log'; -export async function getNodeInfo(rpcUrl: string, pxeRequest: boolean, debugLogger: Logger, log: LogFn) { +export async function getNodeInfo( + rpcUrl: string, + pxeRequest: boolean, + debugLogger: Logger, + json: boolean, + log: LogFn, + logJson: (output: any) => void, +) { let client: AztecNode | PXE; if (pxeRequest) { client = await createCompatibleClient(rpcUrl, debugLogger); @@ -9,26 +16,54 @@ export async function getNodeInfo(rpcUrl: string, pxeRequest: boolean, debugLogg client = createAztecNodeClient(rpcUrl); } const info = await client.getNodeInfo(); - log(`Node Version: ${info.nodeVersion}`); - log(`Chain Id: ${info.l1ChainId}`); - log(`Protocol Version: ${info.protocolVersion}`); - log(`Node ENR: ${info.enr}`); - log(`L1 Contract Addresses:`); - log(` Rollup Address: ${info.l1ContractAddresses.rollupAddress.toString()}`); - log(` Registry Address: ${info.l1ContractAddresses.registryAddress.toString()}`); - log(` L1 -> L2 Inbox Address: ${info.l1ContractAddresses.inboxAddress.toString()}`); - log(` L2 -> L1 Outbox Address: ${info.l1ContractAddresses.outboxAddress.toString()}`); - log(` Fee Juice Address: ${info.l1ContractAddresses.feeJuiceAddress.toString()}`); - log(` Staking Asset Address: ${info.l1ContractAddresses.stakingAssetAddress.toString()}`); - log(` Fee Juice Portal Address: ${info.l1ContractAddresses.feeJuicePortalAddress.toString()}`); - log(` CoinIssuer Address: ${info.l1ContractAddresses.coinIssuerAddress.toString()}`); - log(` RewardDistributor Address: ${info.l1ContractAddresses.rewardDistributorAddress.toString()}`); - log(` GovernanceProposer Address: ${info.l1ContractAddresses.governanceProposerAddress.toString()}`); - log(` Governance Address: ${info.l1ContractAddresses.governanceAddress.toString()}`); + if (json) { + logJson({ + nodeVersion: info.nodeVersion, + l1ChainId: info.l1ChainId, + protocolVersion: info.protocolVersion, + enr: info.enr, + l1ContractAddresses: { + rollup: info.l1ContractAddresses.rollupAddress.toString(), + registry: info.l1ContractAddresses.registryAddress.toString(), + inbox: info.l1ContractAddresses.inboxAddress.toString(), + outbox: info.l1ContractAddresses.outboxAddress.toString(), + feeJuice: info.l1ContractAddresses.feeJuiceAddress.toString(), + stakingAsset: info.l1ContractAddresses.stakingAssetAddress.toString(), + feeJuicePortal: info.l1ContractAddresses.feeJuicePortalAddress.toString(), + coinIssuer: info.l1ContractAddresses.coinIssuerAddress.toString(), + rewardDistributor: info.l1ContractAddresses.rewardDistributorAddress.toString(), + governanceProposer: info.l1ContractAddresses.governanceProposerAddress.toString(), + governance: info.l1ContractAddresses.governanceAddress.toString(), + }, + protocolContractAddresses: { + classRegisterer: info.protocolContractAddresses.classRegisterer.toString(), + feeJuice: info.protocolContractAddresses.feeJuice.toString(), + instanceDeployer: info.protocolContractAddresses.instanceDeployer.toString(), + multiCallEntrypoint: info.protocolContractAddresses.multiCallEntrypoint.toString(), + }, + }); + } else { + log(`Node Version: ${info.nodeVersion}`); + log(`Chain Id: ${info.l1ChainId}`); + log(`Protocol Version: ${info.protocolVersion}`); + log(`Node ENR: ${info.enr}`); + log(`L1 Contract Addresses:`); + log(` Rollup Address: ${info.l1ContractAddresses.rollupAddress.toString()}`); + log(` Registry Address: ${info.l1ContractAddresses.registryAddress.toString()}`); + log(` L1 -> L2 Inbox Address: ${info.l1ContractAddresses.inboxAddress.toString()}`); + log(` L2 -> L1 Outbox Address: ${info.l1ContractAddresses.outboxAddress.toString()}`); + log(` Fee Juice Address: ${info.l1ContractAddresses.feeJuiceAddress.toString()}`); + log(` Staking Asset Address: ${info.l1ContractAddresses.stakingAssetAddress.toString()}`); + log(` Fee Juice Portal Address: ${info.l1ContractAddresses.feeJuicePortalAddress.toString()}`); + log(` CoinIssuer Address: ${info.l1ContractAddresses.coinIssuerAddress.toString()}`); + log(` RewardDistributor Address: ${info.l1ContractAddresses.rewardDistributorAddress.toString()}`); + log(` GovernanceProposer Address: ${info.l1ContractAddresses.governanceProposerAddress.toString()}`); + log(` Governance Address: ${info.l1ContractAddresses.governanceAddress.toString()}`); - log(`L2 Contract Addresses:`); - log(` Class Registerer: ${info.protocolContractAddresses.classRegisterer.toString()}`); - log(` Fee Juice: ${info.protocolContractAddresses.feeJuice.toString()}`); - log(` Instance Deployer: ${info.protocolContractAddresses.instanceDeployer.toString()}`); - log(` MultiCall: ${info.protocolContractAddresses.multiCallEntrypoint.toString()}`); + log(`L2 Contract Addresses:`); + log(` Class Registerer: ${info.protocolContractAddresses.classRegisterer.toString()}`); + log(` Fee Juice: ${info.protocolContractAddresses.feeJuice.toString()}`); + log(` Instance Deployer: ${info.protocolContractAddresses.instanceDeployer.toString()}`); + log(` MultiCall: ${info.protocolContractAddresses.multiCallEntrypoint.toString()}`); + } } diff --git a/yarn-project/cli/src/cmds/pxe/index.ts b/yarn-project/cli/src/cmds/pxe/index.ts index dc8a7a4bb6a..56fe779ac17 100644 --- a/yarn-project/cli/src/cmds/pxe/index.ts +++ b/yarn-project/cli/src/cmds/pxe/index.ts @@ -144,6 +144,7 @@ export function injectCommands(program: Command, log: LogFn, debugLogger: Logger .command('get-node-info') .description('Gets the information of an Aztec node from a PXE or directly from an Aztec node.') .option('--node-url ', 'URL of the node.') + .option('--json', 'Emit output as json') .addOption(makePxeOption(false)) .action(async options => { const { getNodeInfo } = await import('./get_node_info.js'); @@ -153,7 +154,7 @@ export function injectCommands(program: Command, log: LogFn, debugLogger: Logger } else { url = options.rpcUrl; } - await getNodeInfo(url, !options.nodeUrl, debugLogger, log); + await getNodeInfo(url, !options.nodeUrl, debugLogger, options.json, log, logJson(log)); }); program