Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rpc) Implement Filecoin.EthProtocolVersion #4513

Merged
merged 10 commits into from
Jul 15, 2024
20 changes: 20 additions & 0 deletions src/rpc/methods/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1701,6 +1701,26 @@ impl RpcMethod<2> for EthGetTransactionCount {
}
}

pub enum EthProtocolVersion {}
impl RpcMethod<0> for EthProtocolVersion {
const NAME: &'static str = "Filecoin.EthProtocolVersion";
const PARAM_NAMES: [&'static str; 0] = [];
const API_PATHS: ApiPaths = ApiPaths::V1;
const PERMISSION: Permission = Permission::Read;

type Params = ();
type Ok = Uint64;

async fn handle(
ctx: Ctx<impl Blockstore + Send + Sync + 'static>,
(): Self::Params,
) -> Result<Self::Ok, ServerError> {
let epoch = ctx.chain_store.heaviest_tipset().epoch();
let version = u32::from(ctx.state_manager.get_network_version(epoch).0);
Ok(Uint64(version.into()))
}
}

#[cfg(test)]
mod test {
use super::*;
Expand Down
1 change: 1 addition & 0 deletions src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ macro_rules! for_each_method {
$callback!(crate::rpc::eth::EthGetBlockTransactionCountByNumber);
$callback!(crate::rpc::eth::EthGetMessageCidByTransactionHash);
$callback!(crate::rpc::eth::EthGetTransactionCount);
$callback!(crate::rpc::eth::EthProtocolVersion);

// gas vertical
$callback!(crate::rpc::gas::GasEstimateGasLimit);
Expand Down
1 change: 1 addition & 0 deletions src/tool/subcommands/api_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,7 @@ fn eth_tests() -> Vec<RpcTest> {
.unwrap(),
),
RpcTest::basic(Web3ClientVersion::request(()).unwrap()),
RpcTest::identity(EthProtocolVersion::request(()).unwrap()),
]
}

Expand Down
Loading