ppad-bolt3-0.0.1: Bitcoin transaction formats per BOLT #3
Copyright(c) 2025 Jared Tobin
LicenseMIT
MaintainerJared Tobin <jared@ppad.tech>
Safe HaskellNone
LanguageHaskell2010

Lightning.Protocol.BOLT3.Tx

Description

Transaction assembly for BOLT #3.

Constructs:

  • Commitment transactions
  • HTLC-timeout transactions
  • HTLC-success transactions
  • Closing transactions
Synopsis

Commitment transaction

data CommitmentTx Source #

A commitment transaction.

Instances

Instances details
Generic CommitmentTx Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Associated Types

type Rep CommitmentTx 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep CommitmentTx = D1 ('MetaData "CommitmentTx" "Lightning.Protocol.BOLT3.Tx" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "CommitmentTx" 'PrefixI 'True) ((S1 ('MetaSel ('Just "ctx_version") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32) :*: (S1 ('MetaSel ('Just "ctx_locktime") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Locktime) :*: S1 ('MetaSel ('Just "ctx_input_outpoint") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Outpoint))) :*: (S1 ('MetaSel ('Just "ctx_input_sequence") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Sequence) :*: (S1 ('MetaSel ('Just "ctx_outputs") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [TxOutput]) :*: S1 ('MetaSel ('Just "ctx_funding_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script)))))
Show CommitmentTx Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Eq CommitmentTx Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep CommitmentTx Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep CommitmentTx = D1 ('MetaData "CommitmentTx" "Lightning.Protocol.BOLT3.Tx" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "CommitmentTx" 'PrefixI 'True) ((S1 ('MetaSel ('Just "ctx_version") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32) :*: (S1 ('MetaSel ('Just "ctx_locktime") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Locktime) :*: S1 ('MetaSel ('Just "ctx_input_outpoint") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Outpoint))) :*: (S1 ('MetaSel ('Just "ctx_input_sequence") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Sequence) :*: (S1 ('MetaSel ('Just "ctx_outputs") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [TxOutput]) :*: S1 ('MetaSel ('Just "ctx_funding_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script)))))

data CommitmentContext Source #

Context for building a commitment transaction.

Instances

Instances details
Generic CommitmentContext Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Associated Types

type Rep CommitmentContext 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep CommitmentContext = D1 ('MetaData "CommitmentContext" "Lightning.Protocol.BOLT3.Tx" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "CommitmentContext" 'PrefixI 'True) (((S1 ('MetaSel ('Just "cc_funding_outpoint") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Outpoint) :*: (S1 ('MetaSel ('Just "cc_commitment_number") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 CommitmentNumber) :*: S1 ('MetaSel ('Just "cc_local_payment_bp") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 PaymentBasepoint))) :*: (S1 ('MetaSel ('Just "cc_remote_payment_bp") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 PaymentBasepoint) :*: (S1 ('MetaSel ('Just "cc_to_self_delay") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ToSelfDelay) :*: S1 ('MetaSel ('Just "cc_dust_limit") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DustLimit)))) :*: ((S1 ('MetaSel ('Just "cc_feerate") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 FeeratePerKw) :*: (S1 ('MetaSel ('Just "cc_features") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ChannelFeatures) :*: S1 ('MetaSel ('Just "cc_is_funder") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Bool))) :*: ((S1 ('MetaSel ('Just "cc_to_local_msat") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 MilliSatoshi) :*: S1 ('MetaSel ('Just "cc_to_remote_msat") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 MilliSatoshi)) :*: (S1 ('MetaSel ('Just "cc_htlcs") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [HTLC]) :*: S1 ('MetaSel ('Just "cc_keys") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 CommitmentKeys))))))
Show CommitmentContext Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Eq CommitmentContext Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep CommitmentContext Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep CommitmentContext = D1 ('MetaData "CommitmentContext" "Lightning.Protocol.BOLT3.Tx" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "CommitmentContext" 'PrefixI 'True) (((S1 ('MetaSel ('Just "cc_funding_outpoint") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Outpoint) :*: (S1 ('MetaSel ('Just "cc_commitment_number") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 CommitmentNumber) :*: S1 ('MetaSel ('Just "cc_local_payment_bp") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 PaymentBasepoint))) :*: (S1 ('MetaSel ('Just "cc_remote_payment_bp") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 PaymentBasepoint) :*: (S1 ('MetaSel ('Just "cc_to_self_delay") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ToSelfDelay) :*: S1 ('MetaSel ('Just "cc_dust_limit") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DustLimit)))) :*: ((S1 ('MetaSel ('Just "cc_feerate") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 FeeratePerKw) :*: (S1 ('MetaSel ('Just "cc_features") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ChannelFeatures) :*: S1 ('MetaSel ('Just "cc_is_funder") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Bool))) :*: ((S1 ('MetaSel ('Just "cc_to_local_msat") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 MilliSatoshi) :*: S1 ('MetaSel ('Just "cc_to_remote_msat") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 MilliSatoshi)) :*: (S1 ('MetaSel ('Just "cc_htlcs") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [HTLC]) :*: S1 ('MetaSel ('Just "cc_keys") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 CommitmentKeys))))))

data CommitmentKeys Source #

Derived keys needed for commitment transaction outputs.

Instances

Instances details
Generic CommitmentKeys Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Associated Types

type Rep CommitmentKeys 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep CommitmentKeys = D1 ('MetaData "CommitmentKeys" "Lightning.Protocol.BOLT3.Tx" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "CommitmentKeys" 'PrefixI 'True) (((S1 ('MetaSel ('Just "ck_revocation_pubkey") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 RevocationPubkey) :*: S1 ('MetaSel ('Just "ck_local_delayed") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 LocalDelayedPubkey)) :*: (S1 ('MetaSel ('Just "ck_local_htlc") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 LocalHtlcPubkey) :*: S1 ('MetaSel ('Just "ck_remote_htlc") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 RemoteHtlcPubkey))) :*: ((S1 ('MetaSel ('Just "ck_local_payment") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 LocalPubkey) :*: S1 ('MetaSel ('Just "ck_remote_payment") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 RemotePubkey)) :*: (S1 ('MetaSel ('Just "ck_local_funding") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 FundingPubkey) :*: S1 ('MetaSel ('Just "ck_remote_funding") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 FundingPubkey)))))
Show CommitmentKeys Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Eq CommitmentKeys Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep CommitmentKeys Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep CommitmentKeys = D1 ('MetaData "CommitmentKeys" "Lightning.Protocol.BOLT3.Tx" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "CommitmentKeys" 'PrefixI 'True) (((S1 ('MetaSel ('Just "ck_revocation_pubkey") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 RevocationPubkey) :*: S1 ('MetaSel ('Just "ck_local_delayed") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 LocalDelayedPubkey)) :*: (S1 ('MetaSel ('Just "ck_local_htlc") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 LocalHtlcPubkey) :*: S1 ('MetaSel ('Just "ck_remote_htlc") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 RemoteHtlcPubkey))) :*: ((S1 ('MetaSel ('Just "ck_local_payment") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 LocalPubkey) :*: S1 ('MetaSel ('Just "ck_remote_payment") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 RemotePubkey)) :*: (S1 ('MetaSel ('Just "ck_local_funding") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 FundingPubkey) :*: S1 ('MetaSel ('Just "ck_remote_funding") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 FundingPubkey)))))

build_commitment_tx :: CommitmentContext -> CommitmentTx Source #

Build a commitment transaction.

Follows the algorithm from BOLT #3:

  1. Initialize input and locktime with obscured commitment number
  2. Calculate which HTLCs are trimmed
  3. Calculate base fee and subtract from funder
  4. Add untrimmed HTLC outputs
  5. Add to_local output if above dust
  6. Add to_remote output if above dust
  7. Add anchor outputs if option_anchors
  8. Sort outputs per BIP69+CLTV

HTLC transactions

data HTLCTx Source #

An HTLC transaction (timeout or success).

Instances

Instances details
Generic HTLCTx Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Associated Types

type Rep HTLCTx 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep HTLCTx = D1 ('MetaData "HTLCTx" "Lightning.Protocol.BOLT3.Tx" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "HTLCTx" 'PrefixI 'True) ((S1 ('MetaSel ('Just "htx_version") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32) :*: (S1 ('MetaSel ('Just "htx_locktime") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Locktime) :*: S1 ('MetaSel ('Just "htx_input_outpoint") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Outpoint))) :*: (S1 ('MetaSel ('Just "htx_input_sequence") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Sequence) :*: (S1 ('MetaSel ('Just "htx_output_value") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Satoshi) :*: S1 ('MetaSel ('Just "htx_output_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script)))))

Methods

from :: HTLCTx -> Rep HTLCTx x #

to :: Rep HTLCTx x -> HTLCTx #

Show HTLCTx Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Eq HTLCTx Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Methods

(==) :: HTLCTx -> HTLCTx -> Bool #

(/=) :: HTLCTx -> HTLCTx -> Bool #

type Rep HTLCTx Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep HTLCTx = D1 ('MetaData "HTLCTx" "Lightning.Protocol.BOLT3.Tx" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "HTLCTx" 'PrefixI 'True) ((S1 ('MetaSel ('Just "htx_version") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32) :*: (S1 ('MetaSel ('Just "htx_locktime") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Locktime) :*: S1 ('MetaSel ('Just "htx_input_outpoint") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Outpoint))) :*: (S1 ('MetaSel ('Just "htx_input_sequence") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Sequence) :*: (S1 ('MetaSel ('Just "htx_output_value") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Satoshi) :*: S1 ('MetaSel ('Just "htx_output_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script)))))

data HTLCContext Source #

Context for building HTLC transactions.

Instances

Instances details
Generic HTLCContext Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Associated Types

type Rep HTLCContext 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep HTLCContext = D1 ('MetaData "HTLCContext" "Lightning.Protocol.BOLT3.Tx" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "HTLCContext" 'PrefixI 'True) (((S1 ('MetaSel ('Just "hc_commitment_txid") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TxId) :*: S1 ('MetaSel ('Just "hc_output_index") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32)) :*: (S1 ('MetaSel ('Just "hc_htlc") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 HTLC) :*: S1 ('MetaSel ('Just "hc_to_self_delay") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ToSelfDelay))) :*: ((S1 ('MetaSel ('Just "hc_feerate") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 FeeratePerKw) :*: S1 ('MetaSel ('Just "hc_features") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ChannelFeatures)) :*: (S1 ('MetaSel ('Just "hc_revocation_pubkey") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 RevocationPubkey) :*: S1 ('MetaSel ('Just "hc_local_delayed") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 LocalDelayedPubkey)))))
Show HTLCContext Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Eq HTLCContext Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep HTLCContext Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep HTLCContext = D1 ('MetaData "HTLCContext" "Lightning.Protocol.BOLT3.Tx" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "HTLCContext" 'PrefixI 'True) (((S1 ('MetaSel ('Just "hc_commitment_txid") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TxId) :*: S1 ('MetaSel ('Just "hc_output_index") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32)) :*: (S1 ('MetaSel ('Just "hc_htlc") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 HTLC) :*: S1 ('MetaSel ('Just "hc_to_self_delay") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ToSelfDelay))) :*: ((S1 ('MetaSel ('Just "hc_feerate") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 FeeratePerKw) :*: S1 ('MetaSel ('Just "hc_features") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ChannelFeatures)) :*: (S1 ('MetaSel ('Just "hc_revocation_pubkey") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 RevocationPubkey) :*: S1 ('MetaSel ('Just "hc_local_delayed") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 LocalDelayedPubkey)))))

build_htlc_timeout_tx :: HTLCContext -> HTLCTx Source #

Build an HTLC-timeout transaction.

  • locktime: cltv_expiry
  • sequence: 0 (or 1 with option_anchors)
  • output: to_local style script with revocation and delayed paths

build_htlc_success_tx :: HTLCContext -> HTLCTx Source #

Build an HTLC-success transaction.

  • locktime: 0
  • sequence: 0 (or 1 with option_anchors)
  • output: to_local style script with revocation and delayed paths

Closing transaction

data ClosingTx Source #

A closing transaction.

Instances

Instances details
Generic ClosingTx Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Associated Types

type Rep ClosingTx 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep ClosingTx = D1 ('MetaData "ClosingTx" "Lightning.Protocol.BOLT3.Tx" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "ClosingTx" 'PrefixI 'True) ((S1 ('MetaSel ('Just "cltx_version") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32) :*: (S1 ('MetaSel ('Just "cltx_locktime") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Locktime) :*: S1 ('MetaSel ('Just "cltx_input_outpoint") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Outpoint))) :*: (S1 ('MetaSel ('Just "cltx_input_sequence") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Sequence) :*: (S1 ('MetaSel ('Just "cltx_outputs") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [TxOutput]) :*: S1 ('MetaSel ('Just "cltx_funding_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script)))))
Show ClosingTx Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Eq ClosingTx Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep ClosingTx Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep ClosingTx = D1 ('MetaData "ClosingTx" "Lightning.Protocol.BOLT3.Tx" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "ClosingTx" 'PrefixI 'True) ((S1 ('MetaSel ('Just "cltx_version") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Word32) :*: (S1 ('MetaSel ('Just "cltx_locktime") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Locktime) :*: S1 ('MetaSel ('Just "cltx_input_outpoint") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Outpoint))) :*: (S1 ('MetaSel ('Just "cltx_input_sequence") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Sequence) :*: (S1 ('MetaSel ('Just "cltx_outputs") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [TxOutput]) :*: S1 ('MetaSel ('Just "cltx_funding_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script)))))

data ClosingContext Source #

Context for building closing transactions.

Instances

Instances details
Generic ClosingContext Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Associated Types

type Rep ClosingContext 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep ClosingContext = D1 ('MetaData "ClosingContext" "Lightning.Protocol.BOLT3.Tx" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "ClosingContext" 'PrefixI 'True) (((S1 ('MetaSel ('Just "clc_funding_outpoint") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Outpoint) :*: S1 ('MetaSel ('Just "clc_local_amount") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Satoshi)) :*: (S1 ('MetaSel ('Just "clc_remote_amount") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Satoshi) :*: (S1 ('MetaSel ('Just "clc_local_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script) :*: S1 ('MetaSel ('Just "clc_remote_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script)))) :*: ((S1 ('MetaSel ('Just "clc_local_dust_limit") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DustLimit) :*: (S1 ('MetaSel ('Just "clc_remote_dust_limit") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DustLimit) :*: S1 ('MetaSel ('Just "clc_fee") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Satoshi))) :*: (S1 ('MetaSel ('Just "clc_is_funder") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Bool) :*: (S1 ('MetaSel ('Just "clc_locktime") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Locktime) :*: S1 ('MetaSel ('Just "clc_funding_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script))))))
Show ClosingContext Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Eq ClosingContext Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep ClosingContext Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep ClosingContext = D1 ('MetaData "ClosingContext" "Lightning.Protocol.BOLT3.Tx" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "ClosingContext" 'PrefixI 'True) (((S1 ('MetaSel ('Just "clc_funding_outpoint") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Outpoint) :*: S1 ('MetaSel ('Just "clc_local_amount") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Satoshi)) :*: (S1 ('MetaSel ('Just "clc_remote_amount") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Satoshi) :*: (S1 ('MetaSel ('Just "clc_local_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script) :*: S1 ('MetaSel ('Just "clc_remote_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script)))) :*: ((S1 ('MetaSel ('Just "clc_local_dust_limit") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DustLimit) :*: (S1 ('MetaSel ('Just "clc_remote_dust_limit") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DustLimit) :*: S1 ('MetaSel ('Just "clc_fee") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Satoshi))) :*: (S1 ('MetaSel ('Just "clc_is_funder") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Bool) :*: (S1 ('MetaSel ('Just "clc_locktime") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Locktime) :*: S1 ('MetaSel ('Just "clc_funding_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script))))))

build_closing_tx :: ClosingContext -> ClosingTx Source #

Build a closing transaction (option_simple_close).

  • locktime: from closing_complete message
  • sequence: 0xFFFFFFFD
  • outputs: sorted per BIP69

build_legacy_closing_tx :: ClosingContext -> ClosingTx Source #

Build a legacy closing transaction (closing_signed).

  • locktime: 0
  • sequence: 0xFFFFFFFF
  • outputs: sorted per BIP69

Transaction outputs

data TxOutput Source #

A transaction output with value, script, and type information.

Instances

Instances details
Generic TxOutput Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Associated Types

type Rep TxOutput 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep TxOutput = D1 ('MetaData "TxOutput" "Lightning.Protocol.BOLT3.Tx" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "TxOutput" 'PrefixI 'True) (S1 ('MetaSel ('Just "txout_value") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Satoshi) :*: (S1 ('MetaSel ('Just "txout_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script) :*: S1 ('MetaSel ('Just "txout_type") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 OutputType))))

Methods

from :: TxOutput -> Rep TxOutput x #

to :: Rep TxOutput x -> TxOutput #

Show TxOutput Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Eq TxOutput Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep TxOutput Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep TxOutput = D1 ('MetaData "TxOutput" "Lightning.Protocol.BOLT3.Tx" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) (C1 ('MetaCons "TxOutput" 'PrefixI 'True) (S1 ('MetaSel ('Just "txout_value") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Satoshi) :*: (S1 ('MetaSel ('Just "txout_script") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Script) :*: S1 ('MetaSel ('Just "txout_type") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 OutputType))))

data OutputType Source #

Type of output in a commitment transaction.

Instances

Instances details
Generic OutputType Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Associated Types

type Rep OutputType 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep OutputType = D1 ('MetaData "OutputType" "Lightning.Protocol.BOLT3.Tx" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) ((C1 ('MetaCons "OutputToLocal" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "OutputToRemote" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "OutputLocalAnchor" 'PrefixI 'False) (U1 :: Type -> Type))) :+: (C1 ('MetaCons "OutputRemoteAnchor" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "OutputOfferedHTLC" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 CltvExpiry)) :+: C1 ('MetaCons "OutputReceivedHTLC" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 CltvExpiry)))))
Show OutputType Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

Eq OutputType Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep OutputType Source # 
Instance details

Defined in Lightning.Protocol.BOLT3.Tx

type Rep OutputType = D1 ('MetaData "OutputType" "Lightning.Protocol.BOLT3.Tx" "ppad-bolt3-0.0.1-BTVAwWY46FT4MsZtX0EtFp" 'False) ((C1 ('MetaCons "OutputToLocal" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "OutputToRemote" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "OutputLocalAnchor" 'PrefixI 'False) (U1 :: Type -> Type))) :+: (C1 ('MetaCons "OutputRemoteAnchor" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "OutputOfferedHTLC" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 CltvExpiry)) :+: C1 ('MetaCons "OutputReceivedHTLC" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 CltvExpiry)))))

Fee calculation

commitment_fee :: FeeratePerKw -> ChannelFeatures -> Word64 -> Satoshi Source #

Calculate the base commitment transaction fee.

fee = feerate_per_kw * weight / 1000

where weight = base_weight + 172 * num_htlcs

htlc_timeout_fee :: FeeratePerKw -> ChannelFeatures -> Satoshi Source #

Calculate HTLC-timeout transaction fee.

With option_anchors, fee is 0 (CPFP). Otherwise, fee = feerate_per_kw * 663 / 1000

htlc_success_fee :: FeeratePerKw -> ChannelFeatures -> Satoshi Source #

Calculate HTLC-success transaction fee.

With option_anchors, fee is 0 (CPFP). Otherwise, fee = feerate_per_kw * 703 / 1000

commitment_weight :: ChannelFeatures -> Word64 -> Word64 Source #

Calculate commitment transaction weight.

weight = base + 172 * num_htlcs

Trimming

is_trimmed :: DustLimit -> FeeratePerKw -> ChannelFeatures -> HTLC -> Bool Source #

Check if an HTLC should be trimmed.

An HTLC is trimmed if its amount minus the HTLC tx fee is below the dust limit.

trimmed_htlcs :: DustLimit -> FeeratePerKw -> ChannelFeatures -> [HTLC] -> [HTLC] Source #

Filter HTLCs that are trimmed.

untrimmed_htlcs :: DustLimit -> FeeratePerKw -> ChannelFeatures -> [HTLC] -> [HTLC] Source #

Filter HTLCs that are not trimmed.

htlc_trim_threshold :: DustLimit -> FeeratePerKw -> ChannelFeatures -> HTLCDirection -> Satoshi Source #

Calculate the trim threshold for an HTLC.

An HTLC is trimmed if: amount < dust_limit + htlc_tx_fee

Output ordering

sort_outputs :: [TxOutput] -> [TxOutput] Source #

Sort outputs per BOLT #3 ordering.

Outputs are sorted by: 1. Value (smallest first) 2. ScriptPubKey (lexicographic) 3. CLTV expiry (for HTLCs)