@@ -600,18 +600,42 @@ pub struct ValueFlow {
600
600
601
601
/// Total fees collected in this block.
602
602
pub fees_collected : CurrencyCollection ,
603
+
604
+ /// Burned native tokens and extra currencies.
605
+ pub burned : CurrencyCollection ,
606
+
603
607
/// Shard fees imported to this block.
604
608
pub fees_imported : CurrencyCollection ,
605
609
/// Fee recovery (?)
606
610
pub recovered : CurrencyCollection ,
607
611
/// Block creation fees.
608
612
pub created : CurrencyCollection ,
609
- /// Minted extra currencies.
613
+ /// Minted native tokens and extra currencies.
610
614
pub minted : CurrencyCollection ,
611
615
}
612
616
613
617
impl ValueFlow {
614
618
const TAG_V1 : u32 = 0xb8e48dfb ;
619
+ const TAG_V2 : u32 = 0x3ebf98b7 ;
620
+
621
+ /// Returns `true` if an inbound value flow is in sync with an outbound.
622
+ pub fn validate ( & self ) -> Result < bool , Error > {
623
+ let in_val = self
624
+ . from_prev_block
625
+ . checked_add ( & self . imported )
626
+ . and_then ( |val| val. checked_add ( & self . fees_imported ) )
627
+ . and_then ( |val| val. checked_add ( & self . created ) )
628
+ . and_then ( |val| val. checked_add ( & self . minted ) )
629
+ . and_then ( |val| val. checked_add ( & self . recovered ) ) ?;
630
+
631
+ let out_val = self
632
+ . to_next_block
633
+ . checked_add ( & self . exported )
634
+ . and_then ( |val| val. checked_add ( & self . fees_collected ) )
635
+ . and_then ( |val| val. checked_add ( & self . burned ) ) ?;
636
+
637
+ Ok ( in_val == out_val)
638
+ }
615
639
}
616
640
617
641
impl Store for ValueFlow {
@@ -620,6 +644,12 @@ impl Store for ValueFlow {
620
644
builder : & mut CellBuilder ,
621
645
context : & dyn CellContext ,
622
646
) -> Result < ( ) , Error > {
647
+ let ( tag, store_burned) = if self . burned . is_zero ( ) {
648
+ ( Self :: TAG_V1 , false )
649
+ } else {
650
+ ( Self :: TAG_V2 , true )
651
+ } ;
652
+
623
653
let cell1 = {
624
654
let mut builder = CellBuilder :: new ( ) ;
625
655
ok ! ( self . from_prev_block. store_into( & mut builder, context) ) ;
@@ -629,10 +659,13 @@ impl Store for ValueFlow {
629
659
ok ! ( builder. build_ext( context) )
630
660
} ;
631
661
632
- ok ! ( builder. store_u32( Self :: TAG_V1 ) ) ;
662
+ ok ! ( builder. store_u32( tag ) ) ;
633
663
ok ! ( builder. store_reference( cell1) ) ;
634
664
635
665
ok ! ( self . fees_collected. store_into( builder, context) ) ;
666
+ if store_burned {
667
+ ok ! ( self . burned. store_into( builder, context) ) ;
668
+ }
636
669
637
670
let cell2 = {
638
671
let mut builder = CellBuilder :: new ( ) ;
@@ -648,12 +681,19 @@ impl Store for ValueFlow {
648
681
649
682
impl < ' a > Load < ' a > for ValueFlow {
650
683
fn load_from ( slice : & mut CellSlice < ' a > ) -> Result < Self , Error > {
651
- match ok ! ( slice. load_u32( ) ) {
652
- Self :: TAG_V1 => { }
684
+ let with_burned = match ok ! ( slice. load_u32( ) ) {
685
+ Self :: TAG_V1 => false ,
686
+ Self :: TAG_V2 => true ,
653
687
_ => return Err ( Error :: InvalidTag ) ,
654
688
} ;
655
689
656
690
let fees_collected = ok ! ( CurrencyCollection :: load_from( slice) ) ;
691
+ let burned = if with_burned {
692
+ ok ! ( CurrencyCollection :: load_from( slice) )
693
+ } else {
694
+ CurrencyCollection :: ZERO
695
+ } ;
696
+
657
697
let slice1 = & mut ok ! ( slice. load_reference_as_slice( ) ) ;
658
698
let slice2 = & mut ok ! ( slice. load_reference_as_slice( ) ) ;
659
699
@@ -663,6 +703,7 @@ impl<'a> Load<'a> for ValueFlow {
663
703
imported : ok ! ( CurrencyCollection :: load_from( slice1) ) ,
664
704
exported : ok ! ( CurrencyCollection :: load_from( slice1) ) ,
665
705
fees_collected,
706
+ burned,
666
707
fees_imported : ok ! ( CurrencyCollection :: load_from( slice2) ) ,
667
708
recovered : ok ! ( CurrencyCollection :: load_from( slice2) ) ,
668
709
created : ok ! ( CurrencyCollection :: load_from( slice2) ) ,
0 commit comments