forked from MystenLabs/sui
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[framework] use NFT<T> standard in cross-chain airdrop
- Loading branch information
1 parent
9527322
commit 368a434
Showing
8 changed files
with
141 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
module Sui::ERC721Metadata { | ||
use Std::ASCII; | ||
use Sui::Url::{Self, Url}; | ||
use Sui::UTF8; | ||
|
||
// TODO: add symbol()? | ||
/// A wrapper type for the ERC721 metadata standard https://eips.ethereum.org/EIPS/eip-721 | ||
struct ERC721Metadata has store { | ||
/// The token id associated with the source contract on Ethereum | ||
token_id: TokenID, | ||
/// A descriptive name for a collection of NFTs in this contract. | ||
/// This corresponds to the `name()` method in the | ||
/// ERC721Metadata interface in EIP-721. | ||
name: UTF8::String, | ||
/// A distinct Uniform Resource Identifier (URI) for a given asset. | ||
/// This corresponds to the `tokenURI()` method in the ERC721Metadata | ||
/// interface in EIP-721. | ||
token_uri: Url, | ||
} | ||
|
||
// TODO: replace u64 with u256 once the latter is supported | ||
// <https://github.com/MystenLabs/fastnft/issues/618> | ||
/// An ERC721 token ID | ||
struct TokenID has store, copy { | ||
id: u64, | ||
} | ||
|
||
/// Construct a new ERC721Metadata from the given inputs. Does not perform any validation | ||
/// on `token_uri` or `name` | ||
public fun new(token_id: TokenID, name: vector<u8>, token_uri: vector<u8>): ERC721Metadata { | ||
// Note: this will abort if `token_uri` is not valid ASCII | ||
let uri_str = ASCII::string(token_uri); | ||
ERC721Metadata { | ||
token_id, | ||
name: UTF8::string_unsafe(name), | ||
token_uri: Url::new_unsafe(uri_str), | ||
} | ||
} | ||
|
||
public fun new_token_id(id: u64): TokenID { | ||
TokenID { id } | ||
} | ||
|
||
public fun token_id(self: &ERC721Metadata): &TokenID { | ||
&self.token_id | ||
} | ||
|
||
public fun token_uri(self: &ERC721Metadata): &Url { | ||
&self.token_uri | ||
} | ||
|
||
public fun name(self: &ERC721Metadata): &UTF8::String { | ||
&self.name | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module Sui::UTF8 { | ||
use Std::ASCII; | ||
use Std::Option::Option; | ||
|
||
/// Wrapper type that should be interpreted as a UTF8 string by clients | ||
struct String has store, copy, drop { | ||
bytes: vector<u8> | ||
} | ||
|
||
// TODO: also include validating constructor | ||
/// Construct a UTF8 string from `bytes`. Does not | ||
/// perform any validation | ||
public fun string_unsafe(bytes: vector<u8>): String { | ||
String { bytes } | ||
} | ||
|
||
/// Construct a UTF8 string from the ASCII string `s` | ||
public fun from_ascii(s: ASCII::String): String { | ||
String { bytes: ASCII::into_bytes(s) } | ||
} | ||
|
||
/// Try to convert `self` to an ASCCI string | ||
public fun try_into_ascii(self: String): Option<ASCII::String> { | ||
ASCII::try_string(self.bytes) | ||
} | ||
|
||
/// Return the underyling bytes of `self` | ||
public fun bytes(self: &String): &vector<u8> { | ||
&self.bytes | ||
} | ||
|
||
/// Consume `self` and return its underlying bytes | ||
public fun into_bytes(self: String): vector<u8> { | ||
let String { bytes } = self; | ||
bytes | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters