@@ -91,6 +91,7 @@ pub(crate) mod fake_scid {
91
91
pub ( crate ) enum Namespace {
92
92
Phantom ,
93
93
OutboundAlias ,
94
+ Intercept
94
95
}
95
96
96
97
impl Namespace {
@@ -151,14 +152,25 @@ pub(crate) mod fake_scid {
151
152
}
152
153
153
154
/// Returns whether the given fake scid falls into the given namespace.
154
- pub fn is_valid_phantom ( fake_scid_rand_bytes : & [ u8 ; 32 ] , scid : u64 ) -> bool {
155
+ pub fn is_in_namespace ( namespace : Namespace , fake_scid_rand_bytes : & [ u8 ; 32 ] , scid : u64 ) -> bool {
155
156
let block_height = scid_utils:: block_from_scid ( & scid) ;
156
157
let tx_index = scid_utils:: tx_index_from_scid ( & scid) ;
157
- let namespace = Namespace :: Phantom ;
158
158
let valid_vout = namespace. get_encrypted_vout ( block_height, tx_index, fake_scid_rand_bytes) ;
159
159
valid_vout == scid_utils:: vout_from_scid ( & scid) as u8
160
160
}
161
161
162
+ /// Returns whether the given fake scid falls into the phantom namespace.
163
+ pub fn is_valid_phantom ( fake_scid_rand_bytes : & [ u8 ; 32 ] , scid : u64 ) -> bool {
164
+ is_in_namespace ( Namespace :: Phantom , fake_scid_rand_bytes, scid)
165
+ }
166
+
167
+ /// Returns whether the given fake scid falls into the intercept namespace.
168
+ pub fn is_valid_intercept ( fake_scid_rand_bytes : & [ u8 ; 32 ] , scid : u64 ) -> bool {
169
+ is_in_namespace ( Namespace :: Intercept , fake_scid_rand_bytes, scid)
170
+ }
171
+
172
+
173
+
162
174
#[ cfg( test) ]
163
175
mod tests {
164
176
use bitcoin:: blockdata:: constants:: genesis_block;
@@ -168,6 +180,8 @@ pub(crate) mod fake_scid {
168
180
use util:: test_utils;
169
181
use sync:: Arc ;
170
182
183
+ use crate :: util:: scid_utils:: fake_scid:: is_valid_intercept;
184
+
171
185
#[ test]
172
186
fn namespace_identifier_is_within_range ( ) {
173
187
let phantom_namespace = Namespace :: Phantom ;
@@ -201,6 +215,16 @@ pub(crate) mod fake_scid {
201
215
assert ! ( !is_valid_phantom( & fake_scid_rand_bytes, invalid_fake_scid) ) ;
202
216
}
203
217
218
+ fn test_is_valid_intercept ( ) {
219
+ let namespace = Namespace :: Intercept ;
220
+ let fake_scid_rand_bytes = [ 0 ; 32 ] ;
221
+ let valid_encrypted_vout = namespace. get_encrypted_vout ( 0 , 0 , & fake_scid_rand_bytes) ;
222
+ let valid_fake_scid = scid_utils:: scid_from_parts ( 0 , 0 , valid_encrypted_vout as u64 ) . unwrap ( ) ;
223
+ assert ! ( is_valid_intercept( & fake_scid_rand_bytes, valid_fake_scid) ) ;
224
+ let invalid_fake_scid = scid_utils:: scid_from_parts ( 0 , 0 , 12 ) . unwrap ( ) ;
225
+ assert ! ( !is_valid_intercept( & fake_scid_rand_bytes, invalid_fake_scid) ) ;
226
+ }
227
+
204
228
#[ test]
205
229
fn test_get_fake_scid ( ) {
206
230
let mainnet_genesis = genesis_block ( Network :: Bitcoin ) . header . block_hash ( ) ;
0 commit comments