tx

Minimal transaction primitives (docs.ppad.tech/tx).
git clone git://git.ppad.tech/tx.git
Log | Files | Refs | README | LICENSE

commit 6e22072caac8c1db991c2640fcb795afba8c294a
parent 7bb595ed894086fcc03e6d42c820fbecd436b3e4
Author: Jared Tobin <jared@jtobin.io>
Date:   Sat, 18 Apr 2026 20:35:59 +0800

lib: add NFData instances for all transaction types

Add deepseq dependency and NFData instances for TxId, OutPoint,
TxIn, TxOut, Witness, and Tx directly in the library. This
eliminates the need for orphan instances in downstream consumers
(bolt2, bolt3) and bench suites.

Diffstat:
Mbench/Main.hs | 6------
Mbench/Weight.hs | 6------
Mlib/Bitcoin/Prim/Tx.hs | 13+++++++++++++
Mppad-tx.cabal | 1+
4 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/bench/Main.hs b/bench/Main.hs @@ -13,12 +13,6 @@ import Bitcoin.Prim.Tx.Sighash -- NFData instances ------------------------------------------------------------ -instance NFData TxId -instance NFData OutPoint -instance NFData TxIn -instance NFData TxOut -instance NFData Witness -instance NFData Tx instance NFData SighashType -- sample data ----------------------------------------------------------------- diff --git a/bench/Weight.hs b/bench/Weight.hs @@ -13,12 +13,6 @@ import Bitcoin.Prim.Tx.Sighash -- NFData instances ------------------------------------------------------------ -instance NFData TxId -instance NFData OutPoint -instance NFData TxIn -instance NFData TxOut -instance NFData Witness -instance NFData Tx instance NFData SighashType -- sample data ----------------------------------------------------------------- diff --git a/lib/Bitcoin/Prim/Tx.hs b/lib/Bitcoin/Prim/Tx.hs @@ -42,6 +42,7 @@ module Bitcoin.Prim.Tx ( , to_strict ) where +import Control.DeepSeq (NFData(..)) import qualified Crypto.Hash.SHA256 as SHA256 import Data.Bits ((.|.), shiftL) import qualified Data.ByteString as BS @@ -57,6 +58,8 @@ import GHC.Generics (Generic) newtype TxId = TxId BS.ByteString deriving (Eq, Show, Generic) +instance NFData TxId + -- | Construct a TxId from a 32-byte ByteString. -- -- Returns 'Nothing' if the input is not exactly 32 bytes. @@ -76,6 +79,8 @@ data OutPoint = OutPoint , op_vout :: {-# UNPACK #-} !Word32 } deriving (Eq, Show, Generic) +instance NFData OutPoint + -- | Transaction input. data TxIn = TxIn { txin_prevout :: {-# UNPACK #-} !OutPoint @@ -83,16 +88,22 @@ data TxIn = TxIn , txin_sequence :: {-# UNPACK #-} !Word32 } deriving (Eq, Show, Generic) +instance NFData TxIn + -- | Transaction output. data TxOut = TxOut { txout_value :: {-# UNPACK #-} !Word64 -- ^ satoshis , txout_script_pubkey :: !BS.ByteString } deriving (Eq, Show, Generic) +instance NFData TxOut + -- | Witness stack for a single input. newtype Witness = Witness [BS.ByteString] deriving (Eq, Show, Generic) +instance NFData Witness + -- | Complete transaction. -- -- Bitcoin requires at least one input and one output, enforced here @@ -105,6 +116,8 @@ data Tx = Tx , tx_locktime :: {-# UNPACK #-} !Word32 } deriving (Eq, Show, Generic) +instance NFData Tx + -- serialisation --------------------------------------------------------------- -- | Serialise a transaction to bytes. diff --git a/ppad-tx.cabal b/ppad-tx.cabal @@ -37,6 +37,7 @@ library build-depends: base >= 4.9 && < 5 , bytestring >= 0.9 && < 0.13 + , deepseq >= 1.4 && < 2 , ppad-base16 >= 0.2.1 && < 0.3 , ppad-sha256 >= 0.3 && < 0.4