From 649977cbb7109bc3f70d78b16be7b8968bf9aa01 Mon Sep 17 00:00:00 2001 From: 0xpause Date: Wed, 5 Jun 2024 21:38:03 +0800 Subject: [PATCH] add rooch_listFieldStates and Deprecated the rooch_queryFieldStates --- crates/rooch-indexer/src/actor/messages.rs | 18 +----- .../rooch-indexer/src/actor/reader_indexer.rs | 24 +------- crates/rooch-indexer/src/proxy/mod.rs | 26 +-------- crates/rooch-rpc-api/src/api/rooch_api.rs | 19 ++----- .../src/jsonrpc_types/rooch_types.rs | 3 +- .../src/jsonrpc_types/state_view.rs | 50 +---------------- .../src/server/rooch_server.rs | 56 +------------------ .../src/service/rpc_service.rs | 19 +------ 8 files changed, 16 insertions(+), 199 deletions(-) diff --git a/crates/rooch-indexer/src/actor/messages.rs b/crates/rooch-indexer/src/actor/messages.rs index ed2320532a..94d1231793 100644 --- a/crates/rooch-indexer/src/actor/messages.rs +++ b/crates/rooch-indexer/src/actor/messages.rs @@ -9,9 +9,7 @@ use moveos_types::moveos_std::tx_context::TxContext; use moveos_types::state::StateChangeSet; use moveos_types::transaction::{MoveAction, TransactionExecutionInfo, VerifiedMoveOSTransaction}; use rooch_types::indexer::event::{EventFilter, IndexerEvent, IndexerEventID}; -use rooch_types::indexer::state::{ - FieldStateFilter, IndexerFieldState, IndexerObjectState, IndexerStateID, ObjectStateFilter, -}; +use rooch_types::indexer::state::{IndexerObjectState, IndexerStateID, ObjectStateFilter}; use rooch_types::indexer::transaction::{IndexerTransaction, TransactionFilter}; use rooch_types::transaction::LedgerTransaction; use serde::{Deserialize, Serialize}; @@ -110,17 +108,3 @@ pub struct QueryIndexerObjectStatesMessage { impl Message for QueryIndexerObjectStatesMessage { type Result = Result>; } - -/// Query Indexer Table States Message -#[derive(Debug, Serialize, Deserialize)] -pub struct QueryIndexerFieldStatesMessage { - pub filter: FieldStateFilter, - // exclusive cursor if `Some`, otherwise start from the beginning - pub cursor: Option, - pub limit: usize, - pub descending_order: bool, -} - -impl Message for QueryIndexerFieldStatesMessage { - type Result = Result>; -} diff --git a/crates/rooch-indexer/src/actor/reader_indexer.rs b/crates/rooch-indexer/src/actor/reader_indexer.rs index 62a2af026a..5b54a0d880 100644 --- a/crates/rooch-indexer/src/actor/reader_indexer.rs +++ b/crates/rooch-indexer/src/actor/reader_indexer.rs @@ -2,15 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 use crate::actor::messages::{ - QueryIndexerEventsMessage, QueryIndexerFieldStatesMessage, QueryIndexerObjectStatesMessage, - QueryIndexerTransactionsMessage, + QueryIndexerEventsMessage, QueryIndexerObjectStatesMessage, QueryIndexerTransactionsMessage, }; use crate::indexer_reader::IndexerReader; use anyhow::{anyhow, Result}; use async_trait::async_trait; use coerce::actor::{context::ActorContext, message::Handler, Actor}; use rooch_types::indexer::event::IndexerEvent; -use rooch_types::indexer::state::{IndexerFieldState, IndexerObjectState}; +use rooch_types::indexer::state::IndexerObjectState; use rooch_types::indexer::transaction::IndexerTransaction; pub struct IndexerReaderActor { @@ -81,22 +80,3 @@ impl Handler for IndexerReaderActor { .map_err(|e| anyhow!(format!("Failed to query indexer global states: {:?}", e))) } } - -#[async_trait] -impl Handler for IndexerReaderActor { - async fn handle( - &mut self, - msg: QueryIndexerFieldStatesMessage, - _ctx: &mut ActorContext, - ) -> Result> { - let QueryIndexerFieldStatesMessage { - filter, - cursor, - limit, - descending_order, - } = msg; - self.indexer_reader - .query_field_states_with_filter(filter, cursor, limit, descending_order) - .map_err(|e| anyhow!(format!("Failed to query indexer table states: {:?}", e))) - } -} diff --git a/crates/rooch-indexer/src/proxy/mod.rs b/crates/rooch-indexer/src/proxy/mod.rs index 66939a3a80..ee5acad2f0 100644 --- a/crates/rooch-indexer/src/proxy/mod.rs +++ b/crates/rooch-indexer/src/proxy/mod.rs @@ -4,8 +4,8 @@ use crate::actor::indexer::IndexerActor; use crate::actor::messages::{ IndexerEventsMessage, IndexerStatesMessage, IndexerTransactionMessage, - QueryIndexerEventsMessage, QueryIndexerFieldStatesMessage, QueryIndexerObjectStatesMessage, - QueryIndexerTransactionsMessage, UpdateIndexerMessage, + QueryIndexerEventsMessage, QueryIndexerObjectStatesMessage, QueryIndexerTransactionsMessage, + UpdateIndexerMessage, }; use crate::actor::reader_indexer::IndexerReaderActor; use anyhow::Result; @@ -16,9 +16,7 @@ use moveos_types::moveos_std::tx_context::TxContext; use moveos_types::state::StateChangeSet; use moveos_types::transaction::{MoveAction, TransactionExecutionInfo, VerifiedMoveOSTransaction}; use rooch_types::indexer::event::{EventFilter, IndexerEvent, IndexerEventID}; -use rooch_types::indexer::state::{ - FieldStateFilter, IndexerFieldState, IndexerObjectState, IndexerStateID, ObjectStateFilter, -}; +use rooch_types::indexer::state::{IndexerObjectState, IndexerStateID, ObjectStateFilter}; use rooch_types::indexer::transaction::{IndexerTransaction, TransactionFilter}; use rooch_types::transaction::LedgerTransaction; @@ -159,22 +157,4 @@ impl IndexerProxy { }) .await? } - - pub async fn query_field_states( - &self, - filter: FieldStateFilter, - // exclusive cursor if `Some`, otherwise start from the beginning - cursor: Option, - limit: usize, - descending_order: bool, - ) -> Result> { - self.reader_actor - .send(QueryIndexerFieldStatesMessage { - filter, - cursor, - limit, - descending_order, - }) - .await? - } } diff --git a/crates/rooch-rpc-api/src/api/rooch_api.rs b/crates/rooch-rpc-api/src/api/rooch_api.rs index 97db6d6235..89f583abf8 100644 --- a/crates/rooch-rpc-api/src/api/rooch_api.rs +++ b/crates/rooch-rpc-api/src/api/rooch_api.rs @@ -7,10 +7,10 @@ use crate::jsonrpc_types::event_view::EventFilterView; use crate::jsonrpc_types::transaction_view::{TransactionFilterView, TransactionWithInfoView}; use crate::jsonrpc_types::{ AccessPathView, AnnotatedFunctionResultView, BalanceInfoPageView, BytesView, EventOptions, - EventPageView, ExecuteTransactionResponseView, FieldStateFilterView, FieldStatePageView, - FunctionCallView, H256View, IndexerEventPageView, IndexerObjectStatePageView, ObjectIDVecView, - ObjectIDView, ObjectStateFilterView, ObjectStateView, QueryOptions, StateOptions, - StatePageView, StateView, StrView, StructTagView, TransactionWithInfoPageView, TxOptions, + EventPageView, ExecuteTransactionResponseView, FunctionCallView, H256View, + IndexerEventPageView, IndexerObjectStatePageView, ObjectIDVecView, ObjectIDView, + ObjectStateFilterView, ObjectStateView, QueryOptions, StateOptions, StatePageView, StateView, + StrView, StructTagView, TransactionWithInfoPageView, TxOptions, }; use jsonrpsee::core::RpcResult; use jsonrpsee::proc_macros::rpc; @@ -165,15 +165,4 @@ pub trait RoochAPI { limit: Option>, query_option: Option, ) -> RpcResult; - - /// Query the Object field states indexer by state filter - #[method(name = "queryFieldStates")] - async fn query_field_states( - &self, - filter: FieldStateFilterView, - // exclusive cursor if `Some`, otherwise start from the beginning - cursor: Option, - limit: Option>, - query_option: Option, - ) -> RpcResult; } diff --git a/crates/rooch-rpc-api/src/jsonrpc_types/rooch_types.rs b/crates/rooch-rpc-api/src/jsonrpc_types/rooch_types.rs index 5dc1c6e3e3..c11caf4f16 100644 --- a/crates/rooch-rpc-api/src/jsonrpc_types/rooch_types.rs +++ b/crates/rooch-rpc-api/src/jsonrpc_types/rooch_types.rs @@ -8,7 +8,7 @@ use crate::jsonrpc_types::event_view::{EventView, IndexerEventView}; use crate::jsonrpc_types::transaction_view::TransactionWithInfoView; use crate::jsonrpc_types::{ move_types::{MoveActionTypeView, MoveActionView}, - BytesView, FieldStateView, IndexerObjectStateView, StateKVView, StrView, StructTagView, + BytesView, IndexerObjectStateView, StateKVView, StrView, StructTagView, }; use move_core_types::u256::U256; use rooch_types::framework::coin::CoinInfo; @@ -26,7 +26,6 @@ pub type BalanceInfoPageView = PageView; pub type IndexerEventPageView = PageView; pub type IndexerObjectStatePageView = PageView; -pub type FieldStatePageView = PageView; pub type UTXOPageView = PageView; pub type InscriptionPageView = PageView; diff --git a/crates/rooch-rpc-api/src/jsonrpc_types/state_view.rs b/crates/rooch-rpc-api/src/jsonrpc_types/state_view.rs index 3c0a97db8d..04a647df89 100644 --- a/crates/rooch-rpc-api/src/jsonrpc_types/state_view.rs +++ b/crates/rooch-rpc-api/src/jsonrpc_types/state_view.rs @@ -17,8 +17,7 @@ use moveos_types::{ state::{AnnotatedState, State, StateChangeSet, TableTypeInfo}, }; use rooch_types::indexer::state::{ - FieldStateFilter, IndexerFieldState, IndexerObjectState, IndexerStateChangeSet, - ObjectStateFilter, StateSyncFilter, + IndexerObjectState, IndexerStateChangeSet, ObjectStateFilter, StateSyncFilter, }; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; @@ -463,53 +462,6 @@ impl ObjectStateFilterView { } } -#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] -pub struct FieldStateView { - pub object_id: ObjectID, - pub key_hex: String, - pub value: Option, - pub key_type: TypeTagView, - pub value_type: TypeTagView, - pub tx_order: u64, - pub state_index: u64, - pub created_at: u64, - pub updated_at: u64, -} - -impl FieldStateView { - pub fn new_from_field_state( - annotated_state: Option, - state: IndexerFieldState, - ) -> FieldStateView { - FieldStateView { - object_id: state.object_id, - key_hex: state.key_hex, - value: annotated_state.map(|v| AnnotatedMoveValueView::from(v.decoded_value)), - key_type: state.key_type.into(), - value_type: state.value_type.into(), - tx_order: state.tx_order, - state_index: state.state_index, - created_at: state.created_at, - updated_at: state.updated_at, - } - } -} - -#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum FieldStateFilterView { - /// Query by object id. - ObjectId(ObjectID), -} - -impl From for FieldStateFilter { - fn from(state_filter: FieldStateFilterView) -> Self { - match state_filter { - FieldStateFilterView::ObjectId(object_id) => Self::ObjectId(object_id), - } - } -} - /// Object state view. Used as return type of `getObjectStates`. #[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] pub struct ObjectStateView { diff --git a/crates/rooch-rpc-server/src/server/rooch_server.rs b/crates/rooch-rpc-server/src/server/rooch_server.rs index ac122785a7..fba1d544c0 100644 --- a/crates/rooch-rpc-server/src/server/rooch_server.rs +++ b/crates/rooch-rpc-server/src/server/rooch_server.rs @@ -19,10 +19,9 @@ use moveos_types::{ }; use rooch_rpc_api::jsonrpc_types::transaction_view::TransactionFilterView; use rooch_rpc_api::jsonrpc_types::{ - account_view::BalanceInfoView, FieldStateFilterView, FieldStatePageView, FieldStateView, - IndexerEventPageView, IndexerObjectStatePageView, IndexerObjectStateView, KeyStateView, - ObjectIDVecView, ObjectStateFilterView, ObjectStateView, QueryOptions, StateKVView, - StateOptions, TxOptions, + account_view::BalanceInfoView, IndexerEventPageView, IndexerObjectStatePageView, + IndexerObjectStateView, KeyStateView, ObjectIDVecView, ObjectStateFilterView, ObjectStateView, + QueryOptions, StateKVView, StateOptions, TxOptions, }; use rooch_rpc_api::jsonrpc_types::{ event_view::{EventFilterView, EventView, IndexerEventView}, @@ -711,55 +710,6 @@ impl RoochAPIServer for RoochServer { has_next_page, }) } - - async fn query_field_states( - &self, - filter: FieldStateFilterView, - // exclusive cursor if `Some`, otherwise start from the beginning - cursor: Option, - limit: Option>, - query_option: Option, - ) -> RpcResult { - let limit_of = min( - limit.map(Into::into).unwrap_or(DEFAULT_RESULT_LIMIT_USIZE), - MAX_RESULT_LIMIT_USIZE, - ); - let query_option = query_option.unwrap_or_default(); - let descending_order = query_option.descending; - - let states = self - .rpc_service - .query_field_states(filter.into(), cursor, limit_of + 1, descending_order) - .await?; - - let object_ids = states - .iter() - .map(|m| m.object_id.clone()) - .collect::>(); - let access_path = AccessPath::objects(object_ids.clone()); - let mut data = self - .rpc_service - .get_annotated_states(access_path) - .await? - .into_iter() - .zip(states) - .map(|(annotated_state, state)| { - FieldStateView::new_from_field_state(annotated_state, state) - }) - .collect::>(); - - let has_next_page = data.len() > limit_of; - data.truncate(limit_of); - let next_cursor = data.last().cloned().map_or(cursor, |t| { - Some(IndexerStateID::new(t.tx_order, t.state_index)) - }); - - Ok(FieldStatePageView { - data, - next_cursor, - has_next_page, - }) - } } impl RoochRpcModule for RoochServer { diff --git a/crates/rooch-rpc-server/src/service/rpc_service.rs b/crates/rooch-rpc-server/src/service/rpc_service.rs index 91bfc21d25..769edf3420 100644 --- a/crates/rooch-rpc-server/src/service/rpc_service.rs +++ b/crates/rooch-rpc-server/src/service/rpc_service.rs @@ -17,9 +17,7 @@ use rooch_sequencer::proxy::SequencerProxy; use rooch_types::address::{BitcoinAddress, RoochAddress}; use rooch_types::framework::address_mapping::RoochToBitcoinAddressMapping; use rooch_types::indexer::event::{EventFilter, IndexerEvent, IndexerEventID}; -use rooch_types::indexer::state::{ - FieldStateFilter, IndexerFieldState, IndexerObjectState, IndexerStateID, ObjectStateFilter, -}; +use rooch_types::indexer::state::{IndexerObjectState, IndexerStateID, ObjectStateFilter}; use rooch_types::indexer::transaction::{IndexerTransaction, TransactionFilter}; use rooch_types::sequencer::SequencerOrder; use rooch_types::transaction::{ExecuteTransactionResponse, LedgerTransaction, RoochTransaction}; @@ -250,21 +248,6 @@ impl RpcService { Ok(resp) } - pub async fn query_field_states( - &self, - filter: FieldStateFilter, - // exclusive cursor if `Some`, otherwise start from the beginning - cursor: Option, - limit: usize, - descending_order: bool, - ) -> Result> { - let resp = self - .indexer - .query_field_states(filter, cursor, limit, descending_order) - .await?; - Ok(resp) - } - pub async fn get_bitcoin_addresses( &self, rooch_addresses: Vec,