@@ -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 || !opt_anchors) { 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, required) ,
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
@@ -827,18 +833,7 @@ impl PackageTemplate {
827
833
}
828
834
829
835
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) ;
842
837
let mut inputs = Vec :: with_capacity ( 1 ) ;
843
838
inputs. push ( ( BitcoinOutPoint { txid, vout } , input_solving_data) ) ;
844
839
PackageTemplate {
@@ -851,6 +846,20 @@ impl PackageTemplate {
851
846
height_original,
852
847
}
853
848
}
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
+ }
854
863
}
855
864
856
865
impl Writeable for PackageTemplate {
@@ -880,18 +889,7 @@ impl Readable for PackageTemplate {
880
889
inputs. push ( ( outpoint, rev_outp) ) ;
881
890
}
882
891
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)
895
893
} else { return Err ( DecodeError :: InvalidValue ) ; } ;
896
894
let mut soonest_conf_deadline = 0 ;
897
895
let mut feerate_previous = 0 ;
@@ -1033,7 +1031,7 @@ mod tests {
1033
1031
{
1034
1032
let dumb_scalar = SecretKey :: from_slice( & hex:: decode( "0101010101010101010101010101010101010101010101010101010101010101" ) . unwrap( ) [ ..] ) . unwrap( ) ;
1035
1033
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 ) )
1037
1035
}
1038
1036
}
1039
1037
}
0 commit comments