{-# OPTIONS_HADDOCK prune #-}

{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DeriveGeneric #-}

-- |
-- Module: Lightning.Protocol.BOLT7.Types
-- Copyright: (c) 2025 Jared Tobin
-- License: MIT
-- Maintainer: Jared Tobin <jared@ppad.tech>
--
-- Core types for BOLT #7 routing gossip.

module Lightning.Protocol.BOLT7.Types (
  -- * Identifiers (re-exported from BOLT1)
    ChainHash(..)
  , chainHash
  , unChainHash
  , mainnetChainHash
  , ShortChannelId(..)
  , shortChannelId
  , scidBlockHeight
  , scidTxIndex
  , scidOutputIndex
  , scidWord64
  , scidFromBytes
  , scidToBytes
  , formatScid
  , ChannelId(..)
  , channelId
  , unChannelId

  -- * Cryptographic types (re-exported from BOLT1)
  , Signature(..)
  , signature
  , unSignature
  , Point(..)
  , point
  , unPoint
  , NodeId
  , nodeId
  , getNodeId

  -- * Node metadata
  , RgbColor
  , rgbColor
  , getRgbColor
  , Alias
  , alias
  , getAlias
  , Timestamp
  , FeatureBits
  , featureBits
  , getFeatureBits

  -- * Address types
  , Address(..)
  , IPv4Addr
  , ipv4Addr
  , getIPv4Addr
  , IPv6Addr
  , ipv6Addr
  , getIPv6Addr
  , TorV3Addr
  , torV3Addr
  , getTorV3Addr

  -- * Channel update flags
  , MessageFlags(..)
  , encodeMessageFlags
  , decodeMessageFlags
  , ChannelFlags(..)
  , encodeChannelFlags
  , decodeChannelFlags

  -- * Routing parameters
  , CltvExpiryDelta(..)
  , FeeBaseMsat(..)
  , FeeProportionalMillionths(..)
  , HtlcMinimumMsat(..)
  , HtlcMaximumMsat(..)

  -- * Constants
  , chainHashLen
  , shortChannelIdLen
  , channelIdLen
  , signatureLen
  , pointLen
  , nodeIdLen
  , rgbColorLen
  , aliasLen
  , ipv4AddrLen
  , ipv6AddrLen
  , torV3AddrLen
  ) where

import Control.DeepSeq (NFData)
import Data.Bits (shiftL, shiftR, (.&.), (.|.))
import Data.ByteString (ByteString)
import qualified Data.ByteString as BS
import Data.Word (Word8, Word16, Word32, Word64)
import GHC.Generics (Generic)
import Lightning.Protocol.BOLT1.Prim
  ( ChainHash(..), unChainHash, chainHash
  , ShortChannelId(..), shortChannelId
  , scidBlockHeight, scidTxIndex, scidOutputIndex, scidWord64
  , ChannelId(..), unChannelId, channelId
  , Signature(..), unSignature, signature
  , Point(..), unPoint, point
  )

-- Constants -------------------------------------------------------------------

-- | Length of a chain hash (32 bytes).
chainHashLen :: Int
chainHashLen :: Int
chainHashLen = Int
32
{-# INLINE chainHashLen #-}

-- | Length of a short channel ID (8 bytes).
shortChannelIdLen :: Int
shortChannelIdLen :: Int
shortChannelIdLen = Int
8
{-# INLINE shortChannelIdLen #-}

-- | Length of a channel ID (32 bytes).
channelIdLen :: Int
channelIdLen :: Int
channelIdLen = Int
32
{-# INLINE channelIdLen #-}

-- | Length of a signature (64 bytes).
signatureLen :: Int
signatureLen :: Int
signatureLen = Int
64
{-# INLINE signatureLen #-}

-- | Length of a compressed public key (33 bytes).
pointLen :: Int
pointLen :: Int
pointLen = Int
33
{-# INLINE pointLen #-}

-- | Length of a node ID (33 bytes, same as compressed public key).
nodeIdLen :: Int
nodeIdLen :: Int
nodeIdLen = Int
33
{-# INLINE nodeIdLen #-}

-- | Length of RGB color (3 bytes).
rgbColorLen :: Int
rgbColorLen :: Int
rgbColorLen = Int
3
{-# INLINE rgbColorLen #-}

-- | Length of node alias (32 bytes).
aliasLen :: Int
aliasLen :: Int
aliasLen = Int
32
{-# INLINE aliasLen #-}

-- | Length of IPv4 address (4 bytes).
ipv4AddrLen :: Int
ipv4AddrLen :: Int
ipv4AddrLen = Int
4
{-# INLINE ipv4AddrLen #-}

-- | Length of IPv6 address (16 bytes).
ipv6AddrLen :: Int
ipv6AddrLen :: Int
ipv6AddrLen = Int
16
{-# INLINE ipv6AddrLen #-}

-- | Length of Tor v3 address (35 bytes).
torV3AddrLen :: Int
torV3AddrLen :: Int
torV3AddrLen = Int
35
{-# INLINE torV3AddrLen #-}

-- Identifiers -----------------------------------------------------------------

-- | Bitcoin mainnet chain hash (genesis block hash, little-endian).
mainnetChainHash :: ChainHash
mainnetChainHash :: ChainHash
mainnetChainHash = ByteString -> ChainHash
ChainHash (ByteString -> ChainHash) -> ByteString -> ChainHash
forall a b. (a -> b) -> a -> b
$ [Word8] -> ByteString
BS.pack
  [ Word8
0x6f, Word8
0xe2, Word8
0x8c, Word8
0x0a, Word8
0xb6, Word8
0xf1, Word8
0xb3, Word8
0x72
  , Word8
0xc1, Word8
0xa6, Word8
0xa2, Word8
0x46, Word8
0xae, Word8
0x63, Word8
0xf7, Word8
0x4f
  , Word8
0x93, Word8
0x1e, Word8
0x83, Word8
0x65, Word8
0xe1, Word8
0x5a, Word8
0x08, Word8
0x9c
  , Word8
0x68, Word8
0xd6, Word8
0x19, Word8
0x00, Word8
0x00, Word8
0x00, Word8
0x00, Word8
0x00
  ]

-- | Parse ShortChannelId from 8 big-endian bytes.
scidFromBytes :: ByteString -> Maybe ShortChannelId
scidFromBytes :: ByteString -> Maybe ShortChannelId
scidFromBytes !ByteString
bs
  | ByteString -> Int
BS.length ByteString
bs Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Int
shortChannelIdLen = Maybe ShortChannelId
forall a. Maybe a
Nothing
  | Bool
otherwise =
      let !w :: Word64
w = (Word8 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (HasCallStack => ByteString -> Int -> Word8
ByteString -> Int -> Word8
BS.index ByteString
bs Int
0) Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
`shiftL` Int
56)
           Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.|. (Word8 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (HasCallStack => ByteString -> Int -> Word8
ByteString -> Int -> Word8
BS.index ByteString
bs Int
1) Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
`shiftL` Int
48)
           Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.|. (Word8 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (HasCallStack => ByteString -> Int -> Word8
ByteString -> Int -> Word8
BS.index ByteString
bs Int
2) Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
`shiftL` Int
40)
           Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.|. (Word8 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (HasCallStack => ByteString -> Int -> Word8
ByteString -> Int -> Word8
BS.index ByteString
bs Int
3) Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
`shiftL` Int
32)
           Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.|. (Word8 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (HasCallStack => ByteString -> Int -> Word8
ByteString -> Int -> Word8
BS.index ByteString
bs Int
4) Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
`shiftL` Int
24)
           Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.|. (Word8 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (HasCallStack => ByteString -> Int -> Word8
ByteString -> Int -> Word8
BS.index ByteString
bs Int
5) Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
`shiftL` Int
16)
           Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.|. (Word8 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (HasCallStack => ByteString -> Int -> Word8
ByteString -> Int -> Word8
BS.index ByteString
bs Int
6) Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
`shiftL` Int
8)
           Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.|.  Word8 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (HasCallStack => ByteString -> Int -> Word8
ByteString -> Int -> Word8
BS.index ByteString
bs Int
7) :: Word64
      in  ShortChannelId -> Maybe ShortChannelId
forall a. a -> Maybe a
Just (Word64 -> ShortChannelId
ShortChannelId Word64
w)
{-# INLINE scidFromBytes #-}

-- | Encode ShortChannelId as 8 big-endian bytes.
scidToBytes :: ShortChannelId -> ByteString
scidToBytes :: ShortChannelId -> ByteString
scidToBytes !ShortChannelId
sci =
  let !w :: Word64
w = ShortChannelId -> Word64
scidWord64 ShortChannelId
sci
  in  [Word8] -> ByteString
BS.pack
        [ Word64 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64
w Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
`shiftR` Int
56)
        , Word64 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64
w Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
`shiftR` Int
48)
        , Word64 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64
w Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
`shiftR` Int
40)
        , Word64 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64
w Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
`shiftR` Int
32)
        , Word64 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64
w Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
`shiftR` Int
24)
        , Word64 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64
w Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
`shiftR` Int
16)
        , Word64 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64
w Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
`shiftR` Int
8)
        , Word64 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
w
        ]
{-# INLINE scidToBytes #-}

-- | Format short channel ID as human-readable string.
formatScid :: ShortChannelId -> String
formatScid :: ShortChannelId -> String
formatScid ShortChannelId
sci =
  Word32 -> String
forall a. Show a => a -> String
show (ShortChannelId -> Word32
scidBlockHeight ShortChannelId
sci) String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"x" String -> String -> String
forall a. [a] -> [a] -> [a]
++
  Word32 -> String
forall a. Show a => a -> String
show (ShortChannelId -> Word32
scidTxIndex ShortChannelId
sci) String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"x" String -> String -> String
forall a. [a] -> [a] -> [a]
++
  Word16 -> String
forall a. Show a => a -> String
show (ShortChannelId -> Word16
scidOutputIndex ShortChannelId
sci)
{-# INLINE formatScid #-}

-- Cryptographic types ---------------------------------------------------------

-- | Node ID (33 bytes, same as compressed public key).
--
-- Has Ord instance for lexicographic comparison (required by spec for
-- channel announcements where node_id_1 < node_id_2).
newtype NodeId = NodeId { NodeId -> ByteString
getNodeId :: ByteString }
  deriving (NodeId -> NodeId -> Bool
(NodeId -> NodeId -> Bool)
-> (NodeId -> NodeId -> Bool) -> Eq NodeId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: NodeId -> NodeId -> Bool
== :: NodeId -> NodeId -> Bool
$c/= :: NodeId -> NodeId -> Bool
/= :: NodeId -> NodeId -> Bool
Eq, Eq NodeId
Eq NodeId =>
(NodeId -> NodeId -> Ordering)
-> (NodeId -> NodeId -> Bool)
-> (NodeId -> NodeId -> Bool)
-> (NodeId -> NodeId -> Bool)
-> (NodeId -> NodeId -> Bool)
-> (NodeId -> NodeId -> NodeId)
-> (NodeId -> NodeId -> NodeId)
-> Ord NodeId
NodeId -> NodeId -> Bool
NodeId -> NodeId -> Ordering
NodeId -> NodeId -> NodeId
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: NodeId -> NodeId -> Ordering
compare :: NodeId -> NodeId -> Ordering
$c< :: NodeId -> NodeId -> Bool
< :: NodeId -> NodeId -> Bool
$c<= :: NodeId -> NodeId -> Bool
<= :: NodeId -> NodeId -> Bool
$c> :: NodeId -> NodeId -> Bool
> :: NodeId -> NodeId -> Bool
$c>= :: NodeId -> NodeId -> Bool
>= :: NodeId -> NodeId -> Bool
$cmax :: NodeId -> NodeId -> NodeId
max :: NodeId -> NodeId -> NodeId
$cmin :: NodeId -> NodeId -> NodeId
min :: NodeId -> NodeId -> NodeId
Ord, Int -> NodeId -> String -> String
[NodeId] -> String -> String
NodeId -> String
(Int -> NodeId -> String -> String)
-> (NodeId -> String)
-> ([NodeId] -> String -> String)
-> Show NodeId
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> NodeId -> String -> String
showsPrec :: Int -> NodeId -> String -> String
$cshow :: NodeId -> String
show :: NodeId -> String
$cshowList :: [NodeId] -> String -> String
showList :: [NodeId] -> String -> String
Show, (forall x. NodeId -> Rep NodeId x)
-> (forall x. Rep NodeId x -> NodeId) -> Generic NodeId
forall x. Rep NodeId x -> NodeId
forall x. NodeId -> Rep NodeId x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. NodeId -> Rep NodeId x
from :: forall x. NodeId -> Rep NodeId x
$cto :: forall x. Rep NodeId x -> NodeId
to :: forall x. Rep NodeId x -> NodeId
Generic)

instance NFData NodeId

-- | Smart constructor for NodeId. Returns Nothing if not 33 bytes.
nodeId :: ByteString -> Maybe NodeId
nodeId :: ByteString -> Maybe NodeId
nodeId !ByteString
bs
  | ByteString -> Int
BS.length ByteString
bs Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
nodeIdLen = NodeId -> Maybe NodeId
forall a. a -> Maybe a
Just (ByteString -> NodeId
NodeId ByteString
bs)
  | Bool
otherwise = Maybe NodeId
forall a. Maybe a
Nothing
{-# INLINE nodeId #-}

-- Node metadata ---------------------------------------------------------------

-- | RGB color (3 bytes).
newtype RgbColor = RgbColor { RgbColor -> ByteString
getRgbColor :: ByteString }
  deriving (RgbColor -> RgbColor -> Bool
(RgbColor -> RgbColor -> Bool)
-> (RgbColor -> RgbColor -> Bool) -> Eq RgbColor
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: RgbColor -> RgbColor -> Bool
== :: RgbColor -> RgbColor -> Bool
$c/= :: RgbColor -> RgbColor -> Bool
/= :: RgbColor -> RgbColor -> Bool
Eq, Int -> RgbColor -> String -> String
[RgbColor] -> String -> String
RgbColor -> String
(Int -> RgbColor -> String -> String)
-> (RgbColor -> String)
-> ([RgbColor] -> String -> String)
-> Show RgbColor
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> RgbColor -> String -> String
showsPrec :: Int -> RgbColor -> String -> String
$cshow :: RgbColor -> String
show :: RgbColor -> String
$cshowList :: [RgbColor] -> String -> String
showList :: [RgbColor] -> String -> String
Show, (forall x. RgbColor -> Rep RgbColor x)
-> (forall x. Rep RgbColor x -> RgbColor) -> Generic RgbColor
forall x. Rep RgbColor x -> RgbColor
forall x. RgbColor -> Rep RgbColor x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. RgbColor -> Rep RgbColor x
from :: forall x. RgbColor -> Rep RgbColor x
$cto :: forall x. Rep RgbColor x -> RgbColor
to :: forall x. Rep RgbColor x -> RgbColor
Generic)

instance NFData RgbColor

-- | Smart constructor for RgbColor. Returns Nothing if not 3 bytes.
rgbColor :: ByteString -> Maybe RgbColor
rgbColor :: ByteString -> Maybe RgbColor
rgbColor !ByteString
bs
  | ByteString -> Int
BS.length ByteString
bs Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
rgbColorLen = RgbColor -> Maybe RgbColor
forall a. a -> Maybe a
Just (ByteString -> RgbColor
RgbColor ByteString
bs)
  | Bool
otherwise = Maybe RgbColor
forall a. Maybe a
Nothing
{-# INLINE rgbColor #-}

-- | Node alias (32 bytes, UTF-8 padded with zero bytes).
newtype Alias = Alias { Alias -> ByteString
getAlias :: ByteString }
  deriving (Alias -> Alias -> Bool
(Alias -> Alias -> Bool) -> (Alias -> Alias -> Bool) -> Eq Alias
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Alias -> Alias -> Bool
== :: Alias -> Alias -> Bool
$c/= :: Alias -> Alias -> Bool
/= :: Alias -> Alias -> Bool
Eq, Int -> Alias -> String -> String
[Alias] -> String -> String
Alias -> String
(Int -> Alias -> String -> String)
-> (Alias -> String) -> ([Alias] -> String -> String) -> Show Alias
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> Alias -> String -> String
showsPrec :: Int -> Alias -> String -> String
$cshow :: Alias -> String
show :: Alias -> String
$cshowList :: [Alias] -> String -> String
showList :: [Alias] -> String -> String
Show, (forall x. Alias -> Rep Alias x)
-> (forall x. Rep Alias x -> Alias) -> Generic Alias
forall x. Rep Alias x -> Alias
forall x. Alias -> Rep Alias x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Alias -> Rep Alias x
from :: forall x. Alias -> Rep Alias x
$cto :: forall x. Rep Alias x -> Alias
to :: forall x. Rep Alias x -> Alias
Generic)

instance NFData Alias

-- | Smart constructor for Alias. Returns Nothing if not 32 bytes.
alias :: ByteString -> Maybe Alias
alias :: ByteString -> Maybe Alias
alias !ByteString
bs
  | ByteString -> Int
BS.length ByteString
bs Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
aliasLen = Alias -> Maybe Alias
forall a. a -> Maybe a
Just (ByteString -> Alias
Alias ByteString
bs)
  | Bool
otherwise = Maybe Alias
forall a. Maybe a
Nothing
{-# INLINE alias #-}

-- | Timestamp (Unix epoch seconds).
type Timestamp = Word32

-- | Feature bits (variable length).
newtype FeatureBits = FeatureBits { FeatureBits -> ByteString
getFeatureBits :: ByteString }
  deriving (FeatureBits -> FeatureBits -> Bool
(FeatureBits -> FeatureBits -> Bool)
-> (FeatureBits -> FeatureBits -> Bool) -> Eq FeatureBits
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FeatureBits -> FeatureBits -> Bool
== :: FeatureBits -> FeatureBits -> Bool
$c/= :: FeatureBits -> FeatureBits -> Bool
/= :: FeatureBits -> FeatureBits -> Bool
Eq, Int -> FeatureBits -> String -> String
[FeatureBits] -> String -> String
FeatureBits -> String
(Int -> FeatureBits -> String -> String)
-> (FeatureBits -> String)
-> ([FeatureBits] -> String -> String)
-> Show FeatureBits
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> FeatureBits -> String -> String
showsPrec :: Int -> FeatureBits -> String -> String
$cshow :: FeatureBits -> String
show :: FeatureBits -> String
$cshowList :: [FeatureBits] -> String -> String
showList :: [FeatureBits] -> String -> String
Show, (forall x. FeatureBits -> Rep FeatureBits x)
-> (forall x. Rep FeatureBits x -> FeatureBits)
-> Generic FeatureBits
forall x. Rep FeatureBits x -> FeatureBits
forall x. FeatureBits -> Rep FeatureBits x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. FeatureBits -> Rep FeatureBits x
from :: forall x. FeatureBits -> Rep FeatureBits x
$cto :: forall x. Rep FeatureBits x -> FeatureBits
to :: forall x. Rep FeatureBits x -> FeatureBits
Generic)

instance NFData FeatureBits

-- | Smart constructor for FeatureBits (any length).
featureBits :: ByteString -> FeatureBits
featureBits :: ByteString -> FeatureBits
featureBits = ByteString -> FeatureBits
FeatureBits
{-# INLINE featureBits #-}

-- Address types ---------------------------------------------------------------

-- | IPv4 address (4 bytes).
newtype IPv4Addr = IPv4Addr { IPv4Addr -> ByteString
getIPv4Addr :: ByteString }
  deriving (IPv4Addr -> IPv4Addr -> Bool
(IPv4Addr -> IPv4Addr -> Bool)
-> (IPv4Addr -> IPv4Addr -> Bool) -> Eq IPv4Addr
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: IPv4Addr -> IPv4Addr -> Bool
== :: IPv4Addr -> IPv4Addr -> Bool
$c/= :: IPv4Addr -> IPv4Addr -> Bool
/= :: IPv4Addr -> IPv4Addr -> Bool
Eq, Int -> IPv4Addr -> String -> String
[IPv4Addr] -> String -> String
IPv4Addr -> String
(Int -> IPv4Addr -> String -> String)
-> (IPv4Addr -> String)
-> ([IPv4Addr] -> String -> String)
-> Show IPv4Addr
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> IPv4Addr -> String -> String
showsPrec :: Int -> IPv4Addr -> String -> String
$cshow :: IPv4Addr -> String
show :: IPv4Addr -> String
$cshowList :: [IPv4Addr] -> String -> String
showList :: [IPv4Addr] -> String -> String
Show, (forall x. IPv4Addr -> Rep IPv4Addr x)
-> (forall x. Rep IPv4Addr x -> IPv4Addr) -> Generic IPv4Addr
forall x. Rep IPv4Addr x -> IPv4Addr
forall x. IPv4Addr -> Rep IPv4Addr x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. IPv4Addr -> Rep IPv4Addr x
from :: forall x. IPv4Addr -> Rep IPv4Addr x
$cto :: forall x. Rep IPv4Addr x -> IPv4Addr
to :: forall x. Rep IPv4Addr x -> IPv4Addr
Generic)

instance NFData IPv4Addr

-- | Smart constructor for IPv4Addr. Returns Nothing if not 4 bytes.
ipv4Addr :: ByteString -> Maybe IPv4Addr
ipv4Addr :: ByteString -> Maybe IPv4Addr
ipv4Addr !ByteString
bs
  | ByteString -> Int
BS.length ByteString
bs Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
ipv4AddrLen = IPv4Addr -> Maybe IPv4Addr
forall a. a -> Maybe a
Just (ByteString -> IPv4Addr
IPv4Addr ByteString
bs)
  | Bool
otherwise = Maybe IPv4Addr
forall a. Maybe a
Nothing
{-# INLINE ipv4Addr #-}

-- | IPv6 address (16 bytes).
newtype IPv6Addr = IPv6Addr { IPv6Addr -> ByteString
getIPv6Addr :: ByteString }
  deriving (IPv6Addr -> IPv6Addr -> Bool
(IPv6Addr -> IPv6Addr -> Bool)
-> (IPv6Addr -> IPv6Addr -> Bool) -> Eq IPv6Addr
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: IPv6Addr -> IPv6Addr -> Bool
== :: IPv6Addr -> IPv6Addr -> Bool
$c/= :: IPv6Addr -> IPv6Addr -> Bool
/= :: IPv6Addr -> IPv6Addr -> Bool
Eq, Int -> IPv6Addr -> String -> String
[IPv6Addr] -> String -> String
IPv6Addr -> String
(Int -> IPv6Addr -> String -> String)
-> (IPv6Addr -> String)
-> ([IPv6Addr] -> String -> String)
-> Show IPv6Addr
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> IPv6Addr -> String -> String
showsPrec :: Int -> IPv6Addr -> String -> String
$cshow :: IPv6Addr -> String
show :: IPv6Addr -> String
$cshowList :: [IPv6Addr] -> String -> String
showList :: [IPv6Addr] -> String -> String
Show, (forall x. IPv6Addr -> Rep IPv6Addr x)
-> (forall x. Rep IPv6Addr x -> IPv6Addr) -> Generic IPv6Addr
forall x. Rep IPv6Addr x -> IPv6Addr
forall x. IPv6Addr -> Rep IPv6Addr x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. IPv6Addr -> Rep IPv6Addr x
from :: forall x. IPv6Addr -> Rep IPv6Addr x
$cto :: forall x. Rep IPv6Addr x -> IPv6Addr
to :: forall x. Rep IPv6Addr x -> IPv6Addr
Generic)

instance NFData IPv6Addr

-- | Smart constructor for IPv6Addr. Returns Nothing if not 16 bytes.
ipv6Addr :: ByteString -> Maybe IPv6Addr
ipv6Addr :: ByteString -> Maybe IPv6Addr
ipv6Addr !ByteString
bs
  | ByteString -> Int
BS.length ByteString
bs Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
ipv6AddrLen = IPv6Addr -> Maybe IPv6Addr
forall a. a -> Maybe a
Just (ByteString -> IPv6Addr
IPv6Addr ByteString
bs)
  | Bool
otherwise = Maybe IPv6Addr
forall a. Maybe a
Nothing
{-# INLINE ipv6Addr #-}

-- | Tor v3 onion address (35 bytes: 32 pubkey + 2 checksum + 1 version).
newtype TorV3Addr = TorV3Addr { TorV3Addr -> ByteString
getTorV3Addr :: ByteString }
  deriving (TorV3Addr -> TorV3Addr -> Bool
(TorV3Addr -> TorV3Addr -> Bool)
-> (TorV3Addr -> TorV3Addr -> Bool) -> Eq TorV3Addr
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TorV3Addr -> TorV3Addr -> Bool
== :: TorV3Addr -> TorV3Addr -> Bool
$c/= :: TorV3Addr -> TorV3Addr -> Bool
/= :: TorV3Addr -> TorV3Addr -> Bool
Eq, Int -> TorV3Addr -> String -> String
[TorV3Addr] -> String -> String
TorV3Addr -> String
(Int -> TorV3Addr -> String -> String)
-> (TorV3Addr -> String)
-> ([TorV3Addr] -> String -> String)
-> Show TorV3Addr
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> TorV3Addr -> String -> String
showsPrec :: Int -> TorV3Addr -> String -> String
$cshow :: TorV3Addr -> String
show :: TorV3Addr -> String
$cshowList :: [TorV3Addr] -> String -> String
showList :: [TorV3Addr] -> String -> String
Show, (forall x. TorV3Addr -> Rep TorV3Addr x)
-> (forall x. Rep TorV3Addr x -> TorV3Addr) -> Generic TorV3Addr
forall x. Rep TorV3Addr x -> TorV3Addr
forall x. TorV3Addr -> Rep TorV3Addr x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. TorV3Addr -> Rep TorV3Addr x
from :: forall x. TorV3Addr -> Rep TorV3Addr x
$cto :: forall x. Rep TorV3Addr x -> TorV3Addr
to :: forall x. Rep TorV3Addr x -> TorV3Addr
Generic)

instance NFData TorV3Addr

-- | Smart constructor for TorV3Addr. Returns Nothing if not 35 bytes.
torV3Addr :: ByteString -> Maybe TorV3Addr
torV3Addr :: ByteString -> Maybe TorV3Addr
torV3Addr !ByteString
bs
  | ByteString -> Int
BS.length ByteString
bs Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
torV3AddrLen = TorV3Addr -> Maybe TorV3Addr
forall a. a -> Maybe a
Just (ByteString -> TorV3Addr
TorV3Addr ByteString
bs)
  | Bool
otherwise = Maybe TorV3Addr
forall a. Maybe a
Nothing
{-# INLINE torV3Addr #-}

-- | Network address with port.
data Address
  = AddrIPv4 !IPv4Addr !Word16    -- ^ IPv4 address + port
  | AddrIPv6 !IPv6Addr !Word16    -- ^ IPv6 address + port
  | AddrTorV3 !TorV3Addr !Word16  -- ^ Tor v3 address + port
  | AddrDNS !ByteString !Word16   -- ^ DNS hostname + port
  deriving (Address -> Address -> Bool
(Address -> Address -> Bool)
-> (Address -> Address -> Bool) -> Eq Address
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Address -> Address -> Bool
== :: Address -> Address -> Bool
$c/= :: Address -> Address -> Bool
/= :: Address -> Address -> Bool
Eq, Int -> Address -> String -> String
[Address] -> String -> String
Address -> String
(Int -> Address -> String -> String)
-> (Address -> String)
-> ([Address] -> String -> String)
-> Show Address
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> Address -> String -> String
showsPrec :: Int -> Address -> String -> String
$cshow :: Address -> String
show :: Address -> String
$cshowList :: [Address] -> String -> String
showList :: [Address] -> String -> String
Show, (forall x. Address -> Rep Address x)
-> (forall x. Rep Address x -> Address) -> Generic Address
forall x. Rep Address x -> Address
forall x. Address -> Rep Address x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Address -> Rep Address x
from :: forall x. Address -> Rep Address x
$cto :: forall x. Rep Address x -> Address
to :: forall x. Rep Address x -> Address
Generic)

instance NFData Address

-- Channel update flags --------------------------------------------------------

-- | Message flags for channel_update.
--
-- Bit 0: htlc_maximum_msat field is present.
data MessageFlags = MessageFlags
  { MessageFlags -> Bool
mfHtlcMaxPresent :: !Bool  -- ^ htlc_maximum_msat is present
  }
  deriving (MessageFlags -> MessageFlags -> Bool
(MessageFlags -> MessageFlags -> Bool)
-> (MessageFlags -> MessageFlags -> Bool) -> Eq MessageFlags
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MessageFlags -> MessageFlags -> Bool
== :: MessageFlags -> MessageFlags -> Bool
$c/= :: MessageFlags -> MessageFlags -> Bool
/= :: MessageFlags -> MessageFlags -> Bool
Eq, Int -> MessageFlags -> String -> String
[MessageFlags] -> String -> String
MessageFlags -> String
(Int -> MessageFlags -> String -> String)
-> (MessageFlags -> String)
-> ([MessageFlags] -> String -> String)
-> Show MessageFlags
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> MessageFlags -> String -> String
showsPrec :: Int -> MessageFlags -> String -> String
$cshow :: MessageFlags -> String
show :: MessageFlags -> String
$cshowList :: [MessageFlags] -> String -> String
showList :: [MessageFlags] -> String -> String
Show, (forall x. MessageFlags -> Rep MessageFlags x)
-> (forall x. Rep MessageFlags x -> MessageFlags)
-> Generic MessageFlags
forall x. Rep MessageFlags x -> MessageFlags
forall x. MessageFlags -> Rep MessageFlags x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. MessageFlags -> Rep MessageFlags x
from :: forall x. MessageFlags -> Rep MessageFlags x
$cto :: forall x. Rep MessageFlags x -> MessageFlags
to :: forall x. Rep MessageFlags x -> MessageFlags
Generic)

instance NFData MessageFlags

-- | Encode MessageFlags to Word8.
encodeMessageFlags :: MessageFlags -> Word8
encodeMessageFlags :: MessageFlags -> Word8
encodeMessageFlags MessageFlags
mf = if MessageFlags -> Bool
mfHtlcMaxPresent MessageFlags
mf then Word8
0x01 else Word8
0x00
{-# INLINE encodeMessageFlags #-}

-- | Decode Word8 to MessageFlags.
decodeMessageFlags :: Word8 -> MessageFlags
decodeMessageFlags :: Word8 -> MessageFlags
decodeMessageFlags Word8
w = MessageFlags { mfHtlcMaxPresent :: Bool
mfHtlcMaxPresent = Word8
w Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.&. Word8
0x01 Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word8
0 }
{-# INLINE decodeMessageFlags #-}

-- | Channel flags for channel_update.
--
-- Bit 0: direction (0 = node_id_1 is origin, 1 = node_id_2 is origin).
-- Bit 1: disabled (1 = channel disabled).
data ChannelFlags = ChannelFlags
  { ChannelFlags -> Bool
cfDirection :: !Bool  -- ^ True = node_id_2 is origin
  , ChannelFlags -> Bool
cfDisabled  :: !Bool  -- ^ True = channel is disabled
  }
  deriving (ChannelFlags -> ChannelFlags -> Bool
(ChannelFlags -> ChannelFlags -> Bool)
-> (ChannelFlags -> ChannelFlags -> Bool) -> Eq ChannelFlags
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ChannelFlags -> ChannelFlags -> Bool
== :: ChannelFlags -> ChannelFlags -> Bool
$c/= :: ChannelFlags -> ChannelFlags -> Bool
/= :: ChannelFlags -> ChannelFlags -> Bool
Eq, Int -> ChannelFlags -> String -> String
[ChannelFlags] -> String -> String
ChannelFlags -> String
(Int -> ChannelFlags -> String -> String)
-> (ChannelFlags -> String)
-> ([ChannelFlags] -> String -> String)
-> Show ChannelFlags
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> ChannelFlags -> String -> String
showsPrec :: Int -> ChannelFlags -> String -> String
$cshow :: ChannelFlags -> String
show :: ChannelFlags -> String
$cshowList :: [ChannelFlags] -> String -> String
showList :: [ChannelFlags] -> String -> String
Show, (forall x. ChannelFlags -> Rep ChannelFlags x)
-> (forall x. Rep ChannelFlags x -> ChannelFlags)
-> Generic ChannelFlags
forall x. Rep ChannelFlags x -> ChannelFlags
forall x. ChannelFlags -> Rep ChannelFlags x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ChannelFlags -> Rep ChannelFlags x
from :: forall x. ChannelFlags -> Rep ChannelFlags x
$cto :: forall x. Rep ChannelFlags x -> ChannelFlags
to :: forall x. Rep ChannelFlags x -> ChannelFlags
Generic)

instance NFData ChannelFlags

-- | Encode ChannelFlags to Word8.
encodeChannelFlags :: ChannelFlags -> Word8
encodeChannelFlags :: ChannelFlags -> Word8
encodeChannelFlags ChannelFlags
cf =
  (if ChannelFlags -> Bool
cfDirection ChannelFlags
cf then Word8
0x01 else Word8
0x00) Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.|.
  (if ChannelFlags -> Bool
cfDisabled ChannelFlags
cf then Word8
0x02 else Word8
0x00)
{-# INLINE encodeChannelFlags #-}

-- | Decode Word8 to ChannelFlags.
decodeChannelFlags :: Word8 -> ChannelFlags
decodeChannelFlags :: Word8 -> ChannelFlags
decodeChannelFlags Word8
w = ChannelFlags
  { cfDirection :: Bool
cfDirection = Word8
w Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.&. Word8
0x01 Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word8
0
  , cfDisabled :: Bool
cfDisabled  = Word8
w Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.&. Word8
0x02 Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word8
0
  }
{-# INLINE decodeChannelFlags #-}

-- Routing parameters ----------------------------------------------------------

-- | CLTV expiry delta.
newtype CltvExpiryDelta = CltvExpiryDelta { CltvExpiryDelta -> Word16
getCltvExpiryDelta :: Word16 }
  deriving (CltvExpiryDelta -> CltvExpiryDelta -> Bool
(CltvExpiryDelta -> CltvExpiryDelta -> Bool)
-> (CltvExpiryDelta -> CltvExpiryDelta -> Bool)
-> Eq CltvExpiryDelta
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CltvExpiryDelta -> CltvExpiryDelta -> Bool
== :: CltvExpiryDelta -> CltvExpiryDelta -> Bool
$c/= :: CltvExpiryDelta -> CltvExpiryDelta -> Bool
/= :: CltvExpiryDelta -> CltvExpiryDelta -> Bool
Eq, Eq CltvExpiryDelta
Eq CltvExpiryDelta =>
(CltvExpiryDelta -> CltvExpiryDelta -> Ordering)
-> (CltvExpiryDelta -> CltvExpiryDelta -> Bool)
-> (CltvExpiryDelta -> CltvExpiryDelta -> Bool)
-> (CltvExpiryDelta -> CltvExpiryDelta -> Bool)
-> (CltvExpiryDelta -> CltvExpiryDelta -> Bool)
-> (CltvExpiryDelta -> CltvExpiryDelta -> CltvExpiryDelta)
-> (CltvExpiryDelta -> CltvExpiryDelta -> CltvExpiryDelta)
-> Ord CltvExpiryDelta
CltvExpiryDelta -> CltvExpiryDelta -> Bool
CltvExpiryDelta -> CltvExpiryDelta -> Ordering
CltvExpiryDelta -> CltvExpiryDelta -> CltvExpiryDelta
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: CltvExpiryDelta -> CltvExpiryDelta -> Ordering
compare :: CltvExpiryDelta -> CltvExpiryDelta -> Ordering
$c< :: CltvExpiryDelta -> CltvExpiryDelta -> Bool
< :: CltvExpiryDelta -> CltvExpiryDelta -> Bool
$c<= :: CltvExpiryDelta -> CltvExpiryDelta -> Bool
<= :: CltvExpiryDelta -> CltvExpiryDelta -> Bool
$c> :: CltvExpiryDelta -> CltvExpiryDelta -> Bool
> :: CltvExpiryDelta -> CltvExpiryDelta -> Bool
$c>= :: CltvExpiryDelta -> CltvExpiryDelta -> Bool
>= :: CltvExpiryDelta -> CltvExpiryDelta -> Bool
$cmax :: CltvExpiryDelta -> CltvExpiryDelta -> CltvExpiryDelta
max :: CltvExpiryDelta -> CltvExpiryDelta -> CltvExpiryDelta
$cmin :: CltvExpiryDelta -> CltvExpiryDelta -> CltvExpiryDelta
min :: CltvExpiryDelta -> CltvExpiryDelta -> CltvExpiryDelta
Ord, Int -> CltvExpiryDelta -> String -> String
[CltvExpiryDelta] -> String -> String
CltvExpiryDelta -> String
(Int -> CltvExpiryDelta -> String -> String)
-> (CltvExpiryDelta -> String)
-> ([CltvExpiryDelta] -> String -> String)
-> Show CltvExpiryDelta
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> CltvExpiryDelta -> String -> String
showsPrec :: Int -> CltvExpiryDelta -> String -> String
$cshow :: CltvExpiryDelta -> String
show :: CltvExpiryDelta -> String
$cshowList :: [CltvExpiryDelta] -> String -> String
showList :: [CltvExpiryDelta] -> String -> String
Show, (forall x. CltvExpiryDelta -> Rep CltvExpiryDelta x)
-> (forall x. Rep CltvExpiryDelta x -> CltvExpiryDelta)
-> Generic CltvExpiryDelta
forall x. Rep CltvExpiryDelta x -> CltvExpiryDelta
forall x. CltvExpiryDelta -> Rep CltvExpiryDelta x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. CltvExpiryDelta -> Rep CltvExpiryDelta x
from :: forall x. CltvExpiryDelta -> Rep CltvExpiryDelta x
$cto :: forall x. Rep CltvExpiryDelta x -> CltvExpiryDelta
to :: forall x. Rep CltvExpiryDelta x -> CltvExpiryDelta
Generic)

instance NFData CltvExpiryDelta

-- | Base fee in millisatoshis.
newtype FeeBaseMsat = FeeBaseMsat { FeeBaseMsat -> Word32
getFeeBaseMsat :: Word32 }
  deriving (FeeBaseMsat -> FeeBaseMsat -> Bool
(FeeBaseMsat -> FeeBaseMsat -> Bool)
-> (FeeBaseMsat -> FeeBaseMsat -> Bool) -> Eq FeeBaseMsat
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FeeBaseMsat -> FeeBaseMsat -> Bool
== :: FeeBaseMsat -> FeeBaseMsat -> Bool
$c/= :: FeeBaseMsat -> FeeBaseMsat -> Bool
/= :: FeeBaseMsat -> FeeBaseMsat -> Bool
Eq, Eq FeeBaseMsat
Eq FeeBaseMsat =>
(FeeBaseMsat -> FeeBaseMsat -> Ordering)
-> (FeeBaseMsat -> FeeBaseMsat -> Bool)
-> (FeeBaseMsat -> FeeBaseMsat -> Bool)
-> (FeeBaseMsat -> FeeBaseMsat -> Bool)
-> (FeeBaseMsat -> FeeBaseMsat -> Bool)
-> (FeeBaseMsat -> FeeBaseMsat -> FeeBaseMsat)
-> (FeeBaseMsat -> FeeBaseMsat -> FeeBaseMsat)
-> Ord FeeBaseMsat
FeeBaseMsat -> FeeBaseMsat -> Bool
FeeBaseMsat -> FeeBaseMsat -> Ordering
FeeBaseMsat -> FeeBaseMsat -> FeeBaseMsat
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: FeeBaseMsat -> FeeBaseMsat -> Ordering
compare :: FeeBaseMsat -> FeeBaseMsat -> Ordering
$c< :: FeeBaseMsat -> FeeBaseMsat -> Bool
< :: FeeBaseMsat -> FeeBaseMsat -> Bool
$c<= :: FeeBaseMsat -> FeeBaseMsat -> Bool
<= :: FeeBaseMsat -> FeeBaseMsat -> Bool
$c> :: FeeBaseMsat -> FeeBaseMsat -> Bool
> :: FeeBaseMsat -> FeeBaseMsat -> Bool
$c>= :: FeeBaseMsat -> FeeBaseMsat -> Bool
>= :: FeeBaseMsat -> FeeBaseMsat -> Bool
$cmax :: FeeBaseMsat -> FeeBaseMsat -> FeeBaseMsat
max :: FeeBaseMsat -> FeeBaseMsat -> FeeBaseMsat
$cmin :: FeeBaseMsat -> FeeBaseMsat -> FeeBaseMsat
min :: FeeBaseMsat -> FeeBaseMsat -> FeeBaseMsat
Ord, Int -> FeeBaseMsat -> String -> String
[FeeBaseMsat] -> String -> String
FeeBaseMsat -> String
(Int -> FeeBaseMsat -> String -> String)
-> (FeeBaseMsat -> String)
-> ([FeeBaseMsat] -> String -> String)
-> Show FeeBaseMsat
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> FeeBaseMsat -> String -> String
showsPrec :: Int -> FeeBaseMsat -> String -> String
$cshow :: FeeBaseMsat -> String
show :: FeeBaseMsat -> String
$cshowList :: [FeeBaseMsat] -> String -> String
showList :: [FeeBaseMsat] -> String -> String
Show, (forall x. FeeBaseMsat -> Rep FeeBaseMsat x)
-> (forall x. Rep FeeBaseMsat x -> FeeBaseMsat)
-> Generic FeeBaseMsat
forall x. Rep FeeBaseMsat x -> FeeBaseMsat
forall x. FeeBaseMsat -> Rep FeeBaseMsat x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. FeeBaseMsat -> Rep FeeBaseMsat x
from :: forall x. FeeBaseMsat -> Rep FeeBaseMsat x
$cto :: forall x. Rep FeeBaseMsat x -> FeeBaseMsat
to :: forall x. Rep FeeBaseMsat x -> FeeBaseMsat
Generic)

instance NFData FeeBaseMsat

-- | Proportional fee in millionths.
newtype FeeProportionalMillionths = FeeProportionalMillionths
  { FeeProportionalMillionths -> Word32
getFeeProportionalMillionths :: Word32 }
  deriving (FeeProportionalMillionths -> FeeProportionalMillionths -> Bool
(FeeProportionalMillionths -> FeeProportionalMillionths -> Bool)
-> (FeeProportionalMillionths -> FeeProportionalMillionths -> Bool)
-> Eq FeeProportionalMillionths
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FeeProportionalMillionths -> FeeProportionalMillionths -> Bool
== :: FeeProportionalMillionths -> FeeProportionalMillionths -> Bool
$c/= :: FeeProportionalMillionths -> FeeProportionalMillionths -> Bool
/= :: FeeProportionalMillionths -> FeeProportionalMillionths -> Bool
Eq, Eq FeeProportionalMillionths
Eq FeeProportionalMillionths =>
(FeeProportionalMillionths
 -> FeeProportionalMillionths -> Ordering)
-> (FeeProportionalMillionths -> FeeProportionalMillionths -> Bool)
-> (FeeProportionalMillionths -> FeeProportionalMillionths -> Bool)
-> (FeeProportionalMillionths -> FeeProportionalMillionths -> Bool)
-> (FeeProportionalMillionths -> FeeProportionalMillionths -> Bool)
-> (FeeProportionalMillionths
    -> FeeProportionalMillionths -> FeeProportionalMillionths)
-> (FeeProportionalMillionths
    -> FeeProportionalMillionths -> FeeProportionalMillionths)
-> Ord FeeProportionalMillionths
FeeProportionalMillionths -> FeeProportionalMillionths -> Bool
FeeProportionalMillionths -> FeeProportionalMillionths -> Ordering
FeeProportionalMillionths
-> FeeProportionalMillionths -> FeeProportionalMillionths
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: FeeProportionalMillionths -> FeeProportionalMillionths -> Ordering
compare :: FeeProportionalMillionths -> FeeProportionalMillionths -> Ordering
$c< :: FeeProportionalMillionths -> FeeProportionalMillionths -> Bool
< :: FeeProportionalMillionths -> FeeProportionalMillionths -> Bool
$c<= :: FeeProportionalMillionths -> FeeProportionalMillionths -> Bool
<= :: FeeProportionalMillionths -> FeeProportionalMillionths -> Bool
$c> :: FeeProportionalMillionths -> FeeProportionalMillionths -> Bool
> :: FeeProportionalMillionths -> FeeProportionalMillionths -> Bool
$c>= :: FeeProportionalMillionths -> FeeProportionalMillionths -> Bool
>= :: FeeProportionalMillionths -> FeeProportionalMillionths -> Bool
$cmax :: FeeProportionalMillionths
-> FeeProportionalMillionths -> FeeProportionalMillionths
max :: FeeProportionalMillionths
-> FeeProportionalMillionths -> FeeProportionalMillionths
$cmin :: FeeProportionalMillionths
-> FeeProportionalMillionths -> FeeProportionalMillionths
min :: FeeProportionalMillionths
-> FeeProportionalMillionths -> FeeProportionalMillionths
Ord, Int -> FeeProportionalMillionths -> String -> String
[FeeProportionalMillionths] -> String -> String
FeeProportionalMillionths -> String
(Int -> FeeProportionalMillionths -> String -> String)
-> (FeeProportionalMillionths -> String)
-> ([FeeProportionalMillionths] -> String -> String)
-> Show FeeProportionalMillionths
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> FeeProportionalMillionths -> String -> String
showsPrec :: Int -> FeeProportionalMillionths -> String -> String
$cshow :: FeeProportionalMillionths -> String
show :: FeeProportionalMillionths -> String
$cshowList :: [FeeProportionalMillionths] -> String -> String
showList :: [FeeProportionalMillionths] -> String -> String
Show, (forall x.
 FeeProportionalMillionths -> Rep FeeProportionalMillionths x)
-> (forall x.
    Rep FeeProportionalMillionths x -> FeeProportionalMillionths)
-> Generic FeeProportionalMillionths
forall x.
Rep FeeProportionalMillionths x -> FeeProportionalMillionths
forall x.
FeeProportionalMillionths -> Rep FeeProportionalMillionths x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x.
FeeProportionalMillionths -> Rep FeeProportionalMillionths x
from :: forall x.
FeeProportionalMillionths -> Rep FeeProportionalMillionths x
$cto :: forall x.
Rep FeeProportionalMillionths x -> FeeProportionalMillionths
to :: forall x.
Rep FeeProportionalMillionths x -> FeeProportionalMillionths
Generic)

instance NFData FeeProportionalMillionths

-- | Minimum HTLC value in millisatoshis.
newtype HtlcMinimumMsat = HtlcMinimumMsat { HtlcMinimumMsat -> Word64
getHtlcMinimumMsat :: Word64 }
  deriving (HtlcMinimumMsat -> HtlcMinimumMsat -> Bool
(HtlcMinimumMsat -> HtlcMinimumMsat -> Bool)
-> (HtlcMinimumMsat -> HtlcMinimumMsat -> Bool)
-> Eq HtlcMinimumMsat
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: HtlcMinimumMsat -> HtlcMinimumMsat -> Bool
== :: HtlcMinimumMsat -> HtlcMinimumMsat -> Bool
$c/= :: HtlcMinimumMsat -> HtlcMinimumMsat -> Bool
/= :: HtlcMinimumMsat -> HtlcMinimumMsat -> Bool
Eq, Eq HtlcMinimumMsat
Eq HtlcMinimumMsat =>
(HtlcMinimumMsat -> HtlcMinimumMsat -> Ordering)
-> (HtlcMinimumMsat -> HtlcMinimumMsat -> Bool)
-> (HtlcMinimumMsat -> HtlcMinimumMsat -> Bool)
-> (HtlcMinimumMsat -> HtlcMinimumMsat -> Bool)
-> (HtlcMinimumMsat -> HtlcMinimumMsat -> Bool)
-> (HtlcMinimumMsat -> HtlcMinimumMsat -> HtlcMinimumMsat)
-> (HtlcMinimumMsat -> HtlcMinimumMsat -> HtlcMinimumMsat)
-> Ord HtlcMinimumMsat
HtlcMinimumMsat -> HtlcMinimumMsat -> Bool
HtlcMinimumMsat -> HtlcMinimumMsat -> Ordering
HtlcMinimumMsat -> HtlcMinimumMsat -> HtlcMinimumMsat
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: HtlcMinimumMsat -> HtlcMinimumMsat -> Ordering
compare :: HtlcMinimumMsat -> HtlcMinimumMsat -> Ordering
$c< :: HtlcMinimumMsat -> HtlcMinimumMsat -> Bool
< :: HtlcMinimumMsat -> HtlcMinimumMsat -> Bool
$c<= :: HtlcMinimumMsat -> HtlcMinimumMsat -> Bool
<= :: HtlcMinimumMsat -> HtlcMinimumMsat -> Bool
$c> :: HtlcMinimumMsat -> HtlcMinimumMsat -> Bool
> :: HtlcMinimumMsat -> HtlcMinimumMsat -> Bool
$c>= :: HtlcMinimumMsat -> HtlcMinimumMsat -> Bool
>= :: HtlcMinimumMsat -> HtlcMinimumMsat -> Bool
$cmax :: HtlcMinimumMsat -> HtlcMinimumMsat -> HtlcMinimumMsat
max :: HtlcMinimumMsat -> HtlcMinimumMsat -> HtlcMinimumMsat
$cmin :: HtlcMinimumMsat -> HtlcMinimumMsat -> HtlcMinimumMsat
min :: HtlcMinimumMsat -> HtlcMinimumMsat -> HtlcMinimumMsat
Ord, Int -> HtlcMinimumMsat -> String -> String
[HtlcMinimumMsat] -> String -> String
HtlcMinimumMsat -> String
(Int -> HtlcMinimumMsat -> String -> String)
-> (HtlcMinimumMsat -> String)
-> ([HtlcMinimumMsat] -> String -> String)
-> Show HtlcMinimumMsat
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> HtlcMinimumMsat -> String -> String
showsPrec :: Int -> HtlcMinimumMsat -> String -> String
$cshow :: HtlcMinimumMsat -> String
show :: HtlcMinimumMsat -> String
$cshowList :: [HtlcMinimumMsat] -> String -> String
showList :: [HtlcMinimumMsat] -> String -> String
Show, (forall x. HtlcMinimumMsat -> Rep HtlcMinimumMsat x)
-> (forall x. Rep HtlcMinimumMsat x -> HtlcMinimumMsat)
-> Generic HtlcMinimumMsat
forall x. Rep HtlcMinimumMsat x -> HtlcMinimumMsat
forall x. HtlcMinimumMsat -> Rep HtlcMinimumMsat x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. HtlcMinimumMsat -> Rep HtlcMinimumMsat x
from :: forall x. HtlcMinimumMsat -> Rep HtlcMinimumMsat x
$cto :: forall x. Rep HtlcMinimumMsat x -> HtlcMinimumMsat
to :: forall x. Rep HtlcMinimumMsat x -> HtlcMinimumMsat
Generic)

instance NFData HtlcMinimumMsat

-- | Maximum HTLC value in millisatoshis.
newtype HtlcMaximumMsat = HtlcMaximumMsat { HtlcMaximumMsat -> Word64
getHtlcMaximumMsat :: Word64 }
  deriving (HtlcMaximumMsat -> HtlcMaximumMsat -> Bool
(HtlcMaximumMsat -> HtlcMaximumMsat -> Bool)
-> (HtlcMaximumMsat -> HtlcMaximumMsat -> Bool)
-> Eq HtlcMaximumMsat
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: HtlcMaximumMsat -> HtlcMaximumMsat -> Bool
== :: HtlcMaximumMsat -> HtlcMaximumMsat -> Bool
$c/= :: HtlcMaximumMsat -> HtlcMaximumMsat -> Bool
/= :: HtlcMaximumMsat -> HtlcMaximumMsat -> Bool
Eq, Eq HtlcMaximumMsat
Eq HtlcMaximumMsat =>
(HtlcMaximumMsat -> HtlcMaximumMsat -> Ordering)
-> (HtlcMaximumMsat -> HtlcMaximumMsat -> Bool)
-> (HtlcMaximumMsat -> HtlcMaximumMsat -> Bool)
-> (HtlcMaximumMsat -> HtlcMaximumMsat -> Bool)
-> (HtlcMaximumMsat -> HtlcMaximumMsat -> Bool)
-> (HtlcMaximumMsat -> HtlcMaximumMsat -> HtlcMaximumMsat)
-> (HtlcMaximumMsat -> HtlcMaximumMsat -> HtlcMaximumMsat)
-> Ord HtlcMaximumMsat
HtlcMaximumMsat -> HtlcMaximumMsat -> Bool
HtlcMaximumMsat -> HtlcMaximumMsat -> Ordering
HtlcMaximumMsat -> HtlcMaximumMsat -> HtlcMaximumMsat
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: HtlcMaximumMsat -> HtlcMaximumMsat -> Ordering
compare :: HtlcMaximumMsat -> HtlcMaximumMsat -> Ordering
$c< :: HtlcMaximumMsat -> HtlcMaximumMsat -> Bool
< :: HtlcMaximumMsat -> HtlcMaximumMsat -> Bool
$c<= :: HtlcMaximumMsat -> HtlcMaximumMsat -> Bool
<= :: HtlcMaximumMsat -> HtlcMaximumMsat -> Bool
$c> :: HtlcMaximumMsat -> HtlcMaximumMsat -> Bool
> :: HtlcMaximumMsat -> HtlcMaximumMsat -> Bool
$c>= :: HtlcMaximumMsat -> HtlcMaximumMsat -> Bool
>= :: HtlcMaximumMsat -> HtlcMaximumMsat -> Bool
$cmax :: HtlcMaximumMsat -> HtlcMaximumMsat -> HtlcMaximumMsat
max :: HtlcMaximumMsat -> HtlcMaximumMsat -> HtlcMaximumMsat
$cmin :: HtlcMaximumMsat -> HtlcMaximumMsat -> HtlcMaximumMsat
min :: HtlcMaximumMsat -> HtlcMaximumMsat -> HtlcMaximumMsat
Ord, Int -> HtlcMaximumMsat -> String -> String
[HtlcMaximumMsat] -> String -> String
HtlcMaximumMsat -> String
(Int -> HtlcMaximumMsat -> String -> String)
-> (HtlcMaximumMsat -> String)
-> ([HtlcMaximumMsat] -> String -> String)
-> Show HtlcMaximumMsat
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> HtlcMaximumMsat -> String -> String
showsPrec :: Int -> HtlcMaximumMsat -> String -> String
$cshow :: HtlcMaximumMsat -> String
show :: HtlcMaximumMsat -> String
$cshowList :: [HtlcMaximumMsat] -> String -> String
showList :: [HtlcMaximumMsat] -> String -> String
Show, (forall x. HtlcMaximumMsat -> Rep HtlcMaximumMsat x)
-> (forall x. Rep HtlcMaximumMsat x -> HtlcMaximumMsat)
-> Generic HtlcMaximumMsat
forall x. Rep HtlcMaximumMsat x -> HtlcMaximumMsat
forall x. HtlcMaximumMsat -> Rep HtlcMaximumMsat x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. HtlcMaximumMsat -> Rep HtlcMaximumMsat x
from :: forall x. HtlcMaximumMsat -> Rep HtlcMaximumMsat x
$cto :: forall x. Rep HtlcMaximumMsat x -> HtlcMaximumMsat
to :: forall x. Rep HtlcMaximumMsat x -> HtlcMaximumMsat
Generic)

instance NFData HtlcMaximumMsat