diff --git a/nft-contract/src/royalty.rs b/nft-contract/src/royalty.rs index 08e5ad2..bde91f6 100644 --- a/nft-contract/src/royalty.rs +++ b/nft-contract/src/royalty.rs @@ -18,11 +18,10 @@ pub trait NonFungibleTokenCore { #[near_bindgen] impl NonFungibleTokenCore for Contract { - //calculates the payout for a token given the passed in balance. This is a view method fn nft_payout(&self, token_id: TokenId, balance: U128, max_len_payout: u32) -> Payout { //get the token object - let token = self.tokens_by_id.get(&token_id).expect("No token"); + let token = self.tokens_by_id.get(&token_id).expect("No token"); //get the owner of the token let owner_id = token.owner_id; @@ -30,34 +29,34 @@ impl NonFungibleTokenCore for Contract { let mut total_perpetual = 0; //get the u128 version of the passed in balance (which was U128 before) let balance_u128 = u128::from(balance); - //keep track of the payout object to send back + //keep track of the payout object to send back let mut payout_object = Payout { payout: HashMap::new() }; //get the royalty object from token - let royalty = token.royalty; + let royalty = token.royalty; //make sure we're not paying out to too many people (GAS limits this) - assert!(royalty.len() as u32 <= max_len_payout, "Market cannot payout to that many receivers"); + assert!(royalty.len() as u32 <= max_len_payout, "Market cannot payout to that many receivers"); - //go through each key and value in the royalty object - for (k, v) in royalty.iter() { + //go through each key and value in the royalty object + for (k, v) in royalty.iter() { //get the key - let key = k.clone(); + let key = k.clone(); + //only insert into the payout if the key isn't the token owner (we add their payout at the end) - if key != owner_id { - // - payout_object.payout.insert(key, royalty_to_payout(*v, balance_u128)); - total_perpetual += *v; - } - } + if key != owner_id { + payout_object.payout.insert(key, royalty_to_payout(*v, balance_u128)); + total_perpetual += *v; + } + } - // payout to previous owner who gets 100% - total perpetual royalties - payout_object.payout.insert(owner_id, royalty_to_payout(10000 - total_perpetual, balance_u128)); + // payout to previous owner who gets 100% - total perpetual royalties + payout_object.payout.insert(owner_id, royalty_to_payout(10000 - total_perpetual, balance_u128)); //return the payout object - payout_object - } + payout_object + } //transfers the token to the receiver ID and returns the payout object that should be payed given the passed in balance. #[payable] @@ -95,32 +94,32 @@ impl NonFungibleTokenCore for Contract { let mut total_perpetual = 0; //get the u128 version of the passed in balance (which was U128 before) let balance_u128 = u128::from(balance); - //keep track of the payout object to send back + //keep track of the payout object to send back let mut payout_object = Payout { payout: HashMap::new() }; //get the royalty object from token - let royalty = previous_token.royalty; + let royalty = previous_token.royalty; //make sure we're not paying out to too many people (GAS limits this) - assert!(royalty.len() as u32 <= max_len_payout, "Market cannot payout to that many receivers"); + assert!(royalty.len() as u32 <= max_len_payout, "Market cannot payout to that many receivers"); //go through each key and value in the royalty object - for (k, v) in royalty.iter() { + for (k, v) in royalty.iter() { //get the key - let key = k.clone(); + let key = k.clone(); + //only insert into the payout if the key isn't the token owner (we add their payout at the end) - if key != owner_id { - // - payout_object.payout.insert(key, royalty_to_payout(*v, balance_u128)); - total_perpetual += *v; - } - } + if key != owner_id { + payout_object.payout.insert(key, royalty_to_payout(*v, balance_u128)); + total_perpetual += *v; + } + } - // payout to previous owner who gets 100% - total perpetual royalties - payout_object.payout.insert(owner_id, royalty_to_payout(10000 - total_perpetual, balance_u128)); + // payout to previous owner who gets 100% - total perpetual royalties + payout_object.payout.insert(owner_id, royalty_to_payout(10000 - total_perpetual, balance_u128)); //return the payout object - payout_object + payout_object } } \ No newline at end of file