Skip to content

Commit

Permalink
fix: sat offset computation
Browse files Browse the repository at this point in the history
  • Loading branch information
lgalabru committed May 16, 2023
1 parent dbca70c commit b278b66
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions components/chainhook-event-observer/src/hord/db/mod.rs
Expand Up @@ -1325,13 +1325,16 @@ pub fn retrieve_satoshi_point_using_lazy_storage(
}

let fee = total_in - total_out;
accumulated_fees += fee;
if accumulated_fees > ordinal_offset {
if accumulated_fees + fee > ordinal_offset {
// We are looking at the right transaction
// Retraverse the inputs to select the index to be picked
let offset_within_fee = ordinal_offset - accumulated_fees;
total_out += offset_within_fee;
let mut sats_in = 0;

for input in tx.inputs.into_iter() {
sats_in += input.txin_value;

if sats_in >= total_out {
ordinal_offset = total_out - (sats_in - input.txin_value);
ordinal_block_number = input.block_height;
Expand All @@ -1340,6 +1343,8 @@ pub fn retrieve_satoshi_point_using_lazy_storage(
}
}
break;
} else {
accumulated_fees += fee;
}
}
} else {
Expand Down

0 comments on commit b278b66

Please sign in to comment.