Fixtures.hs (5322B)
1 {-# LANGUAGE OverloadedStrings #-} 2 3 module Fixtures ( 4 Fixtures(..) 5 , fixtures 6 ) where 7 8 import qualified Bitcoin.Prim.Tx as Tx 9 import qualified Data.ByteString as BS 10 import qualified Lightning.Protocol.BOLT1 as BOLT1 11 import Lightning.Protocol.BOLT2 12 import qualified Lightning.Protocol.BOLT9 as BOLT9 13 14 -- representative messages, with their encoded payloads 15 data Fixtures = Fixtures 16 { fx_open_channel :: !OpenChannel 17 , fx_open_channel_bytes :: !BS.ByteString 18 , fx_accept_channel2 :: !AcceptChannel2 19 , fx_accept_channel2_bytes :: !BS.ByteString 20 , fx_tx_signatures :: !TxSignatures 21 , fx_tx_signatures_bytes :: !BS.ByteString 22 , fx_closing_complete :: !ClosingComplete 23 , fx_closing_complete_bytes :: !BS.ByteString 24 , fx_update_add_htlc :: !UpdateAddHtlc 25 , fx_update_add_htlc_bytes :: !BS.ByteString 26 , fx_update_add_htlc_wire :: !BS.ByteString 27 , fx_update_fulfill_htlc :: !UpdateFulfillHtlc 28 , fx_update_fulfill_htlc_bytes :: !BS.ByteString 29 , fx_commitment_signed :: !CommitmentSigned 30 , fx_commitment_signed_bytes :: !BS.ByteString 31 , fx_commitment_signed_483 :: !CommitmentSigned 32 , fx_commitment_signed_483_bytes :: !BS.ByteString 33 , fx_revoke_and_ack :: !RevokeAndAck 34 , fx_revoke_and_ack_bytes :: !BS.ByteString 35 , fx_channel_reestablish :: !ChannelReestablish 36 , fx_channel_reestablish_bytes :: !BS.ByteString 37 } 38 39 ok :: Either e a -> Maybe a 40 ok = either (const Nothing) Just 41 42 empty :: BOLT1.TlvStream 43 empty = BOLT1.empty_tlv_stream 44 45 fixtures :: Maybe Fixtures 46 fixtures = do 47 ch <- BOLT1.chain_hash (BS.replicate 32 0x6f) 48 cid <- BOLT1.channel_id (BS.replicate 32 0xab) 49 pts <- traverse (\b -> BOLT1.point (BS.cons 0x02 (BS.replicate 32 b))) 50 [0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77] 51 sig <- BOLT1.signature (BS.replicate 64 0xa1) 52 txid <- Tx.mk_txid (BS.replicate 32 0x7e) 53 spk <- script_pubkey ("\x00\x14" <> BS.replicate 20 0x88) 54 fund <- BOLT1.satoshi 1000000 55 dust <- BOLT1.satoshi 546 56 res <- BOLT1.satoshi 10000 57 push <- BOLT1.milli_satoshi 0 58 hmin <- BOLT1.milli_satoshi 1000 59 amt <- BOLT1.milli_satoshi 100000 60 fee <- BOLT1.satoshi 500 61 ph <- BOLT1.payment_hash (BS.replicate 32 0x9a) 62 pre <- BOLT1.payment_preimage (BS.replicate 32 0x50) 63 sec <- BOLT1.per_commitment_secret (BS.replicate 32 0x5e) 64 onion <- onion_routing_packet (BS.replicate 1366 0x44) 65 att <- attribution_data (BS.replicate 920 0x0b) 66 ws <- traverse witness 67 [ "\x02\x47" <> BS.replicate 71 0x30 <> "\x21" 68 <> BS.replicate 33 0x02 69 , "\x01\x40" <> BS.replicate 64 0x01 ] 70 ext <- BOLT1.tlv_stream [BOLT1.TlvRecord 43 (BS.replicate 16 0x2a)] 71 (p1, p2, p3, p4, p5, p6, p7) <- case pts of 72 [a, b, c, d, e, f, g] -> Just (a, b, c, d, e, f, g) 73 _ -> Nothing 74 let ctype = BOLT9.channel_type_features 75 (BOLT9.ChannelType BOLT9.BasicAnchors False False) 76 77 oc = OpenChannel ch cid fund push dust maxBound res hmin 253 144 483 78 p1 p2 p3 p4 p5 p6 1 (Just spk) (Just ctype) empty 79 ac2 = AcceptChannel2 cid fund dust maxBound hmin 3 144 483 80 p1 p2 p3 p4 p5 p6 p7 (Just spk) (Just ctype) True ext 81 txs = TxSignatures cid txid ws empty 82 cc = ClosingComplete cid spk spk fee 0 (Just sig) Nothing (Just sig) 83 empty 84 add = UpdateAddHtlc cid (HtlcId 42) amt ph 800000 onion (Just p1) 85 empty 86 ful = UpdateFulfillHtlc cid (HtlcId 42) pre (Just att) Nothing empty 87 cs0 = CommitmentSigned cid sig [] (Just txid) empty 88 cs483 = CommitmentSigned cid sig (replicate 483 sig) (Just txid) 89 empty 90 raa = RevokeAndAck cid sec p1 empty 91 rst = ChannelReestablish cid 5 4 sec p1 (Just (NextFunding txid 1)) 92 empty 93 94 oc_b <- ok (encode_open_channel oc) 95 ac2_b <- ok (encode_accept_channel2 ac2) 96 txs_b <- ok (encode_tx_signatures txs) 97 cc_b <- ok (encode_closing_complete cc) 98 add_b <- ok (encode_update_add_htlc add) 99 add_w <- ok (encode_message (MsgUpdateAddHtlc add)) 100 ful_b <- ok (encode_update_fulfill_htlc ful) 101 cs0_b <- ok (encode_commitment_signed cs0) 102 cs483_b <- ok (encode_commitment_signed cs483) 103 rst_b <- ok (encode_channel_reestablish rst) 104 pure Fixtures 105 { fx_open_channel = oc 106 , fx_open_channel_bytes = oc_b 107 , fx_accept_channel2 = ac2 108 , fx_accept_channel2_bytes = ac2_b 109 , fx_tx_signatures = txs 110 , fx_tx_signatures_bytes = txs_b 111 , fx_closing_complete = cc 112 , fx_closing_complete_bytes = cc_b 113 , fx_update_add_htlc = add 114 , fx_update_add_htlc_bytes = add_b 115 , fx_update_add_htlc_wire = add_w 116 , fx_update_fulfill_htlc = ful 117 , fx_update_fulfill_htlc_bytes = ful_b 118 , fx_commitment_signed = cs0 119 , fx_commitment_signed_bytes = cs0_b 120 , fx_commitment_signed_483 = cs483 121 , fx_commitment_signed_483_bytes = cs483_b 122 , fx_revoke_and_ack = raa 123 , fx_revoke_and_ack_bytes = encode_revoke_and_ack raa 124 , fx_channel_reestablish = rst 125 , fx_channel_reestablish_bytes = rst_b 126 }