Some(out)
}
-#[inline]
-pub fn hex_str(value: &[u8]) -> String {
- let mut res = String::with_capacity(64);
- for v in value {
- res += &format!("{:02x}", v);
- }
- res
+pub fn to_composite_index(scid: i64, timestamp: i64, direction: bool) -> String {
+ let scid_be = scid.to_be_bytes();
+ let res = format!("{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}:{}:{}",
+ scid_be[0], scid_be[1], scid_be[2], scid_be[3],
+ scid_be[4], scid_be[5], scid_be[6], scid_be[7],
+ timestamp, direction as u8);
+ assert_eq!(res.len(), 29); // Our SQL Type requires len of 29
+ res
}
pub fn to_compressed_pubkey(hex: &str) -> Option<PublicKey> {
}
GossipMessage::ChannelUpdate(update) => {
let scid = update.contents.short_channel_id as i64;
- let scid_hex = hex_utils::hex_str(&scid.to_be_bytes());
let timestamp = update.contents.timestamp as i64;
- let channel_flags = update.contents.flags as i32;
- let direction = channel_flags & 1;
- let disable = (channel_flags & 2) > 0;
+ let direction = (update.contents.flags & 1) == 1;
+ let disable = (update.contents.flags & 2) > 0;
- let composite_index = format!("{}:{}:{}", scid_hex, timestamp, direction);
+ let composite_index = hex_utils::to_composite_index(scid, timestamp, direction);
let cltv_expiry_delta = update.contents.cltv_expiry_delta as i32;
let htlc_minimum_msat = update.contents.htlc_minimum_msat as i64;
&composite_index,
&scid,
×tamp,
- &channel_flags,
- &(direction == 1),
+ &(update.contents.flags as i32),
+ &direction,
&disable,
&cltv_expiry_delta,
&htlc_minimum_msat,