@@ -98,30 +98,36 @@ pub(crate) struct RevokedOutput {
9898 weight : u64 ,
9999 amount : u64 ,
100100 on_counterparty_tx_csv : u16 ,
101+ opt_anchors : Option < ( ) > ,
102+ is_counterparty_balance_or_non_anchors : Option < ( ) > ,
101103}
102104
103105impl RevokedOutput {
104- pub ( crate ) fn build ( per_commitment_point : PublicKey , counterparty_delayed_payment_base_key : PublicKey , counterparty_htlc_base_key : PublicKey , per_commitment_key : SecretKey , amount : u64 , on_counterparty_tx_csv : u16 ) -> Self {
106+ pub ( crate ) fn build ( per_commitment_point : PublicKey , counterparty_delayed_payment_base_key : PublicKey , counterparty_htlc_base_key : PublicKey , per_commitment_key : SecretKey , amount : u64 , on_counterparty_tx_csv : u16 , opt_anchors : bool , is_counterparty_balance : bool ) -> Self {
105107 RevokedOutput {
106108 per_commitment_point,
107109 counterparty_delayed_payment_base_key,
108110 counterparty_htlc_base_key,
109111 per_commitment_key,
110112 weight : WEIGHT_REVOKED_OUTPUT ,
111113 amount,
112- on_counterparty_tx_csv
114+ on_counterparty_tx_csv,
115+ opt_anchors : if opt_anchors { Some ( ( ) ) } else { None } ,
116+ is_counterparty_balance_or_non_anchors : if is_counterparty_balance { Some ( ( ) ) } else { None } ,
113117 }
114118 }
115119}
116120
117121impl_writeable_tlv_based ! ( RevokedOutput , {
118122 ( 0 , per_commitment_point, required) ,
123+ ( 1 , is_counterparty_balance_or_non_anchors, option) ,
119124 ( 2 , counterparty_delayed_payment_base_key, required) ,
120125 ( 4 , counterparty_htlc_base_key, required) ,
121126 ( 6 , per_commitment_key, required) ,
122127 ( 8 , weight, required) ,
123128 ( 10 , amount, required) ,
124129 ( 12 , on_counterparty_tx_csv, required) ,
130+ ( 14 , opt_anchors, option) ,
125131} ) ;
126132
127133/// A struct to describe a revoked offered output and corresponding information to generate a
@@ -785,18 +791,7 @@ impl PackageTemplate {
785791 }
786792
787793 pub ( crate ) fn build_package ( txid : Txid , vout : u32 , input_solving_data : PackageSolvingData , soonest_conf_deadline : u32 , aggregable : bool , height_original : u32 ) -> Self {
788- let malleability = match input_solving_data {
789- PackageSolvingData :: RevokedOutput ( ..) => PackageMalleability :: Malleable ,
790- PackageSolvingData :: RevokedHTLCOutput ( ..) => PackageMalleability :: Malleable ,
791- PackageSolvingData :: CounterpartyOfferedHTLCOutput ( ..) => PackageMalleability :: Malleable ,
792- PackageSolvingData :: CounterpartyReceivedHTLCOutput ( ..) => PackageMalleability :: Malleable ,
793- PackageSolvingData :: HolderHTLCOutput ( ref outp) => if outp. opt_anchors ( ) {
794- PackageMalleability :: Malleable
795- } else {
796- PackageMalleability :: Untractable
797- } ,
798- PackageSolvingData :: HolderFundingOutput ( ..) => PackageMalleability :: Untractable ,
799- } ;
794+ let ( malleability, aggregable) = Self :: map_output_type_flags ( & input_solving_data) ;
800795 let mut inputs = Vec :: with_capacity ( 1 ) ;
801796 inputs. push ( ( BitcoinOutPoint { txid, vout } , input_solving_data) ) ;
802797 PackageTemplate {
@@ -809,6 +804,20 @@ impl PackageTemplate {
809804 height_original,
810805 }
811806 }
807+
808+ fn map_output_type_flags ( input_solving_data : & PackageSolvingData ) -> ( PackageMalleability , bool ) {
809+ let ( malleability, aggregable) = match input_solving_data {
810+ PackageSolvingData :: RevokedOutput ( RevokedOutput { is_counterparty_balance_or_non_anchors : None , .. } ) => { ( PackageMalleability :: Malleable , true ) } ,
811+ PackageSolvingData :: RevokedOutput ( RevokedOutput { opt_anchors : Some ( ..) , .. } ) => { ( PackageMalleability :: Malleable , false ) } ,
812+ PackageSolvingData :: RevokedOutput ( RevokedOutput { opt_anchors : None , .. } ) => { ( PackageMalleability :: Malleable , true ) } ,
813+ PackageSolvingData :: RevokedHTLCOutput ( ..) => { ( PackageMalleability :: Malleable , true ) } ,
814+ PackageSolvingData :: CounterpartyOfferedHTLCOutput ( ..) => { ( PackageMalleability :: Malleable , true ) } ,
815+ PackageSolvingData :: CounterpartyReceivedHTLCOutput ( ..) => { ( PackageMalleability :: Malleable , false ) } ,
816+ PackageSolvingData :: HolderHTLCOutput ( ..) => { ( PackageMalleability :: Untractable , false ) } ,
817+ PackageSolvingData :: HolderFundingOutput ( ..) => { ( PackageMalleability :: Untractable , false ) } ,
818+ } ;
819+ ( malleability, aggregable)
820+ }
812821}
813822
814823impl Writeable for PackageTemplate {
@@ -838,18 +847,7 @@ impl Readable for PackageTemplate {
838847 inputs. push ( ( outpoint, rev_outp) ) ;
839848 }
840849 let ( malleability, aggregable) = if let Some ( ( _, lead_input) ) = inputs. first ( ) {
841- match lead_input {
842- PackageSolvingData :: RevokedOutput ( ..) => { ( PackageMalleability :: Malleable , true ) } ,
843- PackageSolvingData :: RevokedHTLCOutput ( ..) => { ( PackageMalleability :: Malleable , true ) } ,
844- PackageSolvingData :: CounterpartyOfferedHTLCOutput ( ..) => { ( PackageMalleability :: Malleable , true ) } ,
845- PackageSolvingData :: CounterpartyReceivedHTLCOutput ( ..) => { ( PackageMalleability :: Malleable , false ) } ,
846- PackageSolvingData :: HolderHTLCOutput ( ref outp) => if outp. opt_anchors ( ) {
847- ( PackageMalleability :: Malleable , outp. preimage . is_some ( ) )
848- } else {
849- ( PackageMalleability :: Untractable , false )
850- } ,
851- PackageSolvingData :: HolderFundingOutput ( ..) => { ( PackageMalleability :: Untractable , false ) } ,
852- }
850+ Self :: map_output_type_flags ( & lead_input)
853851 } else { return Err ( DecodeError :: InvalidValue ) ; } ;
854852 let mut soonest_conf_deadline = 0 ;
855853 let mut feerate_previous = 0 ;
@@ -973,7 +971,7 @@ mod tests {
973971 {
974972 let dumb_scalar = SecretKey :: from_slice( & hex:: decode( "0101010101010101010101010101010101010101010101010101010101010101" ) . unwrap( ) [ ..] ) . unwrap( ) ;
975973 let dumb_point = PublicKey :: from_secret_key( & $secp_ctx, & dumb_scalar) ;
976- PackageSolvingData :: RevokedOutput ( RevokedOutput :: build( dumb_point, dumb_point, dumb_point, dumb_scalar, 0 , 0 ) )
974+ PackageSolvingData :: RevokedOutput ( RevokedOutput :: build( dumb_point, dumb_point, dumb_point, dumb_scalar, 0 , 0 , false , false ) )
977975 }
978976 }
979977 }
0 commit comments