sui_json_rpc_api/indexer.rs
1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use jsonrpsee::core::{RpcResult, SubscriptionResult};
5use jsonrpsee::proc_macros::rpc;
6
7use sui_json_rpc_types::SuiTransactionBlockEffects;
8use sui_json_rpc_types::{
9 DynamicFieldPage, EventFilter, EventPage, ObjectsPage, Page, SuiEvent, SuiObjectResponse,
10 SuiObjectResponseQuery, SuiTransactionBlockResponseQuery, TransactionBlocksPage,
11 TransactionFilter,
12};
13use sui_open_rpc_macros::open_rpc;
14use sui_types::base_types::{ObjectID, SuiAddress};
15use sui_types::digests::TransactionDigest;
16use sui_types::dynamic_field::DynamicFieldName;
17use sui_types::event::EventID;
18
19#[open_rpc(namespace = "suix", tag = "Extended API")]
20#[rpc(server, client, namespace = "suix")]
21pub trait IndexerApi {
22 /// Return the list of objects owned by an address.
23 /// Note that if the address owns more than `QUERY_MAX_RESULT_LIMIT` objects,
24 /// the pagination is not accurate, because previous page may have been updated when
25 /// the next page is fetched.
26 /// Please use suix_queryObjects if this is a concern.
27 #[method(name = "getOwnedObjects")]
28 async fn get_owned_objects(
29 &self,
30 /// the owner's Sui address
31 address: SuiAddress,
32 /// the objects query criteria.
33 query: Option<SuiObjectResponseQuery>,
34 /// An optional paging cursor. If provided, the query will start from the next item after the specified cursor. Default to start from the first item if not specified.
35 cursor: Option<ObjectID>,
36 /// Max number of items returned per page, default to [QUERY_MAX_RESULT_LIMIT] if not specified.
37 limit: Option<usize>,
38 ) -> RpcResult<ObjectsPage>;
39
40 /// Return list of transactions for a specified query criteria.
41 #[method(name = "queryTransactionBlocks")]
42 async fn query_transaction_blocks(
43 &self,
44 /// the transaction query criteria.
45 query: SuiTransactionBlockResponseQuery,
46 /// An optional paging cursor. If provided, the query will start from the next item after the specified cursor. Default to start from the first item if not specified.
47 cursor: Option<TransactionDigest>,
48 /// Maximum item returned per page, default to QUERY_MAX_RESULT_LIMIT if not specified.
49 limit: Option<usize>,
50 /// query result ordering, default to false (ascending order), oldest record first.
51 descending_order: Option<bool>,
52 ) -> RpcResult<TransactionBlocksPage>;
53
54 /// Return list of events for a specified query criteria.
55 #[method(name = "queryEvents")]
56 async fn query_events(
57 &self,
58 /// The event query criteria. See [Event filter](https://docs.sui.io/build/event_api#event-filters) documentation for examples.
59 query: EventFilter,
60 /// optional paging cursor
61 cursor: Option<EventID>,
62 /// maximum number of items per page, default to [QUERY_MAX_RESULT_LIMIT] if not specified.
63 limit: Option<usize>,
64 /// query result ordering, default to false (ascending order), oldest record first.
65 descending_order: Option<bool>,
66 ) -> RpcResult<EventPage>;
67
68 /// Subscribe to a stream of Sui event
69 #[subscription(name = "subscribeEvent", item = SuiEvent)]
70 fn subscribe_event(
71 &self,
72 /// The filter criteria of the event stream. See [Event filter](https://docs.sui.io/build/event_api#event-filters) documentation for examples.
73 filter: EventFilter,
74 ) -> SubscriptionResult;
75
76 /// Subscribe to a stream of Sui transaction effects
77 #[subscription(name = "subscribeTransaction", item = SuiTransactionBlockEffects)]
78 fn subscribe_transaction(&self, filter: TransactionFilter) -> SubscriptionResult;
79
80 /// Return the list of dynamic field objects owned by an object.
81 #[method(name = "getDynamicFields")]
82 async fn get_dynamic_fields(
83 &self,
84 /// The ID of the parent object
85 parent_object_id: ObjectID,
86 /// An optional paging cursor. If provided, the query will start from the next item after the specified cursor. Default to start from the first item if not specified.
87 cursor: Option<ObjectID>,
88 /// Maximum item returned per page, default to [QUERY_MAX_RESULT_LIMIT] if not specified.
89 limit: Option<usize>,
90 ) -> RpcResult<DynamicFieldPage>;
91
92 /// Return the dynamic field object information for a specified object
93 #[method(name = "getDynamicFieldObject")]
94 async fn get_dynamic_field_object(
95 &self,
96 /// The ID of the queried parent object
97 parent_object_id: ObjectID,
98 /// The Name of the dynamic field
99 name: DynamicFieldName,
100 ) -> RpcResult<SuiObjectResponse>;
101
102 /// Return the resolved address given resolver and name
103 #[method(name = "resolveNameServiceAddress")]
104 async fn resolve_name_service_address(
105 &self,
106 /// The name to resolve
107 name: String,
108 ) -> RpcResult<Option<SuiAddress>>;
109
110 /// Return the resolved names given address,
111 /// if multiple names are resolved, the first one is the primary name.
112 #[method(name = "resolveNameServiceNames")]
113 async fn resolve_name_service_names(
114 &self,
115 /// The address to resolve
116 address: SuiAddress,
117 cursor: Option<ObjectID>,
118 limit: Option<usize>,
119 ) -> RpcResult<Page<String, ObjectID>>;
120}