BOLT5.hs (2979B)
1 {-# OPTIONS_HADDOCK prune #-} 2 3 -- | 4 -- Module: Lightning.Protocol.BOLT5 5 -- Copyright: (c) 2025 Jared Tobin 6 -- License: MIT 7 -- Maintainer: Jared Tobin <jared@ppad.tech> 8 -- 9 -- On-chain transaction handling for the Lightning Network, per 10 -- [BOLT #5](https://github.com/lightning/bolts/blob/master/05-onchain.md). 11 -- 12 -- This module implements the logic for handling channel closures: 13 -- 14 -- * Mutual close - cooperative closure agreed by both parties 15 -- * Unilateral close - one party publishes their commitment 16 -- transaction 17 -- * Revoked transaction close - penalty for publishing old state 18 -- 19 -- = Design 20 -- 21 -- This is a stateless toolkit of pure functions. The caller 22 -- manages channel state (which outputs are resolved, current 23 -- block height, etc.) and provides explicit inputs. Functions 24 -- produce unsigned 'SpendingTx' values; the caller signs and 25 -- assembles witnesses using bolt3 constructors. 26 -- 27 -- = Usage 28 -- 29 -- @ 30 -- import Lightning.Protocol.BOLT3 31 -- import Lightning.Protocol.BOLT5 32 -- 33 -- -- Classify outputs of our local commitment 34 -- let outputs = classify_local_commit_outputs 35 -- commitTx keys delay features htlcs 36 -- 37 -- -- For each unresolved output, construct spending tx 38 -- case uo_type output of 39 -- SpendToLocal delay revpk delayedpk -> 40 -- spend_to_local (uo_outpoint output) 41 -- (uo_value output) revpk delay delayedpk 42 -- destScript feerate 43 -- ... 44 -- @ 45 46 module Lightning.Protocol.BOLT5 ( 47 -- * Types 48 -- ** Close identification 49 CloseType(..) 50 51 -- ** Output classification 52 , UnresolvedOutput(..) 53 , OutputResolution(..) 54 55 -- ** Spending transactions 56 , SpendingTx(..) 57 58 -- ** Penalty batching 59 , PenaltyContext(..) 60 61 -- * Weight constants (Appendix A) 62 , to_local_penalty_witness_weight 63 , offered_htlc_penalty_witness_weight 64 , accepted_htlc_penalty_witness_weight 65 , to_local_penalty_input_weight 66 , offered_htlc_penalty_input_weight 67 , accepted_htlc_penalty_input_weight 68 , to_remote_input_weight 69 , penalty_tx_base_weight 70 , max_standard_weight 71 72 -- * Fee calculation 73 , spending_fee 74 75 -- * Close identification 76 , identify_close 77 78 -- * Output classification 79 , classify_local_commit_outputs 80 , classify_remote_commit_outputs 81 , classify_revoked_commit_outputs 82 83 -- * Preimage extraction 84 , extract_preimage_offered 85 , extract_preimage_htlc_success 86 87 -- * Timeout check 88 , htlc_timed_out 89 90 -- * Spending transaction construction 91 -- ** Local commitment 92 , spend_to_local 93 , spend_htlc_timeout 94 , spend_htlc_success 95 , spend_htlc_output 96 97 -- ** Remote commitment 98 , spend_remote_htlc_timeout 99 , spend_remote_htlc_preimage 100 101 -- ** Revoked commitment 102 , spend_revoked_to_local 103 , spend_revoked_htlc 104 , spend_revoked_htlc_output 105 , spend_revoked_batch 106 107 -- ** Anchor outputs 108 , spend_anchor_owner 109 , spend_anchor_anyone 110 ) where 111 112 import Lightning.Protocol.BOLT5.Types 113 import Lightning.Protocol.BOLT5.Detect 114 import Lightning.Protocol.BOLT5.Spend