sui_jsonrpc/api/
read.rs

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