Skip to content

Commit

Permalink
chore: simplified method macro logic to use Interface::root method (#913
Browse files Browse the repository at this point in the history
)
  • Loading branch information
chefsale authored Oct 31, 2024
1 parent 25697e0 commit 70222f4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
9 changes: 3 additions & 6 deletions crates/sdk/macros/src/logic/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,8 @@ impl ToTokens for PublicLogicMethod<'_> {
SelfType::Owned(_) | SelfType::Immutable(_) => None,
};
quote! {
let Some(#mutability app) = ::calimero_storage::interface::Interface::find_by_id::<#self_>(
::calimero_storage::address::Id::root()
).ok().flatten() else {
let Some(#mutability app) = ::calimero_storage::interface::Interface::root::<#self_>().ok().flatten()
else {
::calimero_sdk::env::panic_str("Failed to find or read app state")
};
}
Expand All @@ -111,9 +110,7 @@ impl ToTokens for PublicLogicMethod<'_> {
None => (
if init_method {
quote! {
if let Some(mut app) = ::calimero_storage::interface::Interface::find_by_id::<#self_>(
::calimero_storage::address::Id::root()
).ok().flatten() {
if let Some(mut app) = ::calimero_storage::interface::Interface::root::<#self_>().ok().flatten() {
::calimero_sdk::env::panic_str("Cannot initialize over already existing state.")
};

Expand Down
2 changes: 1 addition & 1 deletion crates/storage/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl Id {
Self { bytes }
}

/// Root ID which is set to all zeroes by default.
/// Root ID which is set to the context ID.
#[must_use]
pub fn root() -> Self {
Id::new(context_id())
Expand Down

0 comments on commit 70222f4

Please sign in to comment.