Skip to content

Commit

Permalink
Merge pull request fedimint#6333 from dpc/24-11-10-out-idxs-newtype-more
Browse files Browse the repository at this point in the history
refactor(client): use OutPoint when iterating OutPointRange
  • Loading branch information
elsirion authored Nov 11, 2024
2 parents 97ff8a6 + eabafc5 commit da9ba35
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
9 changes: 6 additions & 3 deletions fedimint-client/src/module/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ impl OutPointRange {
}

impl IntoIterator for OutPointRange {
type Item = (TransactionId, u64);
type Item = OutPoint;

type IntoIter = OutPointRangeIter;

Expand All @@ -1060,10 +1060,13 @@ impl OutPointRange {
}

impl Iterator for OutPointRangeIter {
type Item = (TransactionId, u64);
type Item = OutPoint;

fn next(&mut self) -> Option<Self::Item> {
self.inner.next().map(|idx| (self.txid, idx))
self.inner.next().map(|idx| OutPoint {
txid: self.txid,
out_idx: idx,
})
}
}

Expand Down
10 changes: 3 additions & 7 deletions modules/fedimint-mint-client/src/backup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,12 @@ impl MintClientModule {
common
.out_point_range
.into_iter()
.map(|(txid, out_idx)| {
.map(|out_point| {
let issuance_request = created_state
.issuance_requests
.get(&out_idx)
.get(&out_point.out_idx)
.expect("Must have corresponding out_idx");
(
OutPoint { txid, out_idx },
issuance_request.0,
issuance_request.1,
)
(out_point, issuance_request.0, issuance_request.1)
})
.collect(),
),
Expand Down
4 changes: 2 additions & 2 deletions modules/fedimint-mint-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@ impl MintClientModule {
}

let state_generator = Arc::new(move |out_point_range: OutPointRange| {
assert_eq!(out_point_range.into_iter().count(), issuance_requests.len());
assert_eq!(out_point_range.count(), issuance_requests.len());
vec![MintClientStateMachines::Output(MintOutputStateMachine {
common: MintOutputCommon {
operation_id,
Expand All @@ -1094,7 +1094,7 @@ impl MintClientModule {
state: MintOutputStates::CreatedMulti(MintOutputStatesCreatedMulti {
issuance_requests: out_point_range
.into_iter()
.map(|(_, out_idx)| out_idx)
.map(|out_point| out_point.out_idx)
.zip(issuance_requests.clone())
.collect(),
}),
Expand Down

0 comments on commit da9ba35

Please sign in to comment.