From 93ad30bf972f91ee8bde0f8ea5820d40b9ab7aef Mon Sep 17 00:00:00 2001 From: austinabell Date: Thu, 15 Jul 2021 18:16:59 -0400 Subject: [PATCH 1/5] fix(nft): nft_token method switched to only take reference to token struct --- Cargo.lock | 4 +++- near-contract-standards/Cargo.toml | 2 +- .../src/non_fungible_token/core/core_impl.rs | 5 +++-- near-contract-standards/src/non_fungible_token/core/mod.rs | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cb96b93f1..31cc8fe53 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "Inflector" version = "0.11.4" @@ -1494,7 +1496,7 @@ checksum = "0debeb9fcf88823ea64d64e4a815ab1643f33127d995978e099942ce38f25238" [[package]] name = "near-contract-standards" -version = "3.2.0" +version = "3.3.0" dependencies = [ "near-sdk", ] diff --git a/near-contract-standards/Cargo.toml b/near-contract-standards/Cargo.toml index 76320de7a..cb55b798e 100644 --- a/near-contract-standards/Cargo.toml +++ b/near-contract-standards/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "near-contract-standards" -version = "3.2.0" +version = "3.3.0" authors = ["Near Inc "] edition = "2018" license = "GPL-3.0" diff --git a/near-contract-standards/src/non_fungible_token/core/core_impl.rs b/near-contract-standards/src/non_fungible_token/core/core_impl.rs index e2675b8fc..fd00f52cf 100644 --- a/near-contract-standards/src/non_fungible_token/core/core_impl.rs +++ b/near-contract-standards/src/non_fungible_token/core/core_impl.rs @@ -329,11 +329,12 @@ impl NonFungibleTokenCore for NonFungibleToken { .into() } - fn nft_token(self, token_id: TokenId) -> Option { + fn nft_token(&self, token_id: TokenId) -> Option { let owner_id = self.owner_by_id.get(&token_id)?; - let metadata = self.token_metadata_by_id.and_then(|by_id| by_id.get(&token_id)); + let metadata = self.token_metadata_by_id.as_ref().and_then(|by_id| by_id.get(&token_id)); let approved_account_ids = self .approvals_by_id + .as_ref() .and_then(|by_id| by_id.get(&token_id).or_else(|| Some(HashMap::new()))); Some(Token { token_id, owner_id, metadata, approved_account_ids }) } diff --git a/near-contract-standards/src/non_fungible_token/core/mod.rs b/near-contract-standards/src/non_fungible_token/core/mod.rs index f62947f35..a9ef76e0e 100644 --- a/near-contract-standards/src/non_fungible_token/core/mod.rs +++ b/near-contract-standards/src/non_fungible_token/core/mod.rs @@ -94,7 +94,7 @@ pub trait NonFungibleTokenCore { ) -> PromiseOrValue; /// Returns the token with the given `token_id` or `null` if no such token. - fn nft_token(self, token_id: TokenId) -> Option; + fn nft_token(&self, token_id: TokenId) -> Option; /// Mint a new token. Not part of official standard, but needed in most situations. /// Consuming contract expected to wrap this with an `nft_mint` function. From 87ad46a7f5423c672354e159380e65a2a87327a6 Mon Sep 17 00:00:00 2001 From: austinabell Date: Thu, 15 Jul 2021 18:19:28 -0400 Subject: [PATCH 2/5] update macro generated code too --- near-contract-standards/src/non_fungible_token/macros.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/near-contract-standards/src/non_fungible_token/macros.rs b/near-contract-standards/src/non_fungible_token/macros.rs index 0edf0d80b..1c6620aa6 100644 --- a/near-contract-standards/src/non_fungible_token/macros.rs +++ b/near-contract-standards/src/non_fungible_token/macros.rs @@ -32,7 +32,7 @@ macro_rules! impl_non_fungible_token_core { self.$token.nft_transfer_call(receiver_id, token_id, approval_id, memo, msg) } - fn nft_token(self, token_id: TokenId) -> Option { + fn nft_token(&self, token_id: TokenId) -> Option { self.$token.nft_token(token_id) } From a9aee2b751fafb20605e6df725cdf5183a7768c4 Mon Sep 17 00:00:00 2001 From: austinabell Date: Thu, 15 Jul 2021 18:21:13 -0400 Subject: [PATCH 3/5] update enumeration standard interface also --- .../src/non_fungible_token/enumeration/enumeration_impl.rs | 6 +++--- .../src/non_fungible_token/enumeration/mod.rs | 4 ++-- near-contract-standards/src/non_fungible_token/macros.rs | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/near-contract-standards/src/non_fungible_token/enumeration/enumeration_impl.rs b/near-contract-standards/src/non_fungible_token/enumeration/enumeration_impl.rs index 30b8076b2..62069627f 100644 --- a/near-contract-standards/src/non_fungible_token/enumeration/enumeration_impl.rs +++ b/near-contract-standards/src/non_fungible_token/enumeration/enumeration_impl.rs @@ -19,7 +19,7 @@ impl NonFungibleToken { } impl NonFungibleTokenEnumeration for NonFungibleToken { - fn nft_total_supply(self) -> U128 { + fn nft_total_supply(&self) -> U128 { // An unfortunate cast from the max of TreeMap to the spec (self.owner_by_id.len() as u128).into() } @@ -43,8 +43,8 @@ impl NonFungibleTokenEnumeration for NonFungibleToken { .collect() } - fn nft_supply_for_owner(self, account_id: AccountId) -> U128 { - let tokens_per_owner = self.tokens_per_owner.expect( + fn nft_supply_for_owner(&self, account_id: AccountId) -> U128 { + let tokens_per_owner = self.tokens_per_owner.as_ref().expect( "Could not find tokens_per_owner when calling a method on the enumeration standard.", ); tokens_per_owner diff --git a/near-contract-standards/src/non_fungible_token/enumeration/mod.rs b/near-contract-standards/src/non_fungible_token/enumeration/mod.rs index 15a3e2bea..f38f513d1 100644 --- a/near-contract-standards/src/non_fungible_token/enumeration/mod.rs +++ b/near-contract-standards/src/non_fungible_token/enumeration/mod.rs @@ -8,7 +8,7 @@ use near_sdk::AccountId; pub trait NonFungibleTokenEnumeration { /// Returns the total supply of non-fungible tokens as a string representing an /// unsigned 128-bit integer to avoid JSON number limit of 2^53. - fn nft_total_supply(self) -> U128; + fn nft_total_supply(&self) -> U128; /// Get a list of all tokens /// @@ -32,7 +32,7 @@ pub trait NonFungibleTokenEnumeration { /// Returns the number of non-fungible tokens owned by given `account_id` as /// a string representing the value as an unsigned 128-bit integer to avoid JSON /// number limit of 2^53. - fn nft_supply_for_owner(self, account_id: AccountId) -> U128; + fn nft_supply_for_owner(&self, account_id: AccountId) -> U128; /// Get list of all tokens owned by a given account /// diff --git a/near-contract-standards/src/non_fungible_token/macros.rs b/near-contract-standards/src/non_fungible_token/macros.rs index 1c6620aa6..52ab89a00 100644 --- a/near-contract-standards/src/non_fungible_token/macros.rs +++ b/near-contract-standards/src/non_fungible_token/macros.rs @@ -118,7 +118,7 @@ macro_rules! impl_non_fungible_token_enumeration { #[near_bindgen] impl NonFungibleTokenEnumeration for $contract { - fn nft_total_supply(self) -> U128 { + fn nft_total_supply(&self) -> U128 { self.$token.nft_total_supply() } @@ -126,7 +126,7 @@ macro_rules! impl_non_fungible_token_enumeration { self.$token.nft_tokens(from_index, limit) } - fn nft_supply_for_owner(self, account_id: AccountId) -> U128 { + fn nft_supply_for_owner(&self, account_id: AccountId) -> U128 { self.$token.nft_supply_for_owner(account_id) } From e9a49b948143a15910eee471ec112a790a028fd1 Mon Sep 17 00:00:00 2001 From: austinabell Date: Thu, 15 Jul 2021 18:26:03 -0400 Subject: [PATCH 4/5] reset contract standard version --- near-contract-standards/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/near-contract-standards/Cargo.toml b/near-contract-standards/Cargo.toml index cb55b798e..76320de7a 100644 --- a/near-contract-standards/Cargo.toml +++ b/near-contract-standards/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "near-contract-standards" -version = "3.3.0" +version = "3.2.0" authors = ["Near Inc "] edition = "2018" license = "GPL-3.0" From 7d2d7fa90bd1923b8b74695342e68c4c480a4c39 Mon Sep 17 00:00:00 2001 From: austinabell Date: Wed, 21 Jul 2021 11:48:58 -0400 Subject: [PATCH 5/5] changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d109601fd..668dbef20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,8 @@ * This type will have `ValidAccountId`'s JSON (de)serialization and the borsh serialization will be equivalent to what it was previously * Initializes default for `BLOCKCHAIN_INTERFACE` to avoid requiring to initialize testing environment for tests that don't require custom blockchain interface configuration * This default only affects outside of `wasm32` environments and is optional/backwards compatible +* Updates internal NFT traits to not move the underlying type for methods + * This should not be a breaking change if using the `impl` macros, only if implementing manually ## `3.1.0` [04-06-2021]