@@ -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
@@ -827,18 +833,7 @@ impl PackageTemplate {
827833 }
828834
829835 pub ( crate ) fn build_package ( txid : Txid , vout : u32 , input_solving_data : PackageSolvingData , soonest_conf_deadline : u32 , aggregable : bool , height_original : u32 ) -> Self {
830- let malleability = match input_solving_data {
831- PackageSolvingData :: RevokedOutput ( ..) => PackageMalleability :: Malleable ,
832- PackageSolvingData :: RevokedHTLCOutput ( ..) => PackageMalleability :: Malleable ,
833- PackageSolvingData :: CounterpartyOfferedHTLCOutput ( ..) => PackageMalleability :: Malleable ,
834- PackageSolvingData :: CounterpartyReceivedHTLCOutput ( ..) => PackageMalleability :: Malleable ,
835- PackageSolvingData :: HolderHTLCOutput ( ref outp) => if outp. opt_anchors ( ) {
836- PackageMalleability :: Malleable
837- } else {
838- PackageMalleability :: Untractable
839- } ,
840- PackageSolvingData :: HolderFundingOutput ( ..) => PackageMalleability :: Untractable ,
841- } ;
836+ let ( malleability, aggregable) = Self :: map_output_type_flags ( & input_solving_data) ;
842837 let mut inputs = Vec :: with_capacity ( 1 ) ;
843838 inputs. push ( ( BitcoinOutPoint { txid, vout } , input_solving_data) ) ;
844839 PackageTemplate {
@@ -851,6 +846,20 @@ impl PackageTemplate {
851846 height_original,
852847 }
853848 }
849+
850+ fn map_output_type_flags ( input_solving_data : & PackageSolvingData ) -> ( PackageMalleability , bool ) {
851+ let ( malleability, aggregable) = match input_solving_data {
852+ PackageSolvingData :: RevokedOutput ( RevokedOutput { is_counterparty_balance_or_non_anchors : None , .. } ) => { ( PackageMalleability :: Malleable , true ) } ,
853+ PackageSolvingData :: RevokedOutput ( RevokedOutput { opt_anchors : Some ( ..) , .. } ) => { ( PackageMalleability :: Malleable , false ) } ,
854+ PackageSolvingData :: RevokedOutput ( RevokedOutput { opt_anchors : None , .. } ) => { ( PackageMalleability :: Malleable , true ) } ,
855+ PackageSolvingData :: RevokedHTLCOutput ( ..) => { ( PackageMalleability :: Malleable , true ) } ,
856+ PackageSolvingData :: CounterpartyOfferedHTLCOutput ( ..) => { ( PackageMalleability :: Malleable , true ) } ,
857+ PackageSolvingData :: CounterpartyReceivedHTLCOutput ( ..) => { ( PackageMalleability :: Malleable , false ) } ,
858+ PackageSolvingData :: HolderHTLCOutput ( ..) => { ( PackageMalleability :: Untractable , false ) } ,
859+ PackageSolvingData :: HolderFundingOutput ( ..) => { ( PackageMalleability :: Untractable , false ) } ,
860+ } ;
861+ ( malleability, aggregable)
862+ }
854863}
855864
856865impl Writeable for PackageTemplate {
@@ -880,18 +889,7 @@ impl Readable for PackageTemplate {
880889 inputs. push ( ( outpoint, rev_outp) ) ;
881890 }
882891 let ( malleability, aggregable) = if let Some ( ( _, lead_input) ) = inputs. first ( ) {
883- match lead_input {
884- PackageSolvingData :: RevokedOutput ( ..) => { ( PackageMalleability :: Malleable , true ) } ,
885- PackageSolvingData :: RevokedHTLCOutput ( ..) => { ( PackageMalleability :: Malleable , true ) } ,
886- PackageSolvingData :: CounterpartyOfferedHTLCOutput ( ..) => { ( PackageMalleability :: Malleable , true ) } ,
887- PackageSolvingData :: CounterpartyReceivedHTLCOutput ( ..) => { ( PackageMalleability :: Malleable , false ) } ,
888- PackageSolvingData :: HolderHTLCOutput ( ref outp) => if outp. opt_anchors ( ) {
889- ( PackageMalleability :: Malleable , outp. preimage . is_some ( ) )
890- } else {
891- ( PackageMalleability :: Untractable , false )
892- } ,
893- PackageSolvingData :: HolderFundingOutput ( ..) => { ( PackageMalleability :: Untractable , false ) } ,
894- }
892+ Self :: map_output_type_flags ( & lead_input)
895893 } else { return Err ( DecodeError :: InvalidValue ) ; } ;
896894 let mut soonest_conf_deadline = 0 ;
897895 let mut feerate_previous = 0 ;
@@ -1033,7 +1031,7 @@ mod tests {
10331031 {
10341032 let dumb_scalar = SecretKey :: from_slice( & hex:: decode( "0101010101010101010101010101010101010101010101010101010101010101" ) . unwrap( ) [ ..] ) . unwrap( ) ;
10351033 let dumb_point = PublicKey :: from_secret_key( & $secp_ctx, & dumb_scalar) ;
1036- PackageSolvingData :: RevokedOutput ( RevokedOutput :: build( dumb_point, dumb_point, dumb_point, dumb_scalar, 0 , 0 ) )
1034+ PackageSolvingData :: RevokedOutput ( RevokedOutput :: build( dumb_point, dumb_point, dumb_point, dumb_scalar, 0 , 0 , false , false ) )
10371035 }
10381036 }
10391037 }
0 commit comments