Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/sui-json-rpc-api/src/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub trait IndexerApi {
/// The ID of the parent object
parent_object_id: ObjectID,
/// 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.
cursor: Option<ObjectID>,
cursor: Option<String>,
/// Maximum item returned per page, default to [QUERY_MAX_RESULT_LIMIT] if not specified.
limit: Option<usize>,
) -> RpcResult<DynamicFieldPage>;
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-json-rpc-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ mod sui_object;
mod sui_protocol;
mod sui_transaction;

pub type DynamicFieldPage = Page<DynamicFieldInfo, ObjectID>;
pub type DynamicFieldPage = Page<DynamicFieldInfo, String>;
/// `next_cursor` points to the last item in the page;
/// Reading with `next_cursor` will start from the next item after `next_cursor` if
/// `next_cursor` is `Some`, otherwise it will start from the first item.
Expand Down
17 changes: 15 additions & 2 deletions crates/sui-json-rpc/src/indexer_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ use crate::{
error::{Error, SuiRpcInputError},
with_tracing,
};
use base64::Engine;

pub fn spawn_subscription<S, T>(
sink: PendingSubscriptionSink,
Expand Down Expand Up @@ -345,19 +346,31 @@ impl<R: ReadApiServer> IndexerApiServer for IndexerApi<R> {
&self,
parent_object_id: ObjectID,
// If `Some`, the query will start from the next item after the specified cursor
cursor: Option<ObjectID>,
cursor: Option<String>,
limit: Option<usize>,
) -> RpcResult<DynamicFieldPage> {
with_tracing!(async move {
let limit = cap_page_limit(limit);
self.metrics.get_dynamic_fields_limit.observe(limit as f64);
let cursor = match cursor {
Some(c) => {
let decoded = base64::engine::general_purpose::STANDARD
.decode(&c)
.map_err(|e| Error::SuiRpcInputError(SuiRpcInputError::Base64(e.into())))?;
let object_id: ObjectID = bcs::from_bytes(&decoded).unwrap();
Some(object_id)
}
None => None,
};
let mut data = self
.state
.get_dynamic_fields(parent_object_id, cursor, limit + 1)
.map_err(Error::from)?;
let has_next_page = data.len() > limit;
data.truncate(limit);
let next_cursor = data.last().cloned().map_or(cursor, |c| Some(c.0));
let next_cursor = data.last().cloned().map(|c| {
base64::engine::general_purpose::STANDARD.encode(bcs::to_bytes(&c.0).unwrap())
});
self.metrics
.get_dynamic_fields_result_size
.observe(data.len() as f64);
Expand Down
402 changes: 199 additions & 203 deletions crates/sui-open-rpc/spec/openrpc.json

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions crates/sui-open-rpc/src/examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1169,11 +1169,14 @@ impl RpcExampleProvider {
.map(Into::into)
.collect::<Vec<_>>();

let next_cursor = ObjectID::new(self.rng.r#gen());
let next_cursor = fastcrypto::encoding::Base64::from_bytes(
&bcs::to_bytes(&ObjectID::new(self.rng.r#gen())).unwrap(),
)
.encoded();

let page = DynamicFieldPage {
data: dynamic_fields,
next_cursor: Some(next_cursor),
next_cursor: Some(next_cursor.clone()),
has_next_page: true,
};

Expand All @@ -1183,7 +1186,7 @@ impl RpcExampleProvider {
"Gets dynamic fields for the object the request provides in a paginated list of `limit` dynamic field results per page. The default limit is 50.",
vec![
("parent_object_id", json!(object_id)),
("cursor", json!(ObjectID::new(self.rng.r#gen()))),
("cursor", json!(next_cursor)),
("limit", json!(3)),
],
json!(page),
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-sdk/src/apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl ReadApi {
pub async fn get_dynamic_fields(
&self,
object_id: ObjectID,
cursor: Option<ObjectID>,
cursor: Option<String>,
limit: Option<usize>,
) -> SuiRpcResult<DynamicFieldPage> {
Ok(self
Expand Down
6 changes: 3 additions & 3 deletions crates/sui/src/client_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ pub enum SuiClientCommands {
id: ObjectID,
/// Optional paging cursor
#[clap(long)]
cursor: Option<ObjectID>,
cursor: Option<String>,
/// Maximum item returned per page
#[clap(long, default_value = "50")]
limit: usize,
Expand Down Expand Up @@ -2109,7 +2109,7 @@ impl Display for SuiClientCommandResult {
SuiClientCommandResult::DynamicFieldQuery(df_refs) => {
let df_refs = DynamicFieldOutput {
has_next_page: df_refs.has_next_page,
next_cursor: df_refs.next_cursor,
next_cursor: df_refs.next_cursor.clone(),
data: df_refs.data.clone(),
};

Expand Down Expand Up @@ -2547,7 +2547,7 @@ pub struct AddressesOutput {
#[serde(rename_all = "camelCase")]
pub struct DynamicFieldOutput {
pub has_next_page: bool,
pub next_cursor: Option<ObjectID>,
pub next_cursor: Option<String>,
pub data: Vec<DynamicFieldInfo>,
}

Expand Down
Loading