Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect insufficient state early #269

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
.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 @@
}
})
.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 @@
)]
}
};
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
Loading