@@ -98,30 +98,36 @@ pub(crate) struct RevokedOutput {
98
98
weight : u64 ,
99
99
amount : u64 ,
100
100
on_counterparty_tx_csv : u16 ,
101
+ opt_anchors : Option < ( ) > ,
102
+ is_counterparty_balance_or_non_anchors : Option < ( ) > ,
101
103
}
102
104
103
105
impl 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 {
105
107
RevokedOutput {
106
108
per_commitment_point,
107
109
counterparty_delayed_payment_base_key,
108
110
counterparty_htlc_base_key,
109
111
per_commitment_key,
110
112
weight : WEIGHT_REVOKED_OUTPUT ,
111
113
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 } ,
113
117
}
114
118
}
115
119
}
116
120
117
121
impl_writeable_tlv_based ! ( RevokedOutput , {
118
122
( 0 , per_commitment_point, required) ,
123
+ ( 1 , is_counterparty_balance_or_non_anchors, option) ,
119
124
( 2 , counterparty_delayed_payment_base_key, required) ,
120
125
( 4 , counterparty_htlc_base_key, required) ,
121
126
( 6 , per_commitment_key, required) ,
122
127
( 8 , weight, required) ,
123
128
( 10 , amount, required) ,
124
129
( 12 , on_counterparty_tx_csv, required) ,
130
+ ( 14 , opt_anchors, option) ,
125
131
} ) ;
126
132
127
133
/// A struct to describe a revoked offered output and corresponding information to generate a
@@ -785,18 +791,7 @@ impl PackageTemplate {
785
791
}
786
792
787
793
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) ;
800
795
let mut inputs = Vec :: with_capacity ( 1 ) ;
801
796
inputs. push ( ( BitcoinOutPoint { txid, vout } , input_solving_data) ) ;
802
797
PackageTemplate {
@@ -809,6 +804,20 @@ impl PackageTemplate {
809
804
height_original,
810
805
}
811
806
}
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
+ }
812
821
}
813
822
814
823
impl Writeable for PackageTemplate {
@@ -838,18 +847,7 @@ impl Readable for PackageTemplate {
838
847
inputs. push ( ( outpoint, rev_outp) ) ;
839
848
}
840
849
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)
853
851
} else { return Err ( DecodeError :: InvalidValue ) ; } ;
854
852
let mut soonest_conf_deadline = 0 ;
855
853
let mut feerate_previous = 0 ;
@@ -973,7 +971,7 @@ mod tests {
973
971
{
974
972
let dumb_scalar = SecretKey :: from_slice( & hex:: decode( "0101010101010101010101010101010101010101010101010101010101010101" ) . unwrap( ) [ ..] ) . unwrap( ) ;
975
973
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 ) )
977
975
}
978
976
}
979
977
}
0 commit comments