Skip to content

Commit 65ef6bc

Browse files
authoredFeb 15, 2024··
Merge pull request #53 from garikbesson/main
Update dependencies versions + style fixes
2 parents 16270e3 + fca226d commit 65ef6bc

File tree

11 files changed

+88
-85
lines changed

11 files changed

+88
-85
lines changed
 

‎integration-tests/rs/Cargo.toml

+10-10
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ publish = false
55
edition = "2018"
66

77
[dev-dependencies]
8-
near-sdk = "4.0.0"
9-
anyhow = "1.0"
10-
borsh = "0.9"
11-
maplit = "1.0"
8+
near-sdk = "4.1.1"
9+
anyhow = "1.0.79"
10+
borsh = "1.3.1"
11+
maplit = "1.0.2"
1212
near-units = "0.2.0"
1313
# arbitrary_precision enabled for u128 types that workspaces requires for Balance types
14-
serde_json = { version = "1.0", features = ["arbitrary_precision"] }
15-
tokio = { version = "1.18.1", features = ["full"] }
16-
tracing = "0.1"
17-
tracing-subscriber = { version = "0.3.11", features = ["env-filter"] }
18-
workspaces = "0.3.1"
19-
pkg-config = "0.3.1"
14+
serde_json = { version = "1.0.113", features = ["arbitrary_precision"] }
15+
tokio = { version = "1.36.0", features = ["full"] }
16+
tracing = "0.1.40"
17+
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
18+
workspaces = "0.7.0"
19+
pkg-config = "0.3.29"
2020

2121
[[example]]
2222
name = "integration-tests"

‎market-contract/Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ edition = "2021"
88
crate-type = ["cdylib", "rlib"]
99

1010
[dependencies]
11-
near-sdk = "4.0.0"
11+
near-sdk = "4.1.1"
12+
13+
[patch.crates-io]
14+
parity-secp256k1 = { git = 'https://github.com/paritytech/rust-secp256k1.git' }
1215

1316
[profile.release]
1417
codegen-units=1

‎nft-contract/Cargo.toml

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ edition = "2021"
88
crate-type = ["cdylib", "rlib"]
99

1010
[dependencies]
11-
near-sdk = "4.0.0"
12-
serde_json = "1.0"
11+
near-sdk = "4.1.1"
12+
serde_json = "1.0.113"
13+
14+
[patch.crates-io]
15+
parity-secp256k1 = { git = 'https://github.com/paritytech/rust-secp256k1.git' }
1316

1417
[profile.release]
1518
codegen-units=1

‎nft-contract/src/approval.rs

+11-12
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub trait NonFungibleTokenCore {
66
fn nft_approve(&mut self, token_id: TokenId, account_id: AccountId, msg: Option<String>);
77

88
//check if the passed in account has access to approve the token ID
9-
fn nft_is_approved(
9+
fn nft_is_approved(
1010
&self,
1111
token_id: TokenId,
1212
approved_account_id: AccountId,
@@ -34,7 +34,6 @@ trait NonFungibleTokenApprovalsReceiver {
3434

3535
#[near_bindgen]
3636
impl NonFungibleTokenCore for Contract {
37-
3837
//allow a specific account ID to approve a token on your behalf
3938
#[payable]
4039
fn nft_approve(&mut self, token_id: TokenId, account_id: AccountId, msg: Option<String>) {
@@ -96,7 +95,7 @@ impl NonFungibleTokenCore for Contract {
9695
}
9796

9897
//check if the passed in account has access to approve the token ID
99-
fn nft_is_approved(
98+
fn nft_is_approved(
10099
&self,
101100
token_id: TokenId,
102101
approved_account_id: AccountId,
@@ -106,22 +105,22 @@ impl NonFungibleTokenCore for Contract {
106105
let token = self.tokens_by_id.get(&token_id).expect("No token");
107106

108107
//get the approval number for the passed in account ID
109-
let approval = token.approved_account_ids.get(&approved_account_id);
108+
let approval = token.approved_account_ids.get(&approved_account_id);
110109

111110
//if there was some approval ID found for the account ID
112111
if let Some(approval) = approval {
113112
//if a specific approval_id was passed into the function
114-
if let Some(approval_id) = approval_id {
113+
if let Some(approval_id) = approval_id {
115114
//return if the approval ID passed in matches the actual approval ID for the account
116-
approval_id == *approval
115+
approval_id == *approval
117116
//if there was no approval_id passed into the function, we simply return true
118-
} else {
119-
true
120-
}
117+
} else {
118+
true
119+
}
121120
//if there was no approval ID found for the account ID, we simply return false
122-
} else {
123-
false
124-
}
121+
} else {
122+
false
123+
}
125124
}
126125

127126
//revoke a specific account from transferring the token on your behalf

‎nft-contract/src/internal.rs

+20-23
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ pub(crate) fn bytes_for_approved_account_id(account_id: &AccountId) -> u64 {
1717
pub(crate) fn refund_approved_account_ids_iter<'a, I>(
1818
account_id: AccountId,
1919
approved_account_ids: I, //the approved account IDs must be passed in as an iterator
20-
) -> Promise
21-
where
22-
I: Iterator<Item = &'a AccountId>,
23-
{
20+
) -> Promise where I: Iterator<Item = &'a AccountId> {
2421
//get the storage total by going through and summing all the bytes for each approved account IDs
2522
let storage_released: u64 = approved_account_ids.map(bytes_for_approved_account_id).sum();
2623
//transfer the account the storage that is released
@@ -151,29 +148,29 @@ impl Contract {
151148
let token = self.tokens_by_id.get(token_id).expect("No token");
152149

153150
//if the sender doesn't equal the owner, we check if the sender is in the approval list
154-
if sender_id != &token.owner_id {
155-
//if the token's approved account IDs doesn't contain the sender, we panic
156-
if !token.approved_account_ids.contains_key(sender_id) {
157-
env::panic_str("Unauthorized");
158-
}
159-
160-
// If they included an approval_id, check if the sender's actual approval_id is the same as the one included
161-
if let Some(enforced_approval_id) = approval_id {
151+
if sender_id != &token.owner_id {
152+
//if the token's approved account IDs doesn't contain the sender, we panic
153+
if !token.approved_account_ids.contains_key(sender_id) {
154+
env::panic_str("Unauthorized");
155+
}
156+
157+
// If they included an approval_id, check if the sender's actual approval_id is the same as the one included
158+
if let Some(enforced_approval_id) = approval_id {
162159
//get the actual approval ID
163-
let actual_approval_id = token
164-
.approved_account_ids
165-
.get(sender_id)
166-
//if the sender isn't in the map, we panic
167-
.expect("Sender is not approved account");
160+
let actual_approval_id = token
161+
.approved_account_ids
162+
.get(sender_id)
163+
//if the sender isn't in the map, we panic
164+
.expect("Sender is not approved account");
168165

169166
//make sure that the actual approval ID is the same as the one provided
170167
assert_eq!(
171-
actual_approval_id, &enforced_approval_id,
172-
"The actual approval_id {} is different from the given approval_id {}",
173-
actual_approval_id, enforced_approval_id,
174-
);
175-
}
176-
}
168+
actual_approval_id, &enforced_approval_id,
169+
"The actual approval_id {} is different from the given approval_id {}",
170+
actual_approval_id, enforced_approval_id,
171+
);
172+
}
173+
}
177174

178175
//we make sure that the sender isn't sending the token to themselves
179176
assert_ne!(

‎nft-contract/src/nft_core.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ pub trait NonFungibleTokenCore {
1515
memo: Option<String>,
1616
);
1717

18-
/// Transfers an NFT to a receiver and calls the
19-
/// function `nft_on_transfer` on their contract.
18+
// Transfers an NFT to a receiver and calls the
19+
// function `nft_on_transfer` on their contract.
2020
fn nft_transfer_call(
2121
&mut self,
2222
receiver_id: AccountId,
@@ -67,7 +67,6 @@ trait NonFungibleTokenResolver {
6767

6868
#[near_bindgen]
6969
impl NonFungibleTokenCore for Contract {
70-
7170
//implementation of the nft_transfer method. This transfers the NFT from the current owner to the receiver.
7271
#[payable]
7372
fn nft_transfer(

‎nft-contract/src/royalty.rs

+31-32
Original file line numberDiff line numberDiff line change
@@ -18,46 +18,45 @@ pub trait NonFungibleTokenCore {
1818

1919
#[near_bindgen]
2020
impl NonFungibleTokenCore for Contract {
21-
2221
//calculates the payout for a token given the passed in balance. This is a view method
2322
fn nft_payout(&self, token_id: TokenId, balance: U128, max_len_payout: u32) -> Payout {
2423
//get the token object
25-
let token = self.tokens_by_id.get(&token_id).expect("No token");
24+
let token = self.tokens_by_id.get(&token_id).expect("No token");
2625

2726
//get the owner of the token
2827
let owner_id = token.owner_id;
2928
//keep track of the total perpetual royalties
3029
let mut total_perpetual = 0;
3130
//get the u128 version of the passed in balance (which was U128 before)
3231
let balance_u128 = u128::from(balance);
33-
//keep track of the payout object to send back
32+
//keep track of the payout object to send back
3433
let mut payout_object = Payout {
3534
payout: HashMap::new()
3635
};
3736
//get the royalty object from token
38-
let royalty = token.royalty;
37+
let royalty = token.royalty;
3938

4039
//make sure we're not paying out to too many people (GAS limits this)
41-
assert!(royalty.len() as u32 <= max_len_payout, "Market cannot payout to that many receivers");
40+
assert!(royalty.len() as u32 <= max_len_payout, "Market cannot payout to that many receivers");
4241

43-
//go through each key and value in the royalty object
44-
for (k, v) in royalty.iter() {
42+
//go through each key and value in the royalty object
43+
for (k, v) in royalty.iter() {
4544
//get the key
46-
let key = k.clone();
45+
let key = k.clone();
46+
4747
//only insert into the payout if the key isn't the token owner (we add their payout at the end)
48-
if key != owner_id {
49-
//
50-
payout_object.payout.insert(key, royalty_to_payout(*v, balance_u128));
51-
total_perpetual += *v;
52-
}
53-
}
48+
if key != owner_id {
49+
payout_object.payout.insert(key, royalty_to_payout(*v, balance_u128));
50+
total_perpetual += *v;
51+
}
52+
}
5453

55-
// payout to previous owner who gets 100% - total perpetual royalties
56-
payout_object.payout.insert(owner_id, royalty_to_payout(10000 - total_perpetual, balance_u128));
54+
// payout to previous owner who gets 100% - total perpetual royalties
55+
payout_object.payout.insert(owner_id, royalty_to_payout(10000 - total_perpetual, balance_u128));
5756

5857
//return the payout object
59-
payout_object
60-
}
58+
payout_object
59+
}
6160

6261
//transfers the token to the receiver ID and returns the payout object that should be payed given the passed in balance.
6362
#[payable]
@@ -95,32 +94,32 @@ impl NonFungibleTokenCore for Contract {
9594
let mut total_perpetual = 0;
9695
//get the u128 version of the passed in balance (which was U128 before)
9796
let balance_u128 = u128::from(balance);
98-
//keep track of the payout object to send back
97+
//keep track of the payout object to send back
9998
let mut payout_object = Payout {
10099
payout: HashMap::new()
101100
};
102101
//get the royalty object from token
103-
let royalty = previous_token.royalty;
102+
let royalty = previous_token.royalty;
104103

105104
//make sure we're not paying out to too many people (GAS limits this)
106-
assert!(royalty.len() as u32 <= max_len_payout, "Market cannot payout to that many receivers");
105+
assert!(royalty.len() as u32 <= max_len_payout, "Market cannot payout to that many receivers");
107106

108107
//go through each key and value in the royalty object
109-
for (k, v) in royalty.iter() {
108+
for (k, v) in royalty.iter() {
110109
//get the key
111-
let key = k.clone();
110+
let key = k.clone();
111+
112112
//only insert into the payout if the key isn't the token owner (we add their payout at the end)
113-
if key != owner_id {
114-
//
115-
payout_object.payout.insert(key, royalty_to_payout(*v, balance_u128));
116-
total_perpetual += *v;
117-
}
118-
}
113+
if key != owner_id {
114+
payout_object.payout.insert(key, royalty_to_payout(*v, balance_u128));
115+
total_perpetual += *v;
116+
}
117+
}
119118

120-
// payout to previous owner who gets 100% - total perpetual royalties
121-
payout_object.payout.insert(owner_id, royalty_to_payout(10000 - total_perpetual, balance_u128));
119+
// payout to previous owner who gets 100% - total perpetual royalties
120+
payout_object.payout.insert(owner_id, royalty_to_payout(10000 - total_perpetual, balance_u128));
122121

123122
//return the payout object
124-
payout_object
123+
payout_object
125124
}
126125
}

‎nft-series/Cargo.toml

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ edition = "2021"
88
crate-type = ["cdylib", "rlib"]
99

1010
[dependencies]
11-
near-sdk = "4.0.0"
12-
serde_json = "1.0"
11+
near-sdk = "4.1.1"
12+
serde_json = "1.0.113"
13+
14+
[patch.crates-io]
15+
parity-secp256k1 = { git = 'https://github.com/paritytech/rust-secp256k1.git' }
1316

1417
[profile.release]
1518
codegen-units=1

‎out/main.wasm

-10.3 KB
Binary file not shown.

‎out/market.wasm

-5.83 KB
Binary file not shown.

‎out/series.wasm

-23.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)
Please sign in to comment.