From 0182ee657958c1ead6c7dcf4dfd7ef1ba1e2a3d7 Mon Sep 17 00:00:00 2001 From: Alfonso de la Rocha Date: Wed, 13 Sep 2023 05:43:02 +0200 Subject: [PATCH] ipc-299: implement get-chain-id --- ipc/cli/src/commands/subnet/rpc.rs | 2 +- ipc/provider/src/lib.rs | 12 ++++++++++++ ipc/provider/src/manager/evm/manager.rs | 9 +++++++++ ipc/provider/src/manager/fevm.rs | 4 ++++ ipc/provider/src/manager/fvm/mod.rs | 4 ++++ ipc/provider/src/manager/subnet.rs | 5 +++++ 6 files changed, 35 insertions(+), 1 deletion(-) diff --git a/ipc/cli/src/commands/subnet/rpc.rs b/ipc/cli/src/commands/subnet/rpc.rs index 9d41f519..b6bbc25f 100644 --- a/ipc/cli/src/commands/subnet/rpc.rs +++ b/ipc/cli/src/commands/subnet/rpc.rs @@ -28,7 +28,7 @@ impl CommandLineHandler for RPCSubnet { }; println!("rpc: {:?}", conn.subnet().rpc_http().to_string()); - println!("chainID: {:?}", subnet.chain_id()); + println!("chainID: {:?}", conn.manager().get_chain_id().await?); Ok(()) } } diff --git a/ipc/provider/src/lib.rs b/ipc/provider/src/lib.rs index e1bc316f..7b0730a9 100644 --- a/ipc/provider/src/lib.rs +++ b/ipc/provider/src/lib.rs @@ -625,6 +625,18 @@ impl IpcProvider { conn.manager().get_block_hash(height).await } + + pub async fn get_chain_id(&self, subnet: &SubnetID) -> anyhow::Result { + let conn = match self.connection(subnet) { + None => return Err(anyhow!("target subnet not found")), + Some(conn) => conn, + }; + + let subnet_config = conn.subnet(); + self.check_subnet(subnet_config)?; + + conn.manager().get_chain_id().await + } } /// Lotus JSON keytype format diff --git a/ipc/provider/src/manager/evm/manager.rs b/ipc/provider/src/manager/evm/manager.rs index 44df6cf9..017990dd 100644 --- a/ipc/provider/src/manager/evm/manager.rs +++ b/ipc/provider/src/manager/evm/manager.rs @@ -587,6 +587,15 @@ impl SubnetManager for EthSubnetManager { genesis_epoch, }) } + + async fn get_chain_id(&self) -> Result { + Ok(self + .ipc_contract_info + .provider + .get_chainid() + .await? + .to_string()) + } } #[async_trait] diff --git a/ipc/provider/src/manager/fevm.rs b/ipc/provider/src/manager/fevm.rs index 31c34591..159cfbf2 100644 --- a/ipc/provider/src/manager/fevm.rs +++ b/ipc/provider/src/manager/fevm.rs @@ -230,6 +230,10 @@ impl SubnetManager for FevmSubnetManager { .get_validator_set(subnet_id, gateway, epoch) .await } + + async fn get_chain_id(&self) -> anyhow::Result { + self.evm_subnet_manager.get_chain_id().await + } } #[async_trait] diff --git a/ipc/provider/src/manager/fvm/mod.rs b/ipc/provider/src/manager/fvm/mod.rs index bfc12c3a..9ac87d1d 100644 --- a/ipc/provider/src/manager/fvm/mod.rs +++ b/ipc/provider/src/manager/fvm/mod.rs @@ -395,6 +395,10 @@ impl SubnetManager for LotusSubnetManager { genesis_epoch, }) } + + async fn get_chain_id(&self) -> Result { + unimplemented!() + } } impl LotusSubnetManager { diff --git a/ipc/provider/src/manager/subnet.rs b/ipc/provider/src/manager/subnet.rs index c5c2162d..ac463636 100644 --- a/ipc/provider/src/manager/subnet.rs +++ b/ipc/provider/src/manager/subnet.rs @@ -129,6 +129,11 @@ pub trait SubnetManager: Send + Sync + TopDownCheckpointQuery { gateway: Option
, epoch: Option, ) -> Result; + + /// Get chainID for the network. + /// Returning as a `String` because the maximum value for an EVM + /// networks is a `U256` that wouldn't fit in an integer type. + async fn get_chain_id(&self) -> Result; } /// Trait to interact with a subnet to query the necessary information for top down checkpoint.