Skip to content

Commit 04e517c

Browse files
committed
returned the use U128/U64
1 parent 5dc2161 commit 04e517c

20 files changed

Lines changed: 65 additions & 63 deletions

File tree

market-contract/src/external.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ trait ExtContract {
1616
the price that the token was purchased for. This will be used in conjunction with the royalty percentages
1717
for the token in order to determine how much money should go to which account.
1818
*/
19-
balance: NearToken,
19+
balance: U128,
2020
//the maximum amount of accounts the market can payout at once (this is limited by GAS)
2121
max_len_payout: u32,
2222
);

market-contract/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use near_sdk::borsh::{BorshDeserialize, BorshSerialize};
22
use near_sdk::collections::{LookupMap, UnorderedMap, UnorderedSet};
3+
use near_sdk::json_types::{U128, U64};
34
use near_sdk::serde::{Deserialize, Serialize};
45
use near_sdk::{
56
assert_one_yocto, env, ext_contract, near_bindgen, AccountId, BorshStorageKey, CryptoHash, Gas,
@@ -180,8 +181,8 @@ impl Contract {
180181
}
181182

182183
//return how much storage an account has paid for
183-
pub fn storage_balance_of(&self, account_id: AccountId) -> NearToken {
184-
self.storage_deposits.get(&account_id).unwrap_or(ZERO_NEAR)
184+
pub fn storage_balance_of(&self, account_id: AccountId) -> U128 {
185+
U128(self.storage_deposits.get(&account_id).unwrap_or(ZERO_NEAR).as_yoctonear())
185186
}
186187
}
187188

market-contract/src/sale.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl Contract {
4747
//get the total storage paid by the owner
4848
let owner_paid_storage = self.storage_deposits.get(&owner_id).unwrap_or(ZERO_NEAR);
4949
//get the storage required which is simply the storage for the number of sales they have + 1
50-
let signer_storage_required = storage_amount.saturating_mul((self.get_supply_by_owner_id(owner_id.clone()) + 1).into());
50+
let signer_storage_required = storage_amount.saturating_mul((self.get_supply_by_owner_id(owner_id.clone()).0 + 1).into());
5151

5252
//make sure that the total paid is >= the required storage
5353
assert!(
@@ -145,7 +145,7 @@ impl Contract {
145145
self.process_purchase(
146146
contract_id,
147147
token_id,
148-
deposit,
148+
U128(deposit.as_yoctonear()),
149149
buyer_id,
150150
);
151151
}
@@ -157,7 +157,7 @@ impl Contract {
157157
&mut self,
158158
nft_contract_id: AccountId,
159159
token_id: String,
160-
price: NearToken,
160+
price: U128,
161161
buyer_id: AccountId,
162162
) -> Promise {
163163
//get the sale object by removing the sale
@@ -203,8 +203,8 @@ impl Contract {
203203
pub fn resolve_purchase(
204204
&mut self,
205205
buyer_id: AccountId,
206-
price: NearToken,
207-
) -> NearToken {
206+
price: U128,
207+
) -> U128 {
208208
// checking for payout information returned from the nft_transfer_payout method
209209
let payout_option = promise_result_as_success().and_then(|value| {
210210
//if we set the payout_option to None, that means something went wrong and we should refund the buyer
@@ -221,17 +221,17 @@ impl Contract {
221221
//if the payout object is the correct length, we move forward
222222
} else {
223223
//we'll keep track of how much the nft contract wants us to payout. Starting at the full price payed by the buyer
224-
let mut remainder = price;
224+
let mut remainder = price.0;
225225

226226
//loop through the payout and subtract the values from the remainder.
227227
for &value in payout_object.payout.values() {
228228
//checked sub checks for overflow or any errors and returns None if there are problems
229-
remainder = remainder.checked_sub(value)?;
229+
remainder = remainder.checked_sub(value.as_yoctonear())?;
230230
}
231231
//Check to see if the NFT contract sent back a faulty payout that requires us to pay more or too little.
232232
//The remainder will be 0 if the payout summed to the total price. The remainder will be 1 if the royalties
233233
//we something like 3333 + 3333 + 3333.
234-
if remainder.is_zero() || remainder.eq(&ONE_YOCTONEAR) {
234+
if remainder == 0 || remainder == 1 {
235235
//set the payout_option to be the payout because nothing went wrong
236236
Some(payout_object.payout)
237237
} else {
@@ -247,7 +247,7 @@ impl Contract {
247247
payout_option
248248
//if the payout option was None, we refund the buyer for the price they payed and return
249249
} else {
250-
Promise::new(buyer_id).transfer(price);
250+
Promise::new(buyer_id).transfer(NearToken::from_yoctonear(u128::from(price)));
251251
// leave function and return the price that was refunded
252252
return price;
253253
};

market-contract/src/sale_views.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,24 @@ impl Contract {
77
//returns the number of sales the marketplace has up (as a string)
88
pub fn get_supply_sales(
99
&self,
10-
) -> u64 {
10+
) -> U64 {
1111
//returns the sales object length
12-
self.sales.len()
12+
U64(self.sales.len())
1313
}
1414

1515
//returns the number of sales for a given account (result is a string)
1616
pub fn get_supply_by_owner_id(
1717
&self,
1818
account_id: AccountId,
19-
) -> u64 {
19+
) -> U64 {
2020
//get the set of sales for the given owner Id
2121
let by_owner_id = self.by_owner_id.get(&account_id);
2222

2323
//if there as some set, we return the length but if there wasn't a set, we return 0
2424
if let Some(by_owner_id) = by_owner_id {
25-
by_owner_id.len()
25+
U64(by_owner_id.len())
2626
} else {
27-
0
27+
U64(0)
2828
}
2929
}
3030

@@ -66,15 +66,15 @@ impl Contract {
6666
pub fn get_supply_by_nft_contract_id(
6767
&self,
6868
nft_contract_id: AccountId,
69-
) -> u64 {
69+
) -> U64 {
7070
//get the set of tokens for associated with the given nft contract
7171
let by_nft_contract_id = self.by_nft_contract_id.get(&nft_contract_id);
7272

7373
//if there was some set, return it's length. Otherwise return 0
7474
if let Some(by_nft_contract_id) = by_nft_contract_id {
75-
by_nft_contract_id.len()
75+
U64(by_nft_contract_id.len())
7676
} else {
77-
0
77+
U64(0)
7878
}
7979
}
8080

market-contract/src/tests.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::sale::Sale;
44
use crate::Contract;
55
use near_sdk::{
66
collections::UnorderedSet,
7+
json_types::U128,
78
env,
89
NearToken,
910
test_utils::{accounts, VMContextBuilder},
@@ -71,7 +72,7 @@ fn test_storage_balance_of() {
7172
.build());
7273
contract.storage_deposit(Some(accounts(0)));
7374
let balance = contract.storage_balance_of(accounts(0));
74-
assert!(balance.eq(&MIN_REQUIRED_STORAGE_YOCTO));
75+
assert_eq!(balance, U128(MIN_REQUIRED_STORAGE_YOCTO.as_yoctonear()));
7576
}
7677

7778
#[test]
@@ -97,7 +98,7 @@ fn test_storage_withdraw() {
9798
contract.storage_withdraw();
9899

99100
let remaining_amount = contract.storage_balance_of(accounts(0));
100-
assert!(remaining_amount.is_zero())
101+
assert_eq!(remaining_amount, U128(0))
101102
}
102103

103104
#[test]

nft-contract-approval/src/enumeration.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ 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) -> U64 {
77
//return the length of the token metadata by ID
8-
self.token_metadata_by_id.len()
8+
U64(self.token_metadata_by_id.len())
99
}
1010

1111
//Query for nft tokens on the contract regardless of the owner using pagination
@@ -29,16 +29,16 @@ impl Contract {
2929
pub fn nft_supply_for_owner(
3030
&self,
3131
account_id: AccountId,
32-
) -> u64 {
32+
) -> U64 {
3333
//get the set of tokens for the passed in owner
3434
let tokens_for_owner_set = self.tokens_per_owner.get(&account_id);
3535

3636
//if there is some set of tokens, we'll return the length
3737
if let Some(tokens_for_owner_set) = tokens_for_owner_set {
38-
tokens_for_owner_set.len()
38+
U64(tokens_for_owner_set.len())
3939
} else {
4040
//if there isn't a set of tokens for the passed in account ID, we'll return 0
41-
0
41+
U64(0)
4242
}
4343
}
4444

nft-contract-approval/src/internal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub(crate) fn refund_approved_account_ids_iter<'a, I>(
1414
approved_account_ids: I, //the approved account IDs must be passed in as an iterator
1515
) -> Promise where I: Iterator<Item = &'a AccountId> {
1616
//get the storage total by going through and summing all the bytes for each approved account IDs
17-
let storage_released: u128 = approved_account_ids.map(bytes_for_approved_account_id).sum();
17+
let storage_released = approved_account_ids.map(bytes_for_approved_account_id).sum();
1818
//transfer the account the storage that is released
1919
Promise::new(account_id).transfer(env::storage_byte_cost().saturating_mul(storage_released))
2020
}

nft-contract-approval/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::collections::HashMap;
22
use near_sdk::borsh::{BorshSerialize, BorshDeserialize};
33
use near_sdk::collections::{LazyOption, LookupMap, UnorderedMap, UnorderedSet};
4-
use near_sdk::json_types::Base64VecU8;
4+
use near_sdk::json_types::{Base64VecU8, U64};
55
use near_sdk::serde::{Deserialize, Serialize};
66
use near_sdk::{
77
near_bindgen, env, AccountId, NearToken, CryptoHash, PanicOnDefault, Promise, PromiseOrValue, BorshStorageKey, NearSchema

nft-contract-basic/src/enumeration.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ 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) -> U64 {
77
//return the length of the token metadata by ID
8-
self.token_metadata_by_id.len()
8+
U64(self.token_metadata_by_id.len())
99
}
1010

1111
//Query for nft tokens on the contract regardless of the owner using pagination
@@ -29,16 +29,16 @@ impl Contract {
2929
pub fn nft_supply_for_owner(
3030
&self,
3131
account_id: AccountId,
32-
) -> u64 {
32+
) -> U64 {
3333
//get the set of tokens for the passed in owner
3434
let tokens_for_owner_set = self.tokens_per_owner.get(&account_id);
3535

3636
//if there is some set of tokens, we'll return the length
3737
if let Some(tokens_for_owner_set) = tokens_for_owner_set {
38-
tokens_for_owner_set.len()
38+
U64(tokens_for_owner_set.len())
3939
} else {
4040
//if there isn't a set of tokens for the passed in account ID, we'll return 0
41-
0
41+
U64(0)
4242
}
4343
}
4444

nft-contract-basic/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::collections::HashMap;
22
use near_sdk::borsh::{BorshSerialize, BorshDeserialize};
33
use near_sdk::collections::{LazyOption, LookupMap, UnorderedMap, UnorderedSet};
4-
use near_sdk::json_types::Base64VecU8;
4+
use near_sdk::json_types::{Base64VecU8, U64};
55
use near_sdk::serde::{Deserialize, Serialize};
66
use near_sdk::{
77
near_bindgen, env, AccountId, NearToken, CryptoHash, PanicOnDefault, Promise, PromiseOrValue, BorshStorageKey, NearSchema

0 commit comments

Comments
 (0)