BOLT5.hs (3401B)
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 library's scope is being redesigned, and it is not yet ready 13 -- for release. It covers unilateral closes only partially: it 14 -- identifies a local or remote commitment on chain, classifies its 15 -- outputs, extracts preimages from HTLC spends, and builds unsigned, 16 -- single-input spending transactions. It doesn't detect mutual or 17 -- revoked closes, assemble witnesses, or attach fee inputs to anchor 18 -- spends and zero-fee HTLC transactions. 19 -- 20 -- = Design 21 -- 22 -- This is a stateless toolkit of pure functions. The caller manages 23 -- channel state (which outputs are resolved, the current block 24 -- height, etc.) and provides explicit inputs. Commitment 25 -- transactions are those built by ppad-bolt3, and amounts are 26 -- ppad-bolt1's. Functions produce unsigned t'SpendingTx' values; the 27 -- caller signs them and assembles witnesses with bolt3's witness 28 -- functions. 29 -- 30 -- = Usage 31 -- 32 -- @ 33 -- import qualified Lightning.Protocol.BOLT1 as BOLT1 34 -- import Lightning.Protocol.BOLT3 35 -- import Lightning.Protocol.BOLT5 36 -- 37 -- -- classify the outputs of our local commitment 38 -- let outputs = classify_local_commit_outputs commit keys delay fmt 39 -- 40 -- -- for each unresolved output, build a spending transaction 41 -- case uo_type output of 42 -- SpendToLocal delay revpk delayedpk -> 43 -- spend_to_local (uo_outpoint output) (uo_value output) 44 -- revpk delay delayedpk dest feerate 45 -- ... 46 -- @ 47 48 module Lightning.Protocol.BOLT5 ( 49 -- * Close identification 50 CloseType(..) 51 , identify_close 52 53 -- * Output classification 54 , UnresolvedOutput(..) 55 , OutputResolution(..) 56 , classify_local_commit_outputs 57 , classify_remote_commit_outputs 58 , classify_revoked_commit_outputs 59 60 -- * Preimage extraction 61 , extract_preimage_offered 62 , extract_preimage_htlc_success 63 64 -- * Timeout check 65 , htlc_timed_out 66 67 -- * Spending transactions 68 , SpendingTx(..) 69 70 -- ** Local commitment 71 , spend_to_local 72 , spend_htlc_tx 73 , spend_htlc_output 74 75 -- ** Remote commitment 76 , spend_remote_htlc_timeout 77 , spend_remote_htlc_preimage 78 79 -- ** Revoked commitment 80 , spend_revoked_to_local 81 , spend_revoked_htlc 82 , spend_revoked_htlc_output 83 84 -- ** Anchor outputs 85 , spend_anchor_owner 86 , spend_anchor_anyone 87 88 -- * Revoked outputs 89 , HTLCOutputType(..) 90 , htlc_output_type 91 , RevokedOutput(..) 92 , RevokedOutputType(..) 93 94 -- * Weights (Appendix A) 95 , revoked_output_weight 96 , htlc_output_type_weight 97 , to_local_penalty_witness_weight 98 , offered_htlc_penalty_witness_weight 99 , accepted_htlc_penalty_witness_weight 100 , offered_htlc_penalty_witness_weight_anchors 101 , accepted_htlc_penalty_witness_weight_anchors 102 , to_local_penalty_input_weight 103 , offered_htlc_penalty_input_weight 104 , accepted_htlc_penalty_input_weight 105 , offered_htlc_penalty_input_weight_anchors 106 , accepted_htlc_penalty_input_weight_anchors 107 , to_remote_input_weight 108 , penalty_tx_base_weight 109 , max_standard_weight 110 111 -- * Fees 112 , spending_fee 113 ) where 114 115 import Lightning.Protocol.BOLT5.Detect 116 import Lightning.Protocol.BOLT5.Spend 117 import Lightning.Protocol.BOLT5.Types