Skip to content

Commit

Permalink
feat(rpc): add endpoints for node info and valid node with epochs att…
Browse files Browse the repository at this point in the history
…ached
  • Loading branch information
matthias-wright committed Feb 13, 2024
1 parent 6976f4b commit e0c3a61
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
9 changes: 9 additions & 0 deletions core/rpc/src/api/flk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ pub trait FleekApi {
epoch: Option<u64>,
) -> RpcResult<Option<NodeInfo>>;

#[method(name = "get_node_info_epoch")]
async fn get_node_info_epoch(
&self,
public_key: NodePublicKey,
) -> RpcResult<(Option<NodeInfo>, Epoch)>;

#[method(name = "get_public_keys")]
async fn get_public_keys(&self) -> RpcResult<PublicKeys>;

Expand Down Expand Up @@ -139,6 +145,9 @@ pub trait FleekApi {
#[method(name = "is_valid_node")]
async fn is_valid_node(&self, public_key: NodePublicKey) -> RpcResult<bool>;

#[method(name = "is_valid_node_epoch")]
async fn is_valid_node_epoch(&self, public_key: NodePublicKey) -> RpcResult<(bool, Epoch)>;

#[method(name = "get_node_registry")]
async fn get_node_registry(&self, paging: Option<PagingParams>) -> RpcResult<Vec<NodeInfo>>;

Expand Down
21 changes: 21 additions & 0 deletions core/rpc/src/logic/flk_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,20 @@ impl<C: Collection> FleekApiServer for FleekApi<C> {
}))
}

async fn get_node_info_epoch(&self, pk: NodePublicKey) -> RpcResult<(Option<NodeInfo>, Epoch)> {
Ok((
self.data
.query_runner
.pubkey_to_index(&pk)
.and_then(|node_idx| {
self.data
.query_runner
.get_node_info::<NodeInfo>(&node_idx, |n| n)
}),
self.data.query_runner.get_epoch_info().epoch,
))
}

async fn get_public_keys(&self) -> RpcResult<PublicKeys> {
Ok(PublicKeys {
node_public_key: self.data.node_public_key,
Expand Down Expand Up @@ -283,6 +297,13 @@ impl<C: Collection> FleekApiServer for FleekApi<C> {
Ok(self.data.query_runner.is_valid_node(&pk))
}

async fn is_valid_node_epoch(&self, pk: NodePublicKey) -> RpcResult<(bool, Epoch)> {
Ok((
self.data.query_runner.is_valid_node(&pk),
self.data.query_runner.get_epoch_info().epoch,
))
}

async fn get_node_registry(&self, paging: Option<PagingParams>) -> RpcResult<Vec<NodeInfo>> {
Ok(self
.data
Expand Down

0 comments on commit e0c3a61

Please sign in to comment.