Skip to content

Commit 4339095

Browse files
authored
Merge pull request #269 from RGB-WG/fix/noinputs
Detect insufficient state early
2 parents 55a814a + b4f54bf commit 4339095

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/pay.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ where Self::Descr: DescriptorRgb<K>
187187
.collect();
188188
state.sort_by_key(|(sum, _, _)| *sum);
189189
let mut sum = Amount::ZERO;
190-
state
190+
let selection = state
191191
.iter()
192192
.rev()
193193
.take_while(|(val, _, _)| {
@@ -199,7 +199,12 @@ where Self::Descr: DescriptorRgb<K>
199199
}
200200
})
201201
.map(|(_, seal, _)| *seal)
202-
.collect::<BTreeSet<_>>()
202+
.collect::<BTreeSet<_>>();
203+
if sum < amount {
204+
bset![]
205+
} else {
206+
selection
207+
}
203208
}
204209
InvoiceState::Data(NonFungible::RGB21(allocation)) => {
205210
let data_state = DataState::from(allocation);
@@ -220,6 +225,9 @@ where Self::Descr: DescriptorRgb<K>
220225
)]
221226
}
222227
};
228+
if prev_outputs.is_empty() {
229+
return Err(CompositionError::InsufficientState);
230+
}
223231
let prev_outpoints = prev_outputs
224232
.iter()
225233
// TODO: Support liquid

0 commit comments

Comments
 (0)