2026-01-29 22:20:42 +03:00
|
|
|
use indexer_service_protocol::{Account, AccountId, Block, BlockId, HashType, Transaction};
|
2026-01-28 03:21:43 +03:00
|
|
|
use jsonrpsee::proc_macros::rpc;
|
|
|
|
|
#[cfg(feature = "server")]
|
|
|
|
|
use jsonrpsee::{core::SubscriptionResult, types::ErrorObjectOwned};
|
2026-01-24 04:05:59 +03:00
|
|
|
|
|
|
|
|
#[cfg(all(not(feature = "server"), not(feature = "client")))]
|
|
|
|
|
compile_error!("At least one of `server` or `client` features must be enabled.");
|
|
|
|
|
|
2026-01-28 03:21:43 +03:00
|
|
|
#[cfg_attr(all(feature = "server", not(feature = "client")), rpc(server))]
|
|
|
|
|
#[cfg_attr(all(feature = "client", not(feature = "server")), rpc(client))]
|
|
|
|
|
#[cfg_attr(all(feature = "server", feature = "client"), rpc(server, client))]
|
2026-01-24 04:05:59 +03:00
|
|
|
pub trait Rpc {
|
2026-02-13 01:49:20 +03:00
|
|
|
#[method(name = "getSchema")]
|
2026-01-24 04:05:59 +03:00
|
|
|
fn get_schema(&self) -> Result<serde_json::Value, ErrorObjectOwned> {
|
|
|
|
|
// TODO: Canonical solution would be to provide `describe` method returning OpenRPC spec,
|
|
|
|
|
// But for now it's painful to implement, although can be done if really needed.
|
|
|
|
|
// Currently we can wait until we can auto-generated it: https://github.com/paritytech/jsonrpsee/issues/737
|
|
|
|
|
// and just return JSON schema.
|
|
|
|
|
|
|
|
|
|
// Block schema contains all other types used in the protocol, so it's sufficient to return
|
|
|
|
|
// its schema.
|
|
|
|
|
let block_schema = schemars::schema_for!(Block);
|
|
|
|
|
Ok(serde_json::to_value(block_schema).expect("Schema serialization should not fail"))
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-31 18:56:04 -03:00
|
|
|
#[subscription(name = "subscribeToFinalizedBlocks", item = BlockId)]
|
2026-01-30 21:37:27 +03:00
|
|
|
async fn subscribe_to_finalized_blocks(&self) -> SubscriptionResult;
|
2026-01-24 04:05:59 +03:00
|
|
|
|
2026-02-09 15:05:01 +02:00
|
|
|
#[method(name = "getLastFinalizedBlockId")]
|
|
|
|
|
async fn get_last_finalized_block_id(&self) -> Result<BlockId, ErrorObjectOwned>;
|
|
|
|
|
|
2026-01-24 04:05:59 +03:00
|
|
|
#[method(name = "getBlockById")]
|
|
|
|
|
async fn get_block_by_id(&self, block_id: BlockId) -> Result<Block, ErrorObjectOwned>;
|
|
|
|
|
|
|
|
|
|
#[method(name = "getBlockByHash")]
|
2026-01-29 22:20:42 +03:00
|
|
|
async fn get_block_by_hash(&self, block_hash: HashType) -> Result<Block, ErrorObjectOwned>;
|
2026-01-24 04:05:59 +03:00
|
|
|
|
|
|
|
|
#[method(name = "getAccount")]
|
|
|
|
|
async fn get_account(&self, account_id: AccountId) -> Result<Account, ErrorObjectOwned>;
|
|
|
|
|
|
|
|
|
|
#[method(name = "getTransaction")]
|
2026-01-29 22:20:42 +03:00
|
|
|
async fn get_transaction(&self, tx_hash: HashType) -> Result<Transaction, ErrorObjectOwned>;
|
2026-01-28 03:21:43 +03:00
|
|
|
|
|
|
|
|
#[method(name = "getBlocks")]
|
2026-03-04 21:54:23 +03:00
|
|
|
async fn get_blocks(
|
|
|
|
|
&self,
|
2026-03-03 23:21:08 +03:00
|
|
|
before: Option<BlockId>,
|
|
|
|
|
limit: u64,
|
2026-03-04 21:54:23 +03:00
|
|
|
) -> Result<Vec<Block>, ErrorObjectOwned>;
|
2026-01-28 03:21:43 +03:00
|
|
|
|
|
|
|
|
#[method(name = "getTransactionsByAccount")]
|
|
|
|
|
async fn get_transactions_by_account(
|
|
|
|
|
&self,
|
|
|
|
|
account_id: AccountId,
|
2026-03-03 23:21:08 +03:00
|
|
|
offset: u64,
|
|
|
|
|
limit: u64,
|
2026-01-28 03:21:43 +03:00
|
|
|
) -> Result<Vec<Transaction>, ErrorObjectOwned>;
|
2026-02-09 15:05:01 +02:00
|
|
|
|
|
|
|
|
// ToDo: expand healthcheck response into some kind of report
|
|
|
|
|
#[method(name = "checkHealth")]
|
|
|
|
|
async fn healthcheck(&self) -> Result<(), ErrorObjectOwned>;
|
2026-01-24 04:05:59 +03:00
|
|
|
}
|