@@ -455,15 +455,18 @@ pub fn find_inscription_with_id(
455
455
if block_hash. eq ( & inscription_block_hash) {
456
456
let inscription_number: i64 = row. get ( 0 ) . unwrap ( ) ;
457
457
let ordinal_number: u64 = row. get ( 1 ) . unwrap ( ) ;
458
- let inscription_offset : u64 = row. get ( 3 ) . unwrap ( ) ;
458
+ let inscription_offset_intra_output : u64 = row. get ( 3 ) . unwrap ( ) ;
459
459
let outpoint_to_watch: String = row. get ( 4 ) . unwrap ( ) ;
460
+ let ( transaction_identifier, output_index) =
461
+ parse_outpoint_to_watch ( & outpoint_to_watch) ;
460
462
let ( _, input_index) = parse_inscription_id ( inscription_id) ;
461
463
let traversal = TraversalResult {
462
464
inscription_number,
463
465
ordinal_number,
464
466
input_index,
465
- inscription_offset,
466
- outpoint_to_watch,
467
+ inscription_offset_intra_output,
468
+ transaction_identifier,
469
+ output_index,
467
470
transfers : 0 ,
468
471
} ;
469
472
return Some ( traversal) ;
@@ -490,15 +493,18 @@ pub fn find_all_inscriptions_in_block(
490
493
let inscription_id: String = row. get ( 3 ) . unwrap ( ) ;
491
494
parse_inscription_id ( & inscription_id)
492
495
} ;
493
- let inscription_offset : u64 = row. get ( 4 ) . unwrap ( ) ;
496
+ let inscription_offset_intra_output : u64 = row. get ( 4 ) . unwrap ( ) ;
494
497
let outpoint_to_watch: String = row. get ( 5 ) . unwrap ( ) ;
498
+ let ( transaction_identifier, output_index) = parse_outpoint_to_watch ( & outpoint_to_watch) ;
499
+
495
500
let traversal = TraversalResult {
496
501
inscription_number,
497
502
ordinal_number,
498
503
input_index,
499
504
transfers : 0 ,
500
- inscription_offset,
501
- outpoint_to_watch,
505
+ inscription_offset_intra_output,
506
+ transaction_identifier,
507
+ output_index,
502
508
} ;
503
509
results
504
510
. entry ( block_height)
@@ -849,9 +855,10 @@ pub async fn fetch_and_cache_blocks_in_hord_db(
849
855
#[ derive( Clone , Debug ) ]
850
856
pub struct TraversalResult {
851
857
pub inscription_number : i64 ,
852
- pub inscription_offset : u64 ,
858
+ pub inscription_offset_intra_output : u64 ,
853
859
pub input_index : usize ,
854
- pub outpoint_to_watch : String ,
860
+ pub output_index : usize ,
861
+ pub transaction_identifier : TransactionIdentifier ,
855
862
pub ordinal_number : u64 ,
856
863
pub transfers : u32 ,
857
864
}
@@ -939,14 +946,45 @@ pub fn retrieve_satoshi_point_using_lazy_storage(
939
946
block_identifier. index
940
947
)
941
948
} ) ;
942
- let mut inscription_localized = false ;
943
- let mut inscription_offset = 0 ;
949
+ let mut inscription_offset_intra_output = 0 ;
944
950
let mut inscription_output_index: usize = 0 ;
945
951
let mut ordinal_offset = 0 ;
946
952
let mut ordinal_block_number = block_identifier. index as u32 ;
947
953
let txid = transaction_identifier. get_8_hash_bytes ( ) ;
948
- let mut tx_cursor = ( txid, input_index) ;
954
+
955
+ let ( sats_ranges, inscription_offset_cross_outputs) =
956
+ match traversals_cache. get ( & ( block_identifier. index as u32 , txid. clone ( ) ) ) {
957
+ Some ( entry) => {
958
+ let tx = entry. value ( ) ;
959
+ (
960
+ tx. get_sat_ranges ( ) ,
961
+ tx. get_cumulated_sats_in_until_input_index ( input_index) ,
962
+ )
963
+ }
964
+ None => match find_lazy_block_at_block_height ( ordinal_block_number, 10 , & blocks_db) {
965
+ None => {
966
+ return Err ( format ! ( "block #{ordinal_block_number} not in database" ) ) ;
967
+ }
968
+ Some ( block) => match block. find_and_serialize_transaction_with_txid ( & txid) {
969
+ Some ( tx) => (
970
+ tx. get_sat_ranges ( ) ,
971
+ tx. get_cumulated_sats_in_until_input_index ( input_index) ,
972
+ ) ,
973
+ None => return Err ( format ! ( "block #{ordinal_block_number} not in database" ) ) ,
974
+ } ,
975
+ } ,
976
+ } ;
977
+
978
+ for ( i, ( min, max) ) in sats_ranges. into_iter ( ) . enumerate ( ) {
979
+ if inscription_offset_cross_outputs >= min && inscription_offset_cross_outputs < max {
980
+ inscription_output_index = i;
981
+ inscription_offset_intra_output = inscription_offset_cross_outputs - min;
982
+ }
983
+ }
984
+
985
+ let mut tx_cursor: ( [ u8 ; 8 ] , usize ) = ( txid, input_index) ;
949
986
let mut hops: u32 = 0 ;
987
+
950
988
loop {
951
989
hops += 1 ;
952
990
if hops as u64 > block_identifier. index {
@@ -959,30 +997,6 @@ pub fn retrieve_satoshi_point_using_lazy_storage(
959
997
if let Some ( cached_tx) = traversals_cache. get ( & ( ordinal_block_number, tx_cursor. 0 ) ) {
960
998
let tx = cached_tx. value ( ) ;
961
999
962
- if !inscription_localized {
963
- inscription_localized = true ;
964
- let mut sats_ranges = vec ! [ ] ;
965
- let mut bound = 0 ;
966
- for output_value in tx. outputs . iter ( ) {
967
- sats_ranges. push ( ( bound, bound + output_value) ) ;
968
- bound += output_value;
969
- }
970
- let mut input_offset = 0 ;
971
- for ( i, input) in tx. inputs . iter ( ) . enumerate ( ) {
972
- if i == input_index {
973
- break ;
974
- }
975
- input_offset += input. txin_value ;
976
- }
977
-
978
- for ( i, ( min, max) ) in sats_ranges. into_iter ( ) . enumerate ( ) {
979
- if input_offset >= min && input_offset < max {
980
- inscription_output_index = i;
981
- inscription_offset = input_offset - min;
982
- }
983
- }
984
- }
985
-
986
1000
let mut next_found_in_cache = false ;
987
1001
let mut sats_out = 0 ;
988
1002
for ( index, output_value) in tx. outputs . iter ( ) . enumerate ( ) {
@@ -1022,12 +1036,10 @@ pub fn retrieve_satoshi_point_using_lazy_storage(
1022
1036
inscription_number : 0 ,
1023
1037
ordinal_number : 0 ,
1024
1038
transfers : 0 ,
1025
- inscription_offset ,
1039
+ inscription_offset_intra_output ,
1026
1040
input_index,
1027
- outpoint_to_watch : format_outpoint_to_watch (
1028
- & transaction_identifier,
1029
- inscription_output_index,
1030
- ) ,
1041
+ transaction_identifier : transaction_identifier. clone ( ) ,
1042
+ output_index : inscription_output_index,
1031
1043
} ) ;
1032
1044
}
1033
1045
}
@@ -1095,30 +1107,6 @@ pub fn retrieve_satoshi_point_using_lazy_storage(
1095
1107
None => unreachable ! ( ) ,
1096
1108
} ;
1097
1109
1098
- if !inscription_localized {
1099
- inscription_localized = true ;
1100
- let mut sats_ranges = vec ! [ ] ;
1101
- let mut bound = 0 ;
1102
- for output_value in lazy_tx. outputs . iter ( ) {
1103
- sats_ranges. push ( ( bound, bound + output_value) ) ;
1104
- bound += output_value;
1105
- }
1106
- let mut input_offset = 0 ;
1107
- for ( i, input) in lazy_tx. inputs . iter ( ) . enumerate ( ) {
1108
- if i == input_index {
1109
- break ;
1110
- }
1111
- input_offset += input. txin_value ;
1112
- }
1113
-
1114
- for ( i, ( min, max) ) in sats_ranges. into_iter ( ) . enumerate ( ) {
1115
- if input_offset >= min && input_offset < max {
1116
- inscription_output_index = i;
1117
- inscription_offset = input_offset - min;
1118
- }
1119
- }
1120
- }
1121
-
1122
1110
let mut sats_out = 0 ;
1123
1111
for ( index, output_value) in lazy_tx. outputs . iter ( ) . enumerate ( ) {
1124
1112
if index == tx_cursor. 1 {
@@ -1153,30 +1141,27 @@ pub fn retrieve_satoshi_point_using_lazy_storage(
1153
1141
inscription_number : 0 ,
1154
1142
ordinal_number : 0 ,
1155
1143
transfers : 0 ,
1156
- inscription_offset ,
1144
+ inscription_offset_intra_output ,
1157
1145
input_index,
1158
- outpoint_to_watch : format_outpoint_to_watch (
1159
- & transaction_identifier,
1160
- inscription_output_index,
1161
- ) ,
1146
+ transaction_identifier : transaction_identifier. clone ( ) ,
1147
+ output_index : inscription_output_index,
1162
1148
} ) ;
1163
1149
}
1164
1150
}
1165
1151
}
1166
1152
1167
1153
let height = Height ( ordinal_block_number. into ( ) ) ;
1168
- let ordinal_number = height. starting_sat ( ) . 0 + ordinal_offset + inscription_offset;
1154
+ let ordinal_number =
1155
+ height. starting_sat ( ) . 0 + ordinal_offset + inscription_offset_cross_outputs;
1169
1156
1170
1157
Ok ( TraversalResult {
1171
1158
inscription_number,
1172
1159
ordinal_number,
1173
1160
transfers : hops,
1174
- inscription_offset ,
1161
+ inscription_offset_intra_output ,
1175
1162
input_index,
1176
- outpoint_to_watch : format_outpoint_to_watch (
1177
- & transaction_identifier,
1178
- inscription_output_index,
1179
- ) ,
1163
+ transaction_identifier : transaction_identifier. clone ( ) ,
1164
+ output_index : inscription_output_index,
1180
1165
} )
1181
1166
}
1182
1167
@@ -1197,6 +1182,27 @@ impl LazyBlockTransaction {
1197
1182
pub fn get_average_bytes_size ( ) -> usize {
1198
1183
TXID_LEN + 3 * LazyBlockTransactionInput :: get_average_bytes_size ( ) + 3 * SATS_LEN
1199
1184
}
1185
+
1186
+ pub fn get_sat_ranges ( & self ) -> Vec < ( u64 , u64 ) > {
1187
+ let mut sats_ranges = vec ! [ ] ;
1188
+ let mut bound = 0u64 ;
1189
+ for output_value in self . outputs . iter ( ) {
1190
+ sats_ranges. push ( ( bound, bound + output_value) ) ;
1191
+ bound += output_value;
1192
+ }
1193
+ sats_ranges
1194
+ }
1195
+
1196
+ pub fn get_cumulated_sats_in_until_input_index ( & self , input_index : usize ) -> u64 {
1197
+ let mut cumulated_sats_in = 0 ;
1198
+ for ( i, input) in self . inputs . iter ( ) . enumerate ( ) {
1199
+ if i == input_index {
1200
+ break ;
1201
+ }
1202
+ cumulated_sats_in += input. txin_value ;
1203
+ }
1204
+ cumulated_sats_in
1205
+ }
1200
1206
}
1201
1207
1202
1208
#[ derive( Debug , Clone ) ]
0 commit comments