Skip to content

Commit dc34ca2

Browse files
committed
f Use upstream scid_utils
1 parent acc3324 commit dc34ca2

File tree

2 files changed

+9
-29
lines changed

2 files changed

+9
-29
lines changed

lightning-liquidity/src/lsps2/msgs.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use bitcoin::hashes::{Hash, HashEngine};
88
use chrono::Utc;
99
use serde::{Deserialize, Serialize};
1010

11+
use lightning::util::scid_utils;
12+
1113
use crate::lsps0::ser::{
1214
string_amount, string_amount_option, LSPSMessage, RequestId, ResponseError,
1315
};
@@ -129,9 +131,9 @@ pub struct InterceptScid(String);
129131

130132
impl From<u64> for InterceptScid {
131133
fn from(scid: u64) -> Self {
132-
let block = utils::block_from_scid(&scid);
133-
let tx_index = utils::tx_index_from_scid(&scid);
134-
let vout = utils::vout_from_scid(&scid);
134+
let block = scid_utils::block_from_scid(scid);
135+
let tx_index = scid_utils::tx_index_from_scid(scid);
136+
let vout = scid_utils::vout_from_scid(scid);
135137

136138
Self(format!("{}x{}x{}", block, tx_index, vout))
137139
}

lightning-liquidity/src/utils.rs

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,6 @@ use lightning::sign::EntropySource;
44
use crate::lsps0::ser::RequestId;
55
use 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-
307
pub 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)]
5835
mod 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

Comments
 (0)