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

Actually write to storage in src20 multi asset example #153

Merged
merged 3 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ Description of the upcoming release here.

### Fixed

- Some fix here 1
- Some fix here 2
- [#153](https://github.com/FuelLabs/sway-standards/pull/153) Actually write to storage in `set_src20_data()` in the SRC-20 multi asset example.

#### Breaking

Expand Down
31 changes: 27 additions & 4 deletions examples/src20-native-asset/multi_asset/src/multi_asset.sw
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ impl SRC20 for Contract {
}

abi SetSRC20Data {
#[storage(read)]
#[storage(read, write)]
fn set_src20_data(
asset: AssetId,
total_supply: u64,
Expand All @@ -184,7 +184,7 @@ abi SetSRC20Data {
}

impl SetSRC20Data for Contract {
#[storage(read)]
#[storage(read, write)]
fn set_src20_data(
asset: AssetId,
supply: u64,
Expand All @@ -199,9 +199,32 @@ impl SetSRC20Data for Contract {
}
let sender = msg_sender().unwrap();

SetNameEvent::new(asset, name, sender).log();
SetSymbolEvent::new(asset, symbol, sender).log();
match name {
Some(unwrapped_name) => {
storage.name.get(asset).write_slice(unwrapped_name);
SetNameEvent::new(asset, name, sender).log();
},
None => {
let _ = storage.name.get(asset).clear();
SetNameEvent::new(asset, name, sender).log();
}
}

match symbol {
Some(unwrapped_symbol) => {
storage.symbol.get(asset).write_slice(unwrapped_symbol);
SetSymbolEvent::new(asset, symbol, sender).log();
},
None => {
let _ = storage.symbol.get(asset).clear();
SetSymbolEvent::new(asset, symbol, sender).log();
}
}

storage.decimals.get(asset).write(decimals);
SetDecimalsEvent::new(asset, decimals, sender).log();

storage.total_supply.get(asset).write(supply);
TotalSupplyEvent::new(asset, supply, sender).log();
}
}
Loading