Skip to content

Commit

Permalink
add royalties storage prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
ruseinov committed Aug 20, 2023
1 parent ca930d7 commit 0406030
Showing 1 changed file with 55 additions and 13 deletions.
68 changes: 55 additions & 13 deletions examples/non-fungible-token/nft/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,23 @@ NOTES:
- To prevent the deployed contract from being modified or deleted, it should not have any access
keys on its account.
*/
use std::collections::HashMap;
use near_contract_standards::non_fungible_token::approval::NonFungibleTokenApproval;
use near_contract_standards::non_fungible_token::core::{
NonFungibleTokenCore, NonFungibleTokenResolver,
};
use near_contract_standards::non_fungible_token::enumeration::NonFungibleTokenEnumeration;
use near_contract_standards::non_fungible_token::metadata::{
NFTContractMetadata, NonFungibleTokenMetadataProvider, TokenMetadata, NFT_METADATA_SPEC,
};
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, NonFungibleTokenResolver};
use near_contract_standards::non_fungible_token::enumeration::NonFungibleTokenEnumeration;
use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize};
use near_sdk::collections::LazyOption;
use near_sdk::json_types::U128;
use near_sdk::{
env, near_bindgen, require, AccountId, BorshStorageKey, PanicOnDefault, Promise, PromiseOrValue,
};
use near_sdk::json_types::U128;
use std::collections::HashMap;

#[near_bindgen]
#[derive(BorshDeserialize, BorshSerialize, PanicOnDefault)]
Expand All @@ -47,6 +49,7 @@ enum StorageKey {
TokenMetadata,
Enumeration,
Approval,
Royalties,
}

#[near_bindgen]
Expand Down Expand Up @@ -80,6 +83,7 @@ impl Contract {
Some(StorageKey::TokenMetadata),
Some(StorageKey::Enumeration),
Some(StorageKey::Approval),
Some(StorageKey::Royalties),
),
metadata: LazyOption::new(StorageKey::Metadata, Some(&metadata)),
}
Expand Down Expand Up @@ -108,12 +112,25 @@ impl Contract {
#[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>) {
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> {
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)
}

Expand All @@ -125,15 +142,31 @@ impl NonFungibleTokenCore for Contract {
#[near_bindgen]
impl NonFungibleTokenResolver for Contract {
#[private]
fn nft_resolve_transfer(&mut self, previous_owner_id: AccountId, receiver_id: AccountId, token_id: TokenId, approved_account_ids: Option<HashMap<AccountId, u64>>) -> bool {
self.tokens.nft_resolve_transfer(previous_owner_id, receiver_id, token_id, approved_account_ids)
fn nft_resolve_transfer(
&mut self,
previous_owner_id: AccountId,
receiver_id: AccountId,
token_id: TokenId,
approved_account_ids: Option<HashMap<AccountId, u64>>,
) -> bool {
self.tokens.nft_resolve_transfer(
previous_owner_id,
receiver_id,
token_id,
approved_account_ids,
)
}
}

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

Expand All @@ -145,10 +178,14 @@ impl NonFungibleTokenApproval for Contract {
#[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 {
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)
}
}
Expand All @@ -167,7 +204,12 @@ impl NonFungibleTokenEnumeration for Contract {
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> {
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)
}
}
Expand Down

0 comments on commit 0406030

Please sign in to comment.