From d39956e86d54e2c519c0647fa7d237a27f3d5ee2 Mon Sep 17 00:00:00 2001 From: steelgeek091 Date: Sun, 22 Sep 2024 21:07:10 +0800 Subject: [PATCH] add an command line argument for getStates command --- crates/rooch-executor/src/actor/messages.rs | 3 +- .../src/actor/reader_executor.rs | 4 +- crates/rooch-executor/src/proxy/mod.rs | 39 +++++++++++-------- crates/rooch-rpc-api/src/api/rooch_api.rs | 14 +++++-- .../src/jsonrpc_types/str_view.rs | 17 ++++++++ crates/rooch-rpc-client/src/lib.rs | 11 +++++- crates/rooch-rpc-client/src/rooch_client.rs | 15 +++---- .../src/server/rooch_server.rs | 20 +++++----- .../src/service/aggregate_service.rs | 5 ++- .../src/service/rpc_service.rs | 22 ++++++----- crates/rooch/src/commands/resource.rs | 6 ++- crates/rooch/src/commands/state.rs | 3 +- crates/rooch/src/tx_runner.rs | 11 +++--- crates/testsuite/features/cmd.feature | 12 +++--- moveos/moveos-types/src/lib.rs | 1 + moveos/moveos-types/src/state_root_hash.rs | 28 +++++++++++++ 16 files changed, 146 insertions(+), 65 deletions(-) create mode 100644 moveos/moveos-types/src/state_root_hash.rs diff --git a/crates/rooch-executor/src/actor/messages.rs b/crates/rooch-executor/src/actor/messages.rs index 7a44e506d6..3a844b0e79 100644 --- a/crates/rooch-executor/src/actor/messages.rs +++ b/crates/rooch-executor/src/actor/messages.rs @@ -12,6 +12,7 @@ use moveos_types::moveos_std::event::{AnnotatedEvent, Event, EventID}; use moveos_types::moveos_std::object::ObjectMeta; use moveos_types::state::{AnnotatedState, FieldKey, ObjectState, StateChangeSetExt}; use moveos_types::state_resolver::{AnnotatedStateKV, StateKV}; +use moveos_types::state_root_hash::StateRootHash; use moveos_types::transaction::TransactionExecutionInfo; use moveos_types::transaction::TransactionOutput; use moveos_types::transaction::VerifiedMoveOSTransaction; @@ -99,7 +100,7 @@ impl Message for ExecuteViewFunctionMessage { #[derive(Debug, Serialize, Deserialize)] pub struct StatesMessage { - pub state_root: Option, + pub state_root: StateRootHash, pub access_path: AccessPath, } diff --git a/crates/rooch-executor/src/actor/reader_executor.rs b/crates/rooch-executor/src/actor/reader_executor.rs index 68a81d1566..e4f6e3821a 100644 --- a/crates/rooch-executor/src/actor/reader_executor.rs +++ b/crates/rooch-executor/src/actor/reader_executor.rs @@ -147,8 +147,8 @@ impl Handler for ReaderExecutorActor { msg: StatesMessage, _ctx: &mut ActorContext, ) -> Result>, anyhow::Error> { - let resolver = if let Some(state_root_str) = msg.state_root { - let hex_bytes = hex::decode(state_root_str).expect("decode root state failed"); + let resolver = if !msg.state_root.is_empty() { + let hex_bytes = hex::decode(msg.state_root.0).expect("decode root state failed"); let state_root = H256::from_slice(hex_bytes.as_slice()); let root_object_meta = ObjectMeta::root_metadata(state_root, 55); RootObjectResolver::new(root_object_meta, &self.moveos_store) diff --git a/crates/rooch-executor/src/proxy/mod.rs b/crates/rooch-executor/src/proxy/mod.rs index 4a3f0c7e18..a23116b968 100644 --- a/crates/rooch-executor/src/proxy/mod.rs +++ b/crates/rooch-executor/src/proxy/mod.rs @@ -28,6 +28,7 @@ use moveos_types::moveos_std::object::ObjectMeta; use moveos_types::moveos_std::tx_context::TxContext; use moveos_types::state::{FieldKey, StateChangeSetExt}; use moveos_types::state_resolver::{AnnotatedStateKV, StateKV}; +use moveos_types::state_root_hash::StateRootHash; use moveos_types::transaction::FunctionCall; use moveos_types::transaction::TransactionExecutionInfo; use moveos_types::transaction::TransactionOutput; @@ -118,8 +119,8 @@ impl ExecutorProxy { pub async fn get_states( &self, - state_root: Option, access_path: AccessPath, + state_root: StateRootHash, ) -> Result>> { self.reader_actor .send(StatesMessage { @@ -268,31 +269,37 @@ impl ExecutorProxy { } pub async fn chain_id(&self) -> Result { - self.get_states(None, AccessPath::object(ChainID::chain_id_object_id())) - .await? - .into_iter() - .next() - .ok_or_else(|| anyhow::anyhow!("chain id not found")) - .and_then(|state| state.ok_or_else(|| anyhow::anyhow!("chain id not found"))) - .and_then(|state| Ok(state.into_object::()?.value)) + self.get_states( + AccessPath::object(ChainID::chain_id_object_id()), + StateRootHash::empty(), + ) + .await? + .into_iter() + .next() + .ok_or_else(|| anyhow::anyhow!("chain id not found")) + .and_then(|state| state.ok_or_else(|| anyhow::anyhow!("chain id not found"))) + .and_then(|state| Ok(state.into_object::()?.value)) } pub async fn bitcoin_network(&self) -> Result { - self.get_states(None, AccessPath::object(BitcoinNetwork::object_id())) - .await? - .into_iter() - .next() - .ok_or_else(|| anyhow::anyhow!("bitcoin network not found")) - .and_then(|state| state.ok_or_else(|| anyhow::anyhow!("bitcoin network not found"))) - .and_then(|state| Ok(state.into_object::()?.value)) + self.get_states( + AccessPath::object(BitcoinNetwork::object_id()), + StateRootHash::empty(), + ) + .await? + .into_iter() + .next() + .ok_or_else(|| anyhow::anyhow!("bitcoin network not found")) + .and_then(|state| state.ok_or_else(|| anyhow::anyhow!("bitcoin network not found"))) + .and_then(|state| Ok(state.into_object::()?.value)) } //TODO provide a trait to abstract the async state reader, elemiate the duplicated code bwteen RpcService and Client pub async fn get_sequence_number(&self, address: AccountAddress) -> Result { Ok(self .get_states( - None, AccessPath::object(Account::account_object_id(address)), + StateRootHash::empty(), ) .await? .pop() diff --git a/crates/rooch-rpc-api/src/api/rooch_api.rs b/crates/rooch-rpc-api/src/api/rooch_api.rs index 827254791f..1c8f93056f 100644 --- a/crates/rooch-rpc-api/src/api/rooch_api.rs +++ b/crates/rooch-rpc-api/src/api/rooch_api.rs @@ -12,11 +12,12 @@ use crate::jsonrpc_types::{ FieldKeyView, FunctionCallView, H256View, IndexerEventPageView, IndexerObjectStatePageView, IndexerStateIDView, ModuleABIView, ObjectIDVecView, ObjectIDView, ObjectStateFilterView, ObjectStateView, QueryOptions, RoochAddressView, StateChangeSetPageView, StateOptions, - StatePageView, StrView, StructTagView, SyncStateFilterView, TransactionWithInfoPageView, - TxOptions, + StatePageView, StateRootHashView, StrView, StructTagView, SyncStateFilterView, + TransactionWithInfoPageView, TxOptions, }; use crate::RpcResult; use jsonrpsee::proc_macros::rpc; +use moveos_types::state_root_hash::StateRootHash; use moveos_types::{access_path::AccessPath, state::FieldKey}; use rooch_open_rpc_macros::open_rpc; @@ -57,8 +58,8 @@ pub trait RoochAPI { #[method(name = "getStates")] async fn get_states( &self, - state_root: Option, access_path: AccessPathView, + state_root: StateRootHashView, state_option: Option, ) -> RpcResult>>; @@ -92,7 +93,12 @@ pub trait RoochAPI { let key_states = field_key.into_iter().map(FieldKey::from).collect(); let access_path_view = AccessPathView::from(AccessPath::fields(object_id.into(), key_states)); - self.get_states(None, access_path_view, state_option).await + self.get_states( + access_path_view, + StrView::from(StateRootHash::empty()), + state_option, + ) + .await } /// List Object Fields via ObjectID. diff --git a/crates/rooch-rpc-api/src/jsonrpc_types/str_view.rs b/crates/rooch-rpc-api/src/jsonrpc_types/str_view.rs index d55b6b0b97..a87d2e8d01 100644 --- a/crates/rooch-rpc-api/src/jsonrpc_types/str_view.rs +++ b/crates/rooch-rpc-api/src/jsonrpc_types/str_view.rs @@ -6,6 +6,7 @@ use move_core_types::account_address::AccountAddress; use moveos_types::move_std::string::MoveString; +use moveos_types::state_root_hash::StateRootHash; use schemars::gen::SchemaGenerator; use schemars::schema::{InstanceType, Schema, SchemaObject}; use schemars::JsonSchema; @@ -325,3 +326,19 @@ where self.0.to_human_readable_string(verbose, indent) } } + +pub type StateRootHashView = StrView; + +impl FromStr for StateRootHashView { + type Err = anyhow::Error; + + fn from_str(s: &str) -> anyhow::Result { + Ok(Self(StateRootHash(s.to_string()))) + } +} + +impl std::fmt::Display for StateRootHashView { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", &self.0) + } +} diff --git a/crates/rooch-rpc-client/src/lib.rs b/crates/rooch-rpc-client/src/lib.rs index 780c3026fe..99cb2ad406 100644 --- a/crates/rooch-rpc-client/src/lib.rs +++ b/crates/rooch-rpc-client/src/lib.rs @@ -16,6 +16,7 @@ use moveos_types::moveos_std::move_module::MoveModule; use moveos_types::moveos_std::object::{ObjectID, ObjectMeta, RawField}; use moveos_types::state::{FieldKey, MoveType, ObjectState}; use moveos_types::state_resolver::{StateKV, StateResolver, StatelessResolver}; +use moveos_types::state_root_hash::StateRootHash; use moveos_types::{ function_return_value::FunctionResult, module_binding::MoveFunctionCaller, moveos_std::tx_context::TxContext, transaction::FunctionCall, @@ -114,7 +115,10 @@ impl ModuleResolver for &Client { fn get_module(&self, id: &ModuleId) -> Result>> { tokio::task::block_in_place(|| { Handle::current().block_on(async { - let mut states = self.rooch.get_states(None, AccessPath::module(id)).await?; + let mut states = self + .rooch + .get_states(AccessPath::module(id), StateRootHash::empty()) + .await?; states .pop() .flatten() @@ -196,7 +200,10 @@ impl StatelessResolver for ClientResolver { let mut object_state_view_list = self .client .rooch - .get_states(Some(hex::encode(state_root.0.as_slice())), access_path) + .get_states( + access_path, + StateRootHash::new(hex::encode(state_root.0.as_slice()).as_str()), + ) .await?; Ok(object_state_view_list.pop().flatten().map(|state_view| { let v: ObjectState = state_view.into(); diff --git a/crates/rooch-rpc-client/src/rooch_client.rs b/crates/rooch-rpc-client/src/rooch_client.rs index 4dfd97440e..5190741afe 100644 --- a/crates/rooch-rpc-client/src/rooch_client.rs +++ b/crates/rooch-rpc-client/src/rooch_client.rs @@ -10,6 +10,7 @@ use moveos_types::move_std::string::MoveString; use moveos_types::moveos_std::account::Account; use moveos_types::moveos_std::object::ObjectID; use moveos_types::state::{FieldKey, MoveStructState}; +use moveos_types::state_root_hash::StateRootHash; use moveos_types::{access_path::AccessPath, state::ObjectState, transaction::FunctionCall}; use rooch_rpc_api::api::btc_api::BtcAPIClient; use rooch_rpc_api::api::rooch_api::RoochAPIClient; @@ -91,25 +92,25 @@ impl RoochRpcClient { pub async fn get_states( &self, - state_root: Option, access_path: AccessPath, + state_root: StateRootHash, ) -> Result>> { Ok(self .http - .get_states(state_root, access_path.into(), None) + .get_states(access_path.into(), state_root.into(), None) .await?) } pub async fn get_decoded_states( &self, - state_root: Option, access_path: AccessPath, + state_root: StateRootHash, ) -> Result>> { Ok(self .http .get_states( - state_root, access_path.into(), + state_root.into(), Some(StateOptions::default().decode(true)), ) .await?) @@ -122,8 +123,8 @@ impl RoochRpcClient { Ok(self .http .get_states( - None, access_path.into(), + StateRootHash::empty().into(), Some(StateOptions::default().decode(true).show_display(true)), ) .await?) @@ -176,8 +177,8 @@ impl RoochRpcClient { pub async fn get_sequence_number(&self, sender: RoochAddress) -> Result { Ok(self .get_states( - None, AccessPath::object(Account::account_object_id(sender.into())), + StateRootHash::empty(), ) .await? .pop() @@ -383,7 +384,7 @@ impl RoochRpcClient { account: RoochAddress, ) -> Result> { let access_path = AccessPath::resource(account.into(), T::struct_tag()); - let mut states = self.get_states(None, access_path).await?; + let mut states = self.get_states(access_path, StateRootHash::empty()).await?; let state = states.pop().flatten(); if let Some(state) = state { let state = ObjectState::from(state); diff --git a/crates/rooch-rpc-server/src/server/rooch_server.rs b/crates/rooch-rpc-server/src/server/rooch_server.rs index d0cc93dbb9..a6b9a22b73 100644 --- a/crates/rooch-rpc-server/src/server/rooch_server.rs +++ b/crates/rooch-rpc-server/src/server/rooch_server.rs @@ -8,6 +8,7 @@ use jsonrpsee::{core::async_trait, RpcModule}; use move_core_types::{ account_address::AccountAddress, identifier::Identifier, language_storage::ModuleId, }; +use moveos_types::state_root_hash::StateRootHash; use moveos_types::{ access_path::AccessPath, h256::H256, @@ -25,8 +26,9 @@ use rooch_rpc_api::jsonrpc_types::{ IndexerEventPageView, IndexerObjectStatePageView, IndexerStateIDView, ModuleABIView, ObjectIDVecView, ObjectStateFilterView, ObjectStateView, QueryOptions, RawTransactionOutputView, RoochAddressView, StateChangeSetPageView, - StateChangeSetWithTxOrderView, StateKVView, StateOptions, StatePageView, StrView, - StructTagView, SyncStateFilterView, TransactionWithInfoPageView, TxOptions, UnitedAddressView, + StateChangeSetWithTxOrderView, StateKVView, StateOptions, StatePageView, StateRootHashView, + StrView, StructTagView, SyncStateFilterView, TransactionWithInfoPageView, TxOptions, + UnitedAddressView, }; use rooch_rpc_api::{ api::rooch_api::RoochAPIServer, @@ -195,8 +197,8 @@ impl RoochAPIServer for RoochServer { async fn get_states( &self, - state_root: Option, access_path: AccessPathView, + state_root: StateRootHashView, state_option: Option, ) -> RpcResult>> { let state_option = state_option.unwrap_or_default(); @@ -213,7 +215,7 @@ impl RoochAPIServer for RoochServer { let valid_states = states.iter().filter_map(|s| s.as_ref()).collect::>(); let mut valid_display_field_views = self .rpc_service - .get_display_fields_and_render(state_root, valid_states.as_slice()) + .get_display_fields_and_render(valid_states.as_slice(), state_root.0) .await?; valid_display_field_views.reverse(); states @@ -237,7 +239,7 @@ impl RoochAPIServer for RoochServer { } } else { self.rpc_service - .get_states(state_root, access_path.into()) + .get_states(access_path.into(), state_root.0) .await? .into_iter() .map(|s| s.map(ObjectStateView::from)) @@ -276,7 +278,7 @@ impl RoochAPIServer for RoochServer { if show_display { let display_field_views = self .rpc_service - .get_display_fields_and_render(None, state_refs.as_slice()) + .get_display_fields_and_render(state_refs.as_slice(), StateRootHash::empty()) .await?; key_states .into_iter() @@ -336,7 +338,7 @@ impl RoochAPIServer for RoochServer { let mut valid_display_field_views = if show_display { let valid_states = states.iter().filter_map(|s| s.as_ref()).collect::>(); self.rpc_service - .get_display_fields_and_render(None, valid_states.as_slice()) + .get_display_fields_and_render(valid_states.as_slice(), StateRootHash::empty()) .await? } else { vec![] @@ -369,7 +371,7 @@ impl RoochAPIServer for RoochServer { } } else { self.rpc_service - .get_states(None, access_path) + .get_states(access_path, StateRootHash::empty()) .await? .into_iter() .map(|s| s.map(Into::into)) @@ -622,7 +624,7 @@ impl RoochAPIServer for RoochServer { let access_path = AccessPath::module(&module_id); let module = self .rpc_service - .get_states(None, access_path) + .get_states(access_path, StateRootHash::empty()) .await? .pop() .flatten(); diff --git a/crates/rooch-rpc-server/src/service/aggregate_service.rs b/crates/rooch-rpc-server/src/service/aggregate_service.rs index 9bb3cf7098..831c7f7b26 100644 --- a/crates/rooch-rpc-server/src/service/aggregate_service.rs +++ b/crates/rooch-rpc-server/src/service/aggregate_service.rs @@ -9,6 +9,7 @@ use moveos_types::access_path::AccessPath; use moveos_types::h256::H256; use moveos_types::moveos_std::object::ObjectID; use moveos_types::state::PlaceholderStruct; +use moveos_types::state_root_hash::StateRootHash; use rooch_rpc_api::jsonrpc_types::account_view::BalanceInfoView; use rooch_rpc_api::jsonrpc_types::CoinInfoView; use rooch_types::address::RoochAddress; @@ -45,7 +46,7 @@ impl AggregateService { .collect(), ); self.rpc_service - .get_states(None, access_path) + .get_states(access_path, StateRootHash::empty()) .await? .into_iter() .zip(coin_types) @@ -72,7 +73,7 @@ impl AggregateService { ) -> Result>> { let access_path = AccessPath::objects(coin_store_ids); self.rpc_service - .get_states(None, access_path) + .get_states(access_path, StateRootHash::empty()) .await? .into_iter() .map(|state_opt| state_opt.map(CoinStoreInfo::try_from).transpose()) diff --git a/crates/rooch-rpc-server/src/service/rpc_service.rs b/crates/rooch-rpc-server/src/service/rpc_service.rs index 7d25db328f..2d5aed97c1 100644 --- a/crates/rooch-rpc-server/src/service/rpc_service.rs +++ b/crates/rooch-rpc-server/src/service/rpc_service.rs @@ -14,6 +14,7 @@ use moveos_types::moveos_std::event::{AnnotatedEvent, Event, EventID}; use moveos_types::moveos_std::object::ObjectID; use moveos_types::state::{AnnotatedState, FieldKey, ObjectState, StateChangeSet}; use moveos_types::state_resolver::{AnnotatedStateKV, StateKV}; +use moveos_types::state_root_hash::StateRootHash; use moveos_types::transaction::{FunctionCall, TransactionExecutionInfo}; use rooch_executor::actor::messages::DryRunTransactionResult; use rooch_executor::proxy::ExecutorProxy; @@ -114,15 +115,15 @@ impl RpcService { pub async fn get_states( &self, - state_root: Option, access_path: AccessPath, + state_root: StateRootHash, ) -> Result>> { - self.executor.get_states(state_root, access_path).await + self.executor.get_states(access_path, state_root).await } pub async fn exists_module(&self, module_id: ModuleId) -> Result { let mut resp = self - .get_states(None, AccessPath::module(&module_id)) + .get_states(AccessPath::module(&module_id), StateRootHash::empty()) .await?; Ok(resp.pop().flatten().is_some()) } @@ -374,7 +375,7 @@ impl RpcService { .filter_map(|s| s.as_ref()) .collect::>(); let valid_display_field_views = self - .get_display_fields_and_render(None, &valid_states) + .get_display_fields_and_render(&valid_states, StateRootHash::empty()) .await?; valid_states .iter() @@ -412,7 +413,7 @@ impl RpcService { } object_states } else { - let states = self.get_states(None, access_path).await?; + let states = self.get_states(access_path, StateRootHash::empty()).await?; states .into_iter() .zip(indexer_ids) @@ -473,7 +474,7 @@ impl RpcService { let access_path = AccessPath::fields(mapping_object_id, owner_keys); let address_mapping = self - .get_states(None, access_path) + .get_states(access_path, StateRootHash::empty()) .await? .into_iter() .zip(user_addresses) @@ -495,8 +496,8 @@ impl RpcService { pub async fn get_display_fields_and_render( &self, - state_root: Option, states: &[&AnnotatedState], + state_root: StateRootHash, ) -> Result>> { let mut display_ids = vec![]; let mut displayable_states = vec![]; @@ -512,7 +513,7 @@ impl RpcService { // get display fields let path = AccessPath::objects(display_ids); let mut display_fields = self - .get_states(state_root, path) + .get_states(path, state_root) .await? .into_iter() .map(|option_s| { @@ -604,7 +605,10 @@ impl RpcService { ) -> Result<()> { { let states = self - .get_states(None, AccessPath::objects(object_ids.clone())) + .get_states( + AccessPath::objects(object_ids.clone()), + StateRootHash::empty(), + ) .await?; let mut remove_object_ids = vec![]; diff --git a/crates/rooch/src/commands/resource.rs b/crates/rooch/src/commands/resource.rs index 2aadca9617..4a7c0e85ef 100644 --- a/crates/rooch/src/commands/resource.rs +++ b/crates/rooch/src/commands/resource.rs @@ -6,6 +6,7 @@ use async_trait::async_trait; use clap::Parser; use move_command_line_common::types::ParsedStructType; use moveos_types::access_path::AccessPath; +use moveos_types::state_root_hash::StateRootHash; use rooch_rpc_api::jsonrpc_types::ObjectStateView; use rooch_types::{address::ParsedAddress, error::RoochResult}; @@ -49,7 +50,10 @@ impl CommandAction> for ResourceCommand { } else { client .rooch - .get_decoded_states(None, AccessPath::resource(address, resource)) + .get_decoded_states( + AccessPath::resource(address, resource), + StateRootHash::empty(), + ) .await? .pop() .flatten() diff --git a/crates/rooch/src/commands/state.rs b/crates/rooch/src/commands/state.rs index 770eb55f1c..760b577673 100644 --- a/crates/rooch/src/commands/state.rs +++ b/crates/rooch/src/commands/state.rs @@ -5,6 +5,7 @@ use crate::cli_types::{CommandAction, WalletContextOptions}; use async_trait::async_trait; use clap::Parser; use moveos_types::access_path::AccessPath; +use moveos_types::state_root_hash::StateRootHash; use rooch_rpc_api::jsonrpc_types::ObjectStateView; use rooch_types::error::{RoochError, RoochResult}; @@ -42,7 +43,7 @@ impl CommandAction>> for StateCommand { } else { client .rooch - .get_decoded_states(None, self.access_path) + .get_decoded_states(self.access_path, StateRootHash::empty()) .await .map_err(RoochError::from)? }; diff --git a/crates/rooch/src/tx_runner.rs b/crates/rooch/src/tx_runner.rs index 351d38a75a..e4c6019280 100644 --- a/crates/rooch/src/tx_runner.rs +++ b/crates/rooch/src/tx_runner.rs @@ -22,16 +22,15 @@ use rooch_types::transaction::RoochTransactionData; use std::rc::Rc; use std::str::FromStr; -pub fn execute_tx_locally(state_root_str: String, client: Client, tx: RoochTransactionData) { - let hex_bytes = hex::decode(state_root_str.as_bytes()).expect("decode root state failed"); - let state_root = H256::from_slice(hex_bytes.as_slice()); +pub fn execute_tx_locally(state_root_bytes: Vec, client: Client, tx: RoochTransactionData) { + let state_root = H256::from_slice(state_root_bytes.as_slice()); let root_object_meta = ObjectMeta::root_metadata(state_root, 55); let client_resolver = ClientResolver::new(client, root_object_meta.clone()); let gas_entries = get_gas_schedule_entries(&client_resolver).unwrap(); let cost_table = initial_cost_schedule(gas_entries); - let mut gas_meter = MoveOSGasMeter::new(cost_table, 1000000000); + let mut gas_meter = MoveOSGasMeter::new(cost_table, 100000000); gas_meter.charge_io_write(tx.tx_size()).unwrap(); let verified_tx = convert_to_verified_tx(root_object_meta.clone(), tx) @@ -76,7 +75,9 @@ pub fn execute_tx_locally(state_root_str: String, client: Client, tx: RoochTrans .execute_move_action(action) .expect("execute_move_action failed"); - let _result = moveos_session.finish_with_extensions(Executed); + let (_tx_context, _raw_output) = moveos_session + .finish_with_extensions(Executed) + .expect("finish_with_extensions failed"); } fn convert_to_verified_tx( diff --git a/crates/testsuite/features/cmd.feature b/crates/testsuite/features/cmd.feature index dd0fd3002b..af044b9f78 100644 --- a/crates/testsuite/features/cmd.feature +++ b/crates/testsuite/features/cmd.feature @@ -3,18 +3,18 @@ Feature: Rooch CLI integration tests @serial Scenario: rooch rpc test Given a server for rooch_rpc_test - Then cmd: "rpc request --method rooch_getStates --params '["/resource/0x3/0x3::account_coin_store::AutoAcceptCoins",{"decode":true}]' --json" + Then cmd: "rpc request --method rooch_getStates --params '["/resource/0x3/0x3::account_coin_store::AutoAcceptCoins", "", {"decode":true}]' --json" #The object_type contians blank space, so, we should quote it Then assert: "'{{$.rpc[-1][0].object_type}}' == '0x2::object::DynamicField<0x1::string::String, 0x3::account_coin_store::AutoAcceptCoins>'" - Then cmd: "rpc request --method rooch_getStates --params '["/object/0x3",{"decode":true}]' --json" + Then cmd: "rpc request --method rooch_getStates --params '["/object/0x3", "", {"decode":true}]' --json" Then assert: "{{$.rpc[-1][0].object_type}} == '0x2::account::Account'" Then cmd: "rpc request --method rooch_listStates --params '["/resource/0x3", null, null, {"decode":true}]' --json" Then assert: "'{{$.rpc[-1]}}' contains '0x3::account_coin_store::AutoAcceptCoins'" # named_object_id(0x2::timestamp::Timestamp) == 0x3a7dfe7a9a5cd608810b5ebd60c7adf7316667b17ad5ae703af301b74310bcca - Then cmd: "rpc request --method rooch_getStates --params '["/object/0x3a7dfe7a9a5cd608810b5ebd60c7adf7316667b17ad5ae703af301b74310bcca",{"decode":true}]' --json" + Then cmd: "rpc request --method rooch_getStates --params '["/object/0x3a7dfe7a9a5cd608810b5ebd60c7adf7316667b17ad5ae703af301b74310bcca", "", {"decode":true}]' --json" Then assert: "{{$.rpc[-1][0].object_type}} == '0x2::timestamp::Timestamp'" Then assert: "{{$.rpc[-1][0].decoded_value.value.milliseconds}} == 0" - Then cmd: "rpc request --method rooch_getStates --params '["/object/0x2::timestamp::Timestamp",{"decode":true}]' --json" + Then cmd: "rpc request --method rooch_getStates --params '["/object/0x2::timestamp::Timestamp","",{"decode":true}]' --json" Then assert: "{{$.rpc[-1][0].object_type}} == '0x2::timestamp::Timestamp'" Then cmd: "rpc request --method rooch_getObjectStates --params '["0x3a7dfe7a9a5cd608810b5ebd60c7adf7316667b17ad5ae703af301b74310bcca", {"decode":false}]' --json" Then cmd: "rpc request --method rooch_getObjectStates --params '["0x3a7dfe7a9a5cd608810b5ebd60c7adf7316667b17ad5ae703af301b74310bcca", {"decode":true}]' --json" @@ -58,7 +58,7 @@ Feature: Rooch CLI integration tests Then cmd: "move run --function rooch_framework::gas_coin::faucet_entry --args u256:10000000000 --json" Then assert: "{{$.move[-1].execution_info.status.type}} == executed" - Then cmd: "rpc request --method rooch_getStates --params '["/object/0x3a7dfe7a9a5cd608810b5ebd60c7adf7316667b17ad5ae703af301b74310bcca",{"decode":true}]' --json" + Then cmd: "rpc request --method rooch_getStates --params '["/object/0x3a7dfe7a9a5cd608810b5ebd60c7adf7316667b17ad5ae703af301b74310bcca", "", {"decode":true}]' --json" Then assert: "{{$.rpc[-1][0].object_type}} == '0x2::timestamp::Timestamp'" # ensure the tx_timestamp update the global timestamp Then assert: "{{$.rpc[-1][0].decoded_value.value.milliseconds}} != 0" @@ -388,7 +388,7 @@ Feature: Rooch CLI integration tests Then cmd: "state --access-path /object/{{$.event[-1].data[0].decoded_event_data.value.id}}" Then assert: "{{$.state[-1][0].object_type}} == '{{$.address_mapping.default}}::display::ObjectType'" - Then cmd: "rpc request --method rooch_getStates --params '["/object/{{$.event[-1].data[0].decoded_event_data.value.id}}", {"decode": false, "showDisplay": true}]' --json" + Then cmd: "rpc request --method rooch_getStates --params '["/object/{{$.event[-1].data[0].decoded_event_data.value.id}}", "", {"decode": false, "showDisplay": true}]' --json" Then assert: "{{$.rpc[-1][0].display_fields.fields.name}} == test_object" # because the indexer is async update, so sleep 2 seconds to wait indexer update. diff --git a/moveos/moveos-types/src/lib.rs b/moveos/moveos-types/src/lib.rs index 670d42d678..fce5e3b719 100644 --- a/moveos/moveos-types/src/lib.rs +++ b/moveos/moveos-types/src/lib.rs @@ -14,5 +14,6 @@ pub mod serde; pub mod startup_info; pub mod state; pub mod state_resolver; +pub mod state_root_hash; pub mod test_utils; pub mod transaction; diff --git a/moveos/moveos-types/src/state_root_hash.rs b/moveos/moveos-types/src/state_root_hash.rs new file mode 100644 index 0000000000..e53fa6bc13 --- /dev/null +++ b/moveos/moveos-types/src/state_root_hash.rs @@ -0,0 +1,28 @@ +// Copyright (c) RoochNetwork +// SPDX-License-Identifier: Apache-2.0 + +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] +pub struct StateRootHash(pub String); + +impl StateRootHash { + pub fn new(state_root: &str) -> Self { + StateRootHash(state_root.to_string()) + } + + pub fn empty() -> Self { + StateRootHash("".to_string()) + } + + pub fn is_empty(&self) -> bool { + self.0.is_empty() + } +} + +impl std::fmt::Display for StateRootHash { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.0)?; + Ok(()) + } +}