/
metadata.rs
76 lines (70 loc) · 3.6 KB
/
metadata.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use crate::*;
pub type TokenId = String;
//defines the payout type we'll be returning as a part of the royalty standards.
#[derive(Serialize, Deserialize, NearSchema)]
#[serde(crate = "near_sdk::serde")]
pub struct Payout {
pub payout: HashMap<AccountId, U128>,
}
#[derive(BorshDeserialize, BorshSerialize, Serialize, Deserialize, Clone, NearSchema)]
#[borsh(crate = "near_sdk::borsh")]
#[serde(crate = "near_sdk::serde")]
pub struct NFTContractMetadata {
pub spec: String, // required, essentially a version like "nft-1.0.0"
pub name: String, // required, ex. "Mosaics"
pub symbol: String, // required, ex. "MOSAIC"
pub icon: Option<String>, // Data URL
pub base_uri: Option<String>, // Centralized gateway known to have reliable access to decentralized storage assets referenced by `reference` or `media` URLs
pub reference: Option<String>, // URL to a JSON file with more info
pub reference_hash: Option<Base64VecU8>, // Base64-encoded sha256 hash of JSON from reference field. Required if `reference` is included.
}
#[derive(BorshDeserialize, BorshSerialize, Serialize, Deserialize, NearSchema)]
#[borsh(crate = "near_sdk::borsh")]
#[serde(crate = "near_sdk::serde")]
pub struct TokenMetadata {
pub title: Option<String>, // ex. "Arch Nemesis: Mail Carrier" or "Parcel #5055"
pub description: Option<String>, // free-form description
pub media: Option<String>, // URL to associated media, preferably to decentralized, content-addressed storage
pub media_hash: Option<Base64VecU8>, // Base64-encoded sha256 hash of content referenced by the `media` field. Required if `media` is included.
pub copies: Option<u64>, // number of copies of this set of metadata in existence when token was minted.
pub issued_at: Option<u64>, // When token was issued or minted, Unix epoch in milliseconds
pub expires_at: Option<u64>, // When token expires, Unix epoch in milliseconds
pub starts_at: Option<u64>, // When token starts being valid, Unix epoch in milliseconds
pub updated_at: Option<u64>, // When token was last updated, Unix epoch in milliseconds
pub extra: Option<String>, // anything extra the NFT wants to store on-chain. Can be stringified JSON.
pub reference: Option<String>, // URL to an off-chain JSON file with more info.
pub reference_hash: Option<Base64VecU8>, // Base64-encoded sha256 hash of JSON from reference field. Required if `reference` is included.
}
#[derive(BorshDeserialize, BorshSerialize)]
#[borsh(crate = "near_sdk::borsh")]
pub struct Token {
//owner of the token
pub owner_id: AccountId,
//list of approved account IDs that have access to transfer the token. This maps an account ID to an approval ID
pub approved_account_ids: HashMap<AccountId, u32>,
//the next approval ID to give out.
pub next_approval_id: u32,
}
//The Json token is what will be returned from view calls.
#[derive(Serialize, Deserialize, NearSchema)]
#[serde(crate = "near_sdk::serde")]
pub struct JsonToken {
//token ID
pub token_id: TokenId,
//owner of the token
pub owner_id: AccountId,
//token metadata
pub metadata: TokenMetadata,
//list of approved account IDs that have access to transfer the token. This maps an account ID to an approval ID
pub approved_account_ids: HashMap<AccountId, u32>,
}
pub trait NonFungibleTokenMetadata {
//view call for returning the contract metadata
fn nft_metadata(&self) -> NFTContractMetadata;
}
#[near_bindgen]
impl NonFungibleTokenMetadata for Contract {
fn nft_metadata(&self) -> NFTContractMetadata {
self.metadata.get().unwrap()
}
}