sui_jsonrpc/api/
read.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use af_sui_types::{ObjectId, TransactionDigest};
5use jsonrpsee::proc_macros::rpc;
6use sui_sdk_types::Version;
7
8use crate::msgs::{
9    Checkpoint,
10    CheckpointId,
11    CheckpointPage,
12    ProtocolConfigResponse,
13    SuiEvent,
14    SuiGetPastObjectRequest,
15    SuiObjectDataOptions,
16    SuiObjectResponse,
17    SuiPastObjectResponse,
18    SuiTransactionBlockResponse,
19    SuiTransactionBlockResponseOptions,
20};
21use crate::serde::BigInt;
22
23#[rpc(client, namespace = "sui")]
24pub trait ReadApi {
25    /// Return the transaction response object.
26    #[method(name = "getTransactionBlock")]
27    async fn get_transaction_block(
28        &self,
29        digest: TransactionDigest,
30        options: Option<SuiTransactionBlockResponseOptions>,
31    ) -> RpcResult<SuiTransactionBlockResponse>;
32
33    /// Returns an ordered list of transaction responses
34    /// The method will throw an error if the input contains any duplicate or
35    /// the input size exceeds QUERY_MAX_RESULT_LIMIT
36    #[method(name = "multiGetTransactionBlocks")]
37    async fn multi_get_transaction_blocks(
38        &self,
39        digests: Vec<TransactionDigest>,
40        options: Option<SuiTransactionBlockResponseOptions>,
41    ) -> RpcResult<Vec<SuiTransactionBlockResponse>>;
42
43    /// Return the object information for a specified object
44    #[method(name = "getObject")]
45    async fn get_object(
46        &self,
47        object_id: ObjectId,
48        options: Option<SuiObjectDataOptions>,
49    ) -> RpcResult<SuiObjectResponse>;
50
51    /// Return the object data for a list of objects
52    #[method(name = "multiGetObjects")]
53    async fn multi_get_objects(
54        &self,
55        object_ids: Vec<ObjectId>,
56        options: Option<SuiObjectDataOptions>,
57    ) -> RpcResult<Vec<SuiObjectResponse>>;
58
59    /// Note there is no software-level guarantee/SLA that objects with past versions
60    /// can be retrieved by this API, even if the object and version exists/existed.
61    /// The result may vary across nodes depending on their pruning policies.
62    /// Return the object information for a specified version
63    #[method(name = "tryGetPastObject")]
64    async fn try_get_past_object(
65        &self,
66        object_id: ObjectId,
67        version: Version,
68        options: Option<SuiObjectDataOptions>,
69    ) -> RpcResult<SuiPastObjectResponse>;
70
71    /// Note there is no software-level guarantee/SLA that objects with past versions
72    /// can be retrieved by this API, even if the object and version exists/existed.
73    /// The result may vary across nodes depending on their pruning policies.
74    /// Return the object information for a specified version
75    #[method(name = "tryMultiGetPastObjects")]
76    async fn try_multi_get_past_objects(
77        &self,
78        past_objects: Vec<SuiGetPastObjectRequest>,
79        options: Option<SuiObjectDataOptions>,
80    ) -> RpcResult<Vec<SuiPastObjectResponse>>;
81
82    /// Return a checkpoint
83    #[method(name = "getCheckpoint")]
84    async fn get_checkpoint(&self, id: CheckpointId) -> RpcResult<Checkpoint>;
85
86    /// Return paginated list of checkpoints
87    #[method(name = "getCheckpoints")]
88    async fn get_checkpoints(
89        &self,
90        cursor: Option<BigInt<u64>>,
91        limit: Option<usize>,
92        descending_order: bool,
93    ) -> RpcResult<CheckpointPage>;
94
95    /// Return transaction events.
96    #[method(name = "getEvents")]
97    async fn get_events(&self, transaction_digest: TransactionDigest) -> RpcResult<Vec<SuiEvent>>;
98
99    /// Return the total number of transaction blocks known to the server.
100    #[method(name = "getTotalTransactionBlocks")]
101    async fn get_total_transaction_blocks(&self) -> RpcResult<BigInt<u64>>;
102
103    /// Return the sequence number of the latest checkpoint that has been executed
104    #[method(name = "getLatestCheckpointSequenceNumber")]
105    async fn get_latest_checkpoint_sequence_number(&self) -> RpcResult<BigInt<u64>>;
106
107    /// Return the protocol config table for the given version number.
108    /// If the version number is not specified, If none is specified, the node uses the version of the latest epoch it has processed.
109    #[method(name = "getProtocolConfig")]
110    async fn get_protocol_config(
111        &self,
112        version: Option<BigInt<u64>>,
113    ) -> RpcResult<ProtocolConfigResponse>;
114
115    /// Return the first four bytes of the chain's genesis checkpoint digest.
116    #[method(name = "getChainIdentifier")]
117    async fn get_chain_identifier(&self) -> RpcResult<String>;
118}