From b88a2524c632c6f545d258f5521ab2b1e15f8a59 Mon Sep 17 00:00:00 2001 From: 0xpause Date: Wed, 5 Jun 2024 23:33:58 +0800 Subject: [PATCH] get_field_states --- crates/rooch-rpc-api/src/api/rooch_api.rs | 19 ++++++++++++++----- .../src/server/rooch_server.rs | 13 ++++++++++++- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/crates/rooch-rpc-api/src/api/rooch_api.rs b/crates/rooch-rpc-api/src/api/rooch_api.rs index 89f583abf..dac89adec 100644 --- a/crates/rooch-rpc-api/src/api/rooch_api.rs +++ b/crates/rooch-rpc-api/src/api/rooch_api.rs @@ -8,9 +8,9 @@ use crate::jsonrpc_types::transaction_view::{TransactionFilterView, TransactionW use crate::jsonrpc_types::{ AccessPathView, AnnotatedFunctionResultView, BalanceInfoPageView, BytesView, EventOptions, EventPageView, ExecuteTransactionResponseView, FunctionCallView, H256View, - IndexerEventPageView, IndexerObjectStatePageView, ObjectIDVecView, ObjectIDView, - ObjectStateFilterView, ObjectStateView, QueryOptions, StateOptions, StatePageView, StateView, - StrView, StructTagView, TransactionWithInfoPageView, TxOptions, + IndexerEventPageView, IndexerObjectStatePageView, KeyStateView, ObjectIDVecView, ObjectIDView, + ObjectStateFilterView, ObjectStateView, QueryOptions, SimpleKeyStateView, StateOptions, + StatePageView, StateView, StrView, StructTagView, TransactionWithInfoPageView, TxOptions, }; use jsonrpsee::core::RpcResult; use jsonrpsee::proc_macros::rpc; @@ -76,9 +76,18 @@ pub trait RoochAPI { state_option: Option, ) -> RpcResult>>; + /// Get Object Fields via ObjectID and field keys. + #[method(name = "getFieldStates")] + async fn get_field_states( + &self, + object_id: ObjectIDView, + field_key: Vec, + state_option: Option, + ) -> RpcResult>>; + /// List Object Fields via ObjectID. - #[method(name = "listObjectFields")] - async fn list_object_fields( + #[method(name = "listFieldStates")] + async fn list_field_states( &self, object_id: ObjectIDView, cursor: Option, diff --git a/crates/rooch-rpc-server/src/server/rooch_server.rs b/crates/rooch-rpc-server/src/server/rooch_server.rs index fba1d544c..3ca897319 100644 --- a/crates/rooch-rpc-server/src/server/rooch_server.rs +++ b/crates/rooch-rpc-server/src/server/rooch_server.rs @@ -21,7 +21,7 @@ use rooch_rpc_api::jsonrpc_types::transaction_view::TransactionFilterView; use rooch_rpc_api::jsonrpc_types::{ account_view::BalanceInfoView, IndexerEventPageView, IndexerObjectStatePageView, IndexerObjectStateView, KeyStateView, ObjectIDVecView, ObjectStateFilterView, ObjectStateView, - QueryOptions, StateKVView, StateOptions, TxOptions, + QueryOptions, SimpleKeyStateView, StateKVView, StateOptions, TxOptions, }; use rooch_rpc_api::jsonrpc_types::{ event_view::{EventFilterView, EventView, IndexerEventView}, @@ -343,6 +343,17 @@ impl RoochAPIServer for RoochServer { Ok(objects_view) } + async fn get_field_states( + &self, + object_id: ObjectIDView, + field_key: Vec, + state_option: Option, + ) -> RpcResult>> { + let key_states = field_key.into_iter().map(KeyState::from).collect(); + let access_path_view = + AccessPathView::from(AccessPath::fields(object_id.into(), key_states)); + } + async fn get_events_by_event_handle( &self, event_handle_type: StructTagView,