From e5d6d8f3797fb62e4f490d5deb07731b82ae9d78 Mon Sep 17 00:00:00 2001 From: jolestar Date: Mon, 16 Oct 2023 23:00:57 +0800 Subject: [PATCH 1/5] [RPC] Merge the state API --- .../rooch-open-rpc-spec/schemas/openrpc.json | 18 ++- crates/rooch-rpc-api/src/api/rooch_api.rs | 30 ++--- crates/rooch-rpc-api/src/jsonrpc_types/mod.rs | 2 + .../src/jsonrpc_types/rooch_types.rs | 3 +- .../src/jsonrpc_types/rpc_options.rs | 23 ++++ .../src/jsonrpc_types/state_view.rs | 39 ++----- crates/rooch-rpc-client/src/rooch_client.rs | 37 +++--- .../src/server/rooch_server.rs | 106 +++++++----------- crates/rooch/src/commands/object.rs | 8 +- crates/rooch/src/commands/resource.rs | 8 +- .../src/commands/rpc/commands/request.rs | 4 +- crates/rooch/src/commands/state.rs | 8 +- 12 files changed, 141 insertions(+), 145 deletions(-) create mode 100644 crates/rooch-rpc-api/src/jsonrpc_types/rpc_options.rs diff --git a/crates/rooch-open-rpc-spec/schemas/openrpc.json b/crates/rooch-open-rpc-spec/schemas/openrpc.json index eb54545c28..533a35b775 100644 --- a/crates/rooch-open-rpc-spec/schemas/openrpc.json +++ b/crates/rooch-open-rpc-spec/schemas/openrpc.json @@ -189,7 +189,7 @@ }, { "name": "rooch_getStates", - "description": "Get the states by access_path", + "description": "Get the states by access_path If the StateOptions.decode is true, the state is decoded and the decoded value is returned in the response.", "params": [ { "name": "access_path", @@ -197,6 +197,12 @@ "schema": { "$ref": "#/components/schemas/moveos_types::access_path::AccessPath" } + }, + { + "name": "state_option", + "schema": { + "$ref": "#/components/schemas/ObjectDataOptions" + } } ], "result": { @@ -835,6 +841,16 @@ } } }, + "ObjectDataOptions": { + "type": "object", + "properties": { + "decode": { + "description": "If true, the state is decoded and the decoded value is returned in the response.", + "default": false, + "type": "boolean" + } + } + }, "ObjectID": { "$ref": "#/components/schemas/Hex" }, diff --git a/crates/rooch-rpc-api/src/api/rooch_api.rs b/crates/rooch-rpc-api/src/api/rooch_api.rs index 73e433a49c..f34ab8f548 100644 --- a/crates/rooch-rpc-api/src/api/rooch_api.rs +++ b/crates/rooch-rpc-api/src/api/rooch_api.rs @@ -4,10 +4,9 @@ use crate::jsonrpc_types::account_view::BalanceInfoView; use crate::jsonrpc_types::transaction_view::TransactionWithInfoView; use crate::jsonrpc_types::{ - AccessPathView, AccountAddressView, AnnotatedFunctionResultView, AnnotatedStateView, - AnnotatedStatesPageView, BalanceInfoPageView, BytesView, EventPageView, - ExecuteTransactionResponseView, FunctionCallView, H256View, StateView, StatesPageView, StrView, - StructTagView, TransactionWithInfoPageView, + AccessPathView, AccountAddressView, AnnotatedFunctionResultView, BalanceInfoPageView, + BytesView, EventPageView, ExecuteTransactionResponseView, FunctionCallView, H256View, + StateOptions, StateView, StatesPageView, StrView, StructTagView, TransactionWithInfoPageView, }; use jsonrpsee::core::RpcResult; use jsonrpsee::proc_macros::rpc; @@ -42,36 +41,25 @@ pub trait RoochAPI { ) -> RpcResult; /// Get the states by access_path + /// If the StateOptions.decode is true, the state is decoded and the decoded value is returned in the response. #[method(name = "getStates")] - async fn get_states(&self, access_path: AccessPathView) -> RpcResult>>; - - /// Get the annotated states by access_path - /// The annotated states include the decoded move value of the state - #[method(name = "getAnnotatedStates")] - async fn get_annotated_states( + async fn get_states( &self, access_path: AccessPathView, - ) -> RpcResult>>; + state_option: Option, + ) -> RpcResult>>; /// List the states by access_path + /// If the StateOptions.decode is true, the state is decoded and the decoded value is returned in the response. #[method(name = "listStates")] async fn list_states( &self, access_path: AccessPathView, cursor: Option, limit: Option>, + state_option: Option, ) -> RpcResult; - /// List the annotated states by access_path - /// The annotated states include the decoded move value of the state - #[method(name = "listAnnotatedStates")] - async fn list_annotated_states( - &self, - access_path: AccessPathView, - cursor: Option, - limit: Option>, - ) -> RpcResult; - /// Get the events by event handle id #[method(name = "getEventsByEventHandle")] async fn get_events_by_event_handle( diff --git a/crates/rooch-rpc-api/src/jsonrpc_types/mod.rs b/crates/rooch-rpc-api/src/jsonrpc_types/mod.rs index f0e5a16d35..3808b07636 100644 --- a/crates/rooch-rpc-api/src/jsonrpc_types/mod.rs +++ b/crates/rooch-rpc-api/src/jsonrpc_types/mod.rs @@ -8,6 +8,7 @@ mod execute_tx_response; mod function_return_value_view; mod move_types; mod rooch_types; +mod rpc_options; mod state_view; #[cfg(test)] mod tests; @@ -21,6 +22,7 @@ pub use self::rooch_types::*; pub use execute_tx_response::*; pub use function_return_value_view::*; pub use move_types::*; +pub use rpc_options::*; pub use state_view::*; pub use str_view::*; pub use transaction_argument_view::*; 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 c77c732b74..5ad56195c9 100644 --- a/crates/rooch-rpc-api/src/jsonrpc_types/rooch_types.rs +++ b/crates/rooch-rpc-api/src/jsonrpc_types/rooch_types.rs @@ -5,7 +5,7 @@ use crate::jsonrpc_types::account_view::BalanceInfoView; use crate::jsonrpc_types::transaction_view::TransactionWithInfoView; use crate::jsonrpc_types::{ move_types::{MoveActionTypeView, MoveActionView}, - AnnotatedStateView, BytesView, EventView, StateView, StrView, StructTagView, + AnnotatedMoveStructView, BytesView, EventView, H256View, StateView, StrView, StructTagView, }; use move_core_types::u256::U256; use moveos_types::event::AnnotatedMoveOSEvent; @@ -18,7 +18,6 @@ use std::string::String; pub type EventPageView = PageView; pub type TransactionWithInfoPageView = PageView; pub type StatesPageView = PageView; -pub type AnnotatedStatesPageView = PageView; pub type BalanceInfoPageView = PageView; /// `next_cursor` points to the last item in the page; diff --git a/crates/rooch-rpc-api/src/jsonrpc_types/rpc_options.rs b/crates/rooch-rpc-api/src/jsonrpc_types/rpc_options.rs new file mode 100644 index 0000000000..e296afb030 --- /dev/null +++ b/crates/rooch-rpc-api/src/jsonrpc_types/rpc_options.rs @@ -0,0 +1,23 @@ +// Copyright (c) RoochNetwork +// SPDX-License-Identifier: Apache-2.0 + +use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema, Eq, PartialEq, Default)] +#[serde(rename_all = "camelCase", rename = "ObjectDataOptions", default)] +pub struct StateOptions { + /// If true, the state is decoded and the decoded value is returned in the response. + pub decode: bool, +} + +impl StateOptions { + pub fn new() -> Self { + Self::default() + } + + pub fn decode(mut self, decode: bool) -> Self { + self.decode = decode; + self + } +} 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 581ad81522..1fcce88771 100644 --- a/crates/rooch-rpc-api/src/jsonrpc_types/state_view.rs +++ b/crates/rooch-rpc-api/src/jsonrpc_types/state_view.rs @@ -15,6 +15,7 @@ use std::collections::{BTreeMap, BTreeSet}; pub struct StateView { pub value: BytesView, pub value_type: TypeTagView, + pub decoded_value: Option, } impl From for StateView { @@ -22,47 +23,29 @@ impl From for StateView { Self { value: StrView(state.value), value_type: state.value_type.into(), + decoded_value: None, } } } -impl From for State { - fn from(state: StateView) -> Self { +impl From for StateView { + fn from(state: AnnotatedState) -> Self { Self { - value: state.value.0, - value_type: state.value_type.into(), + value: StrView(state.state.value.0), + value_type: state.state.value_type.into(), + decoded_value: Some(state.move_value.into()), } } } -#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema)] -pub struct AnnotatedStateView { - pub state: StateView, - pub move_value: AnnotatedMoveValueView, -} - -impl From for AnnotatedStateView { - fn from(state: AnnotatedState) -> Self { +impl From for State { + fn from(state: StateView) -> Self { Self { - state: state.state.into(), - move_value: state.move_value.into(), + value: state.value.0, + value_type: state.value_type.into(), } } } - -//TODO Is it need to convert the AnnotatedStateView back to AnnotatedState? -//If not, please remove this code. Otherwise, it needs to be fixed. include TryFrom for AnnotatedMoveValue -// impl TryFrom for AnnotatedState { -// type Error = anyhow::Error; - -// fn try_from(value: AnnotatedStateView) -> Result { -// Ok(Self { -// state: value.state.into(), -// move_value: value.move_value.try_into()?, -// }) -// } -// } - #[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] pub struct TableTypeInfoView { pub key_type: TypeTagView, diff --git a/crates/rooch-rpc-client/src/rooch_client.rs b/crates/rooch-rpc-client/src/rooch_client.rs index 965477d526..f03d14c8bf 100644 --- a/crates/rooch-rpc-client/src/rooch_client.rs +++ b/crates/rooch-rpc-client/src/rooch_client.rs @@ -14,11 +14,11 @@ use rooch_rpc_api::jsonrpc_types::{ account_view::BalanceInfoView, transaction_view::TransactionWithInfoView, }; use rooch_rpc_api::jsonrpc_types::{ - AccessPathView, AccountAddressView, AnnotatedFunctionResultView, AnnotatedStatesPageView, - BalanceInfoPageView, EventPageView, StatesPageView, StructTagView, + AccessPathView, AccountAddressView, AnnotatedFunctionResultView, BalanceInfoPageView, + EventPageView, StateOptions, StatesPageView, StructTagView, }; -use rooch_rpc_api::jsonrpc_types::{AnnotatedStateView, ExecuteTransactionResponseView, StateView}; use rooch_rpc_api::jsonrpc_types::{BytesView, TransactionWithInfoPageView}; +use rooch_rpc_api::jsonrpc_types::{ExecuteTransactionResponseView, StateView}; use rooch_types::{account::Account, address::RoochAddress, transaction::rooch::RoochTransaction}; use std::sync::Arc; @@ -58,20 +58,22 @@ impl RoochRpcClient { } pub async fn get_states(&self, access_path: AccessPath) -> Result>> { - Ok(self.http.get_states(access_path.into()).await?) + Ok(self.http.get_states(access_path.into(), None).await?) } - pub async fn get_annotated_states( + pub async fn get_decoded_states( &self, access_path: AccessPath, - ) -> Result>> { - Ok(self.http.get_annotated_states(access_path.into()).await?) + ) -> Result>> { + Ok(self + .http + .get_states( + access_path.into(), + Some(StateOptions::default().decode(true)), + ) + .await?) } - // pub async fn get_transactions_by_hash(&self, hash: H256) -> Result> { - // Ok(self.http.get_transaction_by_hash(hash.into()).await?) - // } - pub async fn get_transactions_by_order( &self, cursor: Option, @@ -132,19 +134,24 @@ impl RoochRpcClient { ) -> Result { Ok(self .http - .list_states(access_path, cursor, limit.map(Into::into)) + .list_states(access_path, cursor, limit.map(Into::into), None) .await?) } - pub async fn list_annotated_states( + pub async fn list_decoded_states( &self, access_path: AccessPathView, cursor: Option, limit: Option, - ) -> Result { + ) -> Result { Ok(self .http - .list_annotated_states(access_path, cursor, limit.map(Into::into)) + .list_states( + access_path, + cursor, + limit.map(Into::into), + Some(StateOptions::default().decode(true)), + ) .await?) } diff --git a/crates/rooch-rpc-server/src/server/rooch_server.rs b/crates/rooch-rpc-server/src/server/rooch_server.rs index 9d20a24766..7e7747a886 100644 --- a/crates/rooch-rpc-server/src/server/rooch_server.rs +++ b/crates/rooch-rpc-server/src/server/rooch_server.rs @@ -8,13 +8,12 @@ use jsonrpsee::{ RpcModule, }; use moveos_types::h256::H256; -use rooch_rpc_api::jsonrpc_types::account_view::BalanceInfoView; use rooch_rpc_api::jsonrpc_types::transaction_view::TransactionWithInfoView; +use rooch_rpc_api::jsonrpc_types::{account_view::BalanceInfoView, StateOptions}; use rooch_rpc_api::jsonrpc_types::{ - AccessPathView, AccountAddressView, AnnotatedEventView, AnnotatedStateView, - AnnotatedStatesPageView, BalanceInfoPageView, EventPageView, ExecuteTransactionResponseView, - FunctionCallView, H256View, StateView, StatesPageView, StrView, StructTagView, - TransactionWithInfoPageView, + AccessPathView, AccountAddressView, AnnotatedEventView, BalanceInfoPageView, EventPageView, + ExecuteTransactionResponseView, FunctionCallView, H256View, StateView, StatesPageView, StrView, + StructTagView, TransactionWithInfoPageView, }; use rooch_rpc_api::{api::rooch_api::RoochAPIServer, api::DEFAULT_RESULT_LIMIT}; use rooch_rpc_api::{ @@ -86,27 +85,29 @@ impl RoochAPIServer for RoochServer { .into()) } - async fn get_states(&self, access_path: AccessPathView) -> RpcResult>> { - Ok(self - .rpc_service - .get_states(access_path.into()) - .await? - .into_iter() - .map(|s| s.map(StateView::from)) - .collect()) - } - - async fn get_annotated_states( + async fn get_states( &self, access_path: AccessPathView, - ) -> RpcResult>> { - Ok(self - .rpc_service - .get_annotated_states(access_path.into()) - .await? - .into_iter() - .map(|s| s.map(AnnotatedStateView::from)) - .collect()) + state_option: Option, + ) -> RpcResult>> { + let state_option = state_option.unwrap_or_default(); + if state_option.decode { + Ok(self + .rpc_service + .get_annotated_states(access_path.into()) + .await? + .into_iter() + .map(|s| s.map(StateView::from)) + .collect()) + } else { + Ok(self + .rpc_service + .get_states(access_path.into()) + .await? + .into_iter() + .map(|s| s.map(StateView::from)) + .collect()) + } } async fn list_states( @@ -114,19 +115,29 @@ impl RoochAPIServer for RoochServer { access_path: AccessPathView, cursor: Option, limit: Option>, + state_option: Option, ) -> RpcResult { + let state_option = state_option.unwrap_or_default(); let limit_of = min( limit.map(Into::into).unwrap_or(DEFAULT_RESULT_LIMIT_USIZE), MAX_RESULT_LIMIT_USIZE, ); let cursor_of = cursor.clone().map(|v| v.0); - let mut data: Vec<(Vec, StateView)> = self - .rpc_service - .list_states(access_path.into(), cursor_of, limit_of + 1) - .await? - .into_iter() - .map(|(key, state)| (key, StateView::from(state))) - .collect::>(); + let mut data: Vec<(Vec, StateView)> = if state_option.decode { + self.rpc_service + .list_annotated_states(access_path.into(), cursor_of, limit_of + 1) + .await? + .into_iter() + .map(|(key, state)| (key, StateView::from(state))) + .collect::>(); + } else { + self.rpc_service + .list_states(access_path.into(), cursor_of, limit_of + 1) + .await? + .into_iter() + .map(|(key, state)| (key, StateView::from(state))) + .collect::>(); + }; let has_next_page = data.len() > limit_of; data.truncate(limit_of); @@ -142,39 +153,6 @@ impl RoochAPIServer for RoochServer { }) } - async fn list_annotated_states( - &self, - access_path: AccessPathView, - cursor: Option, - limit: Option>, - ) -> RpcResult { - let limit_of = min( - limit.map(Into::into).unwrap_or(DEFAULT_RESULT_LIMIT_USIZE), - MAX_RESULT_LIMIT_USIZE, - ); - let cursor_of = cursor.clone().map(|v| v.0); - let mut data: Vec<(Vec, AnnotatedStateView)> = self - .rpc_service - .list_annotated_states(access_path.into(), cursor_of, limit_of + 1) - .await? - .into_iter() - .map(|(key, state)| (key, AnnotatedStateView::from(state))) - .collect::>(); - - let has_next_page = data.len() > limit_of; - data.truncate(limit_of); - let next_cursor = data - .last() - .map_or(cursor, |(key, _state)| Some(StrView(key.clone()))); - let result = data.into_iter().map(|(_key, state)| state).collect(); - - Ok(AnnotatedStatesPageView { - data: result, - next_cursor, - has_next_page, - }) - } - async fn get_events_by_event_handle( &self, event_handle_type: StructTagView, diff --git a/crates/rooch/src/commands/object.rs b/crates/rooch/src/commands/object.rs index 73e94fb8a9..fd50ab519e 100644 --- a/crates/rooch/src/commands/object.rs +++ b/crates/rooch/src/commands/object.rs @@ -5,7 +5,7 @@ use crate::cli_types::{CommandAction, WalletContextOptions}; use async_trait::async_trait; use clap::Parser; use moveos_types::{access_path::AccessPath, object::ObjectID}; -use rooch_rpc_api::jsonrpc_types::AnnotatedStateView; +use rooch_rpc_api::jsonrpc_types::StateView; use rooch_types::error::RoochResult; /// Get object by object id @@ -20,12 +20,12 @@ pub struct ObjectCommand { } #[async_trait] -impl CommandAction> for ObjectCommand { - async fn execute(self) -> RoochResult> { +impl CommandAction> for ObjectCommand { + async fn execute(self) -> RoochResult> { let client = self.context_options.build().await?.get_client().await?; let resp = client .rooch - .get_annotated_states(AccessPath::object(self.id)) + .get_decoded_states(AccessPath::object(self.id)) .await? .pop() .flatten(); diff --git a/crates/rooch/src/commands/resource.rs b/crates/rooch/src/commands/resource.rs index b143a44cd7..f94e96533b 100644 --- a/crates/rooch/src/commands/resource.rs +++ b/crates/rooch/src/commands/resource.rs @@ -6,7 +6,7 @@ use async_trait::async_trait; use clap::Parser; use move_core_types::{account_address::AccountAddress, language_storage::StructTag}; use moveos_types::access_path::AccessPath; -use rooch_rpc_api::jsonrpc_types::AnnotatedStateView; +use rooch_rpc_api::jsonrpc_types::StateView; use rooch_types::error::RoochResult; #[derive(Debug, Parser)] @@ -27,13 +27,13 @@ pub struct ResourceCommand { } #[async_trait] -impl CommandAction> for ResourceCommand { - async fn execute(self) -> RoochResult> { +impl CommandAction> for ResourceCommand { + async fn execute(self) -> RoochResult> { let client = self.context_options.build().await?.get_client().await?; let resp = client .rooch - .get_annotated_states(AccessPath::resource(self.address, self.resource)) + .get_decoded_states(AccessPath::resource(self.address, self.resource)) .await? .pop() .flatten(); diff --git a/crates/rooch/src/commands/rpc/commands/request.rs b/crates/rooch/src/commands/rpc/commands/request.rs index 78037c97bd..6365a70617 100644 --- a/crates/rooch/src/commands/rpc/commands/request.rs +++ b/crates/rooch/src/commands/rpc/commands/request.rs @@ -10,14 +10,14 @@ use rooch_types::error::RoochResult; #[derive(Debug, Parser)] pub struct RequestCommand { /// The RPC method name - /// --method rooch_getAnnotatedStates + /// --method rooch_getStates #[clap(long)] pub method: String, /// The RPC method params, json value. /// --params '"/resource/0x3/0x3::timestamp::CurrentTimeMicroseconds"' /// or - /// --params '["/resource/0x3/0x3::timestamp::CurrentTimeMicroseconds"]' + /// --params '["/resource/0x3/0x3::timestamp::CurrentTimeMicroseconds", {"decode": true}]' #[clap(long)] pub params: Option, diff --git a/crates/rooch/src/commands/state.rs b/crates/rooch/src/commands/state.rs index 871233a479..4ff1839f99 100644 --- a/crates/rooch/src/commands/state.rs +++ b/crates/rooch/src/commands/state.rs @@ -5,7 +5,7 @@ use crate::cli_types::{CommandAction, WalletContextOptions}; use async_trait::async_trait; use clap::Parser; use moveos_types::access_path::AccessPath; -use rooch_rpc_api::jsonrpc_types::AnnotatedStateView; +use rooch_rpc_api::jsonrpc_types::StateView; use rooch_types::error::{RoochError, RoochResult}; /// Get states by accessPath @@ -24,13 +24,13 @@ pub struct StateCommand { } #[async_trait] -impl CommandAction>> for StateCommand { - async fn execute(self) -> RoochResult>> { +impl CommandAction>> for StateCommand { + async fn execute(self) -> RoochResult>> { let client = self.context_options.build().await?.get_client().await?; let resp = client .rooch - .get_annotated_states(self.access_path) + .get_decoded_states(self.access_path) .await .map_err(RoochError::from)?; Ok(resp) From f87da336246783ae8744b5d1de2d32d83ff3d1d0 Mon Sep 17 00:00:00 2001 From: jolestar Date: Mon, 16 Oct 2023 23:50:28 +0800 Subject: [PATCH 2/5] [RPC] Event API support decode options --- crates/rooch-executor/src/actor/executor.rs | 22 +- crates/rooch-executor/src/actor/messages.rs | 6 +- crates/rooch-executor/src/proxy/mod.rs | 6 +- .../rooch-open-rpc-spec/schemas/openrpc.json | 223 +++++++----------- crates/rooch-rpc-api/src/api/rooch_api.rs | 6 +- .../src/jsonrpc_types/move_types.rs | 16 +- .../src/jsonrpc_types/rooch_types.rs | 24 +- .../src/jsonrpc_types/rpc_options.rs | 20 +- .../src/jsonrpc_types/state_view.rs | 2 +- crates/rooch-rpc-client/src/rooch_client.rs | 4 +- .../src/server/rooch_server.rs | 37 ++- .../src/service/rpc_service.rs | 6 +- crates/rooch/src/commands/event.rs | 9 +- moveos/moveos-types/src/event.rs | 54 +---- moveos/moveos-types/src/event_filter.rs | 12 +- 15 files changed, 187 insertions(+), 260 deletions(-) diff --git a/crates/rooch-executor/src/actor/executor.rs b/crates/rooch-executor/src/actor/executor.rs index 6dd72254af..f8a42d4d0d 100644 --- a/crates/rooch-executor/src/actor/executor.rs +++ b/crates/rooch-executor/src/actor/executor.rs @@ -15,12 +15,12 @@ use async_trait::async_trait; use coerce::actor::{context::ActorContext, message::Handler, Actor}; use move_core_types::account_address::AccountAddress; use move_core_types::vm_status::VMStatus; -use move_resource_viewer::{AnnotatedMoveValue, MoveValueAnnotator}; +use move_resource_viewer::MoveValueAnnotator; use moveos::moveos::MoveOS; use moveos::vm::vm_status_explainer::explain_vm_status; use moveos_store::transaction_store::TransactionStore; use moveos_store::MoveOSStore; -use moveos_types::event::AnnotatedMoveOSEvent; +use moveos_types::event::AnnotatedEvent; use moveos_types::event::EventHandle; use moveos_types::function_return_value::AnnotatedFunctionResult; use moveos_types::function_return_value::AnnotatedFunctionReturnValue; @@ -385,7 +385,7 @@ impl Handler for ExecutorActor { &mut self, msg: GetEventsByEventHandleMessage, _ctx: &mut ActorContext, - ) -> Result> { + ) -> Result> { let GetEventsByEventHandleMessage { event_handle_type, cursor, @@ -400,12 +400,9 @@ impl Handler for ExecutorActor { events .into_iter() .map(|event| { - let state = State::new(event.event_data.clone(), event.type_tag.clone()); let event_move_value = MoveValueAnnotator::new(resolver) - .view_resource(&event_handle_type, state.value.as_slice())?; - let annotated_event_data = - AnnotatedState::new(state, AnnotatedMoveValue::Struct(event_move_value)); - Ok(AnnotatedMoveOSEvent::new(event, annotated_event_data)) + .view_resource(&event_handle_type, event.event_data())?; + Ok(AnnotatedEvent::new(event, event_move_value)) }) .collect::>>() } @@ -417,7 +414,7 @@ impl Handler for ExecutorActor { &mut self, msg: GetEventsMessage, _ctx: &mut ActorContext, - ) -> Result> { + ) -> Result> { let GetEventsMessage { filter } = msg; let event_store = self.moveos.event_store(); let resolver = self.moveos.moveos_resolver(); @@ -426,13 +423,10 @@ impl Handler for ExecutorActor { events .into_iter() .map(|event| { - let state = State::new(event.event_data.clone(), event.type_tag.clone()); let struct_tag = as_struct_tag(event.type_tag.clone())?; let event_move_value = MoveValueAnnotator::new(resolver) - .view_resource(&struct_tag, state.value.as_slice())?; - let annotated_event_data = - AnnotatedState::new(state, AnnotatedMoveValue::Struct(event_move_value)); - Ok(AnnotatedMoveOSEvent::new(event, annotated_event_data)) + .view_resource(&struct_tag, event.event_data())?; + Ok(AnnotatedEvent::new(event, event_move_value)) }) .collect::>>() } diff --git a/crates/rooch-executor/src/actor/messages.rs b/crates/rooch-executor/src/actor/messages.rs index 73fc773b79..eb141600f4 100644 --- a/crates/rooch-executor/src/actor/messages.rs +++ b/crates/rooch-executor/src/actor/messages.rs @@ -6,7 +6,7 @@ use coerce::actor::message::Message; use move_core_types::account_address::AccountAddress; use move_core_types::language_storage::StructTag; use moveos_types::access_path::AccessPath; -use moveos_types::event::AnnotatedMoveOSEvent; +use moveos_types::event::AnnotatedEvent; use moveos_types::event_filter::EventFilter; use moveos_types::function_return_value::AnnotatedFunctionResult; use moveos_types::h256::H256; @@ -112,7 +112,7 @@ pub struct GetEventsByEventHandleMessage { } impl Message for GetEventsByEventHandleMessage { - type Result = Result>; + type Result = Result>; } #[derive(Debug, Serialize, Deserialize)] @@ -121,7 +121,7 @@ pub struct GetEventsMessage { } impl Message for GetEventsMessage { - type Result = Result>; + type Result = Result>; } #[derive(Debug, Serialize, Deserialize)] diff --git a/crates/rooch-executor/src/proxy/mod.rs b/crates/rooch-executor/src/proxy/mod.rs index 1c5cb7928b..a50042c09b 100644 --- a/crates/rooch-executor/src/proxy/mod.rs +++ b/crates/rooch-executor/src/proxy/mod.rs @@ -22,7 +22,7 @@ use moveos_types::transaction::TransactionExecutionInfo; use moveos_types::transaction::TransactionOutput; use moveos_types::{access_path::AccessPath, transaction::VerifiedMoveOSTransaction}; use moveos_types::{ - event::AnnotatedMoveOSEvent, + event::AnnotatedEvent, event_filter::EventFilter, state::{AnnotatedState, State}, }; @@ -117,7 +117,7 @@ impl ExecutorProxy { event_handle_type: StructTag, cursor: Option, limit: u64, - ) -> Result> { + ) -> Result> { self.actor .send(GetEventsByEventHandleMessage { event_handle_type, @@ -127,7 +127,7 @@ impl ExecutorProxy { .await? } - pub async fn get_events(&self, filter: EventFilter) -> Result> { + pub async fn get_events(&self, filter: EventFilter) -> Result> { self.actor.send(GetEventsMessage { filter }).await? } diff --git a/crates/rooch-open-rpc-spec/schemas/openrpc.json b/crates/rooch-open-rpc-spec/schemas/openrpc.json index 533a35b775..d79d627267 100644 --- a/crates/rooch-open-rpc-spec/schemas/openrpc.json +++ b/crates/rooch-open-rpc-spec/schemas/openrpc.json @@ -55,36 +55,6 @@ } } }, - { - "name": "rooch_getAnnotatedStates", - "description": "Get the annotated states by access_path The annotated states include the decoded move value of the state", - "params": [ - { - "name": "access_path", - "required": true, - "schema": { - "$ref": "#/components/schemas/moveos_types::access_path::AccessPath" - } - } - ], - "result": { - "name": "Vec>", - "required": true, - "schema": { - "type": "array", - "items": { - "anyOf": [ - { - "$ref": "#/components/schemas/AnnotatedStateView" - }, - { - "type": "null" - } - ] - } - } - } - }, { "name": "rooch_getBalance", "description": "get account balance by AccountAddress and CoinType", @@ -177,13 +147,19 @@ "schema": { "$ref": "#/components/schemas/u64" } + }, + { + "name": "event_options", + "schema": { + "$ref": "#/components/schemas/EventOptions" + } } ], "result": { "name": "EventPageView", "required": true, "schema": { - "$ref": "#/components/schemas/PageView_for_AnnotatedEventView_and_uint64" + "$ref": "#/components/schemas/PageView_for_EventView_and_uint64" } } }, @@ -201,7 +177,7 @@ { "name": "state_option", "schema": { - "$ref": "#/components/schemas/ObjectDataOptions" + "$ref": "#/components/schemas/StateOptions" } } ], @@ -280,8 +256,8 @@ } }, { - "name": "rooch_listAnnotatedStates", - "description": "List the annotated states by access_path The annotated states include the decoded move value of the state", + "name": "rooch_listStates", + "description": "List the states by access_path If the StateOptions.decode is true, the state is decoded and the decoded value is returned in the response.", "params": [ { "name": "access_path", @@ -301,37 +277,11 @@ "schema": { "$ref": "#/components/schemas/usize" } - } - ], - "result": { - "name": "AnnotatedStatesPageView", - "required": true, - "schema": { - "$ref": "#/components/schemas/PageView_for_AnnotatedStateView_and_alloc::vec::Vec" - } - } - }, - { - "name": "rooch_listStates", - "description": "List the states by access_path", - "params": [ - { - "name": "access_path", - "required": true, - "schema": { - "$ref": "#/components/schemas/moveos_types::access_path::AccessPath" - } - }, - { - "name": "cursor", - "schema": { - "$ref": "#/components/schemas/alloc::vec::Vec" - } }, { - "name": "limit", + "name": "state_option", "schema": { - "$ref": "#/components/schemas/usize" + "$ref": "#/components/schemas/StateOptions" } } ], @@ -366,21 +316,6 @@ ], "components": { "schemas": { - "AnnotatedEventView": { - "type": "object", - "required": [ - "decoded_event_data", - "event" - ], - "properties": { - "decoded_event_data": { - "$ref": "#/components/schemas/AnnotatedStateView" - }, - "event": { - "$ref": "#/components/schemas/EventView" - } - } - }, "AnnotatedFunctionResultView": { "type": "object", "required": [ @@ -494,21 +429,6 @@ } ] }, - "AnnotatedStateView": { - "type": "object", - "required": [ - "move_value", - "state" - ], - "properties": { - "move_value": { - "$ref": "#/components/schemas/AnnotatedMoveValueView" - }, - "state": { - "$ref": "#/components/schemas/StateView" - } - } - }, "AuthenticatorView": { "type": "object", "required": [ @@ -581,6 +501,16 @@ } } }, + "EventOptions": { + "type": "object", + "properties": { + "decode": { + "description": "If true, the event is decoded and the decoded value is returned in the response.", + "default": false, + "type": "boolean" + } + } + }, "EventView": { "type": "object", "required": [ @@ -590,6 +520,16 @@ "type_tag" ], "properties": { + "decoded_event_data": { + "anyOf": [ + { + "$ref": "#/components/schemas/AnnotatedMoveStructView" + }, + { + "type": "null" + } + ] + }, "event_data": { "$ref": "#/components/schemas/alloc::vec::Vec" }, @@ -841,16 +781,6 @@ } } }, - "ObjectDataOptions": { - "type": "object", - "properties": { - "decode": { - "description": "If true, the state is decoded and the decoded value is returned in the response.", - "default": false, - "type": "boolean" - } - } - }, "ObjectID": { "$ref": "#/components/schemas/Hex" }, @@ -864,6 +794,16 @@ "value_type" ], "properties": { + "decoded_value": { + "anyOf": [ + { + "$ref": "#/components/schemas/AnnotatedMoveValueView" + }, + { + "type": "null" + } + ] + }, "type": { "type": "string", "enum": [ @@ -886,6 +826,16 @@ "value_type" ], "properties": { + "decoded_value": { + "anyOf": [ + { + "$ref": "#/components/schemas/AnnotatedMoveValueView" + }, + { + "type": "null" + } + ] + }, "type": { "type": "string", "enum": [ @@ -916,34 +866,7 @@ } ] }, - "PageView_for_AnnotatedEventView_and_uint64": { - "description": "`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.", - "type": "object", - "required": [ - "data", - "has_next_page" - ], - "properties": { - "data": { - "type": "array", - "items": { - "$ref": "#/components/schemas/AnnotatedEventView" - } - }, - "has_next_page": { - "type": "boolean" - }, - "next_cursor": { - "type": [ - "integer", - "null" - ], - "format": "uint64", - "minimum": 0.0 - } - } - }, - "PageView_for_AnnotatedStateView_and_alloc::vec::Vec": { + "PageView_for_BalanceInfoView_and_alloc::vec::Vec": { "description": "`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.", "type": "object", "required": [ @@ -954,7 +877,7 @@ "data": { "type": "array", "items": { - "$ref": "#/components/schemas/AnnotatedStateView" + "$ref": "#/components/schemas/BalanceInfoView" } }, "has_next_page": { @@ -972,7 +895,7 @@ } } }, - "PageView_for_BalanceInfoView_and_alloc::vec::Vec": { + "PageView_for_EventView_and_uint64": { "description": "`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.", "type": "object", "required": [ @@ -983,21 +906,19 @@ "data": { "type": "array", "items": { - "$ref": "#/components/schemas/BalanceInfoView" + "$ref": "#/components/schemas/EventView" } }, "has_next_page": { "type": "boolean" }, "next_cursor": { - "anyOf": [ - { - "$ref": "#/components/schemas/alloc::vec::Vec" - }, - { - "type": "null" - } - ] + "type": [ + "integer", + "null" + ], + "format": "uint64", + "minimum": 0.0 } } }, @@ -1125,6 +1046,16 @@ } } }, + "StateOptions": { + "type": "object", + "properties": { + "decode": { + "description": "If true, the state is decoded and the decoded value is returned in the response.", + "default": false, + "type": "boolean" + } + } + }, "StateView": { "type": "object", "required": [ @@ -1132,6 +1063,16 @@ "value_type" ], "properties": { + "decoded_value": { + "anyOf": [ + { + "$ref": "#/components/schemas/AnnotatedMoveValueView" + }, + { + "type": "null" + } + ] + }, "value": { "$ref": "#/components/schemas/alloc::vec::Vec" }, diff --git a/crates/rooch-rpc-api/src/api/rooch_api.rs b/crates/rooch-rpc-api/src/api/rooch_api.rs index f34ab8f548..b29c1d741e 100644 --- a/crates/rooch-rpc-api/src/api/rooch_api.rs +++ b/crates/rooch-rpc-api/src/api/rooch_api.rs @@ -5,8 +5,9 @@ use crate::jsonrpc_types::account_view::BalanceInfoView; use crate::jsonrpc_types::transaction_view::TransactionWithInfoView; use crate::jsonrpc_types::{ AccessPathView, AccountAddressView, AnnotatedFunctionResultView, BalanceInfoPageView, - BytesView, EventPageView, ExecuteTransactionResponseView, FunctionCallView, H256View, - StateOptions, StateView, StatesPageView, StrView, StructTagView, TransactionWithInfoPageView, + BytesView, EventOptions, EventPageView, ExecuteTransactionResponseView, FunctionCallView, + H256View, StateOptions, StateView, StatesPageView, StrView, StructTagView, + TransactionWithInfoPageView, }; use jsonrpsee::core::RpcResult; use jsonrpsee::proc_macros::rpc; @@ -67,6 +68,7 @@ pub trait RoochAPI { event_handle_type: StructTagView, cursor: Option>, limit: Option>, + event_options: Option, ) -> RpcResult; #[method(name = "getTransactionsByHash")] diff --git a/crates/rooch-rpc-api/src/jsonrpc_types/move_types.rs b/crates/rooch-rpc-api/src/jsonrpc_types/move_types.rs index deb939ab8e..197d9a2dad 100644 --- a/crates/rooch-rpc-api/src/jsonrpc_types/move_types.rs +++ b/crates/rooch-rpc-api/src/jsonrpc_types/move_types.rs @@ -10,7 +10,7 @@ use move_core_types::{ u256, }; use move_resource_viewer::{AnnotatedMoveStruct, AnnotatedMoveValue}; -use moveos_types::event::{Event, EventID}; +use moveos_types::event::{AnnotatedEvent, Event, EventID}; use moveos_types::move_types::parse_module_id; use moveos_types::moveos_std::type_info::TypeInfo; use moveos_types::transaction::MoveAction; @@ -428,6 +428,7 @@ pub struct EventView { pub type_tag: TypeTagView, pub event_data: BytesView, pub event_index: u64, + pub decoded_event_data: Option, } impl From for EventView { @@ -437,6 +438,7 @@ impl From for EventView { type_tag: event.type_tag.into(), event_data: StrView(event.event_data), event_index: event.event_index, + decoded_event_data: None, } } } @@ -452,6 +454,18 @@ impl From for Event { } } +impl From for EventView { + fn from(event: AnnotatedEvent) -> Self { + EventView { + event_id: event.event.event_id, + type_tag: event.event.type_tag.into(), + event_data: StrView(event.event.event_data), + event_index: event.event.event_index, + decoded_event_data: Some(event.decoded_event_data.into()), + } + } +} + #[derive(Debug, Clone, Deserialize, Serialize)] pub struct TypeInfoView { pub account_address: AccountAddress, 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 5ad56195c9..47bbb8a007 100644 --- a/crates/rooch-rpc-api/src/jsonrpc_types/rooch_types.rs +++ b/crates/rooch-rpc-api/src/jsonrpc_types/rooch_types.rs @@ -5,17 +5,16 @@ use crate::jsonrpc_types::account_view::BalanceInfoView; use crate::jsonrpc_types::transaction_view::TransactionWithInfoView; use crate::jsonrpc_types::{ move_types::{MoveActionTypeView, MoveActionView}, - AnnotatedMoveStructView, BytesView, EventView, H256View, StateView, StrView, StructTagView, + BytesView, EventView, StateView, StrView, StructTagView, }; use move_core_types::u256::U256; -use moveos_types::event::AnnotatedMoveOSEvent; use rooch_types::framework::coin::CoinInfo; use rooch_types::transaction::{AbstractTransaction, TransactionType, TypedTransaction}; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use std::string::String; -pub type EventPageView = PageView; +pub type EventPageView = PageView; pub type TransactionWithInfoPageView = PageView; pub type StatesPageView = PageView; pub type BalanceInfoPageView = PageView; @@ -81,25 +80,6 @@ impl From for TransactionView { } } -#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema)] -pub struct AnnotatedEventView { - pub event: EventView, - // pub sender: AccountAddressView, - // pub tx_hash: Option, - // pub timestamp_ms: Option, - // pub block_height: Option, - pub decoded_event_data: AnnotatedStateView, -} - -impl From for AnnotatedEventView { - fn from(event: AnnotatedMoveOSEvent) -> Self { - AnnotatedEventView { - event: event.event.into(), - decoded_event_data: event.decoded_event_data.into(), - } - } -} - #[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] pub struct CoinInfoView { pub coin_type: StructTagView, diff --git a/crates/rooch-rpc-api/src/jsonrpc_types/rpc_options.rs b/crates/rooch-rpc-api/src/jsonrpc_types/rpc_options.rs index e296afb030..f92472e588 100644 --- a/crates/rooch-rpc-api/src/jsonrpc_types/rpc_options.rs +++ b/crates/rooch-rpc-api/src/jsonrpc_types/rpc_options.rs @@ -5,7 +5,7 @@ use schemars::JsonSchema; use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Deserialize, Serialize, JsonSchema, Eq, PartialEq, Default)] -#[serde(rename_all = "camelCase", rename = "ObjectDataOptions", default)] +#[serde(rename_all = "camelCase", default)] pub struct StateOptions { /// If true, the state is decoded and the decoded value is returned in the response. pub decode: bool, @@ -21,3 +21,21 @@ impl StateOptions { self } } + +#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema, Eq, PartialEq, Default)] +#[serde(rename_all = "camelCase", default)] +pub struct EventOptions { + /// If true, the event is decoded and the decoded value is returned in the response. + pub decode: bool, +} + +impl EventOptions { + pub fn new() -> Self { + Self::default() + } + + pub fn decode(mut self, decode: bool) -> Self { + self.decode = decode; + self + } +} 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 1fcce88771..f4cc929e4b 100644 --- a/crates/rooch-rpc-api/src/jsonrpc_types/state_view.rs +++ b/crates/rooch-rpc-api/src/jsonrpc_types/state_view.rs @@ -31,7 +31,7 @@ impl From for StateView { impl From for StateView { fn from(state: AnnotatedState) -> Self { Self { - value: StrView(state.state.value.0), + value: StrView(state.state.value), value_type: state.state.value_type.into(), decoded_value: Some(state.move_value.into()), } diff --git a/crates/rooch-rpc-client/src/rooch_client.rs b/crates/rooch-rpc-client/src/rooch_client.rs index f03d14c8bf..07ad314cdd 100644 --- a/crates/rooch-rpc-client/src/rooch_client.rs +++ b/crates/rooch-rpc-client/src/rooch_client.rs @@ -15,7 +15,7 @@ use rooch_rpc_api::jsonrpc_types::{ }; use rooch_rpc_api::jsonrpc_types::{ AccessPathView, AccountAddressView, AnnotatedFunctionResultView, BalanceInfoPageView, - EventPageView, StateOptions, StatesPageView, StructTagView, + EventOptions, EventPageView, StateOptions, StatesPageView, StructTagView, }; use rooch_rpc_api::jsonrpc_types::{BytesView, TransactionWithInfoPageView}; use rooch_rpc_api::jsonrpc_types::{ExecuteTransactionResponseView, StateView}; @@ -114,6 +114,7 @@ impl RoochRpcClient { event_handle_type: StructTagView, cursor: Option, limit: Option, + event_options: Option, ) -> Result { let s = self .http @@ -121,6 +122,7 @@ impl RoochRpcClient { event_handle_type, cursor.map(Into::into), limit.map(Into::into), + event_options, ) .await?; Ok(s) diff --git a/crates/rooch-rpc-server/src/server/rooch_server.rs b/crates/rooch-rpc-server/src/server/rooch_server.rs index 7e7747a886..d18b01a0e0 100644 --- a/crates/rooch-rpc-server/src/server/rooch_server.rs +++ b/crates/rooch-rpc-server/src/server/rooch_server.rs @@ -8,10 +8,12 @@ use jsonrpsee::{ RpcModule, }; use moveos_types::h256::H256; -use rooch_rpc_api::jsonrpc_types::transaction_view::TransactionWithInfoView; use rooch_rpc_api::jsonrpc_types::{account_view::BalanceInfoView, StateOptions}; use rooch_rpc_api::jsonrpc_types::{ - AccessPathView, AccountAddressView, AnnotatedEventView, BalanceInfoPageView, EventPageView, + transaction_view::TransactionWithInfoView, EventOptions, EventView, +}; +use rooch_rpc_api::jsonrpc_types::{ + AccessPathView, AccountAddressView, BalanceInfoPageView, EventPageView, ExecuteTransactionResponseView, FunctionCallView, H256View, StateView, StatesPageView, StrView, StructTagView, TransactionWithInfoPageView, }; @@ -129,14 +131,14 @@ impl RoochAPIServer for RoochServer { .await? .into_iter() .map(|(key, state)| (key, StateView::from(state))) - .collect::>(); + .collect::>() } else { self.rpc_service .list_states(access_path.into(), cursor_of, limit_of + 1) .await? .into_iter() .map(|(key, state)| (key, StateView::from(state))) - .collect::>(); + .collect::>() }; let has_next_page = data.len() > limit_of; @@ -158,24 +160,35 @@ impl RoochAPIServer for RoochServer { event_handle_type: StructTagView, cursor: Option>, limit: Option>, + event_options: Option, ) -> RpcResult { + let event_options = event_options.unwrap_or_default(); let cursor = cursor.map(|v| v.0); let limit = limit.map(|v| v.0); // NOTE: fetch one more object to check if there is next page let limit_of = min(limit.unwrap_or(DEFAULT_RESULT_LIMIT), MAX_RESULT_LIMIT); - let mut data: Vec = self - .rpc_service - .get_events_by_event_handle(event_handle_type.into(), cursor, limit_of + 1) - .await? - .into_iter() - .map(AnnotatedEventView::from) - .collect(); + let mut data = if event_options.decode { + self.rpc_service + .get_events_by_event_handle(event_handle_type.into(), cursor, limit_of + 1) + .await? + .into_iter() + .map(EventView::from) + .collect::>() + } else { + //TODO provide a function to directly get the Event, not the AnnotatedEvent + self.rpc_service + .get_events_by_event_handle(event_handle_type.into(), cursor, limit_of + 1) + .await? + .into_iter() + .map(|e| EventView::from(e.event)) + .collect::>() + }; let has_next_page = (data.len() as u64) > limit_of; data.truncate(limit_of as usize); let next_cursor = data .last() - .map_or(cursor, |event| Some(event.event.event_id.event_seq)); + .map_or(cursor, |event| Some(event.event_id.event_seq)); Ok(EventPageView { data, diff --git a/crates/rooch-rpc-server/src/service/rpc_service.rs b/crates/rooch-rpc-server/src/service/rpc_service.rs index c81ca22d90..e0dbb8265c 100644 --- a/crates/rooch-rpc-server/src/service/rpc_service.rs +++ b/crates/rooch-rpc-server/src/service/rpc_service.rs @@ -5,7 +5,7 @@ use anyhow::Result; use move_core_types::account_address::AccountAddress; use move_core_types::language_storage::StructTag; use moveos_types::access_path::AccessPath; -use moveos_types::event::AnnotatedMoveOSEvent; +use moveos_types::event::AnnotatedEvent; use moveos_types::event_filter::EventFilter; use moveos_types::function_return_value::AnnotatedFunctionResult; use moveos_types::h256::H256; @@ -133,7 +133,7 @@ impl RpcService { event_handle_type: StructTag, cursor: Option, limit: u64, - ) -> Result> { + ) -> Result> { let resp = self .executor .get_events_by_event_handle(event_handle_type, cursor, limit) @@ -141,7 +141,7 @@ impl RpcService { Ok(resp) } - pub async fn get_events(&self, filter: EventFilter) -> Result> { + pub async fn get_events(&self, filter: EventFilter) -> Result> { let resp = self.executor.get_events(filter).await?; Ok(resp) } diff --git a/crates/rooch/src/commands/event.rs b/crates/rooch/src/commands/event.rs index f211dc1fdc..9b52d2ab36 100644 --- a/crates/rooch/src/commands/event.rs +++ b/crates/rooch/src/commands/event.rs @@ -5,7 +5,7 @@ use crate::cli_types::{CommandAction, WalletContextOptions}; use async_trait::async_trait; use clap::{Parser, Subcommand}; use move_core_types::language_storage::StructTag; -use rooch_rpc_api::jsonrpc_types::EventPageView; +use rooch_rpc_api::jsonrpc_types::{EventOptions, EventPageView}; use rooch_types::error::{RoochError, RoochResult}; /// Tool for interacting with event @@ -52,7 +52,12 @@ impl CommandAction for GetEventsByEventHandle { let client = self.context_options.build().await?.get_client().await?; let resp = client .rooch - .get_events_by_event_handle(self.event_handle_type.into(), self.cursor, self.limit) + .get_events_by_event_handle( + self.event_handle_type.into(), + self.cursor, + self.limit, + Some(EventOptions::default().decode(true)), + ) .await .map_err(RoochError::from)?; Ok(resp) diff --git a/moveos/moveos-types/src/event.rs b/moveos/moveos-types/src/event.rs index 5079f4b8c6..451773c206 100644 --- a/moveos/moveos-types/src/event.rs +++ b/moveos/moveos-types/src/event.rs @@ -6,10 +6,11 @@ use crate::moveos_std::type_info::TypeInfo; use crate::object::ObjectID; -use crate::state::{AnnotatedState, MoveStructType}; +use crate::state::MoveStructType; use anyhow::{ensure, Error, Result}; use move_core_types::account_address::AccountAddress; use move_core_types::{language_storage::StructTag, language_storage::TypeTag}; +use move_resource_viewer::AnnotatedMoveStruct; use schemars::JsonSchema; // #[cfg(any(test, feature = "fuzzing"))] // use rand::{rngs::OsRng, RngCore}; @@ -219,58 +220,17 @@ impl EventHandle { // count, // } // } - - // /// Derive a unique handle by using an AccountAddress and a counter. - // pub fn new_from_address(addr: &AccountAddress, salt: u64) -> Self { - // Self { - // event_id: EventID::new_from_address(addr, salt), - // count: 0, - // } - // } -} - -// #[derive(Eq, PartialEq, Clone, Debug, Serialize, Deserialize, JsonSchema)] -// #[derive(Clone, Debug)] -// #[serde_as] -#[derive(Eq, PartialEq, Clone, Debug)] -pub struct MoveOSEvent { - pub event: Event, - // /// Sender's address. - // pub sender: AccountAddress, - // /// Transaction hash - // pub tx_hash: Option, - // /// UTC timestamp in milliseconds since epoch (1/1/1970) - // #[serde(skip_serializing_if = "Option::is_none")] - // #[schemars(with = "Option")] - // #[serde_as(as = "Option")] - // pub timestamp_ms: Option, - // block height - // #[serde(skip_serializing_if = "Option::is_none")] - // #[schemars(with = "Option")] - // #[serde_as(as = "Option")] - // pub block_height: Option, -} - -impl MoveOSEvent { - pub fn new(event: Event) -> Self { - MoveOSEvent { event } - } } #[derive(Debug, Clone)] -pub struct AnnotatedMoveOSEvent { +pub struct AnnotatedEvent { pub event: Event, - // pub sender: AccountAddress, - // pub tx_hash: Option, - // pub event_data: Vec, - // pub timestamp_ms: Option, - // pub block_height: Option, - pub decoded_event_data: AnnotatedState, + pub decoded_event_data: AnnotatedMoveStruct, } -impl AnnotatedMoveOSEvent { - pub fn new(event: Event, decoded_event_data: AnnotatedState) -> Self { - AnnotatedMoveOSEvent { +impl AnnotatedEvent { + pub fn new(event: Event, decoded_event_data: AnnotatedMoveStruct) -> Self { + AnnotatedEvent { event, decoded_event_data, } diff --git a/moveos/moveos-types/src/event_filter.rs b/moveos/moveos-types/src/event_filter.rs index f9968492a9..ee55dbe0b6 100644 --- a/moveos/moveos-types/src/event_filter.rs +++ b/moveos/moveos-types/src/event_filter.rs @@ -4,7 +4,7 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -use crate::event::MoveOSEvent; +use crate::event::Event; use crate::move_types::type_tag_match; use anyhow::Result; use move_core_types::language_storage::TypeTag; @@ -63,11 +63,9 @@ pub enum EventFilter { } impl EventFilter { - fn try_matches(&self, item: &MoveOSEvent) -> Result { + fn try_matches(&self, item: &Event) -> Result { Ok(match self { - EventFilter::MoveEventType(event_type) => { - type_tag_match(&item.event.type_tag, event_type) - } + EventFilter::MoveEventType(event_type) => type_tag_match(&item.type_tag, event_type), EventFilter::MoveEventField { path: _, value: _ } => { // matches!(item.decoded_event_data.pointer(path), Some(v) if v == value) false @@ -114,8 +112,8 @@ impl EventFilter { } } -impl Filter for EventFilter { - fn matches(&self, item: &MoveOSEvent) -> bool { +impl Filter for EventFilter { + fn matches(&self, item: &Event) -> bool { self.try_matches(item).unwrap_or_default() } } From 00d64a530c8fabd247d3a28880e32e2152dd0f05 Mon Sep 17 00:00:00 2001 From: jolestar Date: Tue, 17 Oct 2023 00:09:35 +0800 Subject: [PATCH 3/5] [sdk] Update sdk --- dashboard/src/store/scan/state/index.ts | 6 +- dashboard/src/store/session/index.ts | 10 +-- sdk/typescript/src/account/account.ts | 20 ++---- .../src/provider/filtered-provider.test.ts | 10 +-- .../src/provider/filtered-provider.ts | 14 ++--- sdk/typescript/src/provider/interface.ts | 12 ++-- .../src/provider/json-rpc-provider.test.ts | 8 +-- .../src/provider/json-rpc-provider.ts | 63 ++++--------------- sdk/typescript/test/e2e/sdk.test.ts | 4 +- .../generator/template/name_mapping.json | 3 +- 10 files changed, 48 insertions(+), 102 deletions(-) diff --git a/dashboard/src/store/scan/state/index.ts b/dashboard/src/store/scan/state/index.ts index 8732c1108a..428d8f268d 100644 --- a/dashboard/src/store/scan/state/index.ts +++ b/dashboard/src/store/scan/state/index.ts @@ -8,7 +8,7 @@ import { createAsyncThunk, Dispatch, AnyAction } from '@reduxjs/toolkit' import { CreateGenericSlice, GenericState } from '../../generic' // ** sdk import -import { AnnotatedStateView, JsonRpcProvider } from '@rooch/sdk' +import { StateView, JsonRpcProvider } from '@rooch/sdk' interface DataParams { dispatch: Dispatch @@ -22,7 +22,7 @@ export const fetchData = createAsyncThunk('state/fetchData', async (params: Data try { console.log(params.provider) - let result = await params.provider.getAnnotatedStates(params.accessPath) + let result = await params.provider.getStates(params.accessPath) params.dispatch(success(result)) return result @@ -35,7 +35,7 @@ export const StateSlice = CreateGenericSlice({ name: 'state', initialState: { result: [], - } as GenericState, + } as GenericState, reducers: {}, }) diff --git a/dashboard/src/store/session/index.ts b/dashboard/src/store/session/index.ts index 38b67f58fd..4b0770adb8 100644 --- a/dashboard/src/store/session/index.ts +++ b/dashboard/src/store/session/index.ts @@ -13,7 +13,7 @@ import { IPage, ISessionKey, JsonRpcProvider, - AnnotatedStatePageView, + StatePageView, parseRoochErrorSubStatus, getErrorCategoryName, } from '@rooch/sdk' @@ -33,11 +33,11 @@ interface RemoveParams { refresh: () => void } -const convertToSessionKey = (data: AnnotatedStatePageView): Array => { +const convertToSessionKey = (data: StatePageView): Array => { const result = new Array() for (const state of data.data as any) { - const moveValue = state?.move_value as any + const moveValue = state?.decoded_value as any if (moveValue) { const val = moveValue.value @@ -79,14 +79,14 @@ export const fetchData = createAsyncThunk('state/fetchData', async (params: Data try { const accessPath = `/resource/${account_address}/0x3::session_key::SessionKeys` - const stateResult = await params.provider.getAnnotatedStates(accessPath) + const stateResult = await params.provider.getStates(accessPath) if (stateResult) { const stateView = stateResult as any if (stateView && stateView.length > 0 && stateView[0]) { const tableId = stateView[0].state.value const accessPath = `/table/${tableId}` - const pageView = await params.provider.listAnnotatedStates(accessPath, cursor, limit) + const pageView = await params.provider.listStates(accessPath, cursor, limit) const result = { data: convertToSessionKey(pageView), diff --git a/sdk/typescript/src/account/account.ts b/sdk/typescript/src/account/account.ts index 894ac986f1..0aa107cefd 100644 --- a/sdk/typescript/src/account/account.ts +++ b/sdk/typescript/src/account/account.ts @@ -5,15 +5,7 @@ import { DEFAULT_MAX_GAS_AMOUNT } from '../constants' import { IAccount, CallOption, ISessionKey } from './interface' import { IProvider } from '../provider' import { IAuthorizer, IAuthorization, PrivateKeyAuth } from '../auth' -import { - AccountAddress, - FunctionId, - TypeTag, - Arg, - AnnotatedStatePageView, - Bytes, - IPage, -} from '../types' +import { AccountAddress, FunctionId, TypeTag, Arg, StatePageView, Bytes, IPage } from '../types' import { BcsSerializer } from '../types/bcs' import { RoochTransaction, @@ -205,13 +197,13 @@ export class Account implements IAccount { async querySessionKeys(cursor: Bytes | null, limit: number): Promise> { const accessPath = `/resource/${this.address}/0x3::session_key::SessionKeys` - const state = await this.provider.getAnnotatedStates(accessPath) + const state = await this.provider.getStates(accessPath) if (state) { const stateView = state as any - const tableId = stateView[0].state.value + const tableId = stateView[0].value const accessPath = `/table/${tableId}` - const pageView = await this.provider.listAnnotatedStates(accessPath, cursor, limit) + const pageView = await this.provider.listStates(accessPath, cursor, limit) return { data: this.convertToSessionKey(pageView), @@ -223,11 +215,11 @@ export class Account implements IAccount { throw new Error('not found state') } - private convertToSessionKey(data: AnnotatedStatePageView): Array { + private convertToSessionKey(data: StatePageView): Array { const result = new Array() for (const state of data.data as any) { - const moveValue = state?.move_value as any + const moveValue = state?.decoded_value as any if (moveValue) { const val = moveValue.value diff --git a/sdk/typescript/src/provider/filtered-provider.test.ts b/sdk/typescript/src/provider/filtered-provider.test.ts index 041f5ae626..2ca3396a01 100644 --- a/sdk/typescript/src/provider/filtered-provider.test.ts +++ b/sdk/typescript/src/provider/filtered-provider.test.ts @@ -15,8 +15,8 @@ import { TypeTag, Arg, AnnotatedFunctionResultView, - AnnotatedStateView, - AnnotatedStatePageView, + StateView, + StatePageView, } from '../types' const mockFilter: ITransactionFilter = { @@ -41,14 +41,14 @@ const mockProvider: IProvider = { ): Promise { throw new Error('Function not implemented.') }, - getAnnotatedStates: function (accessPath: string): Promise { + getStates: function (accessPath: string): Promise { throw new Error('Function not implemented.') }, - listAnnotatedStates: function ( + listStates: function ( access_path: string, cursor: Uint8Array | null, limit: number, - ): Promise { + ): Promise { throw new Error('Function not implemented.') }, } diff --git a/sdk/typescript/src/provider/filtered-provider.ts b/sdk/typescript/src/provider/filtered-provider.ts index 896d72bc42..61cd6a4658 100644 --- a/sdk/typescript/src/provider/filtered-provider.ts +++ b/sdk/typescript/src/provider/filtered-provider.ts @@ -6,8 +6,8 @@ import { TypeTag, Arg, AnnotatedFunctionResultView, - AnnotatedStateView, - AnnotatedStatePageView, + StateView, + StatePageView, } from '../types' import { IProvider } from './interface' @@ -67,16 +67,16 @@ export class FilteredProvider implements IProvider { return this.target.executeViewFunction(funcId, tyArgs, args) } - getAnnotatedStates(accessPath: string): Promise { - return this.target.getAnnotatedStates(accessPath) + getStates(accessPath: string): Promise { + return this.target.getStates(accessPath) } - listAnnotatedStates( + listStates( access_path: string, cursor: Uint8Array | null, limit: number, - ): Promise { - return this.target.listAnnotatedStates(access_path, cursor, limit) + ): Promise { + return this.target.listStates(access_path, cursor, limit) } sendRawTransaction(playload: Uint8Array): Promise { diff --git a/sdk/typescript/src/provider/interface.ts b/sdk/typescript/src/provider/interface.ts index a81dfb326c..b0ddfb32b1 100644 --- a/sdk/typescript/src/provider/interface.ts +++ b/sdk/typescript/src/provider/interface.ts @@ -5,8 +5,8 @@ import { TypeTag, FunctionId, AnnotatedFunctionResultView, - AnnotatedStatePageView, - AnnotatedStateView, + StatePageView, + StateView, Bytes, } from '../types' @@ -23,11 +23,7 @@ export interface IProvider { sendRawTransaction(playload: Bytes): Promise - getAnnotatedStates(accessPath: string): Promise + getStates(accessPath: string): Promise - listAnnotatedStates( - access_path: string, - cursor: Bytes | null, - limit: number, - ): Promise + listStates(access_path: string, cursor: Bytes | null, limit: number): Promise } diff --git a/sdk/typescript/src/provider/json-rpc-provider.test.ts b/sdk/typescript/src/provider/json-rpc-provider.test.ts index 4e53f44c01..1b1377f2ad 100644 --- a/sdk/typescript/src/provider/json-rpc-provider.test.ts +++ b/sdk/typescript/src/provider/json-rpc-provider.test.ts @@ -82,7 +82,7 @@ describe('provider', () => { } }) - describe('#getAnnotatedStates', () => { + describe('#getStates', () => { it('should get annotated statues ok', async () => { const mockFetch = vi.fn().mockImplementation(() => { const mock = fetchMock.sandbox() @@ -113,7 +113,7 @@ describe('provider', () => { try { const assetsPath = '/object::0x1' - const result = await provider.getAnnotatedStates(assetsPath) + const result = await provider.getStates(assetsPath) expect(result).toHaveLength(1) } catch (err: any) { @@ -122,7 +122,7 @@ describe('provider', () => { }) }) - describe('#listAnnotatedStates', () => { + describe('#listStates', () => { it('should list annotated states ok', async () => { const mockFetch = vi.fn().mockImplementation(() => { const mock = fetchMock.sandbox() @@ -170,7 +170,7 @@ describe('provider', () => { const assetsPath = '/table/0x82af1915608fa5f3e5286e4372e289b5b3ef03d0126cdae9ca7f561a145359c8' const cursor = new Uint8Array([0]) - const result = await provider.listAnnotatedStates(assetsPath, cursor, 10) + const result = await provider.listStates(assetsPath, cursor, 10) expect(result.data).toBeDefined() expect(result.next_cursor).toBe( diff --git a/sdk/typescript/src/provider/json-rpc-provider.ts b/sdk/typescript/src/provider/json-rpc-provider.ts index ef46e7be18..f821e42b88 100644 --- a/sdk/typescript/src/provider/json-rpc-provider.ts +++ b/sdk/typescript/src/provider/json-rpc-provider.ts @@ -12,13 +12,13 @@ import { Bytes, // TransactionView, AnnotatedFunctionResultView, - AnnotatedStateView, TransactionWithInfoPageView, - AnnotatedEventPageView, - AnnotatedStatePageView, + EventPageView, StateView, StatePageView, TransactionWithInfoView, + StateOptions, + EventOptions, } from '../types' import { functionIdToStirng, typeTagToString, encodeArg, toHexString } from '../utils' import { IProvider } from './interface' @@ -133,17 +133,6 @@ export class JsonRpcProvider implements IProvider { return await this.client.rooch_getTransactionsByHash(tx_hashes) } - // async getTransactionInfosByHash( - // txHashes: string[], - // ): Promise { - // return await this.client.rooch_getTransactionInfosByHash(txHashes) - // } - - // Get the annotated states by access_path The annotated states include the decoded move value of the state - async getAnnotatedStates(accessPath: string): Promise { - return await this.client.rooch_getAnnotatedStates(accessPath) - } - async getTransactionsByOrder( cursor: number, limit: number, @@ -156,57 +145,27 @@ export class JsonRpcProvider implements IProvider { event_handle_type: string, cursor: number, limit: number, - ): Promise { + ): Promise { return await this.client.rooch_getEventsByEventHandle( event_handle_type, cursor.toString(), limit.toString(), + { decode: true } as EventOptions, ) } // Get the states by access_path async getStates(access_path: string): Promise { - return await this.client.rooch_getStates(access_path) + return await this.client.rooch_getStates(access_path, { decode: true } as StateOptions) } - // List the states by access_path - async listStates(access_path: string, cursor: Uint8Array, limit: number): Promise { - return await this.client.rooch_listStates(access_path, cursor, limit.toString()) - } - - // TODO: - // async getTransactionByHash(hash: string): Promise { - // return this.client.rooch_getTransactionByHash(hash) - // } - - // - // // List the annotated states by access_path The annotated states include the decoded move value of the state - // async listAnnotatedStates( - // access_path: string, - // cursor: Uint8Array, - // limit: number, - // ): Promise { - // return await this.rpcClient.rooch_listAnnotatedStates( - // access_path, - // cursor, - // limit, - // ) - // } - - async listAnnotatedStates( + async listStates( access_path: string, cursor: Bytes | null, limit: number, - ): Promise { - return await this.client.rooch_listAnnotatedStates(access_path, cursor as any, limit.toString()) + ): Promise { + return await this.client.rooch_listStates(access_path, cursor as any, limit.toString(), { + decode: true, + } as StateOptions) } - - // // List the states by access_path - // async listStates( - // access_path: string, - // cursor: Uint8Array, - // limit: number, - // ): Promise { - // return await this.rpcClient.rooch_listStates(access_path, cursor, limit) - // } } diff --git a/sdk/typescript/test/e2e/sdk.test.ts b/sdk/typescript/test/e2e/sdk.test.ts index 597e44087c..3f11f86a98 100644 --- a/sdk/typescript/test/e2e/sdk.test.ts +++ b/sdk/typescript/test/e2e/sdk.test.ts @@ -165,10 +165,10 @@ describe('SDK', () => { }) }) - describe('#getAnnotatedStates', () => { + describe('#getStates', () => { it('get annotated states should be ok', async () => { const provider = new JsonRpcProvider(LocalChain) - const result = provider.getAnnotatedStates('/object/0x1') + const result = provider.getStates('/object/0x1') expect(result).toBeDefined() }) }) diff --git a/sdk/typescript/tools/generator/template/name_mapping.json b/sdk/typescript/tools/generator/template/name_mapping.json index 6f3a16cd73..97f56bfea0 100644 --- a/sdk/typescript/tools/generator/template/name_mapping.json +++ b/sdk/typescript/tools/generator/template/name_mapping.json @@ -7,7 +7,6 @@ "moveos_types_access_path_AccessPath": "AccessPath", "moveos_types_move_types_FunctionId": "RoochFunctionId", "PageView_for_TransactionWithInfoView_and_uint128": "TransactionWithInfoPageView", - "PageView_for_AnnotatedStateView_and_alloc_vec_Vec_U8Array": "AnnotatedStatePageView", - "PageView_for_AnnotatedEventView_and_uint64": "AnnotatedEventPageView", + "PageView_for_EventView_and_uint64": "EventPageView", "PageView_for_StateView_and_alloc_vec_Vec_U8Array": "StatePageView" } From 23d272b41c6dbf9aacef6c9852ed959ef844be45 Mon Sep 17 00:00:00 2001 From: jolestar Date: Tue, 17 Oct 2023 00:34:08 +0800 Subject: [PATCH 4/5] [types] Rename move_value to decoded_value --- crates/rooch-executor/src/actor/executor.rs | 4 +-- .../rooch-open-rpc-spec/schemas/openrpc.json | 4 +-- .../function_return_value_view.rs | 4 +-- .../src/jsonrpc_types/state_view.rs | 2 +- crates/testsuite/features/cmd.feature | 18 ++++++------- dashboard/src/context/auth/AuthContext.tsx | 2 +- .../moveos-types/src/function_return_value.rs | 2 +- moveos/moveos-types/src/state.rs | 17 +++++++----- moveos/moveos-types/src/tx_context.rs | 4 +-- sdk/typescript/src/account/account.ts | 4 +-- .../src/provider/json-rpc-provider.test.ts | 26 +++++++++---------- 11 files changed, 44 insertions(+), 43 deletions(-) diff --git a/crates/rooch-executor/src/actor/executor.rs b/crates/rooch-executor/src/actor/executor.rs index f8a42d4d0d..b7a6fd4521 100644 --- a/crates/rooch-executor/src/actor/executor.rs +++ b/crates/rooch-executor/src/actor/executor.rs @@ -306,10 +306,10 @@ impl Handler for ExecutorActor { values .into_iter() .map(|v| { - let move_value = resoler.view_value(&v.type_tag, &v.value)?; + let decoded_value = resoler.view_value(&v.type_tag, &v.value)?; Ok(AnnotatedFunctionReturnValue { value: v, - move_value, + decoded_value, }) }) .collect::, anyhow::Error>>()?, diff --git a/crates/rooch-open-rpc-spec/schemas/openrpc.json b/crates/rooch-open-rpc-spec/schemas/openrpc.json index d79d627267..549e2f13a5 100644 --- a/crates/rooch-open-rpc-spec/schemas/openrpc.json +++ b/crates/rooch-open-rpc-spec/schemas/openrpc.json @@ -339,11 +339,11 @@ "AnnotatedFunctionReturnValueView": { "type": "object", "required": [ - "move_value", + "decoded_value", "value" ], "properties": { - "move_value": { + "decoded_value": { "$ref": "#/components/schemas/AnnotatedMoveValueView" }, "value": { diff --git a/crates/rooch-rpc-api/src/jsonrpc_types/function_return_value_view.rs b/crates/rooch-rpc-api/src/jsonrpc_types/function_return_value_view.rs index 8c15bcf19e..fb60152d37 100644 --- a/crates/rooch-rpc-api/src/jsonrpc_types/function_return_value_view.rs +++ b/crates/rooch-rpc-api/src/jsonrpc_types/function_return_value_view.rs @@ -142,14 +142,14 @@ impl From for FunctionReturnValue { #[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] pub struct AnnotatedFunctionReturnValueView { pub value: FunctionReturnValueView, - pub move_value: AnnotatedMoveValueView, + pub decoded_value: AnnotatedMoveValueView, } impl From for AnnotatedFunctionReturnValueView { fn from(value: AnnotatedFunctionReturnValue) -> Self { Self { value: value.value.into(), - move_value: value.move_value.into(), + decoded_value: value.decoded_value.into(), } } } 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 f4cc929e4b..f4dd3f3b96 100644 --- a/crates/rooch-rpc-api/src/jsonrpc_types/state_view.rs +++ b/crates/rooch-rpc-api/src/jsonrpc_types/state_view.rs @@ -33,7 +33,7 @@ impl From for StateView { Self { value: StrView(state.state.value), value_type: state.state.value_type.into(), - decoded_value: Some(state.move_value.into()), + decoded_value: Some(state.decoded_value.into()), } } } diff --git a/crates/testsuite/features/cmd.feature b/crates/testsuite/features/cmd.feature index 2bf5327ad8..b32555d590 100644 --- a/crates/testsuite/features/cmd.feature +++ b/crates/testsuite/features/cmd.feature @@ -46,10 +46,10 @@ Feature: Rooch CLI integration tests #FIXME how to pass args at here. #Then cmd: "move run --function {default}::kv_store::add_value --args 'b\"key1\"' 'b\"value1\"' --sender-account default" #Then cmd: "move view --function {default}::kv_store::get_value --args 'b\"key1\"' " - #Then assert: "{{$.move[-1][0].move_value}} == "value1"" + #Then assert: "{{$.move[-1][0].decoded_value}} == "value1"" #Then cmd: "state --access-path /resource/{default}/{default}::kv_store::KVStore - #Then cmd: "state --access-path /table/{{$.move[-1][0].move_value.value.table.value.handle}}/key1" - #Then assert: "{{$.move[-1][0].move_value}} == "value1"" + #Then cmd: "state --access-path /table/{{$.move[-1][0].decoded_value.value.table.value.handle}}/key1" + #Then assert: "{{$.move[-1][0].decoded_value}} == "value1"" Then stop the server @@ -89,12 +89,12 @@ Feature: Rooch CLI integration tests # The counter example Then cmd: "move publish -p ../../examples/counter --sender-account {default} --named-addresses rooch_examples={default} --by-move-action" Then cmd: "move view --function {default}::counter::value" - Then assert: "{{$.move[-1].return_values[0].move_value}} == 0" + Then assert: "{{$.move[-1].return_values[0].decoded_value}} == 0" Then cmd: "move run --function {default}::counter::increase --sender-account {default}" Then cmd: "move view --function {default}::counter::value" - Then assert: "{{$.move[-1].return_values[0].move_value}} == 1" + Then assert: "{{$.move[-1].return_values[0].decoded_value}} == 1" Then cmd: "resource --address {default} --resource {default}::counter::Counter" - Then assert: "{{$.resource[-1].move_value.value.value}} == 1" + Then assert: "{{$.resource[-1].decoded_value.value.value}} == 1" # The entry_function_arguments example Then cmd: "move publish -p ../../examples/entry_function_arguments_old/ --sender-account {default} --named-addresses rooch_examples={default} --by-move-action" @@ -116,12 +116,12 @@ Feature: Rooch CLI integration tests # The counter example Then cmd: "move publish -p ../../examples/counter --sender-account {default} --named-addresses rooch_examples={default}" Then cmd: "move view --function {default}::counter::value" - Then assert: "{{$.move[-1].return_values[0].move_value}} == 0" + Then assert: "{{$.move[-1].return_values[0].decoded_value}} == 0" Then cmd: "move run --function {default}::counter::increase --sender-account {default}" Then cmd: "move view --function {default}::counter::value" - Then assert: "{{$.move[-1].return_values[0].move_value}} == 1" + Then assert: "{{$.move[-1].return_values[0].decoded_value}} == 1" Then cmd: "resource --address {default} --resource {default}::counter::Counter" - Then assert: "{{$.resource[-1].move_value.value.value}} == 1" + Then assert: "{{$.resource[-1].decoded_value.value.value}} == 1" # The entry_function_arguments example Then cmd: "move publish -p ../../examples/entry_function_arguments_old/ --sender-account {default} --named-addresses rooch_examples={default}" diff --git a/dashboard/src/context/auth/AuthContext.tsx b/dashboard/src/context/auth/AuthContext.tsx index baa18aba5c..9cd4b7440d 100644 --- a/dashboard/src/context/auth/AuthContext.tsx +++ b/dashboard/src/context/auth/AuthContext.tsx @@ -183,7 +183,7 @@ const AuthProvider = ({ children }: Props) => { console.log('resoleRoochAddress result:', result) if (result && result.vm_status === 'Executed' && result.return_values) { - return result.return_values[0].move_value as string + return result.return_values[0].decoded_value as string } throw new Error('resolve rooch address fail') diff --git a/moveos/moveos-types/src/function_return_value.rs b/moveos/moveos-types/src/function_return_value.rs index f676011fd1..a02456e70a 100644 --- a/moveos/moveos-types/src/function_return_value.rs +++ b/moveos/moveos-types/src/function_return_value.rs @@ -115,5 +115,5 @@ impl FunctionReturnValue { #[derive(Debug, Clone)] pub struct AnnotatedFunctionReturnValue { pub value: FunctionReturnValue, - pub move_value: AnnotatedMoveValue, + pub decoded_value: AnnotatedMoveValue, } diff --git a/moveos/moveos-types/src/state.rs b/moveos/moveos-types/src/state.rs index fe1fdc5002..b2832c3e49 100644 --- a/moveos/moveos-types/src/state.rs +++ b/moveos/moveos-types/src/state.rs @@ -350,20 +350,23 @@ impl State { self, annotator: &MoveValueAnnotator, ) -> Result { - let move_value = annotator.view_value(&self.value_type, &self.value)?; - Ok(AnnotatedState::new(self, move_value)) + let decoded_value = annotator.view_value(&self.value_type, &self.value)?; + Ok(AnnotatedState::new(self, decoded_value)) } } #[derive(Debug, Clone)] pub struct AnnotatedState { pub state: State, - pub move_value: AnnotatedMoveValue, + pub decoded_value: AnnotatedMoveValue, } impl AnnotatedState { - pub fn new(state: State, move_value: AnnotatedMoveValue) -> Self { - Self { state, move_value } + pub fn new(state: State, decoded_value: AnnotatedMoveValue) -> Self { + Self { + state, + decoded_value, + } } pub fn into_annotated_object(self) -> Result { @@ -373,11 +376,11 @@ impl AnnotatedState { self.state.value_type() ); - match self.move_value { + match self.decoded_value { AnnotatedMoveValue::Struct(annotated_move_object) => { AnnotatedObject::new_from_annotated_struct(annotated_move_object) } - _ => bail!("Expect MoveStruct but found {:?}", self.move_value), + _ => bail!("Expect MoveStruct but found {:?}", self.decoded_value), } } } diff --git a/moveos/moveos-types/src/tx_context.rs b/moveos/moveos-types/src/tx_context.rs index 8674611f63..59d29610d9 100644 --- a/moveos/moveos-types/src/tx_context.rs +++ b/moveos/moveos-types/src/tx_context.rs @@ -182,12 +182,12 @@ mod tests { let serialized = test.to_bytes(); let deserialized: TxContext = bcs::from_bytes(&serialized).unwrap(); assert_eq!(test, deserialized); - let move_value = MoveValue::simple_deserialize( + let decoded_value = MoveValue::simple_deserialize( &serialized, &(MoveTypeLayout::Struct(TxContext::struct_layout())), ) .unwrap(); - let serialized2 = move_value.simple_serialize().unwrap(); + let serialized2 = decoded_value.simple_serialize().unwrap(); assert_eq!(serialized, serialized2); } } diff --git a/sdk/typescript/src/account/account.ts b/sdk/typescript/src/account/account.ts index 0aa107cefd..b1f251d3b7 100644 --- a/sdk/typescript/src/account/account.ts +++ b/sdk/typescript/src/account/account.ts @@ -96,7 +96,7 @@ export class Account implements IAccount { ) if (resp && resp.return_values) { - return resp.return_values[0].move_value as number + return resp.return_values[0].decoded_value as number } return 0 @@ -272,6 +272,6 @@ export class Account implements IAccount { throw new Error('view 0x3::session_key::is_expired_session_key fail') } - return result.return_values![0].move_value as boolean + return result.return_values![0].decoded_value as boolean } } diff --git a/sdk/typescript/src/provider/json-rpc-provider.test.ts b/sdk/typescript/src/provider/json-rpc-provider.test.ts index 1b1377f2ad..5926582ea0 100644 --- a/sdk/typescript/src/provider/json-rpc-provider.test.ts +++ b/sdk/typescript/src/provider/json-rpc-provider.test.ts @@ -25,7 +25,7 @@ describe('provider', () => { type_tag: 'u64', value: '0x0000000000000000', }, - move_value: '0', + decoded_value: '0', }, ], id: '0', @@ -91,11 +91,9 @@ describe('provider', () => { jsonrpc: '2.0', result: [ { - value: { type_tag: 'u64', value: '0x0000000000000000', - }, - move_value: '0', + decoded_value: '0', }, ], id: '0', @@ -136,18 +134,18 @@ describe('provider', () => { value: '0x0e526f6f63682047617320436f696e03524743090000000000000000000000000000000000000000000000000000000000000000', value_type: '0x3::coin::CoinInfo<0x3::gas_coin::GasCoin>', - }, - move_value: { - abilities: 8, - type: '0x3::coin::CoinInfo<0x3::gas_coin::GasCoin>', - value: { - decimals: 9, - name: 'Rooch Gas Coin', - supply: '0', - symbol: 'RGC', + decoded_value: { + abilities: 8, + type: '0x3::coin::CoinInfo<0x3::gas_coin::GasCoin>', + value: { + decimals: 9, + name: 'Rooch Gas Coin', + supply: '0', + symbol: 'RGC', + }, }, }, - }, + } ], next_cursor: '0xa501303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030333a3a636f696e3a3a436f696e496e666f3c303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030333a3a6761735f636f696e3a3a476173436f696e3e', From 946004142e32823bedfc9ef01e9deba27b7b3a72 Mon Sep 17 00:00:00 2001 From: jolestar Date: Tue, 17 Oct 2023 01:04:36 +0800 Subject: [PATCH 5/5] fix sdk lint --- sdk/typescript/src/provider/json-rpc-provider.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sdk/typescript/src/provider/json-rpc-provider.test.ts b/sdk/typescript/src/provider/json-rpc-provider.test.ts index 5926582ea0..daa3913bf2 100644 --- a/sdk/typescript/src/provider/json-rpc-provider.test.ts +++ b/sdk/typescript/src/provider/json-rpc-provider.test.ts @@ -91,9 +91,9 @@ describe('provider', () => { jsonrpc: '2.0', result: [ { - type_tag: 'u64', - value: '0x0000000000000000', - decoded_value: '0', + type_tag: 'u64', + value: '0x0000000000000000', + decoded_value: '0', }, ], id: '0', @@ -145,7 +145,7 @@ describe('provider', () => { }, }, }, - } + }, ], next_cursor: '0xa501303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030333a3a636f696e3a3a436f696e496e666f3c303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030333a3a6761735f636f696e3a3a476173436f696e3e',