Skip to content

Commit

Permalink
fix: handle inscription pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
Ludovic Galabru authored and Ludovic Galabru committed Jan 11, 2024
1 parent 1c80b67 commit 3ce1932
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions components/ordhook-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ serde_json = "1"
serde_derive = "1"
hex = "0.4.3"
rand = "0.8.5"
chainhook-sdk = { version = "=0.12.0", features = ["zeromq"] }
# chainhook-sdk = { version = "=0.12.0", path = "../../../chainhook/components/chainhook-sdk", features = ["zeromq"] }
chainhook-sdk = { version = "=0.12.1", features = ["zeromq"] }
# chainhook-sdk = { version = "=0.12.1", path = "../../../chainhook/components/chainhook-sdk", features = ["zeromq"] }
hiro-system-kit = "0.3.1"
reqwest = { version = "0.11", default-features = false, features = [
"stream",
Expand Down
24 changes: 14 additions & 10 deletions components/ordhook-core/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub fn compute_next_satpoint_data(
offset_intra_input: u64,
inputs: &Vec<u64>,
outputs: &Vec<u64>,
pointer_from_inscription: u64,
) -> SatPosition {
let mut offset_cross_inputs = 0;
for (index, input_value) in inputs.iter().enumerate() {
Expand All @@ -70,6 +71,7 @@ pub fn compute_next_satpoint_data(
offset_cross_inputs += input_value;
}
offset_cross_inputs += offset_intra_input;
offset_cross_inputs += pointer_from_inscription;

let mut offset_intra_outputs = 0;
let mut output_index = 0;
Expand Down Expand Up @@ -194,43 +196,44 @@ pub fn should_sync_ordhook_db(
#[test]
fn test_identify_next_output_index_destination() {
assert_eq!(
compute_next_satpoint_data(0, 10, &vec![20, 30, 45], &vec![20, 30, 45]),
compute_next_satpoint_data(0, 10, &vec![20, 30, 45], &vec![20, 30, 45], 0),
SatPosition::Output((0, 10))
);
assert_eq!(
compute_next_satpoint_data(0, 20, &vec![20, 30, 45], &vec![20, 30, 45]),
compute_next_satpoint_data(0, 20, &vec![20, 30, 45], &vec![20, 30, 45], 0),
SatPosition::Output((1, 0))
);
assert_eq!(
compute_next_satpoint_data(1, 5, &vec![20, 30, 45], &vec![20, 30, 45]),
compute_next_satpoint_data(1, 5, &vec![20, 30, 45], &vec![20, 30, 45], 0),
SatPosition::Output((1, 5))
);
assert_eq!(
compute_next_satpoint_data(1, 6, &vec![20, 30, 45], &vec![20, 5, 45]),
compute_next_satpoint_data(1, 6, &vec![20, 30, 45], &vec![20, 5, 45], 0),
SatPosition::Output((2, 1))
);
assert_eq!(
compute_next_satpoint_data(1, 10, &vec![10, 10, 10], &vec![30]),
compute_next_satpoint_data(1, 10, &vec![10, 10, 10], &vec![30], 0),
SatPosition::Output((0, 20))
);
assert_eq!(
compute_next_satpoint_data(0, 30, &vec![10, 10, 10], &vec![30]),
compute_next_satpoint_data(0, 30, &vec![10, 10, 10], &vec![30], 0),
SatPosition::Fee(0)
);
assert_eq!(
compute_next_satpoint_data(0, 0, &vec![10, 10, 10], &vec![30]),
compute_next_satpoint_data(0, 0, &vec![10, 10, 10], &vec![30], 0),
SatPosition::Output((0, 0))
);
assert_eq!(
compute_next_satpoint_data(2, 45, &vec![20, 30, 45], &vec![20, 30, 45]),
compute_next_satpoint_data(2, 45, &vec![20, 30, 45], &vec![20, 30, 45], 0),
SatPosition::Fee(0)
);
assert_eq!(
compute_next_satpoint_data(
2,
0,
&vec![1000, 600, 546, 63034],
&vec![1600, 10000, 15000]
&vec![1600, 10000, 15000],
0
),
SatPosition::Output((1, 0))
);
Expand All @@ -239,7 +242,8 @@ fn test_identify_next_output_index_destination() {
3,
0,
&vec![6100, 148660, 103143, 7600],
&vec![81434, 173995]
&vec![81434, 173995],
0
),
SatPosition::Fee(2474)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ pub fn parse_inscriptions_from_witness(
inscription_input_index: input_index,
tx_index: 0,
inscription_output_value: 0,
inscription_pointer: envelope.payload.pointer().unwrap_or(0),
inscription_fee: 0,
inscription_number: OrdinalInscriptionNumber::zero(),
inscriber_address: None,
Expand Down

0 comments on commit 3ce1932

Please sign in to comment.