@@ -418,7 +418,7 @@ pub fn blockstack_op_extended_serialize_opt<S: Serializer>(
418
418
}
419
419
420
420
/// Deserialize the burnchain op that was serialized with blockstack_op_to_json
421
- pub fn deserialize_extended_blockstack_op < ' de , D > (
421
+ pub fn blockstack_op_extended_deserialize < ' de , D > (
422
422
deserializer : D ,
423
423
) -> Result < Option < BlockstackOperationType > , D :: Error >
424
424
where
@@ -476,40 +476,29 @@ where
476
476
. map_err ( serde:: de:: Error :: custom)
477
477
}
478
478
479
- macro_rules! normalize_common_fields {
480
- ( $map: ident, $de: ident) => { {
481
- normalize_hex_field:: <$de, _>( & mut $map, "burn_header_hash" , |s| {
482
- BurnchainHeaderHash :: from_hex( s) . map_err( DeError :: custom)
483
- } ) ?;
484
- rename_field( & mut $map, "burn_txid" , "txid" ) ;
485
- rename_field( & mut $map, "burn_block_height" , "block_height" ) ;
486
- } } ;
487
- }
488
-
489
- // Utility function to normalize a hex string to a BurnchainHeaderHash JSON value
490
- fn normalize_hex_field < ' de , D , T > (
479
+ fn normalize_common_fields < ' de , D > (
491
480
map : & mut serde_json:: Map < String , serde_json:: Value > ,
492
- field : & str ,
493
- from_hex : fn ( & str ) -> Result < T , D :: Error > ,
494
481
) -> Result < ( ) , D :: Error >
495
482
where
496
483
D : Deserializer < ' de > ,
497
- T : serde:: Serialize ,
498
484
{
499
- if let Some ( hex_str) = map. get ( field) . and_then ( serde_json:: Value :: as_str) {
485
+ if let Some ( hex_str) = map
486
+ . get ( "burn_header_hash" )
487
+ . and_then ( serde_json:: Value :: as_str)
488
+ {
500
489
let cleaned = hex_str. strip_prefix ( "0x" ) . unwrap_or ( hex_str) ;
501
- let val = from_hex ( cleaned) . map_err ( DeError :: custom) ?;
490
+ let val = BurnchainHeaderHash :: from_hex ( cleaned) . map_err ( DeError :: custom) ?;
502
491
let ser_val = serde_json:: to_value ( val) . map_err ( DeError :: custom) ?;
503
- map. insert ( field . to_string ( ) , ser_val) ;
492
+ map. insert ( "burn_header_hash" . to_string ( ) , ser_val) ;
504
493
}
505
- Ok ( ( ) )
506
- }
507
494
508
- // Normalize renamed field
509
- fn rename_field ( map : & mut serde_json:: Map < String , serde_json:: Value > , from : & str , to : & str ) {
510
- if let Some ( val) = map. remove ( from) {
511
- map. insert ( to. to_string ( ) , val) ;
495
+ if let Some ( val) = map. remove ( "burn_txid" ) {
496
+ map. insert ( "txid" . to_string ( ) , val) ;
497
+ }
498
+ if let Some ( val) = map. remove ( "burn_block_height" ) {
499
+ map. insert ( "block_height" . to_string ( ) , val) ;
512
500
}
501
+ Ok ( ( ) )
513
502
}
514
503
515
504
impl BlockstackOperationType {
@@ -615,25 +604,25 @@ impl BlockstackOperationType {
615
604
616
605
// Replace all the normalize_* functions with minimal implementations
617
606
fn normalize_pre_stx_fields < ' de , D > (
618
- mut map : & mut serde_json:: Map < String , serde_json:: Value > ,
607
+ map : & mut serde_json:: Map < String , serde_json:: Value > ,
619
608
) -> Result < ( ) , D :: Error >
620
609
where
621
610
D : Deserializer < ' de > ,
622
611
{
623
- normalize_common_fields ! ( map, D ) ;
612
+ normalize_common_fields :: < D > ( map) ? ;
624
613
if let Some ( serde_json:: Value :: Object ( obj) ) = map. get_mut ( "output" ) {
625
614
normalize_stacks_addr_fields :: < D > ( obj) ?;
626
615
}
627
616
Ok ( ( ) )
628
617
}
629
618
630
619
fn normalize_stack_stx_fields < ' de , D > (
631
- mut map : & mut serde_json:: Map < String , serde_json:: Value > ,
620
+ map : & mut serde_json:: Map < String , serde_json:: Value > ,
632
621
) -> Result < ( ) , D :: Error >
633
622
where
634
623
D : Deserializer < ' de > ,
635
624
{
636
- normalize_common_fields ! ( map, D ) ;
625
+ normalize_common_fields :: < D > ( map) ? ;
637
626
if let Some ( serde_json:: Value :: Object ( obj) ) = map. get_mut ( "sender" ) {
638
627
normalize_stacks_addr_fields :: < D > ( obj) ?;
639
628
}
@@ -650,12 +639,12 @@ impl BlockstackOperationType {
650
639
}
651
640
652
641
fn normalize_transfer_stx_fields < ' de , D > (
653
- mut map : & mut serde_json:: Map < String , serde_json:: Value > ,
642
+ map : & mut serde_json:: Map < String , serde_json:: Value > ,
654
643
) -> Result < ( ) , D :: Error >
655
644
where
656
645
D : Deserializer < ' de > ,
657
646
{
658
- normalize_common_fields ! ( map, D ) ;
647
+ normalize_common_fields :: < D > ( map) ? ;
659
648
for field in [ "recipient" , "sender" ] {
660
649
if let Some ( serde_json:: Value :: Object ( obj) ) = map. get_mut ( field) {
661
650
normalize_stacks_addr_fields :: < D > ( obj) ?;
@@ -671,12 +660,12 @@ impl BlockstackOperationType {
671
660
}
672
661
673
662
fn normalize_delegate_stx_fields < ' de , D > (
674
- mut map : & mut serde_json:: Map < String , serde_json:: Value > ,
663
+ map : & mut serde_json:: Map < String , serde_json:: Value > ,
675
664
) -> Result < ( ) , D :: Error >
676
665
where
677
666
D : Deserializer < ' de > ,
678
667
{
679
- normalize_common_fields ! ( map, D ) ;
668
+ normalize_common_fields :: < D > ( map) ? ;
680
669
if let Some ( serde_json:: Value :: Array ( arr) ) = map. get ( "reward_addr" ) {
681
670
if arr. len ( ) == 2 {
682
671
let index = arr[ 0 ]
@@ -701,12 +690,12 @@ impl BlockstackOperationType {
701
690
}
702
691
703
692
fn normalize_vote_for_aggregate_key_fields < ' de , D > (
704
- mut map : & mut serde_json:: Map < String , serde_json:: Value > ,
693
+ map : & mut serde_json:: Map < String , serde_json:: Value > ,
705
694
) -> Result < ( ) , D :: Error >
706
695
where
707
696
D : Deserializer < ' de > ,
708
697
{
709
- normalize_common_fields ! ( map, D ) ;
698
+ normalize_common_fields :: < D > ( map) ? ;
710
699
for field in [ "aggregate_key" , "signer_key" ] {
711
700
if let Some ( hex_str) = map. get ( field) . and_then ( serde_json:: Value :: as_str) {
712
701
let cleaned = hex_str. strip_prefix ( "0x" ) . unwrap_or ( hex_str) ;
0 commit comments