@@ -425,17 +425,21 @@ pub fn find_inscription_with_id(
425
425
) -> Option < TraversalResult > {
426
426
let args: & [ & dyn ToSql ] = & [ & inscription_id. to_sql ( ) . unwrap ( ) ] ;
427
427
let mut stmt = inscriptions_db_conn
428
- . prepare ( "SELECT inscription_number, ordinal_number, block_hash FROM inscriptions WHERE inscription_id = ?" )
428
+ . prepare ( "SELECT inscription_number, ordinal_number, block_hash, offset, outpoint_to_watch FROM inscriptions WHERE inscription_id = ?" )
429
429
. unwrap ( ) ;
430
430
let mut rows = stmt. query ( args) . unwrap ( ) ;
431
431
while let Ok ( Some ( row) ) = rows. next ( ) {
432
432
let inscription_block_hash: String = row. get ( 2 ) . unwrap ( ) ;
433
433
if block_hash. eq ( & inscription_block_hash) {
434
434
let inscription_number: i64 = row. get ( 0 ) . unwrap ( ) ;
435
435
let ordinal_number: u64 = row. get ( 1 ) . unwrap ( ) ;
436
+ let inscription_offset: u64 = row. get ( 3 ) . unwrap ( ) ;
437
+ let outpoint_to_watch: String = row. get ( 4 ) . unwrap ( ) ;
436
438
let traversal = TraversalResult {
437
439
inscription_number,
438
440
ordinal_number,
441
+ inscription_offset,
442
+ outpoint_to_watch,
439
443
transfers : 0 ,
440
444
} ;
441
445
return Some ( traversal) ;
@@ -449,7 +453,7 @@ pub fn find_all_inscriptions(
449
453
) -> BTreeMap < u64 , Vec < ( TransactionIdentifier , TraversalResult ) > > {
450
454
let args: & [ & dyn ToSql ] = & [ ] ;
451
455
let mut stmt = inscriptions_db_conn
452
- . prepare ( "SELECT inscription_number, ordinal_number, block_height, inscription_id FROM inscriptions ORDER BY inscription_number ASC" )
456
+ . prepare ( "SELECT inscription_number, ordinal_number, block_height, inscription_id, offset, outpoint_to_watch FROM inscriptions ORDER BY inscription_number ASC" )
453
457
. unwrap ( ) ;
454
458
let mut results: BTreeMap < u64 , Vec < ( TransactionIdentifier , TraversalResult ) > > = BTreeMap :: new ( ) ;
455
459
let mut rows = stmt. query ( args) . unwrap ( ) ;
@@ -463,10 +467,14 @@ pub fn find_all_inscriptions(
463
467
hash : format ! ( "0x{}" , & inscription_id[ 0 ..inscription_id. len( ) - 2 ] ) ,
464
468
}
465
469
} ;
470
+ let inscription_offset: u64 = row. get ( 4 ) . unwrap ( ) ;
471
+ let outpoint_to_watch: String = row. get ( 5 ) . unwrap ( ) ;
466
472
let traversal = TraversalResult {
467
473
inscription_number,
468
474
ordinal_number,
469
475
transfers : 0 ,
476
+ inscription_offset,
477
+ outpoint_to_watch,
470
478
} ;
471
479
results
472
480
. entry ( block_height)
@@ -817,6 +825,8 @@ pub async fn fetch_and_cache_blocks_in_hord_db(
817
825
#[ derive( Clone , Debug ) ]
818
826
pub struct TraversalResult {
819
827
pub inscription_number : i64 ,
828
+ pub inscription_offset : u64 ,
829
+ pub outpoint_to_watch : String ,
820
830
pub ordinal_number : u64 ,
821
831
pub transfers : u32 ,
822
832
}
@@ -880,6 +890,7 @@ pub fn retrieve_satoshi_point_using_lazy_storage(
880
890
blocks_db : & DB ,
881
891
block_identifier : & BlockIdentifier ,
882
892
transaction_identifier : & TransactionIdentifier ,
893
+ input_index : usize ,
883
894
inscription_number : i64 ,
884
895
traversals_cache : Arc <
885
896
DashMap < ( u32 , [ u8 ; 8 ] ) , LazyBlockTransaction , BuildHasherDefault < FxHasher > > ,
@@ -894,16 +905,13 @@ pub fn retrieve_satoshi_point_using_lazy_storage(
894
905
block_identifier. index
895
906
)
896
907
} ) ;
897
-
908
+ let mut inscription_localized = false ;
909
+ let mut inscription_offset = 0 ;
910
+ let mut inscription_output_index: usize = 0 ;
898
911
let mut ordinal_offset = 0 ;
899
912
let mut ordinal_block_number = block_identifier. index as u32 ;
900
- let txid = {
901
- let bytes = hex:: decode ( & transaction_identifier. hash [ 2 ..] ) . unwrap ( ) ;
902
- [
903
- bytes[ 0 ] , bytes[ 1 ] , bytes[ 2 ] , bytes[ 3 ] , bytes[ 4 ] , bytes[ 5 ] , bytes[ 6 ] , bytes[ 7 ] ,
904
- ]
905
- } ;
906
- let mut tx_cursor = ( txid, 0 ) ;
913
+ let txid = transaction_identifier. get_8_hash_bytes ( ) ;
914
+ let mut tx_cursor = ( txid, input_index) ;
907
915
let mut hops: u32 = 0 ;
908
916
loop {
909
917
hops += 1 ;
@@ -916,6 +924,31 @@ pub fn retrieve_satoshi_point_using_lazy_storage(
916
924
917
925
if let Some ( cached_tx) = traversals_cache. get ( & ( ordinal_block_number, tx_cursor. 0 ) ) {
918
926
let tx = cached_tx. value ( ) ;
927
+
928
+ if !inscription_localized {
929
+ inscription_localized = true ;
930
+ let mut sats_ranges = vec ! [ ] ;
931
+ let mut bound = 0 ;
932
+ for output_value in tx. outputs . iter ( ) {
933
+ sats_ranges. push ( ( bound, bound + output_value) ) ;
934
+ bound += output_value;
935
+ }
936
+ let mut input_offset = 0 ;
937
+ for ( i, input) in tx. inputs . iter ( ) . enumerate ( ) {
938
+ if i == input_index {
939
+ break ;
940
+ }
941
+ input_offset += input. txin_value ;
942
+ }
943
+
944
+ for ( i, ( min, max) ) in sats_ranges. into_iter ( ) . enumerate ( ) {
945
+ if input_offset >= min && input_offset < max {
946
+ inscription_output_index = i;
947
+ inscription_offset = input_offset - min;
948
+ }
949
+ }
950
+ }
951
+
919
952
let mut next_found_in_cache = false ;
920
953
let mut sats_out = 0 ;
921
954
for ( index, output_value) in tx. outputs . iter ( ) . enumerate ( ) {
@@ -955,6 +988,11 @@ pub fn retrieve_satoshi_point_using_lazy_storage(
955
988
inscription_number : 0 ,
956
989
ordinal_number : 0 ,
957
990
transfers : 0 ,
991
+ inscription_offset,
992
+ outpoint_to_watch : format_outpoint_to_watch (
993
+ & transaction_identifier,
994
+ inscription_output_index,
995
+ ) ,
958
996
} ) ;
959
997
}
960
998
}
@@ -1022,6 +1060,30 @@ pub fn retrieve_satoshi_point_using_lazy_storage(
1022
1060
None => unreachable ! ( ) ,
1023
1061
} ;
1024
1062
1063
+ if !inscription_localized {
1064
+ inscription_localized = true ;
1065
+ let mut sats_ranges = vec ! [ ] ;
1066
+ let mut bound = 0 ;
1067
+ for output_value in lazy_tx. outputs . iter ( ) {
1068
+ sats_ranges. push ( ( bound, bound + output_value) ) ;
1069
+ bound += output_value;
1070
+ }
1071
+ let mut input_offset = 0 ;
1072
+ for ( i, input) in lazy_tx. inputs . iter ( ) . enumerate ( ) {
1073
+ if i == input_index {
1074
+ break ;
1075
+ }
1076
+ input_offset += input. txin_value ;
1077
+ }
1078
+
1079
+ for ( i, ( min, max) ) in sats_ranges. into_iter ( ) . enumerate ( ) {
1080
+ if input_offset >= min && input_offset < max {
1081
+ inscription_output_index = i;
1082
+ inscription_offset = input_offset - min;
1083
+ }
1084
+ }
1085
+ }
1086
+
1025
1087
let mut sats_out = 0 ;
1026
1088
for ( index, output_value) in lazy_tx. outputs . iter ( ) . enumerate ( ) {
1027
1089
if index == tx_cursor. 1 {
@@ -1056,6 +1118,11 @@ pub fn retrieve_satoshi_point_using_lazy_storage(
1056
1118
inscription_number : 0 ,
1057
1119
ordinal_number : 0 ,
1058
1120
transfers : 0 ,
1121
+ inscription_offset,
1122
+ outpoint_to_watch : format_outpoint_to_watch (
1123
+ & transaction_identifier,
1124
+ inscription_output_index,
1125
+ ) ,
1059
1126
} ) ;
1060
1127
}
1061
1128
}
@@ -1068,6 +1135,11 @@ pub fn retrieve_satoshi_point_using_lazy_storage(
1068
1135
inscription_number,
1069
1136
ordinal_number,
1070
1137
transfers : hops,
1138
+ inscription_offset,
1139
+ outpoint_to_watch : format_outpoint_to_watch (
1140
+ & transaction_identifier,
1141
+ inscription_output_index,
1142
+ ) ,
1071
1143
} )
1072
1144
}
1073
1145
0 commit comments