Skip to content

Commit fca226d

Browse files
committed
style fixes (royalty.rs)
1 parent f13e449 commit fca226d

1 file changed

Lines changed: 31 additions & 32 deletions

File tree

nft-contract/src/royalty.rs

Lines changed: 31 additions & 32 deletions
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
}

0 commit comments

Comments
 (0)