Skip to content

Commit 84a5d40

Browse files
authored
Merge pull request #65 from garikbesson/migrate-and-reorganize
Fixed U/u types
2 parents 55d64e7 + 7294991 commit 84a5d40

33 files changed

+130
-130
lines changed

integration-tests/src/helpers.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use serde_json::json;
22
use near_workspaces::{types::{NearToken, AccountDetails}, Account, Contract};
33

4-
pub const DEFAULT_DEPOSIT: u128 = 10000000000000000000000 as u128;
4+
pub const DEFAULT_DEPOSIT: u128 = 10000000000000000000000;
55
pub const ONE_YOCTO_NEAR: NearToken = NearToken::from_yoctonear(1);
66

77
pub async fn mint_nft(
@@ -70,7 +70,7 @@ pub async fn place_nft_for_sale(
7070
market_contract: &Contract,
7171
nft_contract: &Contract,
7272
token_id: &str,
73-
approval_id: u128,
73+
approval_id: u32,
7474
price: &NearToken,
7575
) -> Result<(), Box<dyn std::error::Error>> {
7676
let request_payload = json!({

market-contract/src/external.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ trait ExtContract {
1010
&mut self,
1111
receiver_id: AccountId, //purchaser (person to transfer the NFT to)
1212
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
13+
approval_id: u32, //market contract's approval ID in order to transfer the token on behalf of the owner
1414
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
@@ -25,6 +25,6 @@ trait ExtContract {
2525
&self,
2626
token_id: TokenId,
2727
approved_account_id: AccountId,
28-
approval_id: u64,
28+
approval_id: u32,
2929
);
3030
}

market-contract/src/nft_callbacks.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ trait NonFungibleTokenApprovalsReceiver {
1212
&mut self,
1313
token_id: TokenId,
1414
owner_id: AccountId,
15-
approval_id: u64,
15+
approval_id: u32,
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: u64,
27+
approval_id: u32,
2828
msg: String,
2929
) {
3030
/*

market-contract/src/sale.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub struct Sale {
1010
//owner of the sale
1111
pub owner_id: AccountId,
1212
//market contract's approval ID to transfer the token on behalf of the owner
13-
pub approval_id: u64,
13+
pub approval_id: u32,
1414
//nft contract where the token was minted
1515
pub nft_contract_id: String,
1616
//actual token ID for sale
@@ -35,7 +35,7 @@ impl Contract {
3535
&mut self,
3636
nft_contract_id: AccountId,
3737
token_id: TokenId,
38-
approval_id: u64,
38+
approval_id: u32,
3939
sale_conditions: SalePriceInYoctoNear,
4040
) {
4141
let owner_id = env::predecessor_account_id();
@@ -267,7 +267,7 @@ impl Contract {
267267
owner_id: AccountId,
268268
nft_contract_id: AccountId,
269269
token_id: TokenId,
270-
approval_id: u64,
270+
approval_id: u32,
271271
sale_conditions: SalePriceInYoctoNear,
272272
#[callback_result] nft_token_result: Result<JsonToken, PromiseError>,
273273
#[callback_result] nft_is_approved_result: Result<bool, PromiseError>,

market-contract/src/sale_views.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ impl Contract {
3232
pub fn get_sales_by_owner_id(
3333
&self,
3434
account_id: AccountId,
35-
from_index: Option<u128>,
36-
limit: Option<u64>,
35+
from_index: Option<U128>,
36+
limit: Option<u32>,
3737
) -> Vec<Sale> {
3838
//get the set of token IDs for sale for the given account ID
3939
let by_owner_id = self.by_owner_id.get(&account_id);
@@ -48,7 +48,7 @@ impl Contract {
4848
let keys = sales.as_vector();
4949

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

5353
//iterate through the keys vector
5454
keys.iter()
@@ -82,8 +82,8 @@ impl Contract {
8282
pub fn get_sales_by_nft_contract_id(
8383
&self,
8484
nft_contract_id: AccountId,
85-
from_index: Option<u128>,
86-
limit: Option<u64>,
85+
from_index: Option<U128>,
86+
limit: Option<u32>,
8787
) -> Vec<Sale> {
8888
//get the set of token IDs for sale for the given contract ID
8989
let by_nft_contract_id = self.by_nft_contract_id.get(&nft_contract_id);
@@ -99,7 +99,7 @@ impl Contract {
9999
let keys = sales.as_vector();
100100

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

104104
//iterate through the keys vector
105105
keys.iter()

nft-contract-approval/src/approval.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub trait NonFungibleTokenCore {
1010
&self,
1111
token_id: TokenId,
1212
approved_account_id: AccountId,
13-
approval_id: Option<u64>,
13+
approval_id: Option<u32>,
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: u64,
30+
approval_id: u32,
3131
msg: String,
3232
);
3333
}
@@ -54,7 +54,7 @@ impl NonFungibleTokenCore for Contract {
5454
);
5555

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

5959
//check if the account has been approved already for this token
6060
let is_new_approval = token
@@ -99,7 +99,7 @@ impl NonFungibleTokenCore for Contract {
9999
&self,
100100
token_id: TokenId,
101101
approved_account_id: AccountId,
102-
approval_id: Option<u64>,
102+
approval_id: Option<u32>,
103103
) -> bool {
104104
//get the token object from the token_id
105105
let token = self.tokens_by_id.get(&token_id).expect("No token");

nft-contract-approval/src/enumeration.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ impl Contract {
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<u64>) -> Vec<JsonToken> {
12+
pub fn nft_tokens(&self, from_index: Option<U128>, limit: Option<u32>) -> Vec<JsonToken> {
1313
//where to start pagination - if we have a from_index, we'll use that - otherwise start from 0 index
14-
let start = from_index.unwrap_or(0);
14+
let start = u128::from(from_index.unwrap_or(U128(0)));
1515

1616
//iterate through each token using an iterator
1717
self.token_metadata_by_id.keys()
@@ -46,8 +46,8 @@ impl Contract {
4646
pub fn nft_tokens_for_owner(
4747
&self,
4848
account_id: AccountId,
49-
from_index: Option<u128>,
50-
limit: Option<u64>,
49+
from_index: Option<U128>,
50+
limit: Option<u32>,
5151
) -> Vec<JsonToken> {
5252
//get the set of tokens for the passed in owner
5353
let tokens_for_owner_set = self.tokens_per_owner.get(&account_id);
@@ -60,7 +60,7 @@ impl Contract {
6060
};
6161

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

6565
//iterate through the keys vector
6666
tokens.iter()

nft-contract-approval/src/internal.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub(crate) fn refund_approved_account_ids_iter<'a, I>(
2222
//refund a map of approved account IDs and send the funds to the passed in account ID
2323
pub(crate) fn refund_approved_account_ids(
2424
account_id: AccountId,
25-
approved_account_ids: &HashMap<AccountId, u64>,
25+
approved_account_ids: &HashMap<AccountId, u32>,
2626
) -> Promise {
2727
//call the refund_approved_account_ids_iter with the approved account IDs as keys
2828
refund_approved_account_ids_iter(account_id, approved_account_ids.keys())
@@ -134,7 +134,7 @@ impl Contract {
134134
receiver_id: &AccountId,
135135
token_id: &TokenId,
136136
//we introduce an approval ID so that people with that approval ID can transfer the token
137-
approval_id: Option<u64>,
137+
approval_id: Option<u32>,
138138
memo: Option<String>,
139139
) -> Token {
140140
//get the token object by passing in the token_id

nft-contract-approval/src/metadata.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ pub struct Token {
4444
//owner of the token
4545
pub owner_id: AccountId,
4646
//list of approved account IDs that have access to transfer the token. This maps an account ID to an approval ID
47-
pub approved_account_ids: HashMap<AccountId, u64>,
47+
pub approved_account_ids: HashMap<AccountId, u32>,
4848
//the next approval ID to give out.
49-
pub next_approval_id: u64,
49+
pub next_approval_id: u32,
5050
}
5151

5252
//The Json token is what will be returned from view calls.
@@ -60,7 +60,7 @@ pub struct JsonToken {
6060
//token metadata
6161
pub metadata: TokenMetadata,
6262
//list of approved account IDs that have access to transfer the token. This maps an account ID to an approval ID
63-
pub approved_account_ids: HashMap<AccountId, u64>,
63+
pub approved_account_ids: HashMap<AccountId, u32>,
6464
}
6565

6666
pub trait NonFungibleTokenMetadata {

nft-contract-approval/src/nft_core.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub trait NonFungibleTokenCore {
1111
receiver_id: AccountId,
1212
token_id: TokenId,
1313
//we introduce an approval ID so that people with that approval ID can transfer the token
14-
approval_id: Option<u64>,
14+
approval_id: Option<u32>,
1515
memo: Option<String>,
1616
);
1717

@@ -22,7 +22,7 @@ pub trait NonFungibleTokenCore {
2222
receiver_id: AccountId,
2323
token_id: TokenId,
2424
//we introduce an approval ID so that people with that approval ID can transfer the token
25-
approval_id: Option<u64>,
25+
approval_id: Option<u32>,
2626
memo: Option<String>,
2727
msg: String,
2828
) -> PromiseOrValue<bool>;
@@ -59,7 +59,7 @@ trait NonFungibleTokenResolver {
5959
receiver_id: AccountId,
6060
token_id: TokenId,
6161
//we introduce the approval map so we can keep track of what the approvals were before the transfer
62-
approved_account_ids: HashMap<AccountId, u64>,
62+
approved_account_ids: HashMap<AccountId, u32>,
6363
//we introduce a memo for logging the transfer event
6464
memo: Option<String>,
6565
) -> bool;
@@ -74,7 +74,7 @@ impl NonFungibleTokenCore for Contract {
7474
receiver_id: AccountId,
7575
token_id: TokenId,
7676
//we introduce an approval ID so that people with that approval ID can transfer the token
77-
approval_id: Option<u64>,
77+
approval_id: Option<u32>,
7878
memo: Option<String>,
7979
) {
8080
//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 {
105105
receiver_id: AccountId,
106106
token_id: TokenId,
107107
//we introduce an approval ID so that people with that approval ID can transfer the token
108-
approval_id: Option<u64>,
108+
approval_id: Option<u32>,
109109
memo: Option<String>,
110110
msg: String,
111111
) -> PromiseOrValue<bool> {
@@ -189,7 +189,7 @@ impl NonFungibleTokenResolver for Contract {
189189
receiver_id: AccountId,
190190
token_id: TokenId,
191191
//we introduce the approval map so we can keep track of what the approvals were before the transfer
192-
approved_account_ids: HashMap<AccountId, u64>,
192+
approved_account_ids: HashMap<AccountId, u32>,
193193
//we introduce a memo for logging the transfer event
194194
memo: Option<String>,
195195
) -> bool {

nft-contract-approval/src/royalty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub trait NonFungibleTokenCore {
99
&mut self,
1010
receiver_id: AccountId,
1111
token_id: TokenId,
12-
approval_id: u64,
12+
approval_id: u32,
1313
memo: Option<String>,
1414
balance: U128,
1515
max_len_payout: u32,
@@ -33,7 +33,7 @@ impl NonFungibleTokenCore for Contract {
3333
&mut self,
3434
receiver_id: AccountId,
3535
token_id: TokenId,
36-
approval_id: u64,
36+
approval_id: u32,
3737
memo: Option<String>,
3838
balance: U128,
3939
max_len_payout: u32,

nft-contract-basic/src/approval.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub trait NonFungibleTokenCore {
1010
&self,
1111
token_id: TokenId,
1212
approved_account_id: AccountId,
13-
approval_id: Option<u64>,
13+
approval_id: Option<u32>,
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: u64,
30+
approval_id: u32,
3131
msg: String,
3232
);
3333
}
@@ -47,7 +47,7 @@ impl NonFungibleTokenCore for Contract {
4747
&self,
4848
token_id: TokenId,
4949
approved_account_id: AccountId,
50-
approval_id: Option<u64>,
50+
approval_id: Option<u32>,
5151
) -> bool {
5252
/*
5353
FILL THIS IN

nft-contract-basic/src/enumeration.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ impl Contract {
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<u64>) -> Vec<JsonToken> {
12+
pub fn nft_tokens(&self, from_index: Option<U128>, limit: Option<u32>) -> Vec<JsonToken> {
1313
//where to start pagination - if we have a from_index, we'll use that - otherwise start from 0 index
14-
let start = from_index.unwrap_or(0);
14+
let start = u128::from(from_index.unwrap_or(U128(0)));
1515

1616
//iterate through each token using an iterator
1717
self.token_metadata_by_id.keys()
@@ -46,8 +46,8 @@ impl Contract {
4646
pub fn nft_tokens_for_owner(
4747
&self,
4848
account_id: AccountId,
49-
from_index: Option<u128>,
50-
limit: Option<u64>,
49+
from_index: Option<U128>,
50+
limit: Option<u32>,
5151
) -> Vec<JsonToken> {
5252
//get the set of tokens for the passed in owner
5353
let tokens_for_owner_set = self.tokens_per_owner.get(&account_id);
@@ -60,7 +60,7 @@ impl Contract {
6060
};
6161

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

6565
//iterate through the keys vector
6666
tokens.iter()

nft-contract-basic/src/royalty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub trait NonFungibleTokenCore {
99
&mut self,
1010
receiver_id: AccountId,
1111
token_id: TokenId,
12-
approval_id: u64,
12+
approval_id: u32,
1313
memo: Option<String>,
1414
balance: U128,
1515
max_len_payout: u32,
@@ -33,7 +33,7 @@ impl NonFungibleTokenCore for Contract {
3333
&mut self,
3434
receiver_id: AccountId,
3535
token_id: TokenId,
36-
approval_id: u64,
36+
approval_id: u32,
3737
memo: Option<String>,
3838
balance: U128,
3939
max_len_payout: u32,

0 commit comments

Comments
 (0)