diff --git a/cmd/faucet/src/faucet.rs b/cmd/faucet/src/faucet.rs index 947c5e7230..915a4300af 100644 --- a/cmd/faucet/src/faucet.rs +++ b/cmd/faucet/src/faucet.rs @@ -1,7 +1,7 @@ // Copyright (c) The Starcoin Core Contributors // SPDX-License-Identifier: Apache-2.0 -use anyhow::{format_err, Result}; +use anyhow::Result; use starcoin_account_api::AccountInfo; use starcoin_crypto::HashValue; use starcoin_logger::prelude::*; @@ -63,12 +63,6 @@ impl Faucet { let chain_state_reader = self.client.state_reader(StateRootOption::Latest)?; chain_state_reader .get_account_resource(*self.faucet_account.address())? - .ok_or_else(|| { - format_err!( - "Can not find account on chain by address:{}", - self.faucet_account.address() - ) - })? .sequence_number() } }; diff --git a/cmd/tx-factory/src/main.rs b/cmd/tx-factory/src/main.rs index f2606c14bc..9eca1eeb98 100644 --- a/cmd/tx-factory/src/main.rs +++ b/cmd/tx-factory/src/main.rs @@ -96,11 +96,11 @@ fn get_account_or_default( let addr = default_account.clone().unwrap().address; let state_reader = client.state_reader(StateRootOption::Latest)?; - let mut balance = state_reader.get_balance(addr)?; + let mut balance = state_reader.get_balance(addr); // balance resource has not been created - while balance.is_none() { + while balance.is_err() { std::thread::sleep(Duration::from_millis(1000)); - balance = state_reader.get_balance(addr)?; + balance = state_reader.get_balance(addr); info!("account balance is null."); } default_account.unwrap() @@ -228,8 +228,8 @@ impl TxnMocker { ) -> Result { let state_reader = client.state_reader(StateRootOption::Latest)?; - let account_resource = state_reader.get_account_resource(account_address)?; - if account_resource.is_none() { + let account_resource = state_reader.get_account_resource(account_address); + if account_resource.is_err() { bail!("account {} not exists, please faucet it", account_address); } let account_resource = account_resource.unwrap(); @@ -277,8 +277,8 @@ impl TxnMocker { None => { let state_reader = self.client.state_reader(StateRootOption::Latest)?; - let account_resource = state_reader.get_account_resource(self.account_address)?; - if account_resource.is_none() { + let account_resource = state_reader.get_account_resource(self.account_address); + if account_resource.is_err() { bail!( "account {} not exists, please faucet it", &self.account_address diff --git a/network-rpc/api/src/lib.rs b/network-rpc/api/src/lib.rs index 225f039bda..b4682f822a 100644 --- a/network-rpc/api/src/lib.rs +++ b/network-rpc/api/src/lib.rs @@ -271,7 +271,7 @@ pub trait NetworkRpc: Sized + Send + Sync + 'static { &self, peer_id: PeerId, req: GetAccountState, - ) -> BoxFuture>>; + ) -> BoxFuture>; fn get_block_ids(&self, peer_id: PeerId, req: GetBlockIds) -> BoxFuture>>; @@ -292,7 +292,7 @@ pub trait NetworkRpc: Sized + Send + Sync + 'static { &self, peer_id: PeerId, request: GetTableInfo, - ) -> BoxFuture>>; + ) -> BoxFuture>; fn get_dag_block_children( &self, diff --git a/network-rpc/api/src/remote_chain_state.rs b/network-rpc/api/src/remote_chain_state.rs index a3f70d7dc2..a7c5946953 100644 --- a/network-rpc/api/src/remote_chain_state.rs +++ b/network-rpc/api/src/remote_chain_state.rs @@ -70,7 +70,7 @@ impl ChainStateReader for RemoteChainStateReader { Ok(state_proof) } - fn get_account_state(&self, account_address: &AccountAddress) -> Result> { + fn get_account_state(&self, account_address: &AccountAddress) -> Result { //TODO: How to verify it let peer_id = self .peer_id @@ -135,9 +135,8 @@ impl ChainStateReader for RemoteChainStateReader { .ok_or_else(|| anyhow!("peer id not set"))?; let req = GetTableInfo(address); let client = self.client.clone(); - let table_info: Option = - futures::executor::block_on(client.get_state_table_info(peer_id, req))?; - Ok(table_info) + let table_info = futures::executor::block_on(client.get_state_table_info(peer_id, req))?; + Ok(Some(table_info)) } } diff --git a/network-rpc/src/rpc.rs b/network-rpc/src/rpc.rs index 5aa6d4e9a6..d295b29cdb 100644 --- a/network-rpc/src/rpc.rs +++ b/network-rpc/src/rpc.rs @@ -226,15 +226,18 @@ impl gen_server::NetworkRpc for NetworkRpcImpl { fn get_state_with_proof( &self, _peer_id: PeerId, - req: GetStateWithProof, + _req: GetStateWithProof, ) -> BoxFuture> { + // XXX FIXME YSG + /* let state_service = self.state_service.clone(); let fut = async move { state_service .get_with_proof_by_root(req.access_path, req.state_root) .await }; - Box::pin(fut) + Box::pin(fut) */ + unimplemented!("") } fn get_state_with_table_item_proof( @@ -255,7 +258,7 @@ impl gen_server::NetworkRpc for NetworkRpcImpl { &self, _peer_id: PeerId, request: GetTableInfo, - ) -> BoxFuture>> { + ) -> BoxFuture> { let state_service = self.state_service.clone(); let fut = async move { state_service.get_table_info(request.0).await }; Box::pin(fut) @@ -265,7 +268,7 @@ impl gen_server::NetworkRpc for NetworkRpcImpl { &self, _peer_id: PeerId, req: GetAccountState, - ) -> BoxFuture>> { + ) -> BoxFuture> { let state_service = self.state_service.clone(); let fut = async move { state_service diff --git a/rpc/client/src/remote_state_reader.rs b/rpc/client/src/remote_state_reader.rs index 6ae0cdc335..62c85984a4 100644 --- a/rpc/client/src/remote_state_reader.rs +++ b/rpc/client/src/remote_state_reader.rs @@ -79,7 +79,7 @@ impl<'a> ChainStateReader for RemoteStateReader<'a> { .map(Into::into) } - fn get_account_state(&self, _address: &AccountAddress) -> Result> { + fn get_account_state(&self, _address: &AccountAddress) -> Result { unimplemented!() //TODO implement get_account_state by root } diff --git a/rpc/server/src/module/chain_rpc.rs b/rpc/server/src/module/chain_rpc.rs index dedee3b0e6..5257c7fe14 100644 --- a/rpc/server/src/module/chain_rpc.rs +++ b/rpc/server/src/module/chain_rpc.rs @@ -21,7 +21,7 @@ use starcoin_rpc_api::types::{ TransactionInfoWithProofView, TransactionView, }; use starcoin_rpc_api::FutureResult; -use starcoin_state_api::StateView; +use starcoin_vm_types::StateView; use starcoin_statedb::ChainStateDB; use starcoin_storage::Storage; use starcoin_types::access_path::AccessPath; diff --git a/rpc/server/src/module/contract_rpc.rs b/rpc/server/src/module/contract_rpc.rs index eee55e3578..aed1db5d3f 100644 --- a/rpc/server/src/module/contract_rpc.rs +++ b/rpc/server/src/module/contract_rpc.rs @@ -31,7 +31,7 @@ use starcoin_types::language_storage::{ModuleId, StructTag}; use starcoin_types::transaction::{DryRunTransaction, RawUserTransaction, TransactionPayload}; use starcoin_vm_types::access_path::AccessPath; use starcoin_vm_types::file_format::CompiledModule; -use starcoin_vm_types::state_view::StateView; +use starcoin_vm_types::state_store::StateView; use starcoin_vm_types::transaction::authenticator::AccountPublicKey; use std::str::FromStr; use std::sync::Arc; diff --git a/state/api/src/chain_state.rs b/state/api/src/chain_state.rs index 5803fc7139..fac085f114 100644 --- a/state/api/src/chain_state.rs +++ b/state/api/src/chain_state.rs @@ -116,13 +116,13 @@ pub trait ChainStateReader: StateView { fn get_with_proof(&self, access_path: &AccessPath) -> Result; /// Gets account state - fn get_account_state(&self, address: &AccountAddress) -> Result>; + fn get_account_state(&self, address: &AccountAddress) -> Result; /// get whole state data of some account address. fn get_account_state_set(&self, address: &AccountAddress) -> Result>; fn exist_account(&self, address: &AccountAddress) -> Result { - self.get_account_state(address).map(|state| state.is_some()) + Ok(self.get_account_state(address).is_ok()) } /// Gets current state root. diff --git a/state/service/src/service.rs b/state/service/src/service.rs index 1a18a7dc11..8976591042 100644 --- a/state/service/src/service.rs +++ b/state/service/src/service.rs @@ -97,7 +97,7 @@ impl ServiceHandler for ChainStateService { StateResponse::StateWithProof(Box::new(self.service.get_with_proof(access_path)?)) } StateRequest::GetAccountState(address) => { - StateResponse::AccountState(self.service.get_account_state(&address)?) + StateResponse::AccountState(Option::from(self.service.get_account_state(&address)?)) } StateRequest::StateRoot() => StateResponse::StateRoot(self.service.state_root()), StateRequest::GetWithProofByRoot(state_key, state_root) => { @@ -113,10 +113,10 @@ impl ServiceHandler for ChainStateService { )) } StateRequest::GetAccountStateByRoot(account, state_root) => { - StateResponse::AccountState( + StateResponse::AccountState(Some( self.service .get_account_state_by_root(account, state_root)?, - ) + )) } StateRequest::GetAccountStateSet { address, @@ -207,7 +207,7 @@ impl Inner { &self, account: AccountAddress, state_root: HashValue, - ) -> Result> { + ) -> Result { let reader = self.state_db.fork_at(state_root); reader.get_account_state(&account) } @@ -234,7 +234,7 @@ impl ChainStateReader for Inner { self.state_db.get_with_proof(access_path) } - fn get_account_state(&self, address: &AccountAddress) -> Result> { + fn get_account_state(&self, address: &AccountAddress) -> Result { self.state_db.get_account_state(address) } fn get_account_state_set(&self, address: &AccountAddress) -> Result> { diff --git a/state/statedb/src/lib.rs b/state/statedb/src/lib.rs index 513ce2516f..21d4df4f26 100644 --- a/state/statedb/src/lib.rs +++ b/state/statedb/src/lib.rs @@ -485,10 +485,12 @@ impl ChainStateReader for ChainStateDB { Ok(state_with_proof) } - fn get_account_state(&self, address: &AccountAddress) -> Result> { - Ok(self - .get_account_state_object_option(address)? - .map(|state_object| state_object.to_state())) + fn get_account_state(&self, address: &AccountAddress) -> Result { + let account_state = self.get_account_state_object_option(address)?; + match account_state { + Some(account_state) => Ok(account_state.to_state()), + None => Err(AccountNotExist(*address).into()), + } } fn get_account_state_set(&self, address: &AccountAddress) -> Result> { diff --git a/txpool/src/pool_client.rs b/txpool/src/pool_client.rs index 450520e3e9..6f95fcb55b 100644 --- a/txpool/src/pool_client.rs +++ b/txpool/src/pool_client.rs @@ -82,9 +82,7 @@ impl CachedSeqNumberClient { ); 0 } - Ok(account_resource) => account_resource - .map(|res| res.sequence_number()) - .unwrap_or_default(), + Ok(account_resource) => account_resource.sequence_number(), } } }