Skip to content

Commit

Permalink
add the show-web3-rpc-list subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
haxjump committed Oct 9, 2024
1 parent be90191 commit 46d0c7a
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 47 deletions.
96 changes: 49 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,26 @@ Manage development clusters on a local host
Usage: nbnet dev [OPTIONS] [COMMAND]

Commands:
create Create a new ENV
destroy Destroy an existing ENV
destroy-all Destroy all existing ENVs
protect Protect an existing ENV
unprotect Unprotect an existing ENV
start Start an existing ENV
start-all Start all existing ENVs
stop Stop an existing ENV
stop-all Stop all existing ENVs
push-node Push a new node to an existing ENV
kick-node Remove an existing node from an existing ENV
switch-EL-to-geth Switch the EL client to `geth`,
NOTE: the node will be left stopped, a `start` operation may be needed
switch-EL-to-reth Switch the EL client to `reth`,
NOTE: the node will be left stopped, a `start` operation may be needed
show Default operation, show the information of an existing ENV
show-all Show informations of all existing ENVs
list Show names of all existing ENVs
help Print this message or the help of the given subcommand(s)
create Create a new ENV
destroy Destroy an existing ENV
destroy-all Destroy all existing ENVs
protect Protect an existing ENV
unprotect Unprotect an existing ENV
start Start an existing ENV
start-all Start all existing ENVs
stop Stop an existing ENV
stop-all Stop all existing ENVs
push-node Push a new node to an existing ENV
kick-node Remove an existing node from an existing ENV
switch-EL-to-geth Switch the EL client to `geth`,
NOTE: the node will be left stopped, a `start` operation may be needed
switch-EL-to-reth Switch the EL client to `reth`,
NOTE: the node will be left stopped, a `start` operation may be needed
show Default operation, show the information of an existing ENV
show-all Show informations of all existing ENVs
show-web3-rpc-list, -w Show the collection of web3 RPC endpoints of the entire ENV
list Show names of all existing ENVs
help Print this message or the help of the given subcommand(s)

Options:
-e, --env-name <ENV_NAME>
Expand All @@ -73,34 +74,35 @@ Manage development clusters on various distributed hosts
Usage: nbnet ddev [OPTIONS] [COMMAND]

Commands:
create Create a new ENV
destroy Destroy an existing ENV
destroy-all Destroy all existing ENVs
protect Protect an existing ENV
unprotect Unprotect an existing ENV
start Start an existing ENV
start-all Start all existing ENVs
stop Stop an existing ENV
stop-all Stop all existing ENVs
push-node Push a new node to an existing ENV
migrate-node Migrate an existing node to another host,
NOTE: the node will be left stopped, a `start` operation may be needed
kick-node Remove an existing node from an existing ENV
switch-EL-to-geth Switch the EL client to `geth`,
NOTE: the node will be left stopped, a `start` operation may be needed
switch-EL-to-reth Switch the EL client to `reth`,
NOTE: the node will be left stopped, a `start` operation may be needed
push-host Add a new host to the cluster
kick-host Remove a host from the cluster
show Default operation, show the information of an existing ENV
show-all Show informations of all existing ENVs
list Show names of all existing ENVs
host-put-file Put a local file to all remote hosts
host-get-file Get a remote file from all remote hosts
host-exec Execute commands on all remote hosts
get-logs Get the remote logs from all nodes of the ENV
dump-vc-data Dump the validator client data from all nodes of the ENV
help Print this message or the help of the given subcommand(s)
create Create a new ENV
destroy Destroy an existing ENV
destroy-all Destroy all existing ENVs
protect Protect an existing ENV
unprotect Unprotect an existing ENV
start Start an existing ENV
start-all Start all existing ENVs
stop Stop an existing ENV
stop-all Stop all existing ENVs
push-node Push a new node to an existing ENV
migrate-node Migrate an existing node to another host,
NOTE: the node will be left stopped, a `start` operation may be needed
kick-node Remove an existing node from an existing ENV
switch-EL-to-geth Switch the EL client to `geth`,
NOTE: the node will be left stopped, a `start` operation may be needed
switch-EL-to-reth Switch the EL client to `reth`,
NOTE: the node will be left stopped, a `start` operation may be needed
push-host Add a new host to the cluster
kick-host Remove a host from the cluster
show Default operation, show the information of an existing ENV
show-all Show informations of all existing ENVs
show-web3-rpc-list, -w Show the collection of web3 RPC endpoints of the entire ENV
list Show names of all existing ENVs
host-put-file Put a local file to all remote hosts
host-get-file Get a remote file from all remote hosts
host-exec Execute commands on all remote hosts
get-logs Get the remote logs from all nodes of the ENV
dump-vc-data Dump the validator client data from all nodes of the ENV
help Print this message or the help of the given subcommand(s)

Options:
-e, --env-name <ENV_NAME>
Expand Down
16 changes: 16 additions & 0 deletions src/cfg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ NOTE: the node will be left stopped, a `start` operation may be needed"
},
#[clap(about = "Show informations of all existing ENVs")]
ShowAll,
#[clap(
short_flag = 'w',
about = "Show the collection of web3 RPC endpoints of the entire ENV"
)]
ShowWeb3RpcList {
#[clap(short = 'e', long)]
env_name: Option<String>,
},
#[clap(about = "Show names of all existing ENVs")]
List,
}
Expand Down Expand Up @@ -357,6 +365,14 @@ NOTE: the node will be left stopped, a `start` operation may be needed"
},
#[clap(about = "Show informations of all existing ENVs")]
ShowAll,
#[clap(
short_flag = 'w',
about = "Show the collection of web3 RPC endpoints of the entire ENV"
)]
ShowWeb3RpcList {
#[clap(short = 'e', long)]
env_name: Option<String>,
},
#[clap(about = "Show names of all existing ENVs")]
List,
#[clap(about = "Put a local file to all remote hosts")]
Expand Down
17 changes: 17 additions & 0 deletions src/ddev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ impl From<DDevCfg> for EnvCfg {
}
Op::Show
}
DDevOp::ShowWeb3RpcList { env_name } => {
if let Some(n) = env_name {
en = n.into();
}
Op::Custom(ExtraOp::ShowWeb3RpcList)
}
DDevOp::ShowAll => Op::ShowAll,
DDevOp::List => Op::List,
DDevOp::HostPutFile {
Expand Down Expand Up @@ -650,6 +656,7 @@ fn env_hosts() -> Option<Hosts> {

#[derive(Clone, Debug, Serialize, Deserialize)]
enum ExtraOp {
ShowWeb3RpcList,
GetLogs(Option<String>),
DumpVcData(Option<String>),
SwitchELToGeth(NodeID),
Expand All @@ -663,6 +670,16 @@ impl CustomOps for ExtraOp {
.c(d!("ENV does not exist!"))?;

match self {
Self::ShowWeb3RpcList => {
env.meta
.bootstraps
.values()
.chain(env.meta.nodes.values())
.for_each(|n| {
println!("{}:{}", n.host.addr.connection_addr(), n.ports.el_rpc);
});
Ok(())
}
Self::GetLogs(ldir) => env_collect_files(
&env,
&[
Expand Down
17 changes: 17 additions & 0 deletions src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ impl From<DevCfg> for EnvCfg {
}
Op::Show
}
DevOp::ShowWeb3RpcList { env_name } => {
if let Some(n) = env_name {
en = n.into();
}
Op::Custom(ExtraOp::ShowWeb3RpcList)
}
DevOp::ShowAll => Op::ShowAll,
DevOp::List => Op::List,
};
Expand Down Expand Up @@ -494,6 +500,7 @@ fi "#

#[derive(Clone, Debug, Serialize, Deserialize)]
enum ExtraOp {
ShowWeb3RpcList,
SwitchELToGeth(NodeID),
SwitchELToReth(NodeID),
}
Expand All @@ -505,6 +512,16 @@ impl CustomOps for ExtraOp {
.c(d!("ENV does not exist!"))?;

match self {
Self::ShowWeb3RpcList => {
env.meta
.bootstraps
.values()
.chain(env.meta.nodes.values())
.for_each(|n| {
println!("{}:{}", &env.meta.host_ip, n.ports.el_rpc);
});
Ok(())
}
Self::SwitchELToGeth(id) => {
let n = env
.meta
Expand Down

0 comments on commit 46d0c7a

Please sign in to comment.