diff --git a/integration-tests/src/helpers.rs b/integration-tests/src/helpers.rs index 9be15c4..5495e51 100644 --- a/integration-tests/src/helpers.rs +++ b/integration-tests/src/helpers.rs @@ -1,7 +1,7 @@ use serde_json::json; use near_workspaces::{types::{NearToken, AccountDetails}, Account, Contract}; -pub const DEFAULT_DEPOSIT: u128 = 10000000000000000000000 as u128; +pub const DEFAULT_DEPOSIT: u128 = 10000000000000000000000; pub const ONE_YOCTO_NEAR: NearToken = NearToken::from_yoctonear(1); pub async fn mint_nft( @@ -70,7 +70,7 @@ pub async fn place_nft_for_sale( market_contract: &Contract, nft_contract: &Contract, token_id: &str, - approval_id: u128, + approval_id: u32, price: &NearToken, ) -> Result<(), Box> { let request_payload = json!({ diff --git a/market-contract/src/external.rs b/market-contract/src/external.rs index 7700642..91540ff 100644 --- a/market-contract/src/external.rs +++ b/market-contract/src/external.rs @@ -10,7 +10,7 @@ trait ExtContract { &mut self, receiver_id: AccountId, //purchaser (person to transfer the NFT to) token_id: TokenId, //token ID to transfer - approval_id: u64, //market contract's approval ID in order to transfer the token on behalf of the owner + approval_id: u32, //market contract's approval ID in order to transfer the token on behalf of the owner memo: String, //memo (to include some context) /* the price that the token was purchased for. This will be used in conjunction with the royalty percentages @@ -25,6 +25,6 @@ trait ExtContract { &self, token_id: TokenId, approved_account_id: AccountId, - approval_id: u64, + approval_id: u32, ); } \ No newline at end of file diff --git a/market-contract/src/nft_callbacks.rs b/market-contract/src/nft_callbacks.rs index 02ab75e..1d4bd68 100644 --- a/market-contract/src/nft_callbacks.rs +++ b/market-contract/src/nft_callbacks.rs @@ -12,7 +12,7 @@ trait NonFungibleTokenApprovalsReceiver { &mut self, token_id: TokenId, owner_id: AccountId, - approval_id: u64, + approval_id: u32, msg: String, ); } @@ -24,7 +24,7 @@ impl NonFungibleTokenApprovalsReceiver for Contract { &mut self, token_id: TokenId, owner_id: AccountId, - approval_id: u64, + approval_id: u32, msg: String, ) { /* diff --git a/market-contract/src/sale.rs b/market-contract/src/sale.rs index 051fe0e..e435fe4 100644 --- a/market-contract/src/sale.rs +++ b/market-contract/src/sale.rs @@ -10,7 +10,7 @@ pub struct Sale { //owner of the sale pub owner_id: AccountId, //market contract's approval ID to transfer the token on behalf of the owner - pub approval_id: u64, + pub approval_id: u32, //nft contract where the token was minted pub nft_contract_id: String, //actual token ID for sale @@ -35,7 +35,7 @@ impl Contract { &mut self, nft_contract_id: AccountId, token_id: TokenId, - approval_id: u64, + approval_id: u32, sale_conditions: SalePriceInYoctoNear, ) { let owner_id = env::predecessor_account_id(); @@ -267,7 +267,7 @@ impl Contract { owner_id: AccountId, nft_contract_id: AccountId, token_id: TokenId, - approval_id: u64, + approval_id: u32, sale_conditions: SalePriceInYoctoNear, #[callback_result] nft_token_result: Result, #[callback_result] nft_is_approved_result: Result, diff --git a/market-contract/src/sale_views.rs b/market-contract/src/sale_views.rs index 9dcf7b4..b1789c2 100644 --- a/market-contract/src/sale_views.rs +++ b/market-contract/src/sale_views.rs @@ -32,8 +32,8 @@ impl Contract { pub fn get_sales_by_owner_id( &self, account_id: AccountId, - from_index: Option, - limit: Option, + from_index: Option, + limit: Option, ) -> Vec { //get the set of token IDs for sale for the given account ID let by_owner_id = self.by_owner_id.get(&account_id); @@ -48,7 +48,7 @@ impl Contract { let keys = sales.as_vector(); //where to start pagination - if we have a from_index, we'll use that - otherwise start from 0 index - let start = from_index.unwrap_or(0); + let start = u128::from(from_index.unwrap_or(U128(0))); //iterate through the keys vector keys.iter() @@ -82,8 +82,8 @@ impl Contract { pub fn get_sales_by_nft_contract_id( &self, nft_contract_id: AccountId, - from_index: Option, - limit: Option, + from_index: Option, + limit: Option, ) -> Vec { //get the set of token IDs for sale for the given contract ID let by_nft_contract_id = self.by_nft_contract_id.get(&nft_contract_id); @@ -99,7 +99,7 @@ impl Contract { let keys = sales.as_vector(); //where to start pagination - if we have a from_index, we'll use that - otherwise start from 0 index - let start = from_index.unwrap_or(0); + let start = u128::from(from_index.unwrap_or(U128(0))); //iterate through the keys vector keys.iter() diff --git a/nft-contract-approval/src/approval.rs b/nft-contract-approval/src/approval.rs index 3dda71a..6ea2317 100644 --- a/nft-contract-approval/src/approval.rs +++ b/nft-contract-approval/src/approval.rs @@ -10,7 +10,7 @@ pub trait NonFungibleTokenCore { &self, token_id: TokenId, approved_account_id: AccountId, - approval_id: Option, + approval_id: Option, ) -> bool; //revoke a specific account from transferring the token on your behalf @@ -27,7 +27,7 @@ trait NonFungibleTokenApprovalsReceiver { &mut self, token_id: TokenId, owner_id: AccountId, - approval_id: u64, + approval_id: u32, msg: String, ); } @@ -54,7 +54,7 @@ impl NonFungibleTokenCore for Contract { ); //get the next approval ID if we need a new approval - let approval_id: u64 = token.next_approval_id; + let approval_id: u32 = token.next_approval_id; //check if the account has been approved already for this token let is_new_approval = token @@ -99,7 +99,7 @@ impl NonFungibleTokenCore for Contract { &self, token_id: TokenId, approved_account_id: AccountId, - approval_id: Option, + approval_id: Option, ) -> bool { //get the token object from the token_id let token = self.tokens_by_id.get(&token_id).expect("No token"); diff --git a/nft-contract-approval/src/enumeration.rs b/nft-contract-approval/src/enumeration.rs index 5926561..49ebc6f 100644 --- a/nft-contract-approval/src/enumeration.rs +++ b/nft-contract-approval/src/enumeration.rs @@ -9,9 +9,9 @@ impl Contract { } //Query for nft tokens on the contract regardless of the owner using pagination - pub fn nft_tokens(&self, from_index: Option, limit: Option) -> Vec { + pub fn nft_tokens(&self, from_index: Option, limit: Option) -> Vec { //where to start pagination - if we have a from_index, we'll use that - otherwise start from 0 index - let start = from_index.unwrap_or(0); + let start = u128::from(from_index.unwrap_or(U128(0))); //iterate through each token using an iterator self.token_metadata_by_id.keys() @@ -46,8 +46,8 @@ impl Contract { pub fn nft_tokens_for_owner( &self, account_id: AccountId, - from_index: Option, - limit: Option, + from_index: Option, + limit: Option, ) -> Vec { //get the set of tokens for the passed in owner let tokens_for_owner_set = self.tokens_per_owner.get(&account_id); @@ -60,7 +60,7 @@ impl Contract { }; //where to start pagination - if we have a from_index, we'll use that - otherwise start from 0 index - let start = from_index.unwrap_or(0); + let start = u128::from(from_index.unwrap_or(U128(0))); //iterate through the keys vector tokens.iter() diff --git a/nft-contract-approval/src/internal.rs b/nft-contract-approval/src/internal.rs index d1695d8..54ce98c 100644 --- a/nft-contract-approval/src/internal.rs +++ b/nft-contract-approval/src/internal.rs @@ -22,7 +22,7 @@ pub(crate) fn refund_approved_account_ids_iter<'a, I>( //refund a map of approved account IDs and send the funds to the passed in account ID pub(crate) fn refund_approved_account_ids( account_id: AccountId, - approved_account_ids: &HashMap, + approved_account_ids: &HashMap, ) -> Promise { //call the refund_approved_account_ids_iter with the approved account IDs as keys refund_approved_account_ids_iter(account_id, approved_account_ids.keys()) @@ -134,7 +134,7 @@ impl Contract { receiver_id: &AccountId, token_id: &TokenId, //we introduce an approval ID so that people with that approval ID can transfer the token - approval_id: Option, + approval_id: Option, memo: Option, ) -> Token { //get the token object by passing in the token_id diff --git a/nft-contract-approval/src/metadata.rs b/nft-contract-approval/src/metadata.rs index 1c9ab53..a582828 100644 --- a/nft-contract-approval/src/metadata.rs +++ b/nft-contract-approval/src/metadata.rs @@ -44,9 +44,9 @@ 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, + pub approved_account_ids: HashMap, //the next approval ID to give out. - pub next_approval_id: u64, + pub next_approval_id: u32, } //The Json token is what will be returned from view calls. @@ -60,7 +60,7 @@ pub struct JsonToken { //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, + pub approved_account_ids: HashMap, } pub trait NonFungibleTokenMetadata { diff --git a/nft-contract-approval/src/nft_core.rs b/nft-contract-approval/src/nft_core.rs index 1be044e..6f04739 100644 --- a/nft-contract-approval/src/nft_core.rs +++ b/nft-contract-approval/src/nft_core.rs @@ -11,7 +11,7 @@ pub trait NonFungibleTokenCore { receiver_id: AccountId, token_id: TokenId, //we introduce an approval ID so that people with that approval ID can transfer the token - approval_id: Option, + approval_id: Option, memo: Option, ); @@ -22,7 +22,7 @@ pub trait NonFungibleTokenCore { receiver_id: AccountId, token_id: TokenId, //we introduce an approval ID so that people with that approval ID can transfer the token - approval_id: Option, + approval_id: Option, memo: Option, msg: String, ) -> PromiseOrValue; @@ -59,7 +59,7 @@ trait NonFungibleTokenResolver { receiver_id: AccountId, token_id: TokenId, //we introduce the approval map so we can keep track of what the approvals were before the transfer - approved_account_ids: HashMap, + approved_account_ids: HashMap, //we introduce a memo for logging the transfer event memo: Option, ) -> bool; @@ -74,7 +74,7 @@ impl NonFungibleTokenCore for Contract { receiver_id: AccountId, token_id: TokenId, //we introduce an approval ID so that people with that approval ID can transfer the token - approval_id: Option, + approval_id: Option, memo: Option, ) { //assert that the user attached exactly 1 yoctoNEAR. This is for security and so that the user will be redirected to the NEAR wallet. @@ -105,7 +105,7 @@ impl NonFungibleTokenCore for Contract { receiver_id: AccountId, token_id: TokenId, //we introduce an approval ID so that people with that approval ID can transfer the token - approval_id: Option, + approval_id: Option, memo: Option, msg: String, ) -> PromiseOrValue { @@ -189,7 +189,7 @@ impl NonFungibleTokenResolver for Contract { receiver_id: AccountId, token_id: TokenId, //we introduce the approval map so we can keep track of what the approvals were before the transfer - approved_account_ids: HashMap, + approved_account_ids: HashMap, //we introduce a memo for logging the transfer event memo: Option, ) -> bool { diff --git a/nft-contract-approval/src/royalty.rs b/nft-contract-approval/src/royalty.rs index 7646f9e..0ee4c7a 100644 --- a/nft-contract-approval/src/royalty.rs +++ b/nft-contract-approval/src/royalty.rs @@ -9,7 +9,7 @@ pub trait NonFungibleTokenCore { &mut self, receiver_id: AccountId, token_id: TokenId, - approval_id: u64, + approval_id: u32, memo: Option, balance: U128, max_len_payout: u32, @@ -33,7 +33,7 @@ impl NonFungibleTokenCore for Contract { &mut self, receiver_id: AccountId, token_id: TokenId, - approval_id: u64, + approval_id: u32, memo: Option, balance: U128, max_len_payout: u32, diff --git a/nft-contract-basic/src/approval.rs b/nft-contract-basic/src/approval.rs index 9d72d6c..8e55739 100644 --- a/nft-contract-basic/src/approval.rs +++ b/nft-contract-basic/src/approval.rs @@ -10,7 +10,7 @@ pub trait NonFungibleTokenCore { &self, token_id: TokenId, approved_account_id: AccountId, - approval_id: Option, + approval_id: Option, ) -> bool; //revoke a specific account from transferring the token on your behalf @@ -27,7 +27,7 @@ trait NonFungibleTokenApprovalsReceiver { &mut self, token_id: TokenId, owner_id: AccountId, - approval_id: u64, + approval_id: u32, msg: String, ); } @@ -47,7 +47,7 @@ impl NonFungibleTokenCore for Contract { &self, token_id: TokenId, approved_account_id: AccountId, - approval_id: Option, + approval_id: Option, ) -> bool { /* FILL THIS IN diff --git a/nft-contract-basic/src/enumeration.rs b/nft-contract-basic/src/enumeration.rs index 5926561..49ebc6f 100644 --- a/nft-contract-basic/src/enumeration.rs +++ b/nft-contract-basic/src/enumeration.rs @@ -9,9 +9,9 @@ impl Contract { } //Query for nft tokens on the contract regardless of the owner using pagination - pub fn nft_tokens(&self, from_index: Option, limit: Option) -> Vec { + pub fn nft_tokens(&self, from_index: Option, limit: Option) -> Vec { //where to start pagination - if we have a from_index, we'll use that - otherwise start from 0 index - let start = from_index.unwrap_or(0); + let start = u128::from(from_index.unwrap_or(U128(0))); //iterate through each token using an iterator self.token_metadata_by_id.keys() @@ -46,8 +46,8 @@ impl Contract { pub fn nft_tokens_for_owner( &self, account_id: AccountId, - from_index: Option, - limit: Option, + from_index: Option, + limit: Option, ) -> Vec { //get the set of tokens for the passed in owner let tokens_for_owner_set = self.tokens_per_owner.get(&account_id); @@ -60,7 +60,7 @@ impl Contract { }; //where to start pagination - if we have a from_index, we'll use that - otherwise start from 0 index - let start = from_index.unwrap_or(0); + let start = u128::from(from_index.unwrap_or(U128(0))); //iterate through the keys vector tokens.iter() diff --git a/nft-contract-basic/src/royalty.rs b/nft-contract-basic/src/royalty.rs index 7646f9e..0ee4c7a 100644 --- a/nft-contract-basic/src/royalty.rs +++ b/nft-contract-basic/src/royalty.rs @@ -9,7 +9,7 @@ pub trait NonFungibleTokenCore { &mut self, receiver_id: AccountId, token_id: TokenId, - approval_id: u64, + approval_id: u32, memo: Option, balance: U128, max_len_payout: u32, @@ -33,7 +33,7 @@ impl NonFungibleTokenCore for Contract { &mut self, receiver_id: AccountId, token_id: TokenId, - approval_id: u64, + approval_id: u32, memo: Option, balance: U128, max_len_payout: u32, diff --git a/nft-contract-events/src/approval.rs b/nft-contract-events/src/approval.rs index 9d72d6c..8e55739 100644 --- a/nft-contract-events/src/approval.rs +++ b/nft-contract-events/src/approval.rs @@ -10,7 +10,7 @@ pub trait NonFungibleTokenCore { &self, token_id: TokenId, approved_account_id: AccountId, - approval_id: Option, + approval_id: Option, ) -> bool; //revoke a specific account from transferring the token on your behalf @@ -27,7 +27,7 @@ trait NonFungibleTokenApprovalsReceiver { &mut self, token_id: TokenId, owner_id: AccountId, - approval_id: u64, + approval_id: u32, msg: String, ); } @@ -47,7 +47,7 @@ impl NonFungibleTokenCore for Contract { &self, token_id: TokenId, approved_account_id: AccountId, - approval_id: Option, + approval_id: Option, ) -> bool { /* FILL THIS IN diff --git a/nft-contract-events/src/enumeration.rs b/nft-contract-events/src/enumeration.rs index 5926561..49ebc6f 100644 --- a/nft-contract-events/src/enumeration.rs +++ b/nft-contract-events/src/enumeration.rs @@ -9,9 +9,9 @@ impl Contract { } //Query for nft tokens on the contract regardless of the owner using pagination - pub fn nft_tokens(&self, from_index: Option, limit: Option) -> Vec { + pub fn nft_tokens(&self, from_index: Option, limit: Option) -> Vec { //where to start pagination - if we have a from_index, we'll use that - otherwise start from 0 index - let start = from_index.unwrap_or(0); + let start = u128::from(from_index.unwrap_or(U128(0))); //iterate through each token using an iterator self.token_metadata_by_id.keys() @@ -46,8 +46,8 @@ impl Contract { pub fn nft_tokens_for_owner( &self, account_id: AccountId, - from_index: Option, - limit: Option, + from_index: Option, + limit: Option, ) -> Vec { //get the set of tokens for the passed in owner let tokens_for_owner_set = self.tokens_per_owner.get(&account_id); @@ -60,7 +60,7 @@ impl Contract { }; //where to start pagination - if we have a from_index, we'll use that - otherwise start from 0 index - let start = from_index.unwrap_or(0); + let start = u128::from(from_index.unwrap_or(U128(0))); //iterate through the keys vector tokens.iter() diff --git a/nft-contract-events/src/royalty.rs b/nft-contract-events/src/royalty.rs index 7646f9e..0ee4c7a 100644 --- a/nft-contract-events/src/royalty.rs +++ b/nft-contract-events/src/royalty.rs @@ -9,7 +9,7 @@ pub trait NonFungibleTokenCore { &mut self, receiver_id: AccountId, token_id: TokenId, - approval_id: u64, + approval_id: u32, memo: Option, balance: U128, max_len_payout: u32, @@ -33,7 +33,7 @@ impl NonFungibleTokenCore for Contract { &mut self, receiver_id: AccountId, token_id: TokenId, - approval_id: u64, + approval_id: u32, memo: Option, balance: U128, max_len_payout: u32, diff --git a/nft-contract-royalty/src/approval.rs b/nft-contract-royalty/src/approval.rs index 3dda71a..6ea2317 100644 --- a/nft-contract-royalty/src/approval.rs +++ b/nft-contract-royalty/src/approval.rs @@ -10,7 +10,7 @@ pub trait NonFungibleTokenCore { &self, token_id: TokenId, approved_account_id: AccountId, - approval_id: Option, + approval_id: Option, ) -> bool; //revoke a specific account from transferring the token on your behalf @@ -27,7 +27,7 @@ trait NonFungibleTokenApprovalsReceiver { &mut self, token_id: TokenId, owner_id: AccountId, - approval_id: u64, + approval_id: u32, msg: String, ); } @@ -54,7 +54,7 @@ impl NonFungibleTokenCore for Contract { ); //get the next approval ID if we need a new approval - let approval_id: u64 = token.next_approval_id; + let approval_id: u32 = token.next_approval_id; //check if the account has been approved already for this token let is_new_approval = token @@ -99,7 +99,7 @@ impl NonFungibleTokenCore for Contract { &self, token_id: TokenId, approved_account_id: AccountId, - approval_id: Option, + approval_id: Option, ) -> bool { //get the token object from the token_id let token = self.tokens_by_id.get(&token_id).expect("No token"); diff --git a/nft-contract-royalty/src/enumeration.rs b/nft-contract-royalty/src/enumeration.rs index 5926561..49ebc6f 100644 --- a/nft-contract-royalty/src/enumeration.rs +++ b/nft-contract-royalty/src/enumeration.rs @@ -9,9 +9,9 @@ impl Contract { } //Query for nft tokens on the contract regardless of the owner using pagination - pub fn nft_tokens(&self, from_index: Option, limit: Option) -> Vec { + pub fn nft_tokens(&self, from_index: Option, limit: Option) -> Vec { //where to start pagination - if we have a from_index, we'll use that - otherwise start from 0 index - let start = from_index.unwrap_or(0); + let start = u128::from(from_index.unwrap_or(U128(0))); //iterate through each token using an iterator self.token_metadata_by_id.keys() @@ -46,8 +46,8 @@ impl Contract { pub fn nft_tokens_for_owner( &self, account_id: AccountId, - from_index: Option, - limit: Option, + from_index: Option, + limit: Option, ) -> Vec { //get the set of tokens for the passed in owner let tokens_for_owner_set = self.tokens_per_owner.get(&account_id); @@ -60,7 +60,7 @@ impl Contract { }; //where to start pagination - if we have a from_index, we'll use that - otherwise start from 0 index - let start = from_index.unwrap_or(0); + let start = u128::from(from_index.unwrap_or(U128(0))); //iterate through the keys vector tokens.iter() diff --git a/nft-contract-royalty/src/internal.rs b/nft-contract-royalty/src/internal.rs index 0f3895b..05e3aa2 100644 --- a/nft-contract-royalty/src/internal.rs +++ b/nft-contract-royalty/src/internal.rs @@ -27,7 +27,7 @@ pub(crate) fn refund_approved_account_ids_iter<'a, I>( //refund a map of approved account IDs and send the funds to the passed in account ID pub(crate) fn refund_approved_account_ids( account_id: AccountId, - approved_account_ids: &HashMap, + approved_account_ids: &HashMap, ) -> Promise { //call the refund_approved_account_ids_iter with the approved account IDs as keys refund_approved_account_ids_iter(account_id, approved_account_ids.keys()) @@ -139,7 +139,7 @@ impl Contract { receiver_id: &AccountId, token_id: &TokenId, //we introduce an approval ID so that people with that approval ID can transfer the token - approval_id: Option, + approval_id: Option, memo: Option, ) -> Token { //get the token object by passing in the token_id diff --git a/nft-contract-royalty/src/metadata.rs b/nft-contract-royalty/src/metadata.rs index 3153b89..7d1c536 100644 --- a/nft-contract-royalty/src/metadata.rs +++ b/nft-contract-royalty/src/metadata.rs @@ -44,9 +44,9 @@ 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, + pub approved_account_ids: HashMap, //the next approval ID to give out. - pub next_approval_id: u64, + pub next_approval_id: u32, //keep track of the royalty percentages for the token in a hash map pub royalty: HashMap, } @@ -62,7 +62,7 @@ pub struct JsonToken { //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, + pub approved_account_ids: HashMap, //keep track of the royalty percentages for the token in a hash map pub royalty: HashMap, } diff --git a/nft-contract-royalty/src/nft_core.rs b/nft-contract-royalty/src/nft_core.rs index 61f4898..5286a97 100644 --- a/nft-contract-royalty/src/nft_core.rs +++ b/nft-contract-royalty/src/nft_core.rs @@ -11,7 +11,7 @@ pub trait NonFungibleTokenCore { receiver_id: AccountId, token_id: TokenId, //we introduce an approval ID so that people with that approval ID can transfer the token - approval_id: Option, + approval_id: Option, memo: Option, ); @@ -22,7 +22,7 @@ pub trait NonFungibleTokenCore { receiver_id: AccountId, token_id: TokenId, //we introduce an approval ID so that people with that approval ID can transfer the token - approval_id: Option, + approval_id: Option, memo: Option, msg: String, ) -> PromiseOrValue; @@ -59,7 +59,7 @@ trait NonFungibleTokenResolver { receiver_id: AccountId, token_id: TokenId, //we introduce the approval map so we can keep track of what the approvals were before the transfer - approved_account_ids: HashMap, + approved_account_ids: HashMap, //we introduce a memo for logging the transfer event memo: Option, ) -> bool; @@ -74,7 +74,7 @@ impl NonFungibleTokenCore for Contract { receiver_id: AccountId, token_id: TokenId, //we introduce an approval ID so that people with that approval ID can transfer the token - approval_id: Option, + approval_id: Option, memo: Option, ) { //assert that the user attached exactly 1 yoctoNEAR. This is for security and so that the user will be redirected to the NEAR wallet. @@ -105,7 +105,7 @@ impl NonFungibleTokenCore for Contract { receiver_id: AccountId, token_id: TokenId, //we introduce an approval ID so that people with that approval ID can transfer the token - approval_id: Option, + approval_id: Option, memo: Option, msg: String, ) -> PromiseOrValue { @@ -190,7 +190,7 @@ impl NonFungibleTokenResolver for Contract { receiver_id: AccountId, token_id: TokenId, //we introduce the approval map so we can keep track of what the approvals were before the transfer - approved_account_ids: HashMap, + approved_account_ids: HashMap, //we introduce a memo for logging the transfer event memo: Option, ) -> bool { diff --git a/nft-contract-royalty/src/royalty.rs b/nft-contract-royalty/src/royalty.rs index 6e6cbb8..a1d6be9 100644 --- a/nft-contract-royalty/src/royalty.rs +++ b/nft-contract-royalty/src/royalty.rs @@ -9,7 +9,7 @@ pub trait NonFungibleTokenCore { &mut self, receiver_id: AccountId, token_id: TokenId, - approval_id: u64, + approval_id: u32, memo: Option, balance: U128, max_len_payout: u32, @@ -72,7 +72,7 @@ impl NonFungibleTokenCore for Contract { &mut self, receiver_id: AccountId, token_id: TokenId, - approval_id: u64, + approval_id: u32, memo: Option, balance: U128, max_len_payout: u32, diff --git a/nft-contract-skeleton/src/approval.rs b/nft-contract-skeleton/src/approval.rs index 9d72d6c..8e55739 100644 --- a/nft-contract-skeleton/src/approval.rs +++ b/nft-contract-skeleton/src/approval.rs @@ -10,7 +10,7 @@ pub trait NonFungibleTokenCore { &self, token_id: TokenId, approved_account_id: AccountId, - approval_id: Option, + approval_id: Option, ) -> bool; //revoke a specific account from transferring the token on your behalf @@ -27,7 +27,7 @@ trait NonFungibleTokenApprovalsReceiver { &mut self, token_id: TokenId, owner_id: AccountId, - approval_id: u64, + approval_id: u32, msg: String, ); } @@ -47,7 +47,7 @@ impl NonFungibleTokenCore for Contract { &self, token_id: TokenId, approved_account_id: AccountId, - approval_id: Option, + approval_id: Option, ) -> bool { /* FILL THIS IN diff --git a/nft-contract-skeleton/src/enumeration.rs b/nft-contract-skeleton/src/enumeration.rs index d80f47a..c41d21b 100644 --- a/nft-contract-skeleton/src/enumeration.rs +++ b/nft-contract-skeleton/src/enumeration.rs @@ -11,7 +11,7 @@ impl Contract { } //Query for nft tokens on the contract regardless of the owner using pagination - pub fn nft_tokens(&self, from_index: Option, limit: Option) -> Vec { + pub fn nft_tokens(&self, from_index: Option, limit: Option) -> Vec { /* FILL THIS IN */ @@ -33,8 +33,8 @@ impl Contract { pub fn nft_tokens_for_owner( &self, account_id: AccountId, - from_index: Option, - limit: Option, + from_index: Option, + limit: Option, ) -> Vec { /* FILL THIS IN diff --git a/nft-contract-skeleton/src/royalty.rs b/nft-contract-skeleton/src/royalty.rs index b71f42e..3eeea83 100644 --- a/nft-contract-skeleton/src/royalty.rs +++ b/nft-contract-skeleton/src/royalty.rs @@ -9,7 +9,7 @@ pub trait NonFungibleTokenCore { &mut self, receiver_id: AccountId, token_id: TokenId, - approval_id: u64, + approval_id: u32, memo: Option, balance: U128, max_len_payout: u32, @@ -32,7 +32,7 @@ impl NonFungibleTokenCore for Contract { &mut self, receiver_id: AccountId, token_id: TokenId, - approval_id: u64, + approval_id: u32, memo: Option, balance: U128, max_len_payout: u32, diff --git a/nft-series/src/approval.rs b/nft-series/src/approval.rs index 6755a53..4791558 100644 --- a/nft-series/src/approval.rs +++ b/nft-series/src/approval.rs @@ -10,7 +10,7 @@ pub trait NonFungibleTokenCore { &self, token_id: TokenId, approved_account_id: AccountId, - approval_id: Option, + approval_id: Option, ) -> bool; //revoke a specific account from transferring the token on your behalf @@ -27,7 +27,7 @@ trait NonFungibleTokenApprovalsReceiver { &mut self, token_id: TokenId, owner_id: AccountId, - approval_id: u64, + approval_id: u32, msg: String, ); } @@ -54,7 +54,7 @@ impl NonFungibleTokenCore for Contract { ); //get the next approval ID if we need a new approval - let approval_id: u64 = token.next_approval_id; + let approval_id: u32 = token.next_approval_id; //check if the account has been approved already for this token let is_new_approval = token @@ -95,7 +95,7 @@ impl NonFungibleTokenCore for Contract { &self, token_id: TokenId, approved_account_id: AccountId, - approval_id: Option, + approval_id: Option, ) -> bool { //get the token object from the token_id let token = self.tokens_by_id.get(&token_id).expect("No token"); diff --git a/nft-series/src/enumeration.rs b/nft-series/src/enumeration.rs index 2dd505b..f04c00e 100644 --- a/nft-series/src/enumeration.rs +++ b/nft-series/src/enumeration.rs @@ -25,9 +25,9 @@ impl Contract { } //Query for nft tokens on the contract regardless of the owner using pagination - pub fn nft_tokens(&self, from_index: Option, limit: Option) -> Vec { + pub fn nft_tokens(&self, from_index: Option, limit: Option) -> Vec { //where to start pagination - if we have a from_index, we'll use that - otherwise start from 0 index - let start = from_index.unwrap_or(0); + let start = u128::from(from_index.unwrap_or(U128(0))); //iterate through each token using an iterator self.tokens_by_id @@ -60,8 +60,8 @@ impl Contract { pub fn nft_tokens_for_owner( &self, account_id: AccountId, - from_index: Option, - limit: Option, + from_index: Option, + limit: Option, ) -> Vec { //get the set of tokens for the passed in owner let tokens_for_owner_set = self.tokens_per_owner.get(&account_id); @@ -74,7 +74,7 @@ impl Contract { }; //where to start pagination - if we have a from_index, we'll use that - otherwise start from 0 index - let start = from_index.unwrap_or(0); + let start = u128::from(from_index.unwrap_or(U128(0))); //iterate through the keys vector tokens @@ -95,9 +95,9 @@ impl Contract { } // Paginate through all the series on the contract and return the a vector of JsonSeries - pub fn get_series(&self, from_index: Option, limit: Option) -> Vec { + pub fn get_series(&self, from_index: Option, limit: Option) -> Vec { //where to start pagination - if we have a from_index, we'll use that - otherwise start from 0 index - let start = from_index.unwrap_or(0); + let start = u128::from(from_index.unwrap_or(U128(0))); //iterate through each series using an iterator self.series_by_id @@ -107,19 +107,19 @@ impl Contract { //take the first "limit" elements in the vector. If we didn't specify a limit, use 50 .take(limit.unwrap_or(50) as usize) //we'll map the series IDs which are strings into Json Series - .map(|series_id| self.get_series_details(series_id.clone()).unwrap()) + .map(|series_id| self.get_series_details(U64(series_id.clone())).unwrap()) //since we turned the keys into an iterator, we need to turn it back into a vector to return .collect() } // get info for a specific series - pub fn get_series_details(&self, id: u64) -> Option { + pub fn get_series_details(&self, id: U64) -> Option { //get the series from the map - let series = self.series_by_id.get(&id); + let series = self.series_by_id.get(&id.0); //if there is some series, we'll return the series if let Some(series) = series { Some(JsonSeries { - series_id: id, + series_id: id.0, metadata: series.metadata, royalty: series.royalty, owner_id: series.owner_id, @@ -131,9 +131,9 @@ impl Contract { } //get the total supply of NFTs on a current series - pub fn nft_supply_for_series(&self, id: u64) -> U64 { + pub fn nft_supply_for_series(&self, id: U64) -> U64 { //get the series - let series = self.series_by_id.get(&id); + let series = self.series_by_id.get(&id.0); //if there is some series, get the length of the tokens. Otherwise return - if let Some(series) = series { @@ -146,12 +146,12 @@ impl Contract { /// Paginate through NFTs within a given series pub fn nft_tokens_for_series( &self, - id: u64, - from_index: Option, - limit: Option, + id: U64, + from_index: Option, + limit: Option, ) -> Vec { // Get the series and its tokens - let series = self.series_by_id.get(&id); + let series = self.series_by_id.get(&id.0); let tokens = if let Some(series) = series { series.tokens } else { @@ -159,7 +159,7 @@ impl Contract { }; //where to start pagination - if we have a from_index, we'll use that - otherwise start from 0 index - let start = from_index.unwrap_or(0); + let start = u128::from(from_index.unwrap_or(U128(0))); //iterate through the tokens tokens diff --git a/nft-series/src/internal.rs b/nft-series/src/internal.rs index 1e9f959..534db42 100644 --- a/nft-series/src/internal.rs +++ b/nft-series/src/internal.rs @@ -31,7 +31,7 @@ pub(crate) fn refund_approved_account_ids_iter<'a, I>( //refund a map of approved account IDs and send the funds to the passed in account ID pub(crate) fn refund_approved_account_ids( account_id: AccountId, - approved_account_ids: &HashMap, + approved_account_ids: &HashMap, ) -> Promise { //call the refund_approved_account_ids_iter with the approved account IDs as keys refund_approved_account_ids_iter(account_id, approved_account_ids.keys()) @@ -172,7 +172,7 @@ impl Contract { receiver_id: &AccountId, token_id: &TokenId, //we introduce an approval ID so that people with that approval ID can transfer the token - approval_id: Option, + approval_id: Option, memo: Option, ) -> Token { //get the token object by passing in the token_id diff --git a/nft-series/src/metadata.rs b/nft-series/src/metadata.rs index 4f2f025..d2cfa5e 100644 --- a/nft-series/src/metadata.rs +++ b/nft-series/src/metadata.rs @@ -46,9 +46,9 @@ 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, + pub approved_account_ids: HashMap, //the next approval ID to give out. - pub next_approval_id: u64, + pub next_approval_id: u32, } //The Json token is what will be returned from view calls. @@ -64,7 +64,7 @@ pub struct JsonToken { //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, + pub approved_account_ids: HashMap, //keep track of the royalty percentages for the token in a hash map pub royalty: Option>, } diff --git a/nft-series/src/nft_core.rs b/nft-series/src/nft_core.rs index 6166edf..9f3d3a1 100644 --- a/nft-series/src/nft_core.rs +++ b/nft-series/src/nft_core.rs @@ -11,7 +11,7 @@ pub trait NonFungibleTokenCore { receiver_id: AccountId, token_id: TokenId, //we introduce an approval ID so that people with that approval ID can transfer the token - approval_id: Option, + approval_id: Option, memo: Option, ); @@ -22,7 +22,7 @@ pub trait NonFungibleTokenCore { receiver_id: AccountId, token_id: TokenId, //we introduce an approval ID so that people with that approval ID can transfer the token - approval_id: Option, + approval_id: Option, memo: Option, msg: String, ) -> PromiseOrValue; @@ -59,7 +59,7 @@ trait NonFungibleTokenResolver { receiver_id: AccountId, token_id: TokenId, //we introduce the approval map so we can keep track of what the approvals were before the transfer - approved_account_ids: HashMap, + approved_account_ids: HashMap, //we introduce a memo for logging the transfer event memo: Option, ) -> bool; @@ -74,7 +74,7 @@ impl NonFungibleTokenCore for Contract { receiver_id: AccountId, token_id: TokenId, //we introduce an approval ID so that people with that approval ID can transfer the token - approval_id: Option, + approval_id: Option, memo: Option, ) { //assert that the user attached exactly 1 yoctoNEAR. This is for security and so that the user will be redirected to the NEAR wallet. @@ -100,7 +100,7 @@ impl NonFungibleTokenCore for Contract { receiver_id: AccountId, token_id: TokenId, //we introduce an approval ID so that people with that approval ID can transfer the token - approval_id: Option, + approval_id: Option, memo: Option, msg: String, ) -> PromiseOrValue { @@ -205,7 +205,7 @@ impl NonFungibleTokenResolver for Contract { receiver_id: AccountId, token_id: TokenId, //we introduce the approval map so we can keep track of what the approvals were before the transfer - approved_account_ids: HashMap, + approved_account_ids: HashMap, //we introduce a memo for logging the transfer event memo: Option, ) -> bool { diff --git a/nft-series/src/royalty.rs b/nft-series/src/royalty.rs index 7e3ab35..25de1a5 100644 --- a/nft-series/src/royalty.rs +++ b/nft-series/src/royalty.rs @@ -9,7 +9,7 @@ pub trait NonFungibleTokenCore { &mut self, receiver_id: AccountId, token_id: TokenId, - approval_id: u64, + approval_id: u32, memo: Option, balance: U128, max_len_payout: u32, @@ -87,7 +87,7 @@ impl NonFungibleTokenCore for Contract { &mut self, receiver_id: AccountId, token_id: TokenId, - approval_id: u64, + approval_id: u32, memo: Option, balance: U128, max_len_payout: u32, diff --git a/nft-series/src/series.rs b/nft-series/src/series.rs index 72b7f9b..a72858b 100644 --- a/nft-series/src/series.rs +++ b/nft-series/src/series.rs @@ -10,7 +10,7 @@ impl Contract { #[payable] pub fn create_series( &mut self, - id: u64, + id: U64, metadata: TokenMetadata, royalty: Option>, price: Option @@ -29,7 +29,7 @@ impl Contract { require!( self.series_by_id .insert( - &id, + &id.0, &Series { metadata, royalty, @@ -37,7 +37,7 @@ impl Contract { // We get a new unique prefix for the collection account_id_hash: hash_account_id(&format!( "{}{}", - id, caller + id.0, caller )), }), owner_id: caller, @@ -58,12 +58,12 @@ impl Contract { /// Mint a new NFT that is part of a series. The caller must be an approved minter. /// The series ID must exist and if the metadata specifies a copy limit, you cannot exceed it. #[payable] - pub fn nft_mint(&mut self, id: u64, receiver_id: AccountId) { + pub fn nft_mint(&mut self, id: U64, receiver_id: AccountId) { // Measure the initial storage being used on the contract let initial_storage_usage = env::storage_usage(); // Get the series and how many tokens currently exist (edition number = cur_len + 1) - let mut series = self.series_by_id.get(&id).expect("Not a series"); + let mut series = self.series_by_id.get(&id.0).expect("Not a series"); // Check if the series has a price per token. If it does, ensure the caller has attached at least that amount let mut price_per_token = NearToken::from_yoctonear(0); @@ -90,14 +90,14 @@ impl Contract { } // The token ID is stored internally as `${series_id}:${edition}` - let token_id = format!("{}:{}", id, cur_len + 1); + let token_id = format!("{}:{}", id.0, cur_len + 1); series.tokens.insert(&token_id); - self.series_by_id.insert(&id, &series); + self.series_by_id.insert(&id.0, &series); //specify the token struct that contains the owner ID let token = Token { // Series ID that the token belongs to - series_id: id, + series_id: id.0, //set the owner ID equal to the receiver ID passed into the function owner_id: receiver_id, //we set the approved account IDs to the default value (an empty map)