fix: imitate overflow behavior

This commit is contained in:
Ludo Galabru
2024-02-02 10:17:01 -05:00
parent 22eb729f33
commit 306f850e7f
2 changed files with 12 additions and 0 deletions

View File

@@ -59,6 +59,12 @@ pub enum SatPosition {
pub fn resolve_absolute_pointer(inputs: &Vec<u64>, absolute_pointer_value: u64) -> (usize, u64) {
let mut selected_index = 0;
let mut cumulated_input_value = 0;
// Check for overflow
let total: u64 = inputs.iter().sum();
if absolute_pointer_value > total {
return (0, 0)
}
// Identify the input + satoshi offset being inscribed
for (index, input_value) in inputs.iter().enumerate() {
if (cumulated_input_value + input_value) > absolute_pointer_value {
selected_index = index;

View File

@@ -21,6 +21,12 @@ pub fn parse_inscriptions_from_witness(
witness_bytes: Vec<Vec<u8>>,
txid: &str,
) -> Option<Vec<OrdinalInscriptionRevealData>> {
// Efficient debugging: Isolate one specific transaction
// if !txid.eq("aa2ab56587c7d6609c95157e6dff37c5c3fa6531702f41229a289a5613887077") {
// return None
// }
let witness = Witness::from_slice(&witness_bytes);
let tapscript = witness.tapscript()?;
let envelopes: Vec<Envelope<Inscription>> = RawEnvelope::from_tapscript(tapscript, input_index)