Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge storage declarations into derive macro Storage #288

Open
clearloop opened this issue Nov 30, 2024 · 0 comments · May be fixed by #301
Open

Merge storage declarations into derive macro Storage #288

clearloop opened this issue Nov 30, 2024 · 0 comments · May be fixed by #301
Assignees
Labels
refactor This issue requires a refactor to the design

Comments

@clearloop
Copy link
Member

clearloop commented Nov 30, 2024

As we can see in

zink/examples/erc20.rs

Lines 12 to 25 in d340f7e

#[zink::storage(String32)]
pub struct Name;
#[zink::storage(String32)]
pub struct Symbol;
#[zink::storage(U256)]
pub struct TotalSupply;
#[zink::storage(Address, U256)]
pub struct Balances;
#[zink::storage(Address, Address, U256)]
pub struct Allowance;
the storage interfaces are currently distributed into different structs, instead, we want an interface like below to improve the developer experience

#[derive(Storage)]
pub struct MyERC20 {
  // #[zink::storage(String32)]
  // struct Name(String32);
  pub name: String32,
  // #[zink::storage(String32)]
  // struct Symbol(String32);
  pub symbol: String32,
  // ...
  pub total_supply: U256,
  pub balances: Mapping<Address, U256>,
  pub allowances: DoubleKeyMapping<Address, Address, U256>,
}

#[zink::contract]
impl MyERC20 {
  /// this method will be compiled as an external call because we have `pub` here
  /// 
  /// `self` here will be the entrance of the storage
  pub fn set_and_get(&self, new_name: String32) -> String32 {
    self.name.set(new_name);
    self.name.get()
  }
}

related to #260

@clearloop clearloop added the refactor This issue requires a refactor to the design label Nov 30, 2024
@clearloop clearloop self-assigned this Nov 30, 2024
@clearloop clearloop changed the title Merge storage declaration in macro Contract Merge storage declarations into derive macro Storage Nov 30, 2024
@clearloop clearloop linked a pull request Dec 29, 2024 that will close this issue
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor This issue requires a refactor to the design
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

1 participant