Skip to content

Commit 55ef238

Browse files
committed
update types
1 parent 5155899 commit 55ef238

34 files changed

+633
-706
lines changed

integration-tests/src/helpers.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub async fn place_nft_for_sale(
7676
market_contract: &Contract,
7777
nft_contract: &Contract,
7878
token_id: &str,
79-
approval_id: u32,
79+
approval_id: u64,
8080
price: &NearToken,
8181
) -> Result<(), Box<dyn std::error::Error>> {
8282
let request_payload = json!({

market-contract/src/external.rs

+7-12
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,17 @@ trait ExtContract {
99
fn nft_transfer_payout(
1010
&mut self,
1111
receiver_id: AccountId, //purchaser (person to transfer the NFT to)
12-
token_id: TokenId, //token ID to transfer
13-
approval_id: u32, //market contract's approval ID in order to transfer the token on behalf of the owner
14-
memo: String, //memo (to include some context)
12+
token_id: TokenId, //token ID to transfer
13+
approval_id: u64, //market contract's approval ID in order to transfer the token on behalf of the owner
14+
memo: String, //memo (to include some context)
1515
/*
1616
the price that the token was purchased for. This will be used in conjunction with the royalty percentages
17-
for the token in order to determine how much money should go to which account.
17+
for the token in order to determine how much money should go to which account.
1818
*/
1919
balance: NearToken,
2020
//the maximum amount of accounts the market can payout at once (this is limited by GAS)
21-
max_len_payout: u32,
21+
max_len_payout: u32,
2222
);
2323
fn nft_token(&self, token_id: TokenId);
24-
fn nft_is_approved(
25-
&self,
26-
token_id: TokenId,
27-
approved_account_id: AccountId,
28-
approval_id: u32,
29-
);
30-
}
24+
fn nft_is_approved(&self, token_id: TokenId, approved_account_id: AccountId, approval_id: u64);
25+
}

market-contract/src/nft_callbacks.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ use crate::*;
55
/*
66
trait that will be used as the callback from the NFT contract. When nft_approve is
77
called, it will fire a cross contract call to this marketplace and this is the function
8-
that is invoked.
8+
that is invoked.
99
*/
1010
trait NonFungibleTokenApprovalsReceiver {
1111
fn nft_on_approve(
1212
&mut self,
1313
token_id: TokenId,
1414
owner_id: AccountId,
15-
approval_id: u32,
15+
approval_id: u64,
1616
msg: String,
1717
);
1818
}
@@ -24,7 +24,7 @@ impl NonFungibleTokenApprovalsReceiver for Contract {
2424
&mut self,
2525
token_id: TokenId,
2626
owner_id: AccountId,
27-
approval_id: u32,
27+
approval_id: u64,
2828
msg: String,
2929
) {
3030
/*

market-contract/src/sale.rs

+95-113
Large diffs are not rendered by default.

nft-contract-approval/src/approval.rs

+16-24
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::*;
2-
use near_sdk::{ext_contract};
2+
use near_sdk::ext_contract;
33

44
pub trait NonFungibleTokenCore {
55
//approve an account ID to transfer a token on your behalf
@@ -10,7 +10,7 @@ pub trait NonFungibleTokenCore {
1010
&self,
1111
token_id: TokenId,
1212
approved_account_id: AccountId,
13-
approval_id: Option<u32>,
13+
approval_id: Option<u64>,
1414
) -> bool;
1515

1616
//revoke a specific account from transferring the token on your behalf
@@ -27,7 +27,7 @@ trait NonFungibleTokenApprovalsReceiver {
2727
&mut self,
2828
token_id: TokenId,
2929
owner_id: AccountId,
30-
approval_id: u32,
30+
approval_id: u64,
3131
msg: String,
3232
);
3333
}
@@ -54,12 +54,12 @@ impl NonFungibleTokenCore for Contract {
5454
);
5555

5656
//get the next approval ID if we need a new approval
57-
let approval_id: u32 = token.next_approval_id;
57+
let approval_id: u64 = token.next_approval_id;
5858

5959
//check if the account has been approved already for this token
6060
let is_new_approval = token
6161
.approved_account_ids
62-
//insert returns none if the key was not present.
62+
//insert returns none if the key was not present.
6363
.insert(account_id.clone(), approval_id)
6464
//if the key was not present, .is_none() will return true so it is a new approval.
6565
.is_none();
@@ -77,36 +77,32 @@ impl NonFungibleTokenCore for Contract {
7777
//insert the token back into the tokens_by_id collection
7878
self.tokens_by_id.insert(&token_id, &token);
7979

80-
//refund any excess storage attached by the user. If the user didn't attach enough, panic.
80+
//refund any excess storage attached by the user. If the user didn't attach enough, panic.
8181
refund_deposit(storage_used);
8282

8383
//if some message was passed into the function, we initiate a cross contract call on the
84-
//account we're giving access to.
84+
//account we're giving access to.
8585
if let Some(msg) = msg {
8686
// Defaulting GAS weight to 1, no attached deposit, and no static GAS to attach.
8787
ext_non_fungible_approval_receiver::ext(account_id)
88-
.nft_on_approve(
89-
token_id,
90-
token.owner_id,
91-
approval_id,
92-
msg
93-
).as_return();
88+
.nft_on_approve(token_id, token.owner_id, approval_id, msg)
89+
.as_return();
9490
}
9591
}
9692

9793
//check if the passed in account has access to approve the token ID
98-
fn nft_is_approved(
94+
fn nft_is_approved(
9995
&self,
10096
token_id: TokenId,
10197
approved_account_id: AccountId,
102-
approval_id: Option<u32>,
98+
approval_id: Option<u64>,
10399
) -> bool {
104100
//get the token object from the token_id
105101
let token = self.tokens_by_id.get(&token_id).expect("No token");
106-
102+
107103
//get the approval number for the passed in account ID
108104
let approval = token.approved_account_ids.get(&approved_account_id);
109-
105+
110106
//if there was some approval ID found for the account ID
111107
if let Some(approval) = approval {
112108
//if a specific approval_id was passed into the function
@@ -123,7 +119,7 @@ impl NonFungibleTokenCore for Contract {
123119
}
124120
}
125121

126-
//revoke a specific account from transferring the token on your behalf
122+
//revoke a specific account from transferring the token on your behalf
127123
#[payable]
128124
fn nft_revoke(&mut self, token_id: TokenId, account_id: AccountId) {
129125
//assert that the user attached exactly 1 yoctoNEAR for security reasons
@@ -136,11 +132,7 @@ impl NonFungibleTokenCore for Contract {
136132
assert_eq!(&predecessor_account_id, &token.owner_id);
137133

138134
//if the account ID was in the token's approval, we remove it and the if statement logic executes
139-
if token
140-
.approved_account_ids
141-
.remove(&account_id)
142-
.is_some()
143-
{
135+
if token.approved_account_ids.remove(&account_id).is_some() {
144136
//refund the funds released by removing the approved_account_id to the caller of the function
145137
refund_approved_account_ids_iter(predecessor_account_id, [account_id].iter());
146138

@@ -171,4 +163,4 @@ impl NonFungibleTokenCore for Contract {
171163
self.tokens_by_id.insert(&token_id, &token);
172164
}
173165
}
174-
}
166+
}

nft-contract-approval/src/enumeration.rs

+17-18
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,40 @@ use crate::*;
33
#[near_bindgen]
44
impl Contract {
55
//Query for the total supply of NFTs on the contract
6-
pub fn nft_total_supply(&self) -> U64 {
6+
pub fn nft_total_supply(&self) -> U128 {
77
//return the length of the token metadata by ID
8-
U64(self.token_metadata_by_id.len())
8+
U128(self.token_metadata_by_id.len().into())
99
}
1010

1111
//Query for nft tokens on the contract regardless of the owner using pagination
12-
pub fn nft_tokens(&self, from_index: Option<U128>, limit: Option<u32>) -> Vec<JsonToken> {
12+
pub fn nft_tokens(&self, from_index: Option<U128>, limit: Option<u64>) -> Vec<JsonToken> {
1313
//where to start pagination - if we have a from_index, we'll use that - otherwise start from 0 index
1414
let start = u128::from(from_index.unwrap_or(U128(0)));
1515

1616
//iterate through each token using an iterator
17-
self.token_metadata_by_id.keys()
17+
self.token_metadata_by_id
18+
.keys()
1819
//skip to the index we specified in the start variable
19-
.skip(start as usize)
20+
.skip(start as usize)
2021
//take the first "limit" elements in the vector. If we didn't specify a limit, use 50
21-
.take(limit.unwrap_or(50) as usize)
22+
.take(limit.unwrap_or(50) as usize)
2223
//we'll map the token IDs which are strings into Json Tokens
2324
.map(|token_id| self.nft_token(token_id.clone()).unwrap())
2425
//since we turned the keys into an iterator, we need to turn it back into a vector to return
2526
.collect()
2627
}
2728

2829
//get the total supply of NFTs for a given owner
29-
pub fn nft_supply_for_owner(
30-
&self,
31-
account_id: AccountId,
32-
) -> U64 {
30+
pub fn nft_supply_for_owner(&self, account_id: AccountId) -> U128 {
3331
//get the set of tokens for the passed in owner
3432
let tokens_for_owner_set = self.tokens_per_owner.get(&account_id);
3533

3634
//if there is some set of tokens, we'll return the length
3735
if let Some(tokens_for_owner_set) = tokens_for_owner_set {
38-
U64(tokens_for_owner_set.len())
36+
U128(tokens_for_owner_set.len().into())
3937
} else {
4038
//if there isn't a set of tokens for the passed in account ID, we'll return 0
41-
U64(0)
39+
U128(0)
4240
}
4341
}
4442

@@ -47,30 +45,31 @@ impl Contract {
4745
&self,
4846
account_id: AccountId,
4947
from_index: Option<U128>,
50-
limit: Option<u32>,
48+
limit: Option<u64>,
5149
) -> Vec<JsonToken> {
5250
//get the set of tokens for the passed in owner
5351
let tokens_for_owner_set = self.tokens_per_owner.get(&account_id);
5452
//if there is some set of tokens, we'll set the tokens variable equal to that set
5553
let tokens = if let Some(tokens_for_owner_set) = tokens_for_owner_set {
5654
tokens_for_owner_set
5755
} else {
58-
//if there is no set of tokens, we'll simply return an empty vector.
56+
//if there is no set of tokens, we'll simply return an empty vector.
5957
return vec![];
6058
};
6159

6260
//where to start pagination - if we have a from_index, we'll use that - otherwise start from 0 index
6361
let start = u128::from(from_index.unwrap_or(U128(0)));
6462

6563
//iterate through the keys vector
66-
tokens.iter()
64+
tokens
65+
.iter()
6766
//skip to the index we specified in the start variable
68-
.skip(start as usize)
67+
.skip(start as usize)
6968
//take the first "limit" elements in the vector. If we didn't specify a limit, use 50
70-
.take(limit.unwrap_or(50) as usize)
69+
.take(limit.unwrap_or(50) as usize)
7170
//we'll map the token IDs which are strings into Json Tokens
7271
.map(|token_id| self.nft_token(token_id.clone()).unwrap())
7372
//since we turned the keys into an iterator, we need to turn it back into a vector to return
7473
.collect()
7574
}
76-
}
75+
}

0 commit comments

Comments
 (0)