Skip to content

Commit

Permalink
Extract offer result in separate function.
Browse files Browse the repository at this point in the history
  • Loading branch information
raress96 committed Oct 2, 2023
1 parent 6a181ea commit 7bc06fe
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions contracts/nft-escrow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ pub trait NftEscrowContract {
let mut result = MultiValueEncoded::new();

for offer_id in self.created_offers(&address).iter() {
result.push(MultiValue2::from((offer_id, self.offers(offer_id).get())));
result.push(self.get_offer_result(offer_id));
}

result
Expand All @@ -157,12 +157,19 @@ pub trait NftEscrowContract {
let mut result = MultiValueEncoded::new();

for offer_id in self.wanted_offers(&address).iter() {
result.push(MultiValue2::from((offer_id, self.offers(offer_id).get())));
result.push(self.get_offer_result(offer_id));
}

result
}

fn get_offer_result(&self, offer_id: u32) -> MultiValue2<u32, Offer<Self::Api>> {
let offer = self.offers(offer_id).get();
let offer_result = MultiValue2::from((offer_id, offer));

offer_result
}

#[view]
#[storage_mapper("createdOffers")]
fn created_offers(&self, address: &ManagedAddress) -> UnorderedSetMapper<u32>;
Expand Down

0 comments on commit 7bc06fe

Please sign in to comment.