Skip to content

Commit

Permalink
feat(axelar-std-derive): add status support to contractstorage macro (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
nbayindirli authored Jan 31, 2025
1 parent 94632d8 commit 4ffb0cb
Show file tree
Hide file tree
Showing 7 changed files with 339 additions and 226 deletions.
4 changes: 4 additions & 0 deletions contracts/stellar-example/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ enum DataKey {
#[instance]
#[value(Address)]
InterchainTokenService,

#[instance]
#[status]
Paused,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#[derive(Clone, Debug)] enum DataKey
{
#[instance] #[value(Address)] Gateway, #[instance] #[value(Address)]
GasService, #[instance] #[value(Address)] InterchainTokenService,
#[instance] #[status] Paused,
}
4 changes: 2 additions & 2 deletions packages/stellar-axelar-std-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ proc-macro = true
[features]

[dependencies]
goldie = { workspace = true }
heck = "0.5"
itertools = "0.14"
prettyplease = "0.2"
proc-macro2 = { workspace = true }
quote = { version = "1.0", default-features = false }
syn = { version = "2.0", features = ["full", "extra-traits"] }

[dev-dependencies]
goldie = { workspace = true }
prettyplease = "0.2"

[lints]
workspace = true
20 changes: 13 additions & 7 deletions packages/stellar-axelar-std-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ pub fn derive_its_executable(input: TokenStream) -> TokenStream {
/// Implements a storage interface for a Stellar contract storage enum.
///
/// The enum variants define contract data keys, with optional named fields as contract data map keys.
/// Each variant requires a `#[value(Type)]` attribute to specify the stored value type.
/// Each variant requires a `#[value(Type)]` xor `#[status]` attribute to specify the stored value type.
/// Storage type can be specified with `#[instance]`, `#[persistent]`, or `#[temporary]` attributes (defaults to instance).
///
/// # Example
Expand All @@ -261,6 +261,10 @@ pub fn derive_its_executable(input: TokenStream) -> TokenStream {
/// #[temporary]
/// #[value(u64)]
/// LastUpdate { account: Address },
///
/// #[instance]
/// #[status]
/// Paused,
/// }
///
/// #[contract]
Expand All @@ -273,19 +277,21 @@ pub fn derive_its_executable(input: TokenStream) -> TokenStream {
/// token_id: u32,
/// name: String,
/// ) {
/// // Generates: DataKey::set_token_name(env, token_id, &name);
/// DataKey::set_token_name(env, token_id, &name);
/// storage::set_token_name(env, token_id, &name);
/// }
///
/// pub fn foo(env: &Env, token_id: u32) -> Option<String> {
/// storage::token_name(env, token_id);
/// }
///
/// pub fn token_name(env: &Env, token_id: u32) -> Option<String> {
/// // Generates: DataKey::get_token_name(env, token_id)
/// DataKey::get_token_name(env, token_id)
/// pub fn bar(env: &Env, token_id: u32) -> Option<String> {
/// storage::remove_token_name(env, token_id)
/// }
/// }
/// # }
/// ```
#[proc_macro_attribute]
pub fn contractstorage(_attr: TokenStream, item: TokenStream) -> TokenStream {
let input = parse_macro_input!(item as DeriveInput);
storage::contractstorage(&input).into()
storage::contract_storage(&input).into()
}
Loading

0 comments on commit 4ffb0cb

Please sign in to comment.