Skip to content

Commit

Permalink
feat: json output for get_node_info (#10771)
Browse files Browse the repository at this point in the history
Need this to (easily) update the network joiner script.
  • Loading branch information
just-mitch authored Dec 16, 2024
1 parent c8e7763 commit b086c52
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 23 deletions.
79 changes: 57 additions & 22 deletions yarn-project/cli/src/cmds/pxe/get_node_info.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,69 @@
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);
} else {
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()}`);
}
}
3 changes: 2 additions & 1 deletion yarn-project/cli/src/cmds/pxe/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <string>', 'URL of the node.')
.option('--json', 'Emit output as json')
.addOption(makePxeOption(false))
.action(async options => {
const { getNodeInfo } = await import('./get_node_info.js');
Expand All @@ -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
Expand Down

0 comments on commit b086c52

Please sign in to comment.