Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.

Commit

Permalink
ipc-299: implement get-chain-id
Browse files Browse the repository at this point in the history
  • Loading branch information
adlrocha committed Sep 13, 2023
1 parent b7c701d commit 0182ee6
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ipc/cli/src/commands/subnet/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
}
Expand Down
12 changes: 12 additions & 0 deletions ipc/provider/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,18 @@ impl IpcProvider {

conn.manager().get_block_hash(height).await
}

pub async fn get_chain_id(&self, subnet: &SubnetID) -> anyhow::Result<String> {
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
Expand Down
9 changes: 9 additions & 0 deletions ipc/provider/src/manager/evm/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,15 @@ impl SubnetManager for EthSubnetManager {
genesis_epoch,
})
}

async fn get_chain_id(&self) -> Result<String> {
Ok(self
.ipc_contract_info
.provider
.get_chainid()
.await?
.to_string())
}
}

#[async_trait]
Expand Down
4 changes: 4 additions & 0 deletions ipc/provider/src/manager/fevm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ impl SubnetManager for FevmSubnetManager {
.get_validator_set(subnet_id, gateway, epoch)
.await
}

async fn get_chain_id(&self) -> anyhow::Result<String> {
self.evm_subnet_manager.get_chain_id().await
}
}

#[async_trait]
Expand Down
4 changes: 4 additions & 0 deletions ipc/provider/src/manager/fvm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,10 @@ impl<T: JsonRpcClient + Send + Sync> SubnetManager for LotusSubnetManager<T> {
genesis_epoch,
})
}

async fn get_chain_id(&self) -> Result<String> {
unimplemented!()
}
}

impl<T: JsonRpcClient + Send + Sync> LotusSubnetManager<T> {
Expand Down
5 changes: 5 additions & 0 deletions ipc/provider/src/manager/subnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ pub trait SubnetManager: Send + Sync + TopDownCheckpointQuery {
gateway: Option<Address>,
epoch: Option<ChainEpoch>,
) -> Result<QueryValidatorSetResponse>;

/// 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<String>;
}

/// Trait to interact with a subnet to query the necessary information for top down checkpoint.
Expand Down

0 comments on commit 0182ee6

Please sign in to comment.