-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
109 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,38 @@ | ||
// Copyright 2019-2024 ChainSafe Systems | ||
// SPDX-License-Identifier: Apache-2.0, MIT | ||
|
||
use crate::rpc::error::JsonRpcError; | ||
use crate::rpc::Ctx; | ||
use crate::rpc::{ | ||
reflect::SelfDescribingRpcModule, ApiVersion, Ctx, JsonRpcError, RPCState, RpcMethod, | ||
RpcMethodExt as _, | ||
}; | ||
use crate::{beacon::BeaconEntry, lotus_json::LotusJson, shim::clock::ChainEpoch}; | ||
use anyhow::Result; | ||
use fvm_ipld_blockstore::Blockstore; | ||
use jsonrpsee::types::Params; | ||
|
||
pub const BEACON_GET_ENTRY: &str = "Filecoin.BeaconGetEntry"; | ||
pub fn register_all( | ||
module: &mut SelfDescribingRpcModule<RPCState<impl Blockstore + Send + Sync + 'static>>, | ||
) { | ||
BeaconGetEntry::register(module); | ||
} | ||
|
||
/// `BeaconGetEntry` returns the beacon entry for the given Filecoin epoch. If | ||
/// the entry has not yet been produced, the call will block until the entry | ||
/// becomes available | ||
pub async fn beacon_get_entry<DB: Blockstore>( | ||
params: Params<'_>, | ||
data: Ctx<DB>, | ||
) -> Result<LotusJson<BeaconEntry>, JsonRpcError> { | ||
let (first,): (ChainEpoch,) = params.parse()?; | ||
|
||
let (_, beacon) = data.beacon.beacon_for_epoch(first)?; | ||
let rr = | ||
beacon.max_beacon_round_for_epoch(data.state_manager.get_network_version(first), first); | ||
let e = beacon.entry(rr).await?; | ||
Ok(e.into()) | ||
pub enum BeaconGetEntry {} | ||
impl RpcMethod<1> for BeaconGetEntry { | ||
const NAME: &'static str = "Filecoin.BeaconGetEntry"; | ||
const PARAM_NAMES: [&'static str; 1] = ["first"]; | ||
const API_VERSION: ApiVersion = ApiVersion::V0; | ||
type Params = (ChainEpoch,); | ||
type Ok = LotusJson<BeaconEntry>; | ||
async fn handle( | ||
ctx: Ctx<impl Blockstore>, | ||
(first,): Self::Params, | ||
) -> Result<Self::Ok, JsonRpcError> { | ||
let (_, beacon) = ctx.beacon.beacon_for_epoch(first)?; | ||
let rr = | ||
beacon.max_beacon_round_for_epoch(ctx.state_manager.get_network_version(first), first); | ||
let e = beacon.entry(rr).await?; | ||
Ok(e.into()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters