Skip to content

Commit

Permalink
[Enhancement] NFT: remove declarative macros.
Browse files Browse the repository at this point in the history
  • Loading branch information
ruseinov committed Jun 30, 2023
1 parent 6887b41 commit debe8b8
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 143 deletions.
65 changes: 62 additions & 3 deletions examples/non-fungible-token/nft/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@ use near_contract_standards::non_fungible_token::metadata::{
};
use near_contract_standards::non_fungible_token::NonFungibleToken;
use near_contract_standards::non_fungible_token::{Token, TokenId};
use near_contract_standards::non_fungible_token::approval::NonFungibleTokenApproval;
use near_contract_standards::non_fungible_token::core::NonFungibleTokenCore;
use near_contract_standards::non_fungible_token::enumeration::NonFungibleTokenEnumeration;
use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize};
use near_sdk::collections::LazyOption;
use near_sdk::{
env, near_bindgen, require, AccountId, BorshStorageKey, PanicOnDefault, Promise, PromiseOrValue,
};
use near_sdk::json_types::U128;

#[near_bindgen]
#[derive(BorshDeserialize, BorshSerialize, PanicOnDefault)]
Expand Down Expand Up @@ -100,9 +104,64 @@ impl Contract {
}
}

near_contract_standards::impl_non_fungible_token_core!(Contract, tokens);
near_contract_standards::impl_non_fungible_token_approval!(Contract, tokens);
near_contract_standards::impl_non_fungible_token_enumeration!(Contract, tokens);
#[near_bindgen]
impl NonFungibleTokenCore for Contract {
#[payable]
fn nft_transfer(&mut self, receiver_id: AccountId, token_id: TokenId, approval_id: Option<u64>, memo: Option<String>) {
self.tokens.nft_transfer(receiver_id, token_id, approval_id, memo);
}

#[payable]
fn nft_transfer_call(&mut self, receiver_id: AccountId, token_id: TokenId, approval_id: Option<u64>, memo: Option<String>, msg: String) -> PromiseOrValue<bool> {
self.tokens.nft_transfer_call(receiver_id, token_id, approval_id, memo, msg)
}

fn nft_token(&self, token_id: TokenId) -> Option<Token> {
self.tokens.nft_token(token_id)
}
}

#[near_bindgen]
impl NonFungibleTokenApproval for Contract {
#[payable]
fn nft_approve(&mut self, token_id: TokenId, account_id: AccountId, msg: Option<String>) -> Option<Promise> {
self.tokens.nft_approve(token_id, account_id, msg)
}

#[payable]
fn nft_revoke(&mut self, token_id: TokenId, account_id: AccountId) {
self.tokens.nft_revoke(token_id, account_id);
}

#[payable]
fn nft_revoke_all(&mut self, token_id: TokenId) {
self.tokens.nft_revoke_all(token_id);

}

fn nft_is_approved(&self, token_id: TokenId, approved_account_id: AccountId, approval_id: Option<u64>) -> bool {
self.tokens.nft_is_approved(token_id, approved_account_id, approval_id)
}
}

#[near_bindgen]
impl NonFungibleTokenEnumeration for Contract {
fn nft_total_supply(&self) -> U128 {
self.tokens.nft_total_supply()
}

fn nft_tokens(&self, from_index: Option<U128>, limit: Option<u64>) -> Vec<Token> {
self.tokens.nft_tokens(from_index, limit)
}

fn nft_supply_for_owner(&self, account_id: AccountId) -> U128 {
self.tokens.nft_supply_for_owner(account_id)
}

fn nft_tokens_for_owner(&self, account_id: AccountId, from_index: Option<U128>, limit: Option<u64>) -> Vec<Token> {
self.tokens.nft_tokens_for_owner(account_id, from_index, limit)
}
}

#[near_bindgen]
impl NonFungibleTokenMetadataProvider for Contract {
Expand Down
136 changes: 0 additions & 136 deletions near-contract-standards/src/non_fungible_token/macros.rs

This file was deleted.

4 changes: 0 additions & 4 deletions near-contract-standards/src/non_fungible_token/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ pub mod core;
/// Trait for the [NFT enumeration standard](https://nomicon.io/Standards/NonFungibleToken/Enumeration.html).
/// This provides useful view-only methods returning token supply, tokens by owner, etc.
pub mod enumeration;
/// Macros typically used by a contract wanting to take advantage of the non-fungible
/// token NEAR contract standard approach.
mod macros;
/// Metadata traits and implementation according to the [NFT enumeration standard](https://nomicon.io/Standards/NonFungibleToken/Metadata.html).
/// This covers both the contract metadata and the individual token metadata.
pub mod metadata;
Expand All @@ -21,6 +18,5 @@ mod utils;
pub use utils::*;

pub use self::core::NonFungibleToken;
pub use macros::*;

pub mod events;

0 comments on commit debe8b8

Please sign in to comment.