From 7ce70c9cc021d0e9281c7223142d724978edc591 Mon Sep 17 00:00:00 2001 From: Cameron Carstens Date: Fri, 30 Aug 2024 21:47:38 +0800 Subject: [PATCH] Remove metadata functions (#148) --- CHANGELOG.md | 2 +- standards/src/src7.sw | 214 ------------------------------------------ 2 files changed, 1 insertion(+), 215 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1fa7634..198680e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ Description of the upcoming release here. ### Added Unreleased -- [#144](https://github.com/FuelLabs/sway-standards/pull/144) Adds the following helper functions for `Metadata` to check and return the underlying type: `as_string()`, `is_string()`, `as_bytes()`, `is_bytes()`, `as_b256()`, `is_u64()`, `as_u64()`. +- None ### Changed Unreleased diff --git a/standards/src/src7.sw b/standards/src/src7.sw index eac11cb..9bd030e 100644 --- a/standards/src/src7.sw +++ b/standards/src/src7.sw @@ -74,217 +74,3 @@ impl core::ops::Eq for Metadata { } } } - -impl Metadata { - /// Returns the underlying metadata as a `String`. - /// - /// # Returns - /// - /// * [Option] - `Some` if the underlying type is a `String`, otherwise `None`. - /// - /// # Examples - /// - /// ```sway - /// use std::string::String; - /// use standards::src7::{SRC7, Metadata}; - /// - /// fn foo(contract_id: ContractId, asset: AssetId, key: String) { - /// let metadata_abi = abi(SRC7, contract_id); - /// let metadata: Option = metadata_abi.metadata(asset, key); - /// - /// let string = metadata.unwrap().as_string(); - /// assert(string.len() != 0); - /// } - /// ``` - pub fn as_string(self) -> Option { - match self { - Self::String(data) => Option::Some(data), - _ => Option::None, - } - } - - /// Returns whether the underlying metadata is a `String`. - /// - /// # Returns - /// - /// * [bool] - `true` if the metadata is a `String`, otherwise `false`. - /// - /// # Examples - /// - /// ```sway - /// use std::string::String; - /// use standards::src7::{SRC7, Metadata}; - /// - /// fn foo(contract_id: ContractId, asset: AssetId, key: String) { - /// let metadata_abi = abi(SRC7, contract_id); - /// let metadata: Option = metadata_abi.metadata(asset, key); - /// - /// assert(metadata.unwrap().is_string()); - /// } - /// ``` - pub fn is_string(self) -> bool { - match self { - Self::String(_) => true, - _ => false, - } - } - - /// Returns the underlying metadata as a `u64`. - /// - /// # Returns - /// - /// * [Option] - `Some` if the underlying type is a `u64`, otherwise `None`. - /// - /// # Examples - /// - /// ```sway - /// use std::string::String; - /// use standards::src7::{SRC7, Metadata}; - /// - /// fn foo(contract_id: ContractId, asset: AssetId, key: String) { - /// let metadata_abi = abi(SRC7, contract_id); - /// let metadata: Option = metadata_abi.metadata(asset, key); - /// - /// let int = metadata.unwrap().as_u64(); - /// assert(int != 0); - /// } - /// ``` - pub fn as_u64(self) -> Option { - match self { - Self::Int(data) => Option::Some(data), - _ => Option::None, - } - } - - /// Returns whether the underlying metadata is a `u64`. - /// - /// # Returns - /// - /// * [bool] - `true` if the metadata is a `u64`, otherwise `false`. - /// - /// # Examples - /// - /// ```sway - /// use std::string::String; - /// use standards::src7::{SRC7, Metadata}; - /// - /// fn foo(contract_id: ContractId, asset: AssetId, key: String) { - /// let metadata_abi = abi(SRC7, contract_id); - /// let metadata: Option = metadata_abi.metadata(asset, key); - /// - /// assert(metadata.unwrap().is_u64()); - /// } - /// ``` - pub fn is_u64(self) -> bool { - match self { - Self::Int(_) => true, - _ => false, - } - } - - /// Returns the underlying metadata as `Bytes`. - /// - /// # Returns - /// - /// * [Option] - `Some` if the underlying type is `Bytes`, otherwise `None`. - /// - /// # Examples - /// - /// ```sway - /// use std::{bytes::Bytes, string::String}; - /// use standards::src7::{SRC7, Metadata}; - /// - /// fn foo(contract_id: ContractId, asset: AssetId, key: String) { - /// let metadata_abi = abi(SRC7, contract_id); - /// let metadata: Option = metadata_abi.metadata(asset, key); - /// - /// let bytes = metadata.unwrap().as_bytes(); - /// assert(bytes.len() != 0); - /// } - /// ``` - pub fn as_bytes(self) -> Option { - match self { - Self::Bytes(data) => Option::Some(data), - _ => Option::None, - } - } - - /// Returns whether the underlying metadata is `Bytes`. - /// - /// # Returns - /// - /// * [bool] - `true` if the metadata is `Bytes`, otherwise `false`. - /// - /// # Examples - /// - /// ```sway - /// use std::{bytes::Bytes, string::String}; - /// use standards::src7::{SRC7, Metadata}; - /// - /// fn foo(contract_id: ContractId, asset: AssetId, key: String) { - /// let metadata_abi = abi(SRC7, contract_id); - /// let metadata: Option = metadata_abi.metadata(asset, key); - /// - /// assert(metadata.unwrap().is_bytes()); - /// } - /// ``` - pub fn is_bytes(self) -> bool { - match self { - Self::Bytes(_) => true, - _ => false, - } - } - - /// Returns the underlying metadata as a `b256`. - /// - /// # Returns - /// - /// * [Option] - `Some` if the underlying type is a `b256`, otherwise `None`. - /// - /// # Examples - /// - /// ```sway - /// use std::string::String; - /// use standards::src7::{SRC7, Metadata}; - /// - /// fn foo(contract_id: ContractId, asset: AssetId, key: String) { - /// let metadata_abi = abi(SRC7, contract_id); - /// let metadata: Option = metadata_abi.metadata(asset, key); - /// - /// let val = metadata.unwrap().as_b256(); - /// assert(val != b256::zero()); - /// } - /// ``` - pub fn as_b256(self) -> Option { - match self { - Self::B256(data) => Option::Some(data), - _ => Option::None, - } - } - - /// Returns whether the underlying metadata is a `b256`. - /// - /// # Returns - /// - /// * [bool] - `true` if the metadata is a `b256`, otherwise `false`. - /// - /// # Examples - /// - /// ```sway - /// use std::string::String; - /// use standards::src7::{SRC7, Metadata}; - /// - /// fn foo(contract_id: ContractId, asset: AssetId, key: String) { - /// let metadata_abi = abi(SRC7, contract_id); - /// let metadata: Option = metadata_abi.metadata(asset, key); - /// - /// assert(metadata.unwrap().is_b256()); - /// } - /// ``` - pub fn is_b256(self) -> bool { - match self { - Self::B256(_) => true, - _ => false, - } - } -}