Skip to content

Commit

Permalink
Merge pull request #153 from FuelLabs/swaystar123/fix-set_src20_data-bug
Browse files Browse the repository at this point in the history
Actually write to storage in src20 multi asset example
  • Loading branch information
SwayStar123 authored Sep 17, 2024
2 parents 04a5248 + 55541de commit 408d81a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,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();
}
}

0 comments on commit 408d81a

Please sign in to comment.