@@ -4,29 +4,6 @@ use lightning::sign::EntropySource;
44use crate :: lsps0:: ser:: RequestId ;
55use crate :: prelude:: String ;
66
7- /// Maximum transaction index that can be used in a `short_channel_id`.
8- /// This value is based on the 3-bytes available for tx index.
9- pub const MAX_SCID_TX_INDEX : u64 = 0x00ffffff ;
10-
11- /// Maximum vout index that can be used in a `short_channel_id`. This
12- /// value is based on the 2-bytes available for the vout index.
13- pub const MAX_SCID_VOUT_INDEX : u64 = 0xffff ;
14-
15- /// Extracts the block height (most significant 3-bytes) from the `short_channel_id`.
16- pub fn block_from_scid ( short_channel_id : & u64 ) -> u32 {
17- ( short_channel_id >> 40 ) as u32
18- }
19-
20- /// Extracts the tx index (bytes [2..4]) from the `short_channel_id`.
21- pub fn tx_index_from_scid ( short_channel_id : & u64 ) -> u32 {
22- ( ( short_channel_id >> 16 ) & MAX_SCID_TX_INDEX ) as u32
23- }
24-
25- /// Extracts the vout (bytes [0..2]) from the `short_channel_id`.
26- pub fn vout_from_scid ( short_channel_id : & u64 ) -> u16 {
27- ( ( short_channel_id) & MAX_SCID_VOUT_INDEX ) as u16
28- }
29-
307pub fn scid_from_human_readable_string ( human_readable_scid : & str ) -> Result < u64 , ( ) > {
318 let mut parts = human_readable_scid. split ( 'x' ) ;
329
@@ -57,6 +34,7 @@ pub fn hex_str(value: &[u8]) -> String {
5734#[ cfg( test) ]
5835mod tests {
5936 use super :: * ;
37+ use lightning:: util:: scid_utils:: { block_from_scid, tx_index_from_scid, vout_from_scid} ;
6038
6139 #[ test]
6240 fn parses_human_readable_scid_correctly ( ) {
@@ -68,8 +46,8 @@ mod tests {
6846
6947 let scid = scid_from_human_readable_string ( & human_readable_scid) . unwrap ( ) ;
7048
71- assert_eq ! ( block_from_scid( & scid) , block) ;
72- assert_eq ! ( tx_index_from_scid( & scid) , tx_index) ;
73- assert_eq ! ( vout_from_scid( & scid) , vout) ;
49+ assert_eq ! ( block_from_scid( scid) , block) ;
50+ assert_eq ! ( tx_index_from_scid( scid) , tx_index) ;
51+ assert_eq ! ( vout_from_scid( scid) , vout) ;
7452 }
7553}
0 commit comments