bolt2

Lightning peer protocol, per BOLT #2.
git clone git://git.ppad.tech/bolt2.git
Log | Files | Refs | README | LICENSE

commit 55e7004eb892f0cb69399c383fe82a00b3748831
parent 6ba35318c4c58c15f4e78e88a8a24bb0a3c480d9
Author: Jared Tobin <jared@jtobin.io>
Date:   Sat, 18 Apr 2026 13:13:38 +0800

lib: use unsafeTlvStream constructor

Diffstat:
Mbench/Main.hs | 4++--
Mbench/Weight.hs | 4++--
Mlib/Lightning/Protocol/BOLT2/Codec.hs | 7++++---
Mtest/Main.hs | 4++--
4 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/bench/Main.hs b/bench/Main.hs @@ -13,7 +13,7 @@ module Main where import Criterion.Main import qualified Data.ByteString as BS -import Lightning.Protocol.BOLT1 (TlvStream(..)) +import Lightning.Protocol.BOLT1 (TlvStream, unsafeTlvStream) import Lightning.Protocol.BOLT2 -- Test data construction ------------------------------------------------------ @@ -74,7 +74,7 @@ testOnionPacket = case onionPacket (BS.replicate 1366 0x00) of -- | Empty TLV stream. emptyTlvs :: TlvStream -emptyTlvs = TlvStream [] +emptyTlvs = unsafeTlvStream [] {-# NOINLINE emptyTlvs #-} -- V1 messages ----------------------------------------------------------------- diff --git a/bench/Weight.hs b/bench/Weight.hs @@ -12,7 +12,7 @@ module Main where import qualified Data.ByteString as BS -import Lightning.Protocol.BOLT1 (TlvStream(..)) +import Lightning.Protocol.BOLT1 (TlvStream, unsafeTlvStream) import Lightning.Protocol.BOLT2 import Weigh @@ -80,7 +80,7 @@ testOnionPacket = case onionPacket (BS.replicate 1366 0x00) of -- | Empty TLV stream. emptyTlvs :: TlvStream -emptyTlvs = TlvStream [] +emptyTlvs = unsafeTlvStream [] {-# NOINLINE emptyTlvs #-} -- Message constructors -------------------------------------------------------- diff --git a/lib/Lightning/Protocol/BOLT2/Codec.hs b/lib/Lightning/Protocol/BOLT2/Codec.hs @@ -91,7 +91,8 @@ import qualified Data.ByteString as BS import Data.Word (Word8, Word16, Word32) import GHC.Generics (Generic) import Lightning.Protocol.BOLT1 - ( TlvStream(..) + ( TlvStream + , unsafeTlvStream , TlvError , encodeU16 , encodeU32 @@ -227,7 +228,7 @@ decodeMilliSatoshis !bs = do -- | Decode optional TLV stream from remaining bytes. decodeTlvs :: BS.ByteString -> Either DecodeError TlvStream decodeTlvs !bs - | BS.null bs = Right (TlvStream []) + | BS.null bs = Right (unsafeTlvStream []) | otherwise = either (Left . DecodeTlvError) Right (decodeTlvStreamRaw bs) {-# INLINE decodeTlvs #-} @@ -311,7 +312,7 @@ decodeU16Bytes !bs = do decodeOptionalTlvs :: BS.ByteString -> Either DecodeError (TlvStream, BS.ByteString) decodeOptionalTlvs !bs - | BS.null bs = Right (TlvStream [], BS.empty) + | BS.null bs = Right (unsafeTlvStream [], BS.empty) | otherwise = case decodeTlvStreamRaw bs of Left e -> Left (DecodeTlvError e) Right t -> Right (t, BS.empty) diff --git a/test/Main.hs b/test/Main.hs @@ -6,7 +6,7 @@ import qualified Data.ByteString as BS import qualified Data.ByteString.Base16 as B16 import Data.Maybe (fromJust) import Data.Word (Word8, Word16, Word32, Word64) -import Lightning.Protocol.BOLT1 (TlvStream(..)) +import Lightning.Protocol.BOLT1 (TlvStream, unsafeTlvStream) import Lightning.Protocol.BOLT2 import Test.Tasty import Test.Tasty.HUnit @@ -67,7 +67,7 @@ testSecret = fromJust $ secret (BS.replicate 32 0x11) -- | Empty TLV stream for messages. emptyTlvs :: TlvStream -emptyTlvs = TlvStream [] +emptyTlvs = unsafeTlvStream [] -- V1 Channel Establishment Tests ----------------------------------------------