Messages.hs (22945B)
1 {-# OPTIONS_HADDOCK hide #-} 2 {-# LANGUAGE DeriveGeneric #-} 3 4 -- | 5 -- Module: Lightning.Protocol.BOLT2.Messages 6 -- Copyright: (c) 2025 Jared Tobin 7 -- License: MIT 8 -- Maintainer: Jared Tobin <jared@ppad.tech> 9 -- 10 -- The messages defined by BOLT #2. 11 12 module Lightning.Protocol.BOLT2.Messages ( 13 Message(..) 14 , message_type 15 16 , OpenChannel(..) 17 , AcceptChannel(..) 18 , FundingCreated(..) 19 , FundingSigned(..) 20 , ChannelReady(..) 21 22 , OpenChannel2(..) 23 , AcceptChannel2(..) 24 , TxAddInput(..) 25 , TxAddOutput(..) 26 , TxRemoveInput(..) 27 , TxRemoveOutput(..) 28 , TxComplete(..) 29 , TxSignatures(..) 30 , TxInitRbf(..) 31 , TxAckRbf(..) 32 , TxAbort(..) 33 34 , Stfu(..) 35 36 , Shutdown(..) 37 , ClosingComplete(..) 38 , ClosingSig(..) 39 , ClosingSigned(..) 40 41 , UpdateAddHtlc(..) 42 , UpdateFulfillHtlc(..) 43 , UpdateFailHtlc(..) 44 , UpdateFailMalformedHtlc(..) 45 , CommitmentSigned(..) 46 , RevokeAndAck(..) 47 , UpdateFee(..) 48 49 , ChannelReestablish(..) 50 ) where 51 52 import Bitcoin.Prim.Tx (TxId) 53 import Control.DeepSeq (NFData) 54 import qualified Data.ByteString as BS 55 import Data.Int (Int64) 56 import Data.Word (Word8, Word16, Word32, Word64) 57 import GHC.Generics (Generic) 58 import Lightning.Protocol.BOLT1 59 ( ChainHash, ChannelId, Signature, Point, PaymentHash, PaymentPreimage 60 , PerCommitmentSecret, ShortChannelId, Satoshi, MilliSatoshi, TlvStream ) 61 import qualified Lightning.Protocol.BOLT9 as BOLT9 62 import Lightning.Protocol.BOLT2.Types 63 64 -- channel establishment v1 --------------------------------------------------- 65 66 -- | The @open_channel@ message (type 32). 67 data OpenChannel = OpenChannel 68 { open_channel_chain_hash :: !ChainHash 69 , open_channel_temporary_channel_id :: !ChannelId 70 , open_channel_funding_satoshis :: {-# UNPACK #-} !Satoshi 71 , open_channel_push_msat :: {-# UNPACK #-} !MilliSatoshi 72 , open_channel_dust_limit_satoshis :: {-# UNPACK #-} !Satoshi 73 , open_channel_max_htlc_value_in_flight_msat :: {-# UNPACK #-} !Word64 74 -- ^ a cap, often @maxBound@, so not a bounded amount 75 , open_channel_channel_reserve_satoshis :: {-# UNPACK #-} !Satoshi 76 , open_channel_htlc_minimum_msat :: {-# UNPACK #-} !MilliSatoshi 77 , open_channel_feerate_per_kw :: {-# UNPACK #-} !Word32 78 , open_channel_to_self_delay :: {-# UNPACK #-} !Word16 79 , open_channel_max_accepted_htlcs :: {-# UNPACK #-} !Word16 80 , open_channel_funding_pubkey :: !Point 81 , open_channel_revocation_basepoint :: !Point 82 , open_channel_payment_basepoint :: !Point 83 , open_channel_delayed_payment_basepoint :: !Point 84 , open_channel_htlc_basepoint :: !Point 85 , open_channel_first_per_commitment_point :: !Point 86 , open_channel_channel_flags :: {-# UNPACK #-} !Word8 87 -- ^ bit 0: @announce_channel@ 88 , open_channel_upfront_shutdown_script :: !(Maybe ScriptPubKey) 89 -- ^ TLV type 0; an empty script commits to no particular script 90 , open_channel_channel_type :: !(Maybe BOLT9.FeatureVector) 91 -- ^ TLV type 1 92 , open_channel_tlvs :: !TlvStream 93 -- ^ unknown TLV records 94 } deriving (Eq, Show, Generic) 95 96 instance NFData OpenChannel 97 98 -- | The @accept_channel@ message (type 33). 99 data AcceptChannel = AcceptChannel 100 { accept_channel_temporary_channel_id :: !ChannelId 101 , accept_channel_dust_limit_satoshis :: {-# UNPACK #-} !Satoshi 102 , accept_channel_max_htlc_value_in_flight_msat :: {-# UNPACK #-} !Word64 103 -- ^ a cap, often @maxBound@, so not a bounded amount 104 , accept_channel_channel_reserve_satoshis :: {-# UNPACK #-} !Satoshi 105 , accept_channel_htlc_minimum_msat 106 :: {-# UNPACK #-} !MilliSatoshi 107 , accept_channel_minimum_depth :: {-# UNPACK #-} !Word32 108 , accept_channel_to_self_delay :: {-# UNPACK #-} !Word16 109 , accept_channel_max_accepted_htlcs :: {-# UNPACK #-} !Word16 110 , accept_channel_funding_pubkey :: !Point 111 , accept_channel_revocation_basepoint :: !Point 112 , accept_channel_payment_basepoint :: !Point 113 , accept_channel_delayed_payment_basepoint :: !Point 114 , accept_channel_htlc_basepoint :: !Point 115 , accept_channel_first_per_commitment_point :: !Point 116 , accept_channel_upfront_shutdown_script :: !(Maybe ScriptPubKey) 117 -- ^ TLV type 0; an empty script commits to no particular script 118 , accept_channel_channel_type 119 :: !(Maybe BOLT9.FeatureVector) 120 -- ^ TLV type 1 121 , accept_channel_tlvs :: !TlvStream 122 -- ^ unknown TLV records 123 } deriving (Eq, Show, Generic) 124 125 instance NFData AcceptChannel 126 127 -- | The @funding_created@ message (type 34). 128 data FundingCreated = FundingCreated 129 { funding_created_temporary_channel_id :: !ChannelId 130 , funding_created_funding_txid :: !TxId 131 , funding_created_funding_output_index :: {-# UNPACK #-} !Word16 132 , funding_created_signature :: !Signature 133 , funding_created_tlvs :: !TlvStream 134 -- ^ unknown TLV records 135 } deriving (Eq, Show, Generic) 136 137 instance NFData FundingCreated 138 139 -- | The @funding_signed@ message (type 35). 140 data FundingSigned = FundingSigned 141 { funding_signed_channel_id :: !ChannelId 142 , funding_signed_signature :: !Signature 143 , funding_signed_tlvs :: !TlvStream 144 -- ^ unknown TLV records 145 } deriving (Eq, Show, Generic) 146 147 instance NFData FundingSigned 148 149 -- | The @channel_ready@ message (type 36). 150 data ChannelReady = ChannelReady 151 { channel_ready_channel_id :: !ChannelId 152 , channel_ready_second_per_commitment_point :: !Point 153 , channel_ready_alias :: !(Maybe ShortChannelId) 154 -- ^ the @short_channel_id@ record (TLV type 1) 155 , channel_ready_tlvs :: !TlvStream 156 -- ^ unknown TLV records 157 } deriving (Eq, Show, Generic) 158 159 instance NFData ChannelReady 160 161 -- channel establishment v2 --------------------------------------------------- 162 163 -- | The @open_channel2@ message (type 64). 164 data OpenChannel2 = OpenChannel2 165 { open_channel2_chain_hash :: !ChainHash 166 , open_channel2_temporary_channel_id :: !ChannelId 167 , open_channel2_funding_feerate_perkw :: {-# UNPACK #-} !Word32 168 , open_channel2_commitment_feerate_perkw :: {-# UNPACK #-} !Word32 169 , open_channel2_funding_satoshis :: {-# UNPACK #-} !Satoshi 170 , open_channel2_dust_limit_satoshis :: {-# UNPACK #-} !Satoshi 171 , open_channel2_max_htlc_value_in_flight_msat :: {-# UNPACK #-} !Word64 172 -- ^ a cap, often @maxBound@, so not a bounded amount 173 , open_channel2_htlc_minimum_msat 174 :: {-# UNPACK #-} !MilliSatoshi 175 , open_channel2_to_self_delay :: {-# UNPACK #-} !Word16 176 , open_channel2_max_accepted_htlcs :: {-# UNPACK #-} !Word16 177 , open_channel2_locktime :: {-# UNPACK #-} !Word32 178 , open_channel2_funding_pubkey :: !Point 179 , open_channel2_revocation_basepoint :: !Point 180 , open_channel2_payment_basepoint :: !Point 181 , open_channel2_delayed_payment_basepoint :: !Point 182 , open_channel2_htlc_basepoint :: !Point 183 , open_channel2_first_per_commitment_point :: !Point 184 , open_channel2_second_per_commitment_point :: !Point 185 , open_channel2_channel_flags :: {-# UNPACK #-} !Word8 186 -- ^ bit 0: @announce_channel@ 187 , open_channel2_upfront_shutdown_script :: !(Maybe ScriptPubKey) 188 -- ^ TLV type 0; an empty script commits to no particular script 189 , open_channel2_channel_type 190 :: !(Maybe BOLT9.FeatureVector) 191 -- ^ TLV type 1 192 , open_channel2_require_confirmed_inputs :: !Bool 193 -- ^ TLV type 2 194 , open_channel2_tlvs :: !TlvStream 195 -- ^ unknown TLV records 196 } deriving (Eq, Show, Generic) 197 198 instance NFData OpenChannel2 199 200 -- | The @accept_channel2@ message (type 65). 201 data AcceptChannel2 = AcceptChannel2 202 { accept_channel2_temporary_channel_id :: !ChannelId 203 , accept_channel2_funding_satoshis :: {-# UNPACK #-} !Satoshi 204 , accept_channel2_dust_limit_satoshis :: {-# UNPACK #-} !Satoshi 205 , accept_channel2_max_htlc_value_in_flight_msat :: {-# UNPACK #-} !Word64 206 -- ^ a cap, often @maxBound@, so not a bounded amount 207 , accept_channel2_htlc_minimum_msat 208 :: {-# UNPACK #-} !MilliSatoshi 209 , accept_channel2_minimum_depth :: {-# UNPACK #-} !Word32 210 , accept_channel2_to_self_delay :: {-# UNPACK #-} !Word16 211 , accept_channel2_max_accepted_htlcs :: {-# UNPACK #-} !Word16 212 , accept_channel2_funding_pubkey :: !Point 213 , accept_channel2_revocation_basepoint :: !Point 214 , accept_channel2_payment_basepoint :: !Point 215 , accept_channel2_delayed_payment_basepoint :: !Point 216 , accept_channel2_htlc_basepoint :: !Point 217 , accept_channel2_first_per_commitment_point :: !Point 218 , accept_channel2_second_per_commitment_point :: !Point 219 , accept_channel2_upfront_shutdown_script 220 :: !(Maybe ScriptPubKey) 221 -- ^ TLV type 0; an empty script commits to no particular script 222 , accept_channel2_channel_type 223 :: !(Maybe BOLT9.FeatureVector) 224 -- ^ TLV type 1 225 , accept_channel2_require_confirmed_inputs :: !Bool 226 -- ^ TLV type 2 227 , accept_channel2_tlvs :: !TlvStream 228 -- ^ unknown TLV records 229 } deriving (Eq, Show, Generic) 230 231 instance NFData AcceptChannel2 232 233 -- | The @tx_add_input@ message (type 66). 234 data TxAddInput = TxAddInput 235 { tx_add_input_channel_id :: !ChannelId 236 , tx_add_input_serial_id :: !SerialId 237 , tx_add_input_prevtx :: !BS.ByteString 238 -- ^ the serialized previous transaction 239 , tx_add_input_prevtx_vout :: {-# UNPACK #-} !Word32 240 , tx_add_input_sequence :: {-# UNPACK #-} !Word32 241 , tx_add_input_tlvs :: !TlvStream 242 -- ^ unknown TLV records 243 } deriving (Eq, Show, Generic) 244 245 instance NFData TxAddInput 246 247 -- | The @tx_add_output@ message (type 67). 248 data TxAddOutput = TxAddOutput 249 { tx_add_output_channel_id :: !ChannelId 250 , tx_add_output_serial_id :: !SerialId 251 , tx_add_output_sats :: {-# UNPACK #-} !Satoshi 252 , tx_add_output_script :: !ScriptPubKey 253 , tx_add_output_tlvs :: !TlvStream 254 -- ^ unknown TLV records 255 } deriving (Eq, Show, Generic) 256 257 instance NFData TxAddOutput 258 259 -- | The @tx_remove_input@ message (type 68). 260 data TxRemoveInput = TxRemoveInput 261 { tx_remove_input_channel_id :: !ChannelId 262 , tx_remove_input_serial_id :: !SerialId 263 , tx_remove_input_tlvs :: !TlvStream 264 -- ^ unknown TLV records 265 } deriving (Eq, Show, Generic) 266 267 instance NFData TxRemoveInput 268 269 -- | The @tx_remove_output@ message (type 69). 270 data TxRemoveOutput = TxRemoveOutput 271 { tx_remove_output_channel_id :: !ChannelId 272 , tx_remove_output_serial_id :: !SerialId 273 , tx_remove_output_tlvs :: !TlvStream 274 -- ^ unknown TLV records 275 } deriving (Eq, Show, Generic) 276 277 instance NFData TxRemoveOutput 278 279 -- | The @tx_complete@ message (type 70). 280 data TxComplete = TxComplete 281 { tx_complete_channel_id :: !ChannelId 282 , tx_complete_tlvs :: !TlvStream 283 -- ^ unknown TLV records 284 } deriving (Eq, Show, Generic) 285 286 instance NFData TxComplete 287 288 -- | The @tx_signatures@ message (type 71). 289 data TxSignatures = TxSignatures 290 { tx_signatures_channel_id :: !ChannelId 291 , tx_signatures_txid :: !TxId 292 , tx_signatures_witnesses :: ![Witness] 293 -- ^ ordered by the @serial_id@ of the inputs they spend 294 , tx_signatures_tlvs :: !TlvStream 295 -- ^ unknown TLV records 296 } deriving (Eq, Show, Generic) 297 298 instance NFData TxSignatures 299 300 -- | The @tx_init_rbf@ message (type 72). 301 data TxInitRbf = TxInitRbf 302 { tx_init_rbf_channel_id :: !ChannelId 303 , tx_init_rbf_locktime :: {-# UNPACK #-} !Word32 304 , tx_init_rbf_feerate :: {-# UNPACK #-} !Word32 305 , tx_init_rbf_funding_output_contribution :: !(Maybe Int64) 306 -- ^ TLV type 0, in satoshis 307 , tx_init_rbf_require_confirmed_inputs :: !Bool 308 -- ^ TLV type 2 309 , tx_init_rbf_tlvs :: !TlvStream 310 -- ^ unknown TLV records 311 } deriving (Eq, Show, Generic) 312 313 instance NFData TxInitRbf 314 315 -- | The @tx_ack_rbf@ message (type 73). 316 data TxAckRbf = TxAckRbf 317 { tx_ack_rbf_channel_id :: !ChannelId 318 , tx_ack_rbf_funding_output_contribution :: !(Maybe Int64) 319 -- ^ TLV type 0, in satoshis 320 , tx_ack_rbf_require_confirmed_inputs :: !Bool 321 -- ^ TLV type 2 322 , tx_ack_rbf_tlvs :: !TlvStream 323 -- ^ unknown TLV records 324 } deriving (Eq, Show, Generic) 325 326 instance NFData TxAckRbf 327 328 -- | The @tx_abort@ message (type 74). 329 data TxAbort = TxAbort 330 { tx_abort_channel_id :: !ChannelId 331 , tx_abort_data :: !BS.ByteString 332 , tx_abort_tlvs :: !TlvStream 333 -- ^ unknown TLV records 334 } deriving (Eq, Show, Generic) 335 336 instance NFData TxAbort 337 338 -- channel quiescence --------------------------------------------------------- 339 340 -- | The @stfu@ message (type 2). 341 data Stfu = Stfu 342 { stfu_channel_id :: !ChannelId 343 , stfu_initiator :: !Bool 344 -- ^ whether the sender initiated quiescence (sent as 1 or 0) 345 , stfu_tlvs :: !TlvStream 346 -- ^ unknown TLV records 347 } deriving (Eq, Show, Generic) 348 349 instance NFData Stfu 350 351 -- channel close -------------------------------------------------------------- 352 353 -- | The @shutdown@ message (type 38). 354 data Shutdown = Shutdown 355 { shutdown_channel_id :: !ChannelId 356 , shutdown_scriptpubkey :: !ScriptPubKey 357 , shutdown_tlvs :: !TlvStream 358 -- ^ unknown TLV records 359 } deriving (Eq, Show, Generic) 360 361 instance NFData Shutdown 362 363 -- | The @closing_complete@ message (type 40). 364 data ClosingComplete = ClosingComplete 365 { closing_complete_channel_id :: !ChannelId 366 , closing_complete_closer_scriptpubkey :: !ScriptPubKey 367 , closing_complete_closee_scriptpubkey :: !ScriptPubKey 368 , closing_complete_fee_satoshis :: {-# UNPACK #-} !Satoshi 369 , closing_complete_locktime :: {-# UNPACK #-} !Word32 370 , closing_complete_closer_output_only :: !(Maybe Signature) 371 -- ^ TLV type 1 372 , closing_complete_closee_output_only :: !(Maybe Signature) 373 -- ^ TLV type 2 374 , closing_complete_closer_and_closee_outputs :: !(Maybe Signature) 375 -- ^ TLV type 3 376 , closing_complete_tlvs :: !TlvStream 377 -- ^ unknown TLV records 378 } deriving (Eq, Show, Generic) 379 380 instance NFData ClosingComplete 381 382 -- | The @closing_sig@ message (type 41). A valid @closing_sig@ carries 383 -- exactly one signature, in a field set in the @closing_complete@ it 384 -- answers; checking that is left to the caller. 385 data ClosingSig = ClosingSig 386 { closing_sig_channel_id :: !ChannelId 387 , closing_sig_closer_scriptpubkey :: !ScriptPubKey 388 , closing_sig_closee_scriptpubkey :: !ScriptPubKey 389 , closing_sig_fee_satoshis :: {-# UNPACK #-} !Satoshi 390 , closing_sig_locktime :: {-# UNPACK #-} !Word32 391 , closing_sig_closer_output_only :: !(Maybe Signature) 392 -- ^ TLV type 1 393 , closing_sig_closee_output_only :: !(Maybe Signature) 394 -- ^ TLV type 2 395 , closing_sig_closer_and_closee_outputs :: !(Maybe Signature) 396 -- ^ TLV type 3 397 , closing_sig_tlvs :: !TlvStream 398 -- ^ unknown TLV records 399 } deriving (Eq, Show, Generic) 400 401 instance NFData ClosingSig 402 403 -- | The legacy @closing_signed@ message (type 39), used when 404 -- @option_simple_close@ is not negotiated. 405 data ClosingSigned = ClosingSigned 406 { closing_signed_channel_id :: !ChannelId 407 , closing_signed_fee_satoshis :: {-# UNPACK #-} !Satoshi 408 , closing_signed_signature :: !Signature 409 , closing_signed_fee_range :: !(Maybe FeeRange) 410 -- ^ TLV type 1 411 , closing_signed_tlvs :: !TlvStream 412 -- ^ unknown TLV records 413 } deriving (Eq, Show, Generic) 414 415 instance NFData ClosingSigned 416 417 -- normal operation ----------------------------------------------------------- 418 419 -- | The @update_add_htlc@ message (type 128). 420 data UpdateAddHtlc = UpdateAddHtlc 421 { update_add_htlc_channel_id :: !ChannelId 422 , update_add_htlc_id :: !HtlcId 423 , update_add_htlc_amount_msat :: {-# UNPACK #-} !MilliSatoshi 424 , update_add_htlc_payment_hash :: !PaymentHash 425 , update_add_htlc_cltv_expiry :: {-# UNPACK #-} !Word32 426 , update_add_htlc_onion_routing_packet :: !OnionRoutingPacket 427 , update_add_htlc_path_key :: !(Maybe Point) 428 -- ^ the @blinded_path@ record (TLV type 0) 429 , update_add_htlc_tlvs :: !TlvStream 430 -- ^ unknown TLV records 431 } deriving (Eq, Show, Generic) 432 433 instance NFData UpdateAddHtlc 434 435 -- | The @update_fulfill_htlc@ message (type 130). 436 data UpdateFulfillHtlc = UpdateFulfillHtlc 437 { update_fulfill_htlc_channel_id :: !ChannelId 438 , update_fulfill_htlc_id :: !HtlcId 439 , update_fulfill_htlc_payment_preimage :: !PaymentPreimage 440 , update_fulfill_htlc_attribution_data :: !(Maybe AttributionData) 441 -- ^ TLV type 1 442 , update_fulfill_htlc_fulfillment_payload :: !(Maybe BS.ByteString) 443 -- ^ TLV type 3 444 , update_fulfill_htlc_tlvs :: !TlvStream 445 -- ^ unknown TLV records 446 } deriving (Eq, Show, Generic) 447 448 instance NFData UpdateFulfillHtlc 449 450 -- | The @update_fail_htlc@ message (type 131). 451 data UpdateFailHtlc = UpdateFailHtlc 452 { update_fail_htlc_channel_id :: !ChannelId 453 , update_fail_htlc_id :: !HtlcId 454 , update_fail_htlc_reason :: !BS.ByteString 455 , update_fail_htlc_attribution_data :: !(Maybe AttributionData) 456 -- ^ TLV type 1 457 , update_fail_htlc_tlvs :: !TlvStream 458 -- ^ unknown TLV records 459 } deriving (Eq, Show, Generic) 460 461 instance NFData UpdateFailHtlc 462 463 -- | The @update_fail_malformed_htlc@ message (type 135). 464 data UpdateFailMalformedHtlc = UpdateFailMalformedHtlc 465 { update_fail_malformed_htlc_channel_id :: !ChannelId 466 , update_fail_malformed_htlc_id :: !HtlcId 467 , update_fail_malformed_htlc_sha256_of_onion :: !OnionHash 468 , update_fail_malformed_htlc_failure_code :: {-# UNPACK #-} !Word16 469 , update_fail_malformed_htlc_tlvs :: !TlvStream 470 -- ^ unknown TLV records 471 } deriving (Eq, Show, Generic) 472 473 instance NFData UpdateFailMalformedHtlc 474 475 -- | The @commitment_signed@ message (type 132). 476 data CommitmentSigned = CommitmentSigned 477 { commitment_signed_channel_id :: !ChannelId 478 , commitment_signed_signature :: !Signature 479 , commitment_signed_htlc_signatures :: ![Signature] 480 , commitment_signed_funding_txid :: !(Maybe TxId) 481 -- ^ TLV type 1 482 , commitment_signed_tlvs :: !TlvStream 483 -- ^ unknown TLV records 484 } deriving (Eq, Show, Generic) 485 486 instance NFData CommitmentSigned 487 488 -- | The @revoke_and_ack@ message (type 133). 489 data RevokeAndAck = RevokeAndAck 490 { revoke_and_ack_channel_id :: !ChannelId 491 , revoke_and_ack_per_commitment_secret :: !PerCommitmentSecret 492 , revoke_and_ack_next_per_commitment_point :: !Point 493 , revoke_and_ack_tlvs :: !TlvStream 494 -- ^ unknown TLV records 495 } deriving (Eq, Show, Generic) 496 497 instance NFData RevokeAndAck 498 499 -- | The @update_fee@ message (type 134). 500 data UpdateFee = UpdateFee 501 { update_fee_channel_id :: !ChannelId 502 , update_fee_feerate_per_kw :: {-# UNPACK #-} !Word32 503 , update_fee_tlvs :: !TlvStream 504 -- ^ unknown TLV records 505 } deriving (Eq, Show, Generic) 506 507 instance NFData UpdateFee 508 509 -- message retransmission ----------------------------------------------------- 510 511 -- | The @channel_reestablish@ message (type 136). 512 data ChannelReestablish = ChannelReestablish 513 { channel_reestablish_channel_id :: !ChannelId 514 , channel_reestablish_next_commitment_number 515 :: {-# UNPACK #-} !Word64 516 , channel_reestablish_next_revocation_number 517 :: {-# UNPACK #-} !Word64 518 , channel_reestablish_your_last_per_commitment_secret 519 :: !PerCommitmentSecret 520 , channel_reestablish_my_current_per_commitment_point :: !Point 521 , channel_reestablish_next_funding 522 :: !(Maybe NextFunding) 523 -- ^ TLV type 1 524 , channel_reestablish_tlvs :: !TlvStream 525 -- ^ unknown TLV records 526 } deriving (Eq, Show, Generic) 527 528 instance NFData ChannelReestablish 529 530 -- messages ------------------------------------------------------------------- 531 532 -- | A BOLT #2 message. 533 data Message 534 = MsgOpenChannel !OpenChannel 535 | MsgAcceptChannel !AcceptChannel 536 | MsgFundingCreated !FundingCreated 537 | MsgFundingSigned !FundingSigned 538 | MsgChannelReady !ChannelReady 539 | MsgOpenChannel2 !OpenChannel2 540 | MsgAcceptChannel2 !AcceptChannel2 541 | MsgTxAddInput !TxAddInput 542 | MsgTxAddOutput !TxAddOutput 543 | MsgTxRemoveInput !TxRemoveInput 544 | MsgTxRemoveOutput !TxRemoveOutput 545 | MsgTxComplete !TxComplete 546 | MsgTxSignatures !TxSignatures 547 | MsgTxInitRbf !TxInitRbf 548 | MsgTxAckRbf !TxAckRbf 549 | MsgTxAbort !TxAbort 550 | MsgStfu !Stfu 551 | MsgShutdown !Shutdown 552 | MsgClosingComplete !ClosingComplete 553 | MsgClosingSig !ClosingSig 554 | MsgClosingSigned !ClosingSigned 555 | MsgUpdateAddHtlc !UpdateAddHtlc 556 | MsgUpdateFulfillHtlc !UpdateFulfillHtlc 557 | MsgUpdateFailHtlc !UpdateFailHtlc 558 | MsgUpdateFailMalformedHtlc !UpdateFailMalformedHtlc 559 | MsgCommitmentSigned !CommitmentSigned 560 | MsgRevokeAndAck !RevokeAndAck 561 | MsgUpdateFee !UpdateFee 562 | MsgChannelReestablish !ChannelReestablish 563 deriving (Eq, Show, Generic) 564 565 instance NFData Message 566 567 -- | The wire type of a 'Message'. 568 -- 569 -- >>> message_type (MsgTxComplete (TxComplete cid BOLT1.empty_tlv_stream)) 570 -- 70 571 message_type :: Message -> Word16 572 message_type m = case m of 573 MsgOpenChannel {} -> 32 574 MsgAcceptChannel {} -> 33 575 MsgFundingCreated {} -> 34 576 MsgFundingSigned {} -> 35 577 MsgChannelReady {} -> 36 578 MsgOpenChannel2 {} -> 64 579 MsgAcceptChannel2 {} -> 65 580 MsgTxAddInput {} -> 66 581 MsgTxAddOutput {} -> 67 582 MsgTxRemoveInput {} -> 68 583 MsgTxRemoveOutput {} -> 69 584 MsgTxComplete {} -> 70 585 MsgTxSignatures {} -> 71 586 MsgTxInitRbf {} -> 72 587 MsgTxAckRbf {} -> 73 588 MsgTxAbort {} -> 74 589 MsgStfu {} -> 2 590 MsgShutdown {} -> 38 591 MsgClosingComplete {} -> 40 592 MsgClosingSig {} -> 41 593 MsgClosingSigned {} -> 39 594 MsgUpdateAddHtlc {} -> 128 595 MsgUpdateFulfillHtlc {} -> 130 596 MsgUpdateFailHtlc {} -> 131 597 MsgUpdateFailMalformedHtlc {} -> 135 598 MsgCommitmentSigned {} -> 132 599 MsgRevokeAndAck {} -> 133 600 MsgUpdateFee {} -> 134 601 MsgChannelReestablish {} -> 136