massa_api/
api_trait.rs

1//! Copyright (c) 2022 MASSA LABS <info@massa.net>
2//! Json RPC API for a massa-node
3use jsonrpsee::core::{RpcResult, SubscriptionResult};
4use jsonrpsee::proc_macros::rpc;
5use massa_api_exports::page::PagedVecV2;
6use massa_api_exports::ApiRequest;
7use massa_models::address::Address;
8use massa_models::block_id::BlockId;
9use massa_models::version::Version;
10
11/// Exposed API methods
12#[rpc(server)]
13pub trait MassaApi {
14    /// Get the active stakers and their active roll counts for the current cycle sorted by largest roll counts.
15    #[method(name = "get_largest_stakers")]
16    async fn get_largest_stakers(
17        &self,
18        page_request: Option<ApiRequest>,
19    ) -> RpcResult<PagedVecV2<(Address, u64)>>;
20
21    /// Get the ids of best parents for the next block to be produced along with their period
22    #[method(name = "get_next_block_best_parents")]
23    async fn get_next_block_best_parents(&self) -> RpcResult<Vec<(BlockId, u64)>>;
24
25    /// Get Massa node version.
26    #[method(name = "get_version")]
27    async fn get_version(&self) -> RpcResult<Version>;
28
29    /// New produced block.
30    #[subscription(
31		name = "subscribe_new_blocks" => "new_blocks",
32		unsubscribe = "unsubscribe_new_blocks",
33		item = Block
34	)]
35    async fn subscribe_new_blocks(&self) -> SubscriptionResult;
36
37    /// New produced blocks headers.
38    #[subscription(
39        name = "subscribe_new_blocks_headers" => "new_blocks_headers",
40        unsubscribe = "unsubscribe_new_blocks_headers",
41        item = SecureShare<BlockHeader, BlockId>
42    )]
43    async fn subscribe_new_blocks_headers(&self) -> SubscriptionResult;
44
45    /// New produced blocks with operations content.
46    #[subscription(
47		name = "subscribe_new_filled_blocks" => "new_filled_blocks",
48		unsubscribe = "unsubscribe_new_filled_blocks",
49		item = FilledBlock
50	)]
51    async fn subscribe_new_filled_blocks(&self) -> SubscriptionResult;
52
53    /// New produced operations.
54    #[subscription(
55		name = "subscribe_new_operations" => "new_operations",
56		unsubscribe = "unsubscribe_new_operations",
57		item = Operation
58	)]
59    async fn subscribe_new_operations(&self) -> SubscriptionResult;
60}