bolt5

On-chain transaction handling for Lightning (docs.ppad.tech/bolt5).
git clone git://git.ppad.tech/bolt5.git
Log | Files | Refs | README | LICENSE

commit 316f0920ba6324b634ba3509a1f169c3fc5da817
parent d1d7330cda2235183a881fa48fd8f081f4e4bd8c
Author: Jared Tobin <jared@jtobin.io>
Date:   Sat, 10 Oct 2026 19:16:50 +0400

port to ppad-tx's abstract TxId and per-input witnesses

Give each TxIn its witness, use null_txid and mk_txid in tests and
benches, and update the ppad-bolt3 and ppad-tx locks.

Diffstat:
Mbench/Fixtures.hs | 2+-
Mflake.lock | 16++++++++--------
Mlib/Lightning/Protocol/BOLT5/Spend.hs | 4++--
Mtest/Main.hs | 15++++++++-------
4 files changed, 19 insertions(+), 18 deletions(-)

diff --git a/bench/Fixtures.hs b/bench/Fixtures.hs @@ -84,7 +84,7 @@ build = do "023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb" remote_fund <- pt "030e9f7b623d2ccc7c9bd44d66d5ce21ce504c0acf6385a132cec6d3c39fa711c1" - funding_txid <- BT.mkTxId =<< unhex + funding_txid <- BT.mk_txid =<< unhex "bef67e4e2fb9ddeeb3461973cd4c62abb35050b1add772995b820b584a488489" cn <- commitment_number 42 dust <- BOLT1.satoshi 546 diff --git a/flake.lock b/flake.lock @@ -277,11 +277,11 @@ ] }, "locked": { - "lastModified": 1791630066, - "narHash": "sha256-dEMBydCq9B3nZnpK97Na43IqT+c841nTdFPK5b/PoLw=", + "lastModified": 1791645360, + "narHash": "sha256-h+ZV1kWjq3mo5CJY/vwKrRpQ/hktTkpXzkzbTn4eE9M=", "ref": "master", - "rev": "b6b3c35e24b99b2538475f27cff76d0556993160", - "revCount": 70, + "rev": "2918e786adc17000c5a31e8dbf9c9fbcead30aa6", + "revCount": 73, "type": "git", "url": "git://git.ppad.tech/bolt3.git" }, @@ -581,11 +581,11 @@ ] }, "locked": { - "lastModified": 1791643261, - "narHash": "sha256-Zng+Z6E1NnsDGTvL8MQuRiMaJlm4TPOfdLV2Jhe9u4g=", + "lastModified": 1791644539, + "narHash": "sha256-Ap1kEJmNrO+8bw6IWhnWiIKewRIad2MCjyPdGMUDxDs=", "ref": "master", - "rev": "25defad8bbaddc05c969872947968e2de35be3fe", - "revCount": 38, + "rev": "0f09078de350d0965f1039ac39b26f288530742b", + "revCount": 42, "type": "git", "url": "git://git.ppad.tech/tx.git" }, diff --git a/lib/Lightning/Protocol/BOLT5/Spend.hs b/lib/Lightning/Protocol/BOLT5/Spend.hs @@ -34,7 +34,7 @@ module Lightning.Protocol.BOLT5.Spend ( , spend_anchor_anyone ) where -import Bitcoin.Prim.Tx (OutPoint, Tx(..), TxIn(..), TxOut(..)) +import Bitcoin.Prim.Tx (OutPoint, Tx(..), TxIn(..), TxOut(..), Witness(..)) import Bitcoin.Prim.Tx.Sighash (SighashType(..)) import qualified Data.ByteString as BS import Data.List.NonEmpty (NonEmpty(..)) @@ -401,11 +401,11 @@ mk_spending_tx !op !sq (Script dest) !value !locktime = Tx { txin_prevout = op , txin_script_sig = BS.empty , txin_sequence = sq + , txin_witness = Witness [] } :| [] , tx_outputs = TxOut { txout_value = BOLT1.un_satoshi value , txout_script_pubkey = dest } :| [] - , tx_witnesses = [] , tx_locktime = locktime } diff --git a/test/Main.hs b/test/Main.hs @@ -2,7 +2,7 @@ module Main where -import Bitcoin.Prim.Tx (OutPoint(..), Tx(..), TxId(..), TxIn(..), +import Bitcoin.Prim.Tx (OutPoint(..), Tx(..), TxId, TxIn(..), TxOut(..), Witness(..)) import qualified Bitcoin.Prim.Tx as BT import Bitcoin.Prim.Tx.Sighash (SighashType(..), encode_sighash) @@ -175,7 +175,7 @@ prop_fx k = case fixtures of Just fx -> property (k fx) dummyTxId :: TxId -dummyTxId = TxId (BS.replicate 32 0x00) +dummyTxId = BT.null_txid dummyOutPoint :: OutPoint dummyOutPoint = OutPoint dummyTxId 0 @@ -280,7 +280,7 @@ vecCommitment -> IO CommitmentTx vecCommitment feerate fmt toLocal htlcs = do keys <- vecKeys - fundingTxid <- need "funding txid" $ BT.mkTxId =<< unhex + fundingTxid <- need "funding txid" $ BT.mk_txid =<< unhex "bef67e4e2fb9ddeeb3461973cd4c62abb35050b1add772995b820b584a488489" cn <- need "commitment number" (commitment_number 42) localBp <- pt @@ -437,9 +437,9 @@ parseTx = need "invalid transaction hex" . BT.from_base16 -- | Witness stack of a single-input transaction. singleWitness :: Tx -> IO [BS.ByteString] -singleWitness tx = case tx_witnesses tx of - [Witness items] -> pure items - _ -> assertFailure "expected a single witness" +singleWitness tx = case tx_inputs tx of + i :| [] | Witness items <- txin_witness i -> pure items + _ -> assertFailure "expected a single input" -- | Remote signature and offered HTLC witness script, taken from the -- Appendix C HTLC-timeout tx for htlc #5. @@ -487,7 +487,8 @@ assertHtlcTx :: B5.SpendingTx -> BS.ByteString -> Assertion assertHtlcTx stx vec = do tx <- parseTx vec items <- singleWitness tx - B5.stx_tx stx @?= tx { tx_witnesses = [] } + B5.stx_tx stx @?= tx { tx_inputs = fmap + (\i -> i { txin_witness = Witness [] }) (tx_inputs tx) } case reverse items of script : _ -> B5.stx_input_script stx @?= Script script [] -> assertFailure "empty witness"