Skip to content

Commit

Permalink
chore: Optimize closures
Browse files Browse the repository at this point in the history
  • Loading branch information
maneva3 committed Nov 5, 2024
1 parent 500795a commit eb71bd0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 21 deletions.
20 changes: 7 additions & 13 deletions platform/contracts/admin/src/contracts/impl_mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ pub(crate) fn execute(
.map(MessageResponse::messages_only)
}

pub(super) fn migrate_contract(batches: Batches, address: Addr, migrate: MigrationSpec) -> Batches {
pub(super) fn migrate_contract(address: Addr, migrate: MigrationSpec, batches: Batches) -> Batches {
let post_migration_execute_batch = match migrate.post_migrate_execute_msg {
Some(post_migrate_execute_msg) => execute_contract(
batches.post_migration_execute_batch,
address.clone(),
post_migrate_execute_msg,
batches.post_migration_execute_batch,
),
None => batches.post_migration_execute_batch,
};
Expand Down Expand Up @@ -198,11 +198,7 @@ trait MigrateContracts: ForEachPair<Item = Addr> + Sized {
batches: Batches,
migration_msgs: <Self::HigherOrderType as HigherOrderType>::Of<MigrationSpec>,
) -> Batches {
self.for_each_pair(
migration_msgs,
batches,
|address, migration_spec, batches| migrate_contract(batches, address, migration_spec),
)
self.for_each_pair(migration_msgs, batches, migrate_contract)
}

fn maybe_migrate(
Expand All @@ -215,7 +211,7 @@ trait MigrateContracts: ForEachPair<Item = Addr> + Sized {
batches,
|address, migration_spec, batches| {
if let Some(migration_spec) = migration_spec {
migrate_contract(batches, address, migration_spec)
migrate_contract(address, migration_spec, batches)
} else {
batches
}
Expand All @@ -230,9 +226,7 @@ trait ExecuteContracts: ForEachPair<Item = Addr> + Sized {
batch: Batch,
execute_messages: <Self::HigherOrderType as HigherOrderType>::Of<String>,
) -> Batch {
self.for_each_pair(execute_messages, batch, |address, migration_spec, batch| {
execute_contract(batch, address, migration_spec)
})
self.for_each_pair(execute_messages, batch, execute_contract)
}

fn maybe_execute(
Expand All @@ -242,7 +236,7 @@ trait ExecuteContracts: ForEachPair<Item = Addr> + Sized {
) -> Batch {
self.for_each_pair(execute_messages, batch, |address, migration_spec, batch| {
if let Some(migration_spec) = migration_spec {
execute_contract(batch, address, migration_spec)
execute_contract(address, migration_spec, batch)
} else {
batch
}
Expand All @@ -261,7 +255,7 @@ where
state_contracts::load_all(storage).and_then(f)
}

fn execute_contract(batch: Batch, address: Addr, execute_message: String) -> Batch {
fn execute_contract(address: Addr, execute_message: String, batch: Batch) -> Batch {
batch.schedule_execute_no_reply(WasmMsg::Execute {
contract_addr: address.into_string(),
msg: Binary::new(execute_message.into_bytes()),
Expand Down
6 changes: 1 addition & 5 deletions platform/contracts/admin/src/contracts/protocol/impl_mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ impl ProtocolContracts<Addr> {
let post_migration_execute_batch = Batch::default();
let batches = Batches::default();

self.for_each_pair(
migration_msgs,
batches,
|address, migration_spec, batches| migrate_contract(batches, address, migration_spec),
);
self.for_each_pair(migration_msgs, batches, migrate_contract);

migration_batch.merge(post_migration_execute_batch)
}
Expand Down
4 changes: 1 addition & 3 deletions platform/packages/platform/src/bank_ibc/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,9 @@ fn new_msg(

impl<'c> From<Sender<'c>> for Batch {
fn from(sender: Sender<'c>) -> Self {
let batch = Self::default();

sender
.into_ibc_msgs()
.fold(batch, |batch, msg| batch.schedule_execute_no_reply(msg))
.fold(Self::default(), Self::schedule_execute_no_reply)
}
}

Expand Down

0 comments on commit eb71bd0

Please sign in to comment.