-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
93 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copied from `rust-lightning` | ||
// | ||
// This file is Copyright its original authors, visible in version control | ||
// history. | ||
// | ||
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE | ||
// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option. | ||
// You may not use this file except in accordance with one or both of these | ||
// licenses. | ||
|
||
/// Maximum transaction index that can be used in a `short_channel_id`. | ||
/// This value is based on the 3-bytes available for tx index. | ||
pub const MAX_SCID_TX_INDEX: u64 = 0x00ffffff; | ||
|
||
/// Maximum vout index that can be used in a `short_channel_id`. This | ||
/// value is based on the 2-bytes available for the vout index. | ||
pub const MAX_SCID_VOUT_INDEX: u64 = 0xffff; | ||
|
||
/// Extracts the block height (most significant 3-bytes) from the `short_channel_id` | ||
pub fn block_from_scid(short_channel_id: &u64) -> u32 { | ||
return (short_channel_id >> 40) as u32; | ||
} | ||
|
||
/// Extracts the tx index (bytes [2..4]) from the `short_channel_id` | ||
pub fn tx_index_from_scid(short_channel_id: &u64) -> u32 { | ||
return ((short_channel_id >> 16) & MAX_SCID_TX_INDEX) as u32; | ||
} | ||
|
||
/// Extracts the vout (bytes [0..2]) from the `short_channel_id` | ||
pub fn vout_from_scid(short_channel_id: &u64) -> u16 { | ||
return ((short_channel_id) & MAX_SCID_VOUT_INDEX) as u16; | ||
} |