@@ -32,6 +32,11 @@ pub fn block_from_scid(short_channel_id: &u64) -> u32 {
32
32
return ( short_channel_id >> 40 ) as u32 ;
33
33
}
34
34
35
+ /// Extracts the tx index (bytes [2..4]) from the `short_channel_id` // XXX
36
+ pub fn tx_index_from_scid ( short_channel_id : & u64 ) -> u32 {
37
+ return ( short_channel_id >> 16 & MAX_SCID_TX_INDEX ) as u32 ;
38
+ }
39
+
35
40
/// Constructs a `short_channel_id` using the components pieces. Results in an error
36
41
/// if the block height, tx index, or vout index overflow the maximum sizes.
37
42
pub fn scid_from_parts ( block : u64 , tx_index : u64 , vout_index : u64 ) -> Result < u64 , ShortChannelIdError > {
@@ -63,6 +68,15 @@ mod tests {
63
68
assert_eq ! ( block_from_scid( & 0xffffff_ffffff_ffff ) , 0xffffff ) ;
64
69
}
65
70
71
+ #[ test]
72
+ fn test_tx_index_from_scid ( ) {
73
+ assert_eq ! ( tx_index_from_scid( & 0x000000_000000_0000 ) , 0 ) ;
74
+ assert_eq ! ( tx_index_from_scid( & 0x000000_000001_0000 ) , 1 ) ;
75
+ assert_eq ! ( tx_index_from_scid( & 0xffffff_000001_ffff ) , 1 ) ;
76
+ assert_eq ! ( tx_index_from_scid( & 0xffffff_800000_ffff ) , 0x800000 ) ;
77
+ assert_eq ! ( tx_index_from_scid( & 0xffffff_ffffff_ffff ) , 0xffffff ) ;
78
+ }
79
+
66
80
#[ test]
67
81
fn test_scid_from_parts ( ) {
68
82
assert_eq ! ( scid_from_parts( 0x00000000 , 0x00000000 , 0x0000 ) . unwrap( ) , 0x000000_000000_0000 ) ;
0 commit comments