Skip to content

Commit

Permalink
Add b256 to the Metadata enum and rename varients
Browse files Browse the repository at this point in the history
  • Loading branch information
bitzoic committed Sep 14, 2023
1 parent 9721324 commit 820db28
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
18 changes: 11 additions & 7 deletions standards/src_7/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,27 @@ We also take a look at existing common metadata practices such as [OpenSea's Met

The following describes an enum that wraps various metadata types into a single return type. There SHALL be the following variants in the `Metadata` enum:

### - `StringData: String`
### - `B256`

The `StringData` variant SHALL be used when the stored metadata for the corresponding asset and `String` key pair is of the `String` type. The `StringData` variant MUST be used when a URI is required but MAY contain any arbitrary `String`.
The `B256` variant SHALL be used when the stored metadata for the corresponding `AssetId` and `Sting` key pair is of the `b256` type.

### - `IntData: u64`
### - `Bytes`

The `IntData` variant SHALL be used when the stored metadata for the corresponding asset and `Sting` key pair is of the `u64` type.
The `Bytes` variant SHALL be used when the stored metadata for the corresponding `AssetId` and `String` key pair is of the `Bytes` type. The `Bytes` variant should be used when storing custom data such as but not limited to structs and enums.

### - `BytesData: Bytes`
### - `Int`

The `BytesData` variant SHALL be used when the stored metadata for the corresponding asset and `String` key pair is of the `Bytes` type. The `BytesData` variant should be used when storing custom data such as but not limited to structs and enums.
The `Int` variant SHALL be used when the stored metadata for the corresponding `AssetId` and `Sting` key pair is of the `u64` type.

### - `String`

The `String` variant SHALL be used when the stored metadata for the corresponding `AssetId` and `String` key pair is of the `String` type. The `String` variant MUST be used when a URI is required but MAY contain any arbitrary `String` data.

## Require Functions

### `fn metadata(asset: AssetId, key: String) -> Option<Metadata>`

This function MUST return valid metadata for the corresponding `asset` and `key`, where the data is either a `StringData`, `IntData`, or `BytesData` variant. If the asset does not exist or no metadata exists, the function MUST return `None`.
This function MUST return valid metadata for the corresponding `asset` and `key`, where the data is either a `B256`, `Bytes`, `Int`, or `String` variant. If the asset does not exist or no metadata exists, the function MUST return `None`.

# Rationale

Expand Down
25 changes: 15 additions & 10 deletions standards/src_7/src/src_7.sw
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,30 @@ abi SRC7 {

/// Universal return type for metadata.
pub enum Metadata {
/// Used when the stored metadata is a `String`.
StringData: String,
/// Used when the stored metadata is a `u64`.
IntData: u64,
// Used when the stored metadata is a `b256`.
B256: b256,
/// Used when the stored metadata is `Bytes`.
BytesData: Bytes,
Bytes: Bytes,
/// Used when the stored metadata is a `u64`.
Int: u64,
/// Used when the stored metadata is a `String`.
String: String,
}

impl core::ops::Eq for Metadata {
fn eq(self, other: Self) -> bool {
match (self, other) {
(Metadata::StringData(string1), Metadata::StringData(string2)) => {
string1 == string2
(Metadata::B256(bytes1), Metadata::B256(bytes2)) => {
bytes1 == bytes2
},
(Metadata::Bytes(bytes1), Metadata::Bytes(bytes2)) => {
bytes1 == bytes2
},
(Metadata::IntData(int1), Metadata::IntData(int2)) => {
(Metadata::Int(int1), Metadata::Int(int2)) => {
int1 == int2
},
(Metadata::BytesData(bytes1), Metadata::BytesData(bytes2)) => {
bytes1 == bytes2
(Metadata::String(string1), Metadata::String(string2)) => {
string1 == string2
},
_ => false,
}
Expand Down

0 comments on commit 820db28

Please sign in to comment.