@@ -2,13 +2,14 @@ mod blocks_pool;
2
2
3
3
pub use blocks_pool:: StacksBlockPool ;
4
4
5
+ use crate :: chainhooks:: stacks:: try_decode_clarity_value;
5
6
use crate :: indexer:: AssetClassCache ;
6
7
use crate :: indexer:: { IndexerConfig , StacksChainContext } ;
7
8
use crate :: utils:: Context ;
8
9
use chainhook_types:: * ;
9
10
use clarity_repl:: clarity:: codec:: StacksMessageCodec ;
10
11
use clarity_repl:: clarity:: util:: hash:: hex_bytes;
11
- use clarity_repl:: clarity:: vm:: types:: Value as ClarityValue ;
12
+ use clarity_repl:: clarity:: vm:: types:: { SequenceData , Value as ClarityValue } ;
12
13
use clarity_repl:: codec:: { StacksTransaction , TransactionAuth , TransactionPayload } ;
13
14
use hiro_system_kit:: slog;
14
15
use rocket:: serde:: json:: Value as JsonValue ;
@@ -539,8 +540,108 @@ pub fn get_tx_description(
539
540
"stacked: {} µSTX by {} through Bitcoin transaction" ,
540
541
data. locked_amount, data. locked_address,
541
542
) ;
542
- let tx_type = StacksTransactionKind :: Other ;
543
+ let tx_type =
544
+ StacksTransactionKind :: BitcoinOp ( BitcoinOpData :: StackSTX ( StackSTXData {
545
+ locked_amount : data. locked_amount ,
546
+ unlock_height : data. unlock_height ,
547
+ stacking_address : data. locked_address . clone ( ) ,
548
+ } ) ) ;
543
549
return Ok ( ( description, tx_type, 0 , 0 , data. locked_address , None ) ) ;
550
+ } else if let Some ( ref event_data) = event. contract_event {
551
+ let data: SmartContractEventData = serde_json:: from_value ( event_data. clone ( ) )
552
+ . map_err ( |e| format ! ( "unable to decode event_data {}" , e. to_string( ) ) ) ?;
553
+ if let Some ( ClarityValue :: Response ( data) ) =
554
+ try_decode_clarity_value ( & data. hex_value )
555
+ {
556
+ if data. committed {
557
+ if let ClarityValue :: Tuple ( outter) = * data. data {
558
+ if let Some ( ClarityValue :: Tuple ( inner) ) = outter. data_map . get ( "data" ) {
559
+ match (
560
+ & outter. data_map . get ( "stacker" ) ,
561
+ & inner. data_map . get ( "amount-ustx" ) ,
562
+ & inner. data_map . get ( "delegate-to" ) ,
563
+ & inner. data_map . get ( "pox-addr" ) ,
564
+ & inner. data_map . get ( "unlock-burn-height" ) ,
565
+ ) {
566
+ (
567
+ Some ( ClarityValue :: Principal ( stacking_address) ) ,
568
+ Some ( ClarityValue :: UInt ( amount_ustx) ) ,
569
+ Some ( ClarityValue :: Principal ( delegate) ) ,
570
+ Some ( ClarityValue :: Optional ( pox_addr) ) ,
571
+ Some ( ClarityValue :: Optional ( unlock_burn_height) ) ,
572
+ ) => {
573
+ let description = format ! (
574
+ "stacked: {} µSTX delegated to {} through Bitcoin transaction" ,
575
+ amount_ustx, delegate. to_string( ) ,
576
+ ) ;
577
+ let tx_type = StacksTransactionKind :: BitcoinOp (
578
+ BitcoinOpData :: DelegateStackSTX ( DelegateStackSTXData {
579
+ stacking_address : stacking_address. to_string ( ) ,
580
+ amount : amount_ustx. to_string ( ) ,
581
+ delegate : delegate. to_string ( ) ,
582
+ pox_address : match & pox_addr. data {
583
+ Some ( value) => match & * * value {
584
+ ClarityValue :: Tuple ( address_comps) => {
585
+ match (
586
+ & address_comps
587
+ . data_map
588
+ . get ( "version" ) ,
589
+ & address_comps
590
+ . data_map
591
+ . get ( "hashbytes" ) ,
592
+ ) {
593
+ (
594
+ Some ( ClarityValue :: UInt (
595
+ _version,
596
+ ) ) ,
597
+ Some ( ClarityValue :: Sequence (
598
+ SequenceData :: Buffer (
599
+ _hashbytes,
600
+ ) ,
601
+ ) ) ,
602
+ ) => None ,
603
+ _ => None ,
604
+ }
605
+ }
606
+ _ => None ,
607
+ } ,
608
+ _ => None ,
609
+ } ,
610
+ unlock_height : match & * ( & unlock_burn_height. data ) {
611
+ Some ( value) => match & * * value {
612
+ ClarityValue :: UInt ( value) => {
613
+ Some ( value. to_string ( ) )
614
+ }
615
+ _ => None ,
616
+ } ,
617
+ _ => None ,
618
+ } ,
619
+ } ) ,
620
+ ) ;
621
+ return Ok ( (
622
+ description,
623
+ tx_type,
624
+ 0 ,
625
+ 0 ,
626
+ "" . to_string ( ) ,
627
+ None ,
628
+ ) ) ;
629
+ }
630
+ _ => { }
631
+ }
632
+ }
633
+ }
634
+ }
635
+ }
636
+ } else {
637
+ return Ok ( (
638
+ "unsupported transaction" . into ( ) ,
639
+ StacksTransactionKind :: Unsupported ,
640
+ 0 ,
641
+ 0 ,
642
+ "" . to_string ( ) ,
643
+ None ,
644
+ ) ) ;
544
645
}
545
646
}
546
647
return Err ( format ! (
@@ -627,7 +728,7 @@ pub fn get_tx_description(
627
728
TransactionPayload :: Coinbase ( _, _) => {
628
729
( format ! ( "coinbase" ) , StacksTransactionKind :: Coinbase )
629
730
}
630
- _ => ( format ! ( "other" ) , StacksTransactionKind :: Other ) ,
731
+ _ => ( format ! ( "other" ) , StacksTransactionKind :: Unsupported ) ,
631
732
} ;
632
733
Ok ( ( description, tx_type, fee, nonce, sender, sponsor) )
633
734
}
0 commit comments