feat: machine readable registry utils (#4444)

### Description

- **Add --contract option to registry addresses cmd**
- **Add registry rpc cmd**

### Backward compatibility

Yes

### Testing

Manual
pull/4477/head
Yorke Rhodes 2 months ago committed by GitHub
parent 518a1bef91
commit a46fe434a4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      .changeset/pink-paws-fry.md
  2. 52
      typescript/cli/src/commands/registry.ts

@ -0,0 +1,5 @@
---
'@hyperlane-xyz/cli': minor
---
Add hyperlane registry rpc and addresses --contract utils

@ -20,6 +20,7 @@ export const registryCommand: CommandModule = {
builder: (yargs) =>
yargs
.command(addressesCommand)
.command(rpcCommand)
.command(createAgentConfigCommand)
.command(initCommand)
.command(listCommand)
@ -71,8 +72,12 @@ const listCommand: CommandModuleWithContext<{ type: ChainType }> = {
/**
* Addresses command
*/
const addressesCommand: CommandModuleWithContext<{ name: string }> = {
const addressesCommand: CommandModuleWithContext<{
name: string;
contract: string;
}> = {
command: 'addresses',
aliases: ['address', 'addy'],
describe: 'Display the addresses of core Hyperlane contracts',
builder: {
name: {
@ -80,10 +85,21 @@ const addressesCommand: CommandModuleWithContext<{ name: string }> = {
description: 'Chain to display addresses for',
alias: 'chain',
},
contract: {
type: 'string',
description: 'Specific contract name to print addresses for',
implies: 'name',
},
},
handler: async ({ name, context }) => {
handler: async ({ name, context, contract }) => {
if (name) {
const result = await context.registry.getChainAddresses(name);
if (contract && result?.[contract.toLowerCase()]) {
// log only contract address for machine readability
log(result[contract]);
return;
}
logBlue('Hyperlane contract addresses for:', name);
logGray('---------------------------------');
log(JSON.stringify(result, null, 2));
@ -96,6 +112,38 @@ const addressesCommand: CommandModuleWithContext<{ name: string }> = {
},
};
const rpcCommand: CommandModuleWithContext<{
name: string;
index: number;
}> = {
command: 'rpc',
describe: 'Display the public rpc of a Hyperlane chain',
builder: {
name: {
type: 'string',
description: 'Chain to display addresses for',
alias: 'chain',
demandOption: true,
},
index: {
type: 'number',
description: 'Index of the rpc to display',
default: 0,
demandOption: false,
},
},
handler: async ({ name, context, index }) => {
const result = await context.registry.getChainMetadata(name);
const rpcUrl = result?.rpcUrls[index]?.http;
if (!rpcUrl) {
errorRed(`❌ No rpc found for chain ${name}`);
process.exit(1);
}
log(rpcUrl);
},
};
/**
* agent-config command
*/

Loading…
Cancel
Save