| Copyright | (c) 2025 Jared Tobin |
|---|---|
| License | MIT |
| Maintainer | Jared Tobin <jared@ppad.tech> |
| Safe Haskell | None |
| Language | Haskell2010 |
Lightning.Protocol.BOLT2.Codec
Description
Encode/decode functions for BOLT #2 messages.
Synopsis
- data EncodeError = EncodeLengthOverflow
- data DecodeError
- encodeOpenChannel :: OpenChannel -> ByteString
- decodeOpenChannel :: ByteString -> Either DecodeError (OpenChannel, ByteString)
- encodeAcceptChannel :: AcceptChannel -> ByteString
- decodeAcceptChannel :: ByteString -> Either DecodeError (AcceptChannel, ByteString)
- encodeFundingCreated :: FundingCreated -> ByteString
- decodeFundingCreated :: ByteString -> Either DecodeError (FundingCreated, ByteString)
- encodeFundingSigned :: FundingSigned -> ByteString
- decodeFundingSigned :: ByteString -> Either DecodeError (FundingSigned, ByteString)
- encodeChannelReady :: ChannelReady -> ByteString
- decodeChannelReady :: ByteString -> Either DecodeError (ChannelReady, ByteString)
- encodeOpenChannel2 :: OpenChannel2 -> ByteString
- decodeOpenChannel2 :: ByteString -> Either DecodeError (OpenChannel2, ByteString)
- encodeAcceptChannel2 :: AcceptChannel2 -> ByteString
- decodeAcceptChannel2 :: ByteString -> Either DecodeError (AcceptChannel2, ByteString)
- encodeTxAddInput :: TxAddInput -> Either EncodeError ByteString
- decodeTxAddInput :: ByteString -> Either DecodeError (TxAddInput, ByteString)
- encodeTxAddOutput :: TxAddOutput -> Either EncodeError ByteString
- decodeTxAddOutput :: ByteString -> Either DecodeError (TxAddOutput, ByteString)
- encodeTxRemoveInput :: TxRemoveInput -> ByteString
- decodeTxRemoveInput :: ByteString -> Either DecodeError (TxRemoveInput, ByteString)
- encodeTxRemoveOutput :: TxRemoveOutput -> ByteString
- decodeTxRemoveOutput :: ByteString -> Either DecodeError (TxRemoveOutput, ByteString)
- encodeTxComplete :: TxComplete -> ByteString
- decodeTxComplete :: ByteString -> Either DecodeError (TxComplete, ByteString)
- encodeTxSignatures :: TxSignatures -> Either EncodeError ByteString
- decodeTxSignatures :: ByteString -> Either DecodeError (TxSignatures, ByteString)
- encodeTxInitRbf :: TxInitRbf -> ByteString
- decodeTxInitRbf :: ByteString -> Either DecodeError (TxInitRbf, ByteString)
- encodeTxAckRbf :: TxAckRbf -> ByteString
- decodeTxAckRbf :: ByteString -> Either DecodeError (TxAckRbf, ByteString)
- encodeTxAbort :: TxAbort -> Either EncodeError ByteString
- decodeTxAbort :: ByteString -> Either DecodeError (TxAbort, ByteString)
- encodeStfu :: Stfu -> ByteString
- decodeStfu :: ByteString -> Either DecodeError (Stfu, ByteString)
- encodeShutdown :: Shutdown -> Either EncodeError ByteString
- decodeShutdown :: ByteString -> Either DecodeError (Shutdown, ByteString)
- encodeClosingSigned :: ClosingSigned -> ByteString
- decodeClosingSigned :: ByteString -> Either DecodeError (ClosingSigned, ByteString)
- encodeClosingComplete :: ClosingComplete -> Either EncodeError ByteString
- decodeClosingComplete :: ByteString -> Either DecodeError (ClosingComplete, ByteString)
- encodeClosingSig :: ClosingSig -> Either EncodeError ByteString
- decodeClosingSig :: ByteString -> Either DecodeError (ClosingSig, ByteString)
- encodeUpdateAddHtlc :: UpdateAddHtlc -> ByteString
- decodeUpdateAddHtlc :: ByteString -> Either DecodeError (UpdateAddHtlc, ByteString)
- encodeUpdateFulfillHtlc :: UpdateFulfillHtlc -> ByteString
- decodeUpdateFulfillHtlc :: ByteString -> Either DecodeError (UpdateFulfillHtlc, ByteString)
- encodeUpdateFailHtlc :: UpdateFailHtlc -> Either EncodeError ByteString
- decodeUpdateFailHtlc :: ByteString -> Either DecodeError (UpdateFailHtlc, ByteString)
- encodeUpdateFailMalformedHtlc :: UpdateFailMalformedHtlc -> ByteString
- decodeUpdateFailMalformedHtlc :: ByteString -> Either DecodeError (UpdateFailMalformedHtlc, ByteString)
- encodeCommitmentSigned :: CommitmentSigned -> Either EncodeError ByteString
- decodeCommitmentSigned :: ByteString -> Either DecodeError (CommitmentSigned, ByteString)
- encodeRevokeAndAck :: RevokeAndAck -> ByteString
- decodeRevokeAndAck :: ByteString -> Either DecodeError (RevokeAndAck, ByteString)
- encodeUpdateFee :: UpdateFee -> ByteString
- decodeUpdateFee :: ByteString -> Either DecodeError (UpdateFee, ByteString)
- encodeChannelReestablish :: ChannelReestablish -> ByteString
- decodeChannelReestablish :: ByteString -> Either DecodeError (ChannelReestablish, ByteString)
Error types
data EncodeError Source #
Encoding errors.
Constructors
| EncodeLengthOverflow | Payload exceeds u16 max (65535 bytes) |
Instances
| NFData EncodeError Source # | |||||
Defined in Lightning.Protocol.BOLT2.Codec Methods rnf :: EncodeError -> () # | |||||
| Generic EncodeError Source # | |||||
Defined in Lightning.Protocol.BOLT2.Codec Associated Types
| |||||
| Show EncodeError Source # | |||||
Defined in Lightning.Protocol.BOLT2.Codec Methods showsPrec :: Int -> EncodeError -> ShowS # show :: EncodeError -> String # showList :: [EncodeError] -> ShowS # | |||||
| Eq EncodeError Source # | |||||
Defined in Lightning.Protocol.BOLT2.Codec | |||||
| type Rep EncodeError Source # | |||||
data DecodeError Source #
Decoding errors.
Constructors
Instances
| NFData DecodeError Source # | |||||
Defined in Lightning.Protocol.BOLT2.Codec Methods rnf :: DecodeError -> () # | |||||
| Generic DecodeError Source # | |||||
Defined in Lightning.Protocol.BOLT2.Codec Associated Types
| |||||
| Show DecodeError Source # | |||||
Defined in Lightning.Protocol.BOLT2.Codec Methods showsPrec :: Int -> DecodeError -> ShowS # show :: DecodeError -> String # showList :: [DecodeError] -> ShowS # | |||||
| Eq DecodeError Source # | |||||
Defined in Lightning.Protocol.BOLT2.Codec | |||||
| type Rep DecodeError Source # | |||||
Defined in Lightning.Protocol.BOLT2.Codec type Rep DecodeError = D1 ('MetaData "DecodeError" "Lightning.Protocol.BOLT2.Codec" "ppad-bolt2-0.0.1-GZp2eCd2tiE8fNOn3OFks8" 'False) (((C1 ('MetaCons "DecodeInsufficientBytes" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "DecodeInvalidLength" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "DecodeInvalidChannelId" 'PrefixI 'False) (U1 :: Type -> Type))) :+: (C1 ('MetaCons "DecodeInvalidChainHash" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "DecodeInvalidSignature" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "DecodeInvalidPoint" 'PrefixI 'False) (U1 :: Type -> Type)))) :+: ((C1 ('MetaCons "DecodeInvalidTxId" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "DecodeInvalidPaymentHash" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "DecodeInvalidPaymentPreimage" 'PrefixI 'False) (U1 :: Type -> Type))) :+: (C1 ('MetaCons "DecodeInvalidOnionPacket" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "DecodeInvalidSecret" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "DecodeTlvError" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TlvError)))))) | |||||
Channel establishment v1
encodeOpenChannel :: OpenChannel -> ByteString Source #
Encode an OpenChannel message (type 32).
Wire format: - chain_hash: 32 bytes - temporary_channel_id: 32 bytes - funding_satoshis: u64 - push_msat: u64 - dust_limit_satoshis: u64 - max_htlc_value_in_flight_msat: u64 - channel_reserve_satoshis: u64 - htlc_minimum_msat: u64 - feerate_per_kw: u32 - to_self_delay: u16 - max_accepted_htlcs: u16 - funding_pubkey: 33 bytes - revocation_basepoint: 33 bytes - payment_basepoint: 33 bytes - delayed_payment_basepoint: 33 bytes - htlc_basepoint: 33 bytes - first_per_commitment_point: 33 bytes - channel_flags: 1 byte - tlvs: TLV stream
decodeOpenChannel :: ByteString -> Either DecodeError (OpenChannel, ByteString) Source #
Decode an OpenChannel message (type 32).
encodeAcceptChannel :: AcceptChannel -> ByteString Source #
Encode an AcceptChannel message (type 33).
Wire format: - temporary_channel_id: 32 bytes - dust_limit_satoshis: u64 - max_htlc_value_in_flight_msat: u64 - channel_reserve_satoshis: u64 - htlc_minimum_msat: u64 - minimum_depth: u32 - to_self_delay: u16 - max_accepted_htlcs: u16 - funding_pubkey: 33 bytes - revocation_basepoint: 33 bytes - payment_basepoint: 33 bytes - delayed_payment_basepoint: 33 bytes - htlc_basepoint: 33 bytes - first_per_commitment_point: 33 bytes - tlvs: TLV stream
decodeAcceptChannel :: ByteString -> Either DecodeError (AcceptChannel, ByteString) Source #
Decode an AcceptChannel message (type 33).
encodeFundingCreated :: FundingCreated -> ByteString Source #
Encode a FundingCreated message (type 34).
Wire format: - temporary_channel_id: 32 bytes - funding_txid: 32 bytes - funding_output_index: u16 - signature: 64 bytes
decodeFundingCreated :: ByteString -> Either DecodeError (FundingCreated, ByteString) Source #
Decode a FundingCreated message (type 34).
encodeFundingSigned :: FundingSigned -> ByteString Source #
Encode a FundingSigned message (type 35).
Wire format: - channel_id: 32 bytes - signature: 64 bytes
decodeFundingSigned :: ByteString -> Either DecodeError (FundingSigned, ByteString) Source #
Decode a FundingSigned message (type 35).
encodeChannelReady :: ChannelReady -> ByteString Source #
Encode a ChannelReady message (type 36).
Wire format: - channel_id: 32 bytes - second_per_commitment_point: 33 bytes - tlvs: TLV stream
decodeChannelReady :: ByteString -> Either DecodeError (ChannelReady, ByteString) Source #
Decode a ChannelReady message (type 36).
Channel establishment v2 (interactive-tx)
encodeOpenChannel2 :: OpenChannel2 -> ByteString Source #
Encode an OpenChannel2 message (type 64).
decodeOpenChannel2 :: ByteString -> Either DecodeError (OpenChannel2, ByteString) Source #
Decode an OpenChannel2 message (type 64).
encodeAcceptChannel2 :: AcceptChannel2 -> ByteString Source #
Encode an AcceptChannel2 message (type 65).
decodeAcceptChannel2 :: ByteString -> Either DecodeError (AcceptChannel2, ByteString) Source #
Decode an AcceptChannel2 message (type 65).
encodeTxAddInput :: TxAddInput -> Either EncodeError ByteString Source #
Encode a TxAddInput message (type 66).
decodeTxAddInput :: ByteString -> Either DecodeError (TxAddInput, ByteString) Source #
Decode a TxAddInput message (type 66).
encodeTxAddOutput :: TxAddOutput -> Either EncodeError ByteString Source #
Encode a TxAddOutput message (type 67).
decodeTxAddOutput :: ByteString -> Either DecodeError (TxAddOutput, ByteString) Source #
Decode a TxAddOutput message (type 67).
encodeTxRemoveInput :: TxRemoveInput -> ByteString Source #
Encode a TxRemoveInput message (type 68).
decodeTxRemoveInput :: ByteString -> Either DecodeError (TxRemoveInput, ByteString) Source #
Decode a TxRemoveInput message (type 68).
encodeTxRemoveOutput :: TxRemoveOutput -> ByteString Source #
Encode a TxRemoveOutput message (type 69).
decodeTxRemoveOutput :: ByteString -> Either DecodeError (TxRemoveOutput, ByteString) Source #
Decode a TxRemoveOutput message (type 69).
encodeTxComplete :: TxComplete -> ByteString Source #
Encode a TxComplete message (type 70).
decodeTxComplete :: ByteString -> Either DecodeError (TxComplete, ByteString) Source #
Decode a TxComplete message (type 70).
encodeTxSignatures :: TxSignatures -> Either EncodeError ByteString Source #
Encode a TxSignatures message (type 71).
decodeTxSignatures :: ByteString -> Either DecodeError (TxSignatures, ByteString) Source #
Decode a TxSignatures message (type 71).
encodeTxInitRbf :: TxInitRbf -> ByteString Source #
Encode a TxInitRbf message (type 72).
decodeTxInitRbf :: ByteString -> Either DecodeError (TxInitRbf, ByteString) Source #
Decode a TxInitRbf message (type 72).
encodeTxAckRbf :: TxAckRbf -> ByteString Source #
Encode a TxAckRbf message (type 73).
decodeTxAckRbf :: ByteString -> Either DecodeError (TxAckRbf, ByteString) Source #
Decode a TxAckRbf message (type 73).
encodeTxAbort :: TxAbort -> Either EncodeError ByteString Source #
Encode a TxAbort message (type 74).
decodeTxAbort :: ByteString -> Either DecodeError (TxAbort, ByteString) Source #
Decode a TxAbort message (type 74).
Channel close
encodeStfu :: Stfu -> ByteString Source #
Encode a Stfu message (type 2).
Wire format: - channel_id: 32 bytes - initiator: 1 byte
decodeStfu :: ByteString -> Either DecodeError (Stfu, ByteString) Source #
Decode a Stfu message (type 2).
encodeShutdown :: Shutdown -> Either EncodeError ByteString Source #
Encode a Shutdown message (type 38).
Wire format: - channel_id: 32 bytes - len: u16 - scriptpubkey: len bytes
decodeShutdown :: ByteString -> Either DecodeError (Shutdown, ByteString) Source #
Decode a Shutdown message (type 38).
encodeClosingSigned :: ClosingSigned -> ByteString Source #
Encode a ClosingSigned message (type 39).
Wire format: - channel_id: 32 bytes - fee_satoshis: u64 - signature: 64 bytes - tlvs: TLV stream
decodeClosingSigned :: ByteString -> Either DecodeError (ClosingSigned, ByteString) Source #
Decode a ClosingSigned message (type 39).
encodeClosingComplete :: ClosingComplete -> Either EncodeError ByteString Source #
Encode a ClosingComplete message (type 40).
Wire format: - channel_id: 32 bytes - len: u16 (closer script length) - closer_script: len bytes - len: u16 (closee script length) - closee_script: len bytes - fee_satoshis: u64 - locktime: u32 - tlvs: TLV stream
decodeClosingComplete :: ByteString -> Either DecodeError (ClosingComplete, ByteString) Source #
Decode a ClosingComplete message (type 40).
encodeClosingSig :: ClosingSig -> Either EncodeError ByteString Source #
Encode a ClosingSig message (type 41).
Wire format: - channel_id: 32 bytes - len: u16 (closer script length) - closer_script: len bytes - len: u16 (closee script length) - closee_script: len bytes - fee_satoshis: u64 - locktime: u32 - tlvs: TLV stream
decodeClosingSig :: ByteString -> Either DecodeError (ClosingSig, ByteString) Source #
Decode a ClosingSig message (type 41).
Normal operation
encodeUpdateAddHtlc :: UpdateAddHtlc -> ByteString Source #
Encode an UpdateAddHtlc message (type 128).
decodeUpdateAddHtlc :: ByteString -> Either DecodeError (UpdateAddHtlc, ByteString) Source #
Decode an UpdateAddHtlc message (type 128).
encodeUpdateFulfillHtlc :: UpdateFulfillHtlc -> ByteString Source #
Encode an UpdateFulfillHtlc message (type 130).
decodeUpdateFulfillHtlc :: ByteString -> Either DecodeError (UpdateFulfillHtlc, ByteString) Source #
Decode an UpdateFulfillHtlc message (type 130).
encodeUpdateFailHtlc :: UpdateFailHtlc -> Either EncodeError ByteString Source #
Encode an UpdateFailHtlc message (type 131).
decodeUpdateFailHtlc :: ByteString -> Either DecodeError (UpdateFailHtlc, ByteString) Source #
Decode an UpdateFailHtlc message (type 131).
encodeUpdateFailMalformedHtlc :: UpdateFailMalformedHtlc -> ByteString Source #
Encode an UpdateFailMalformedHtlc message (type 135).
decodeUpdateFailMalformedHtlc :: ByteString -> Either DecodeError (UpdateFailMalformedHtlc, ByteString) Source #
Decode an UpdateFailMalformedHtlc message (type 135).
encodeCommitmentSigned :: CommitmentSigned -> Either EncodeError ByteString Source #
Encode a CommitmentSigned message (type 132).
decodeCommitmentSigned :: ByteString -> Either DecodeError (CommitmentSigned, ByteString) Source #
Decode a CommitmentSigned message (type 132).
encodeRevokeAndAck :: RevokeAndAck -> ByteString Source #
Encode a RevokeAndAck message (type 133).
decodeRevokeAndAck :: ByteString -> Either DecodeError (RevokeAndAck, ByteString) Source #
Decode a RevokeAndAck message (type 133).
encodeUpdateFee :: UpdateFee -> ByteString Source #
Encode an UpdateFee message (type 134).
decodeUpdateFee :: ByteString -> Either DecodeError (UpdateFee, ByteString) Source #
Decode an UpdateFee message (type 134).
Channel reestablishment
encodeChannelReestablish :: ChannelReestablish -> ByteString Source #
Encode a ChannelReestablish message (type 136).
decodeChannelReestablish :: ByteString -> Either DecodeError (ChannelReestablish, ByteString) Source #
Decode a ChannelReestablish message (type 136).