Skip to content

Merge storage declarations into derive macro Storage #288

Closed
@clearloop

Description

@clearloop

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

Metadata

Metadata

Labels

refactorThis issue requires a refactor to the design

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions