Skip to content

Commit

Permalink
[Ignition]: Use unwrap_or_else for address reservations.
Browse files Browse the repository at this point in the history
  • Loading branch information
0xOmarA committed Feb 20, 2024
1 parent 2e2f167 commit b1aa045
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 29 deletions.
15 changes: 8 additions & 7 deletions packages/caviarnine-v1-adapter-v1/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,14 @@ pub mod adapter {
owner_role: OwnerRole,
address_reservation: Option<GlobalAddressReservation>,
) -> Global<CaviarnineV1Adapter> {
let address_reservation = address_reservation.unwrap_or(
Runtime::allocate_component_address(BlueprintId {
package_address: Runtime::package_address(),
blueprint_name: Runtime::blueprint_name(),
})
.0,
);
let address_reservation =
address_reservation.unwrap_or_else(|| {
Runtime::allocate_component_address(BlueprintId {
package_address: Runtime::package_address(),
blueprint_name: Runtime::blueprint_name(),
})
.0
});

Self {
pool_information_cache: KeyValueStore::new_with_registered_type(
Expand Down
2 changes: 1 addition & 1 deletion packages/ignition/src/blueprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ mod ignition {
// If no address reservation is provided then reserve an address to
// globalize the component to - this is to provide us with a non
// branching way of globalizing the component.
let address_reservation = address_reservation.unwrap_or(
let address_reservation = address_reservation.unwrap_or_else(||
Runtime::allocate_component_address(Ignition::blueprint_id()).0,
);

Expand Down
15 changes: 8 additions & 7 deletions packages/ociswap-v1-adapter-v1/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ pub mod adapter {
owner_role: OwnerRole,
address_reservation: Option<GlobalAddressReservation>,
) -> Global<OciswapV1Adapter> {
let address_reservation = address_reservation.unwrap_or(
Runtime::allocate_component_address(BlueprintId {
package_address: Runtime::package_address(),
blueprint_name: Runtime::blueprint_name(),
})
.0,
);
let address_reservation =
address_reservation.unwrap_or_else(|| {
Runtime::allocate_component_address(BlueprintId {
package_address: Runtime::package_address(),
blueprint_name: Runtime::blueprint_name(),
})
.0
});

Self {}
.instantiate()
Expand Down
15 changes: 8 additions & 7 deletions packages/ociswap-v2-adapter-v1/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ pub mod adapter {
owner_role: OwnerRole,
address_reservation: Option<GlobalAddressReservation>,
) -> Global<OciswapV2Adapter> {
let address_reservation = address_reservation.unwrap_or(
Runtime::allocate_component_address(BlueprintId {
package_address: Runtime::package_address(),
blueprint_name: Runtime::blueprint_name(),
})
.0,
);
let address_reservation =
address_reservation.unwrap_or_else(|| {
Runtime::allocate_component_address(BlueprintId {
package_address: Runtime::package_address(),
blueprint_name: Runtime::blueprint_name(),
})
.0
});

Self {}
.instantiate()
Expand Down
15 changes: 8 additions & 7 deletions packages/simple-oracle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ mod simple_oracle {
owner_role: OwnerRole,
address_reservation: Option<GlobalAddressReservation>,
) -> Global<SimpleOracle> {
let address_reservation = address_reservation.unwrap_or(
Runtime::allocate_component_address(BlueprintId {
package_address: Runtime::package_address(),
blueprint_name: Runtime::blueprint_name(),
})
.0,
);
let address_reservation =
address_reservation.unwrap_or_else(|| {
Runtime::allocate_component_address(BlueprintId {
package_address: Runtime::package_address(),
blueprint_name: Runtime::blueprint_name(),
})
.0
});

Self {
prices: KeyValueStore::new_with_registered_type(),
Expand Down

0 comments on commit b1aa045

Please sign in to comment.