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 67c4e00
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 28 deletions.
7 changes: 2 additions & 5 deletions contracts/nft-escrow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ publish = false
[lib]
path = "src/lib.rs"

[dev-dependencies]
num-bigint = "0.4.2"

[dependencies.multiversx-sc]
version = "0.41.1"
version = "0.43.4"

[dev-dependencies.multiversx-sc-scenario]
version = "0.41.1"
version = "0.43.4"
2 changes: 1 addition & 1 deletion contracts/nft-escrow/meta/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ authors = [ "you",]
path = ".."

[dependencies.multiversx-sc-meta]
version = "0.41.1"
version = "0.43.4"
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));

Check warning on line 168 in contracts/nft-escrow/src/lib.rs

View workflow job for this annotation

GitHub Actions / Contracts / Clippy linter check

[clippy] reported by reviewdog 🐶 warning: returning the result of a `let` binding from a block --> contracts/nft-escrow/src/lib.rs:170:9 | 168 | let offer_result = MultiValue2::from((offer_id, offer)); | -------------------------------------------------------- unnecessary `let` binding 169 | 170 | offer_result | ^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_and_return = note: `#[warn(clippy::let_and_return)]` on by default help: return the expression directly | 168 ~ 169 | 170 ~ MultiValue2::from((offer_id, offer)) | Raw Output: contracts/nft-escrow/src/lib.rs:168:9:w:warning: returning the result of a `let` binding from a block --> contracts/nft-escrow/src/lib.rs:170:9 | 168 | let offer_result = MultiValue2::from((offer_id, offer)); | -------------------------------------------------------- unnecessary `let` binding 169 | 170 | offer_result | ^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_and_return = note: `#[warn(clippy::let_and_return)]` on by default help: return the expression directly | 168 ~ 169 | 170 ~ MultiValue2::from((offer_id, offer)) | __END__

Check warning on line 168 in contracts/nft-escrow/src/lib.rs

View workflow job for this annotation

GitHub Actions / Contracts / Clippy linter check

[clippy] reported by reviewdog 🐶 warning: returning the result of a `let` binding from a block --> contracts/nft-escrow/src/lib.rs:170:9 | 168 | let offer_result = MultiValue2::from((offer_id, offer)); | -------------------------------------------------------- unnecessary `let` binding 169 | 170 | offer_result | ^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_and_return = note: `#[warn(clippy::let_and_return)]` on by default help: return the expression directly | 168 ~ 169 | 170 ~ MultiValue2::from((offer_id, offer)) | Raw Output: contracts/nft-escrow/src/lib.rs:168:9:w:warning: returning the result of a `let` binding from a block --> contracts/nft-escrow/src/lib.rs:170:9 | 168 | let offer_result = MultiValue2::from((offer_id, offer)); | -------------------------------------------------------- unnecessary `let` binding 169 | 170 | offer_result | ^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_and_return = note: `#[warn(clippy::let_and_return)]` on by default help: return the expression directly | 168 ~ 169 | 170 ~ MultiValue2::from((offer_id, offer)) | __END__

offer_result
}

#[view]
#[storage_mapper("createdOffers")]
fn created_offers(&self, address: &ManagedAddress) -> UnorderedSetMapper<u32>;
Expand Down
20 changes: 10 additions & 10 deletions contracts/nft-escrow/wasm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion contracts/nft-escrow/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ panic = "abort"
path = ".."

[dependencies.multiversx-sc-wasm-adapter]
version = "0.41.1"
version = "0.43.4"
22 changes: 13 additions & 9 deletions contracts/nft-escrow/wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
// Total number of exported functions: 10

#![no_std]

// Configuration that works with rustc < 1.73.0.
// TODO: Recommended rustc version: 1.73.0 or newer.
#![feature(lang_items)]

multiversx_sc_wasm_adapter::allocator!();
Expand All @@ -18,15 +21,16 @@ multiversx_sc_wasm_adapter::panic_handler!();
multiversx_sc_wasm_adapter::endpoints! {
nft_escrow
(
escrow
cancel
accept
getCreatedOffers
getWantedOffers
created_offers
wanted_offers
offers
init => init
escrow => escrow
cancel => cancel
accept => accept
getCreatedOffers => get_created_offers
getWantedOffers => get_wanted_offers
created_offers => created_offers
wanted_offers => wanted_offers
offers => offers
)
}

multiversx_sc_wasm_adapter::empty_callback! {}
multiversx_sc_wasm_adapter::async_callback_empty! {}

0 comments on commit 67c4e00

Please sign in to comment.