Skip to content

Commit

Permalink
[bug] Check the module is exist before execute the view function (#1700)
Browse files Browse the repository at this point in the history
  • Loading branch information
vegetabledogdog authored May 20, 2024
1 parent e71af32 commit bcb3056
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion crates/rooch-rpc-server/src/service/rpc_service.rs
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@

use anyhow::Result;
use move_core_types::account_address::AccountAddress;
use move_core_types::language_storage::StructTag;
use move_core_types::language_storage::{ModuleId, StructTag};
use moveos_types::access_path::AccessPath;
use moveos_types::function_return_value::AnnotatedFunctionResult;
use moveos_types::h256::H256;
@@ -77,6 +77,11 @@ impl RpcService {
&self,
function_call: FunctionCall,
) -> Result<AnnotatedFunctionResult> {
let module_id = function_call.function_id.module_id.clone();
if !self.exists_module(module_id.clone()).await? {
return Err(anyhow::anyhow!("Module does not exist: {}", module_id));
}

let resp = self.executor.execute_view_function(function_call).await?;
Ok(resp)
}
@@ -96,6 +101,16 @@ impl RpcService {
Ok(resp.pop().flatten().is_some())
}

pub async fn exists_module(&self, module_id: ModuleId) -> Result<bool> {
let mut resp = self
.get_states(AccessPath::module(
*module_id.address(),
module_id.name().into(),
))
.await?;
Ok(resp.pop().flatten().is_some())
}

pub async fn get_annotated_states(
&self,
access_path: AccessPath,

0 comments on commit bcb3056

Please sign in to comment.