-/// Tracks localfeatures which are only in init messages
-#[derive(Clone, PartialEq)]
-pub struct LocalFeatures {
- flags: Vec<u8>,
-}
-
-impl LocalFeatures {
- /// Create a blank LocalFeatures flags (visibility extended for fuzz tests)
- #[cfg(not(feature = "fuzztarget"))]
- pub(crate) fn new() -> LocalFeatures {
- LocalFeatures {
- flags: vec![2 | 1 << 5],
- }
- }
- #[cfg(feature = "fuzztarget")]
- pub fn new() -> LocalFeatures {
- LocalFeatures {
- flags: vec![2 | 1 << 5],
- }
- }
-
- pub(crate) fn supports_data_loss_protect(&self) -> bool {
- self.flags.len() > 0 && (self.flags[0] & 3) != 0
- }
- pub(crate) fn initial_routing_sync(&self) -> bool {
- self.flags.len() > 0 && (self.flags[0] & (1 << 3)) != 0
- }
- pub(crate) fn set_initial_routing_sync(&mut self) {
- if self.flags.len() == 0 {
- self.flags.resize(1, 1 << 3);
- } else {
- self.flags[0] |= 1 << 3;
- }
- }
-
- pub(crate) fn supports_upfront_shutdown_script(&self) -> bool {
- self.flags.len() > 0 && (self.flags[0] & (3 << 4)) != 0
- }
- #[cfg(test)]
- pub(crate) fn unset_upfront_shutdown_script(&mut self) {
- self.flags[0] ^= 1 << 5;
- }
-
- pub(crate) fn requires_unknown_bits(&self) -> bool {
- self.flags.iter().enumerate().any(|(idx, &byte)| {
- ( idx != 0 && (byte & 0x55) != 0 ) || ( idx == 0 && (byte & 0x14) != 0 )
- })
- }
-
- pub(crate) fn supports_unknown_bits(&self) -> bool {
- self.flags.iter().enumerate().any(|(idx, &byte)| {
- ( idx != 0 && byte != 0 ) || ( idx == 0 && (byte & 0xc4) != 0 )
- })
- }
-}
-
-/// Tracks globalfeatures which are in init messages and routing announcements
-#[derive(Clone, PartialEq, Debug)]
-pub struct GlobalFeatures {
- #[cfg(not(test))]
- flags: Vec<u8>,
- // Used to test encoding of diverse msgs
- #[cfg(test)]
- pub flags: Vec<u8>
-}
-
-impl GlobalFeatures {
- pub(crate) fn new() -> GlobalFeatures {
- GlobalFeatures {
- flags: Vec::new(),
- }
- }
-
- pub(crate) fn requires_unknown_bits(&self) -> bool {
- for &byte in self.flags.iter() {
- if (byte & 0x55) != 0 {
- return true;
- }
- }
- return false;
- }
-
- pub(crate) fn supports_unknown_bits(&self) -> bool {
- for &byte in self.flags.iter() {
- if byte != 0 {
- return true;
- }
- }
- return false;
- }
-}
-