Skip to content

Commit

Permalink
refactor as_struct_tag
Browse files Browse the repository at this point in the history
  • Loading branch information
simonjiao committed Jan 27, 2025
1 parent 2d5f013 commit 83854cf
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions rpc/api/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,7 @@ fn merge_ap_write_set(
action: WriteOpView::Value,
value: Some(WriteOpValueView::Resource(data.to_vec().into())),
}),
// Parsing resources in group and expanding them into individual actions.
DataPath::ResourceGroup(_) => {
let group_data: BTreeMap<StructTag, Bytes> =
bcs_ext::from_bytes(&data).expect("resource group data must be valid");
Expand Down
2 changes: 1 addition & 1 deletion rpc/server/src/module/contract_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ pub fn dry_run<S: StateView>(
view.abi = Some(resolver.resolve_module_code(view.code.0.as_slice())?);
}
WriteOpValueView::Resource(view) => {
let struct_tag = access_path.path.as_struct_tag().ok_or_else(|| {
let struct_tag = access_path.path.resource_tag().ok_or_else(|| {
format_err!("invalid resource access path: {}", access_path)
})?;
let struct_abi = resolver.resolve_struct_tag(struct_tag)?;
Expand Down
10 changes: 6 additions & 4 deletions state/statedb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,12 @@ impl AccountStateObject {
if data_path.is_code() {
bail!("Not supported remove code currently.");
}
let struct_tag = data_path
.as_struct_tag()
.expect("DataPath must been struct tag at here.");
self.resource_tree.lock().remove(struct_tag);
if let Some(struct_tag) = data_path.resource_tag() {
self.resource_tree.lock().remove(struct_tag);
}
if let Some(struct_tag) = data_path.resource_group_tag() {
self.resource_tree.lock().remove(struct_tag);
}
Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion vm/dev/src/playground.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ pub fn dry_run_explain<S: StateView>(
view.abi = Some(resolver.resolve_module_code(view.code.0.as_slice())?);
}
WriteOpValueView::Resource(view) => {
let struct_tag = access_path.path.as_struct_tag().ok_or_else(|| {
let struct_tag = access_path.path.resource_tag().ok_or_else(|| {
format_err!("invalid resource access path: {}", access_path)
})?;
let struct_abi = resolver.resolve_struct_tag(struct_tag)?;
Expand Down
10 changes: 8 additions & 2 deletions vm/types/src/access_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
use starcoin_crypto::hash::HashValue;
use std::fmt;
use std::str::FromStr;

#[derive(Clone, Eq, PartialEq, Hash, Ord, PartialOrd, JsonSchema)]
#[cfg_attr(any(test, feature = "fuzzing"), derive(Arbitrary))]
#[schemars(with = "String")]
Expand Down Expand Up @@ -328,13 +329,18 @@ impl DataPath {
pub fn is_code(&self) -> bool {
matches!(self, Self::Code(_))
}
// todo(simon): handle ResourceGroup
pub fn as_struct_tag(&self) -> Option<&StructTag> {
pub fn resource_tag(&self) -> Option<&StructTag> {
match self {
Self::Resource(struct_tag) => Some(struct_tag),
_ => None,
}
}
pub fn resource_group_tag(&self) -> Option<&StructTag> {
match self {
Self::ResourceGroup(struct_tag) => Some(struct_tag),
_ => None,
}
}
pub fn data_type(&self) -> DataType {
match self {
Self::Code(_) => DataType::CODE,
Expand Down

0 comments on commit 83854cf

Please sign in to comment.