tempo_node/rpc/token/
mod.rs

1use crate::rpc::token::{
2    role_history::{RoleHistoryFilters, RoleHistoryResponse},
3    tokens::{TokensFilters, TokensResponse},
4    tokens_by_address::{TokensByAddressParams, TokensByAddressResponse},
5};
6use jsonrpsee::{core::RpcResult, proc_macros::rpc};
7use reth_node_core::rpc::result::internal_rpc_err;
8use reth_rpc_eth_api::RpcNodeCore;
9use tempo_alloy::rpc::pagination::PaginationParams;
10
11pub mod role_history;
12pub mod tokens;
13pub mod tokens_by_address;
14
15#[rpc(server, namespace = "token")]
16pub trait TempoTokenApi {
17    /// Gets paginated role change history for TIP-20 tokens on Tempo.
18    ///
19    /// Tracks role grants and revocations from the RoleMembershipUpdated event for audit trails and compliance monitoring.
20    ///
21    /// Uses cursor-based pagination for stable iteration through role changes.
22    #[method(name = "getRoleHistory")]
23    async fn role_history(
24        &self,
25        params: PaginationParams<RoleHistoryFilters>,
26    ) -> RpcResult<RoleHistoryResponse>;
27
28    /// Gets paginated TIP-20 tokens on Tempo.
29    ///
30    /// Uses cursor-based pagination for stable iteration through tokens.
31    #[method(name = "getTokens")]
32    async fn tokens(&self, params: PaginationParams<TokensFilters>) -> RpcResult<TokensResponse>;
33
34    /// Gets paginated TIP-20 tokens associated with an account address on Tempo.
35    ///
36    /// Returns tokens where the account has a balance or specific roles.
37    ///
38    /// Uses cursor-based pagination for stable iteration through tokens.
39    #[method(name = "getTokensByAddress")]
40    async fn tokens_by_address(
41        &self,
42        params: TokensByAddressParams,
43    ) -> RpcResult<TokensByAddressResponse>;
44}
45
46/// The JSON-RPC handlers for the `token_` namespace.
47#[derive(Debug, Clone, Default)]
48pub struct TempoToken<EthApi> {
49    eth_api: EthApi,
50}
51
52impl<EthApi> TempoToken<EthApi> {
53    pub fn new(eth_api: EthApi) -> Self {
54        Self { eth_api }
55    }
56}
57
58#[async_trait::async_trait]
59impl<EthApi: RpcNodeCore> TempoTokenApiServer for TempoToken<EthApi> {
60    async fn role_history(
61        &self,
62        _params: PaginationParams<RoleHistoryFilters>,
63    ) -> RpcResult<RoleHistoryResponse> {
64        Err(internal_rpc_err("unimplemented"))
65    }
66
67    async fn tokens(&self, _params: PaginationParams<TokensFilters>) -> RpcResult<TokensResponse> {
68        Err(internal_rpc_err("unimplemented"))
69    }
70
71    async fn tokens_by_address(
72        &self,
73        _params: TokensByAddressParams,
74    ) -> RpcResult<TokensByAddressResponse> {
75        Err(internal_rpc_err("unimplemented"))
76    }
77}
78
79impl<EthApi: RpcNodeCore> TempoToken<EthApi> {
80    /// Access the underlying provider.
81    pub fn provider(&self) -> &EthApi::Provider {
82        self.eth_api.provider()
83    }
84}