@@ -9,26 +9,29 @@ use crate::chainhooks::types::{
9
9
use crate :: indexer:: IndexerConfig ;
10
10
use crate :: observer:: BitcoinConfig ;
11
11
use crate :: utils:: Context ;
12
- use bitcoincore_rpc:: bitcoin:: { self , Script } ;
12
+ use bitcoincore_rpc:: bitcoin:: {
13
+ self , Address , BlockHeader , OutPoint as OutPointS , PackedLockTime , Script , Transaction , Txid ,
14
+ Witness ,
15
+ } ;
13
16
use bitcoincore_rpc_json:: { GetRawTransactionResult , GetRawTransactionResultVout } ;
14
17
pub use blocks_pool:: BitcoinBlockPool ;
15
18
use chainhook_types:: bitcoin:: { OutPoint , TxIn , TxOut } ;
16
19
use chainhook_types:: {
17
20
BitcoinBlockData , BitcoinBlockMetadata , BitcoinTransactionData , BitcoinTransactionMetadata ,
18
21
BlockCommitmentData , BlockIdentifier , KeyRegistrationData , LockSTXData ,
19
- OrdinalInscriptionRevealData , OrdinalInscriptionRevealInscriptionData ,
20
- OrdinalInscriptionRevealOrdinalData , OrdinalOperation , PobBlockCommitmentData ,
21
- PoxBlockCommitmentData , PoxReward , StacksBaseChainOperation , TransactionIdentifier ,
22
- TransferSTXData ,
22
+ OrdinalInscriptionRevealData , OrdinalOperation , PobBlockCommitmentData , PoxBlockCommitmentData ,
23
+ PoxReward , StacksBaseChainOperation , TransactionIdentifier , TransferSTXData ,
23
24
} ;
24
25
use clarity_repl:: clarity:: util:: hash:: to_hex;
25
26
use hiro_system_kit:: slog;
26
27
use rocket:: serde:: json:: Value as JsonValue ;
27
28
28
- use super :: ordinals:: indexing:: updater:: OrdinalIndexUpdater ;
29
+ use super :: ordinals:: indexing:: entry:: InscriptionEntry ;
30
+ use super :: ordinals:: indexing:: updater:: { BlockData , OrdinalIndexUpdater } ;
29
31
use super :: ordinals:: indexing:: OrdinalIndex ;
30
32
use super :: ordinals:: inscription:: InscriptionParser ;
31
33
use super :: ordinals:: inscription_id:: InscriptionId ;
34
+ use super :: ordinals:: sat:: Sat ;
32
35
use super :: BitcoinChainContext ;
33
36
34
37
#[ derive( Clone , PartialEq , Debug , Deserialize , Serialize ) ]
@@ -115,25 +118,111 @@ pub fn standardize_bitcoin_block(
115
118
ctx : & Context ,
116
119
) -> Result < BitcoinBlockData , String > {
117
120
let mut transactions = vec ! [ ] ;
118
- ctx. try_log ( |logger| slog:: info!( logger, "Updating ordinal index" , ) ) ;
121
+ ctx. try_log ( |logger| slog:: info!( logger, "Updating ordinal index" ) ) ;
119
122
120
123
let ordinal_index = bitcoin_context. ordinal_index . take ( ) ;
121
124
let ctx_ = ctx. clone ( ) ;
125
+
126
+ let block_data = if let Some ( ref ordinal_index) = ordinal_index {
127
+ if let Ok ( count) = ordinal_index. block_count ( ) {
128
+ ctx. try_log ( |logger| slog:: info!( logger, "Blocks: {} / {}" , count, block. height) ) ;
129
+ if count as usize == block. height + 10 {
130
+ ctx. try_log ( |logger| slog:: info!( logger, "Will use cached block" ) ) ;
131
+
132
+ // let bits = hex::decode(block.bits).unwrap();
133
+ // let block_data = BlockData {
134
+ // header: BlockHeader {
135
+ // version: block.version,
136
+ // prev_blockhash: block.previousblockhash,
137
+ // merkle_root: block.merkleroot,
138
+ // time: block.time as u32,
139
+ // bits: u32::from_be_bytes([bits[0], bits[1], bits[2], bits[3]]),
140
+ // nonce: block.nonce,
141
+ // },
142
+ // txdata: block
143
+ // .tx
144
+ // .iter()
145
+ // .map(|tx| {
146
+ // (
147
+ // Transaction {
148
+ // version: tx.version as i32,
149
+ // lock_time: PackedLockTime(tx.locktime),
150
+ // input: tx
151
+ // .vin
152
+ // .iter()
153
+ // .map(|i| bitcoin::TxIn {
154
+ // previous_output: match (i.txid, i.vout) {
155
+ // (Some(txid), Some(vout)) => {
156
+ // OutPointS { txid, vout }
157
+ // }
158
+ // _ => OutPointS::null(),
159
+ // },
160
+ // script_sig: match i.script_sig {
161
+ // Some(ref script_sig) => {
162
+ // script_sig.script().unwrap()
163
+ // }
164
+ // None => Script::default(),
165
+ // },
166
+ // sequence: bitcoincore_rpc::bitcoin::Sequence(
167
+ // i.sequence,
168
+ // ),
169
+ // witness: Witness::from_vec(
170
+ // i.txinwitness.clone().unwrap_or(vec![]),
171
+ // ),
172
+ // })
173
+ // .collect(),
174
+ // output: tx
175
+ // .vout
176
+ // .iter()
177
+ // .map(|o| bitcoin::TxOut {
178
+ // value: o.value.to_sat(),
179
+ // script_pubkey: o.script_pub_key.script().unwrap(),
180
+ // })
181
+ // .collect(),
182
+ // },
183
+ // tx.txid,
184
+ // )
185
+ // })
186
+ // .collect::<Vec<(Transaction, Txid)>>(),
187
+ // };
188
+ // ctx.try_log(|logger| slog::info!(logger, "BlockData: {:?}", block_data));
189
+ // Some(block_data)
190
+ None
191
+ } else {
192
+ None
193
+ }
194
+ } else {
195
+ None
196
+ }
197
+ } else {
198
+ None
199
+ } ;
200
+
122
201
let handle: JoinHandle < Result < _ , String > > =
123
202
hiro_system_kit:: thread_named ( "Ordinal index update" )
124
203
. spawn ( move || {
125
204
if let Some ( ref ordinal_index) = ordinal_index {
126
205
match hiro_system_kit:: nestable_block_on ( OrdinalIndexUpdater :: update (
127
206
& ordinal_index,
207
+ block_data,
208
+ & ctx_,
128
209
) ) {
129
210
Ok ( _) => {
130
211
ctx_. try_log ( |logger| {
131
- slog:: info!( logger, "Ordinal index successfully updated" , )
212
+ slog:: info!(
213
+ logger,
214
+ "Ordinal index successfully updated {:?}" ,
215
+ ordinal_index. block_count( )
216
+ )
132
217
} ) ;
133
218
}
134
219
Err ( e) => {
135
220
ctx_. try_log ( |logger| {
136
- slog:: error!( logger, "Error updating ordinal index" , )
221
+ slog:: error!(
222
+ logger,
223
+ "Error updating ordinal index: {}" ,
224
+ e. to_string( )
225
+ )
137
226
} ) ;
138
227
}
139
228
} ;
@@ -276,31 +365,39 @@ fn try_parse_ordinal_operation(
276
365
Ok ( Some ( entry) ) => entry,
277
366
_ => {
278
367
ctx. try_log ( |logger| slog:: info!( logger, "No inscriptions entry found in index, despite inscription detected in transaction" ) ) ;
279
- return None ;
368
+ InscriptionEntry {
369
+ fee : 0 ,
370
+ height : 0 ,
371
+ number : 0 ,
372
+ sat : Some ( Sat ( 0 ) ) ,
373
+ timestamp : 0 ,
374
+ }
280
375
}
281
376
} ;
282
377
378
+ let authors = tx. vout [ 0 ]
379
+ . script_pub_key
380
+ . addresses
381
+ . clone ( )
382
+ . unwrap_or ( vec ! [ ] ) ;
383
+ let sat = & inscription_entry. sat . unwrap ( ) ;
283
384
let no_content_bytes = vec ! [ ] ;
284
385
let inscription_content_bytes = inscription. body ( ) . unwrap_or ( & no_content_bytes) ;
386
+
285
387
return Some ( OrdinalOperation :: InscriptionRevealed (
286
388
OrdinalInscriptionRevealData {
287
- inscription : OrdinalInscriptionRevealInscriptionData {
288
- content_type : inscription
289
- . content_type ( )
290
- . unwrap_or ( "unknown" )
291
- . to_string ( ) ,
292
- content_bytes : format ! ( "0x{}" , to_hex( & inscription_content_bytes) ) ,
293
- content_length : inscription_content_bytes. len ( ) ,
294
- inscription_id : inscription_id. to_string ( ) ,
295
- inscription_number : inscription_entry. number ,
296
- inscription_author : "" . into ( ) ,
297
- inscription_fee : inscription_entry. fee ,
298
- } ,
299
- ordinal : Some ( OrdinalInscriptionRevealOrdinalData {
300
- ordinal_number : inscription_entry. sat . unwrap ( ) . n ( ) ,
301
- ordinal_block_height : 0 ,
302
- ordinal_offset : 0 ,
303
- } ) ,
389
+ content_type : inscription. content_type ( ) . unwrap_or ( "unknown" ) . to_string ( ) ,
390
+ content_bytes : format ! ( "0x{}" , to_hex( & inscription_content_bytes) ) ,
391
+ content_length : inscription_content_bytes. len ( ) ,
392
+ inscription_id : inscription_id. to_string ( ) ,
393
+ inscription_number : inscription_entry. number ,
394
+ inscription_authors : authors
395
+ . into_iter ( )
396
+ . map ( |a| a. to_string ( ) )
397
+ . collect :: < Vec < String > > ( ) ,
398
+ inscription_fee : inscription_entry. fee ,
399
+ ordinal_number : sat. n ( ) ,
400
+ ordinal_block_height : sat. height ( ) . n ( ) ,
304
401
} ,
305
402
) ) ;
306
403
}
0 commit comments