FuelLabs / sway-libs

Miscellaneous Sway libraries.
https://docs.fuel.network/docs/sway-libs/
Apache License 2.0
146 stars 61 forks source link

Update to Sway-Standards v0.6.0 #286

Closed bitzoic closed 2 months ago

bitzoic commented 2 months ago

Type of change

Breaking

The following breaking changes have been made:

  1. The support functions for Metadata have been removed. They have been moved to sway-standards.

Before:

use sway_libs::asset::metadata::*;

fn foo(my_metadata: Metadata) {
     let res: bool = my_metadata.is_b256(); 
     let res: bool = my_metadata.is_string(); 
     let res: bool = my_metadata.is_bytes(); 
     let res: bool = my_metadata.is_uint();
}

After:

use standards::src7::*;

fn foo(my_metadata: Metadata) {
     let res: bool = my_metadata.is_b256(); 
     let res: bool = my_metadata.is_string(); 
     let res: bool = my_metadata.is_bytes(); 
     let res: bool = my_metadata.is_uint();
}
  1. The SetMetadata and _set_metadata function definitions have changed. The metadata argument is now an Option<Metadata> and the argument order has changed.

Before:

impl SetAssetMetadata for Contract {
    #[storage(read, write)]
    fn set_metadata(asset: AssetId, key: String, metadata: Metadata) {
        _set_metadata(storage.metadata, asset, key, metadata);
    }
}

After:

impl SetAssetMetadata for Contract {
    #[storage(read, write)]
    fn set_metadata(asset: AssetId, metadata: Option<Metadata>, key: String) {
        _set_metadata(storage.metadata, asset, metadata, key);
    }
}
  1. The _set_name() function's name argument is now an Option<String>

Before:

fn foo(asset: AssetId) {
    _set_name(storage.name, asset, String::from_ascii_str("Ether"));
}

After:

fn foo(asset: AssetId) {
    _set_name(storage.name, asset, Some(String::from_ascii_str("Ether")));
}
  1. The _set_symbol() function's name argument is now an Option<String>

Before:

fn foo(asset: AssetId) {
    _set_symbol(storage.name, asset, String::from_ascii_str("ETH"));
}

After:

fn foo(asset: AssetId) {
    _set_symbol(storage.name, asset, Some(String::from_ascii_str("ETH")));
}
  1. The _mint() function's sub_id argument is now an Option<SubId>

Before:

fn foo(recipient: Identity, amount: u64) {
    let asset_id = _mint(storage.total_assets, storage.total_supply, recipient, SubId::zero(), amount);
}

After:

fn foo(recipient: Identity, amount: u64) {
    let asset_id = _mint(storage.total_assets, storage.total_supply, recipient, Some(SubId::zero()), amount);
}

Changes

The following changes have been made:

Checklist