Skip to content

Commit

Permalink
pay: detect insufficient state early
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Jan 7, 2025
1 parent 55a814a commit b4f54bf
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/pay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ where Self::Descr: DescriptorRgb<K>
.collect();
state.sort_by_key(|(sum, _, _)| *sum);
let mut sum = Amount::ZERO;
state
let selection = state

Check warning on line 190 in src/pay.rs

View check run for this annotation

Codecov / codecov/patch

src/pay.rs#L190

Added line #L190 was not covered by tests
.iter()
.rev()
.take_while(|(val, _, _)| {
Expand All @@ -199,7 +199,12 @@ where Self::Descr: DescriptorRgb<K>
}
})
.map(|(_, seal, _)| *seal)
.collect::<BTreeSet<_>>()
.collect::<BTreeSet<_>>();
if sum < amount {
bset![]

Check warning on line 204 in src/pay.rs

View check run for this annotation

Codecov / codecov/patch

src/pay.rs#L202-L204

Added lines #L202 - L204 were not covered by tests
} else {
selection

Check warning on line 206 in src/pay.rs

View check run for this annotation

Codecov / codecov/patch

src/pay.rs#L206

Added line #L206 was not covered by tests
}
}
InvoiceState::Data(NonFungible::RGB21(allocation)) => {
let data_state = DataState::from(allocation);
Expand All @@ -220,6 +225,9 @@ where Self::Descr: DescriptorRgb<K>
)]
}
};
if prev_outputs.is_empty() {
return Err(CompositionError::InsufficientState);
}

Check warning on line 230 in src/pay.rs

View check run for this annotation

Codecov / codecov/patch

src/pay.rs#L228-L230

Added lines #L228 - L230 were not covered by tests
let prev_outpoints = prev_outputs
.iter()
// TODO: Support liquid
Expand Down

0 comments on commit b4f54bf

Please sign in to comment.