1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Copyright 2019-2024 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

use crate::rpc::{ApiPaths, Ctx, Permission, RpcMethod, ServerError};
use crate::{beacon::BeaconEntry, shim::clock::ChainEpoch};
use anyhow::Result;
use fvm_ipld_blockstore::Blockstore;

/// `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 enum BeaconGetEntry {}
impl RpcMethod<1> for BeaconGetEntry {
    const NAME: &'static str = "Filecoin.BeaconGetEntry";
    const PARAM_NAMES: [&'static str; 1] = ["first"];
    const API_PATHS: ApiPaths = ApiPaths::V0; // Not supported in V1
    const PERMISSION: Permission = Permission::Read;

    type Params = (ChainEpoch,);
    type Ok = BeaconEntry;

    async fn handle(
        ctx: Ctx<impl Blockstore>,
        (first,): Self::Params,
    ) -> Result<Self::Ok, ServerError> {
        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)
    }
}