diff --git a/docs/src/src-15-offchain-asset-metadata.md b/docs/src/src-15-offchain-asset-metadata.md index 8f4ee1f..068209b 100644 --- a/docs/src/src-15-offchain-asset-metadata.md +++ b/docs/src/src-15-offchain-asset-metadata.md @@ -26,13 +26,12 @@ The following logs MUST be implemented and emitted to follow the SRC-15 standard #### SRC15MetadataEvent -The `SRC15MetadataEvent` MUST be emitted once for each distinct piece of metadata. +The `SRC15MetadataEvent` MUST be emitted at least once for each distinct piece of metadata. The latest emitted `SRC15MetadataEvent` is determined to be the current metadata. There SHALL be the following fields in the `SRC15MetadataEvent` struct: * `asset`: The `asset` field SHALL be used for the corresponding `AssetId` for the metadata. * `metadata`: The `metadata` field SHALL be used for the corresponding `Metadata` which represents the metadata of the asset. -* `nonce`: The nonce of the metadata. This SHALL begin at zero and increment by one upon every emission such that each emission has a unique nonce. Example: @@ -40,7 +39,6 @@ Example: pub struct SRC15MetadataEvent { pub asset: AssetId, pub metadata: Metadata, - pub nonce: u64, } ``` diff --git a/examples/src15-offchain-metadata/multi_asset/src/multi_asset.sw b/examples/src15-offchain-metadata/multi_asset/src/multi_asset.sw index a5ca028..96dac73 100644 --- a/examples/src15-offchain-metadata/multi_asset/src/multi_asset.sw +++ b/examples/src15-offchain-metadata/multi_asset/src/multi_asset.sw @@ -37,17 +37,15 @@ storage { total_assets: u64 = 0, /// The total supply of a particular asset. total_supply: StorageMap = StorageMap {}, - /// The nonce for the SRC15 Metadata event. - src_15_nonce: u64 = 0, } abi EmitSRC15Events { - #[storage(read, write)] + #[storage(read)] fn emit_src15_events(asset: AssetId, svg_image: String, health_attribute: u64); } impl EmitSRC15Events for Contract { - #[storage(read, write)] + #[storage(read)] fn emit_src15_events(asset: AssetId, svg_image: String, health_attribute: u64) { // NOTE: There are no checks for if the caller has permissions to emit the metadata // NOTE: Nothing is stored in storage and there is no method to retrieve the configurables. @@ -62,14 +60,10 @@ impl EmitSRC15Events for Contract { let metadata_3 = Metadata::String(svg_image); let metadata_4 = Metadata::Int(health_attribute); - // Update the nonce - let nonce = storage.src_15_nonce.read(); - storage.src_15_nonce.write(nonce + 1); - - SRC15MetadataEvent::new(asset, metadata_1, nonce).log(); - SRC15MetadataEvent::new(asset, metadata_2, nonce).log(); - SRC15MetadataEvent::new(asset, metadata_3, nonce).log(); - SRC15MetadataEvent::new(asset, metadata_4, nonce).log(); + SRC15MetadataEvent::new(asset, metadata_1).log(); + SRC15MetadataEvent::new(asset, metadata_2).log(); + SRC15MetadataEvent::new(asset, metadata_3).log(); + SRC15MetadataEvent::new(asset, metadata_4).log(); } } diff --git a/examples/src15-offchain-metadata/single_asset/src/single_asset.sw b/examples/src15-offchain-metadata/single_asset/src/single_asset.sw index a2a4369..ea9d9e8 100644 --- a/examples/src15-offchain-metadata/single_asset/src/single_asset.sw +++ b/examples/src15-offchain-metadata/single_asset/src/single_asset.sw @@ -35,18 +35,11 @@ configurable { ATTR_HEALTH: u64 = 100, } -storage { - /// The nonce for the SRC15 Metadata event. - src_15_nonce: u64 = 0, -} - abi EmitSRC15Events { - #[storage(read, write)] fn emit_src15_events(); } impl EmitSRC15Events for Contract { - #[storage(read, write)] fn emit_src15_events() { // NOTE: There are no checks for if the caller has permissions to emit the metadata. // NOTE: Nothing is stored in storage and there is no method to retrieve the configurables. @@ -55,13 +48,9 @@ impl EmitSRC15Events for Contract { let metadata_2 = Metadata::String(String::from_ascii_str(from_str_array(SITE_FORUM))); let metadata_3 = Metadata::Int(ATTR_HEALTH); - // Update the nonce - let nonce = storage.src_15_nonce.read(); - storage.src_15_nonce.write(nonce + 1); - - SRC15MetadataEvent::new(asset, metadata_1, nonce).log(); - SRC15MetadataEvent::new(asset, metadata_2, nonce).log(); - SRC15MetadataEvent::new(asset, metadata_3, nonce).log(); + SRC15MetadataEvent::new(asset, metadata_1).log(); + SRC15MetadataEvent::new(asset, metadata_2).log(); + SRC15MetadataEvent::new(asset, metadata_3).log(); } } diff --git a/standards/src/src15.sw b/standards/src/src15.sw index 26e7822..7facc3e 100644 --- a/standards/src/src15.sw +++ b/standards/src/src15.sw @@ -8,13 +8,11 @@ pub struct SRC15MetadataEvent { pub asset: AssetId, /// The Metadata of the SRC-15 event. pub metadata: Metadata, - /// The unique nonce for the metadata. - pub nonce: u64, } impl core::ops::Eq for SRC15MetadataEvent { fn eq(self, other: Self) -> bool { - self.asset == other.asset && self.metadata == other.metadata && self.nonce == other.nonce + self.asset == other.asset && self.metadata == other.metadata } } @@ -25,7 +23,6 @@ impl SRC15MetadataEvent { /// /// * `asset`: [AssetId] - The asset for which metadata is set. /// * `metadata`: [Option] - The Metadata that is set. - /// * `nonce`: [u64] - The unique nonce of the metadata. /// /// # Returns /// @@ -36,18 +33,16 @@ impl SRC15MetadataEvent { /// ```sway /// use standards::{src7::Metadata, src15::SRC15MetadataEvent}; /// - /// fn foo(asset: AssetId, metadata: Metadata, nonce: u64) { - /// let my_src15_metadata_event = SRC15MetadataEvent::new(asset, metadata, nonce); + /// fn foo(asset: AssetId, metadata: Metadata) { + /// let my_src15_metadata_event = SRC15MetadataEvent::new(asset, metadata); /// assert(my_src15_metadata_event.asset == asset); /// assert(my_src15_metadata_event.metadata == metadata); - /// assert(my_src15_metadata_event.nonce == nonce); /// } /// ``` - pub fn new(asset: AssetId, metadata: Metadata, nonce: u64) -> Self { + pub fn new(asset: AssetId, metadata: Metadata) -> Self { Self { asset, metadata, - nonce, } } @@ -62,8 +57,8 @@ impl SRC15MetadataEvent { /// ```sway /// use standards::{src7::Metadata, src15::SRC15MetadataEvent}; /// - /// fn foo(asset: AssetId, metadata: Metadata, nonce: u64) { - /// let my_src15_metadata_event = SRC15MetadataEvent::new(asset, metadata, nonce); + /// fn foo(asset: AssetId, metadata: Metadata) { + /// let my_src15_metadata_event = SRC15MetadataEvent::new(asset, metadata); /// assert(my_src15_metadata_event.asset() == asset); /// } /// ``` @@ -71,7 +66,7 @@ impl SRC15MetadataEvent { self.asset } - /// Returns the metadata of the `v` event. + /// Returns the metadata of the `SRC15MetadataEvent` event. /// /// # Returns /// @@ -82,8 +77,8 @@ impl SRC15MetadataEvent { /// ```sway /// use standards::{src7::Metadata, src15::SRC15MetadataEvent}; /// - /// fn foo(asset: AssetId, metadata: Metadata, nonce: u64) { - /// let my_src15_metadata_event = SRC15MetadataEvent::new(asset, metadata, nonce); + /// fn foo(asset: AssetId, metadata: Metadata) { + /// let my_src15_metadata_event = SRC15MetadataEvent::new(asset, metadata); /// assert(my_src15_metadata_event.metadata() == metadata); /// } /// ``` @@ -91,26 +86,6 @@ impl SRC15MetadataEvent { self.metadata } - /// Returns the unique nonce of the `SRC15MetadataEvent` event. - /// - /// # Returns - /// - /// * [u64] - The nonce of the event. - /// - /// # Examples - /// - /// ```sway - /// use standards::{src7::Metadata, src15::SRC15MetadataEvent}; - /// - /// fn foo(asset: AssetId, metadata: Metadata, nonce: u64) { - /// let my_src15_metadata_event = SRC15MetadataEvent::new(asset, metadata, nonce); - /// assert(my_src15_metadata_event.nonce() == nonce); - /// } - /// ``` - pub fn nonce(self) -> u64 { - self.nonce - } - /// Logs the `SRC15MetadataEvent`. /// /// # Examples @@ -118,8 +93,8 @@ impl SRC15MetadataEvent { /// ```sway /// use standards::{src7::Metadata, src15::SRC15MetadataEvent}; /// - /// fn foo(asset: AssetId, metadata: Metadata, nonce: u64) { - /// let my_event = SRC15MetadataEvent::new(asset, metadata, nonce); + /// fn foo(asset: AssetId, metadata: Metadata) { + /// let my_event = SRC15MetadataEvent::new(asset, metadata); /// my_event.log(); /// } /// ```