Skip to content

Commit

Permalink
Revert "Add helper functions to SRC7 standard's Metadata (#144)"
Browse files Browse the repository at this point in the history
This reverts commit 955061b.
  • Loading branch information
SwayStar123 authored Aug 30, 2024
1 parent 955061b commit 0a666e0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 215 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ 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()`.
- Something new here 1
- Something new here 2

### Changed Unreleased

Expand Down
214 changes: 0 additions & 214 deletions standards/src/src7.sw
Original file line number Diff line number Diff line change
Expand Up @@ -74,217 +74,3 @@ impl core::ops::Eq for Metadata {
}
}
}

impl Metadata {
/// Returns the underlying metadata as a `String`.
///
/// # Returns
///
/// * [Option<String>] - `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> = metadata_abi.metadata(asset, key);
///
/// let string = metadata.unwrap().as_string();
/// assert(string.len() != 0);
/// }
/// ```
pub fn as_string(self) -> Option<String> {
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> = 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<u64>] - `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> = metadata_abi.metadata(asset, key);
///
/// let int = metadata.unwrap().as_u64();
/// assert(int != 0);
/// }
/// ```
pub fn as_u64(self) -> Option<u64> {
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> = 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<Bytes>] - `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> = metadata_abi.metadata(asset, key);
///
/// let bytes = metadata.unwrap().as_bytes();
/// assert(bytes.len() != 0);
/// }
/// ```
pub fn as_bytes(self) -> Option<Bytes> {
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> = 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<u64>] - `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> = metadata_abi.metadata(asset, key);
///
/// let val = metadata.unwrap().as_b256();
/// assert(val != b256::zero());
/// }
/// ```
pub fn as_b256(self) -> Option<b256> {
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> = metadata_abi.metadata(asset, key);
///
/// assert(metadata.unwrap().is_b256());
/// }
/// ```
pub fn is_b256(self) -> bool {
match self {
Self::B256(_) => true,
_ => false,
}
}
}

0 comments on commit 0a666e0

Please sign in to comment.