Transactions

object Transactions

Created by PM on 15/12/2016.

Types

CommitmentOutputLink
Link copied to clipboard
common
data class CommitmentOutputLink<T : CommitmentOutput>(output: TxOut, redeemScript: List<ScriptElt>, commitmentOutput: T) : Comparable<Transactions.CommitmentOutputLink<T>>

Represent a link between a commitment spec item (to-local, to-remote, htlc) and the actual output in the commit tx

InputInfo
Link copied to clipboard
common
data class InputInfo(outPoint: OutPoint, txOut: TxOut, redeemScript: ByteVector)
TransactionWithInputInfo
Link copied to clipboard
common
sealed class TransactionWithInputInfo
TxGenerationSkipped
Link copied to clipboard
common
sealed class TxGenerationSkipped
TxResult
Link copied to clipboard
common
sealed class TxResult<T>

Functions

addSigs
Link copied to clipboard
common
fun addSigs(mainPenaltyTx: Transactions.TransactionWithInputInfo.MainPenaltyTx, revocationSig: ByteVector64): Transactions.TransactionWithInputInfo.MainPenaltyTx
fun addSigs(claimHtlcSuccessTx: Transactions.TransactionWithInputInfo.ClaimHtlcTx.ClaimHtlcSuccessTx, localSig: ByteVector64, paymentPreimage: ByteVector32): Transactions.TransactionWithInputInfo.ClaimHtlcTx.ClaimHtlcSuccessTx
fun addSigs(htlcPenaltyTx: Transactions.TransactionWithInputInfo.HtlcPenaltyTx, revocationSig: ByteVector64, revocationPubkey: PublicKey): Transactions.TransactionWithInputInfo.HtlcPenaltyTx
fun addSigs(htlcTimeoutTx: Transactions.TransactionWithInputInfo.HtlcTx.HtlcTimeoutTx, localSig: ByteVector64, remoteSig: ByteVector64): Transactions.TransactionWithInputInfo.HtlcTx.HtlcTimeoutTx
fun addSigs(htlcSuccessTx: Transactions.TransactionWithInputInfo.HtlcTx.HtlcSuccessTx, localSig: ByteVector64, remoteSig: ByteVector64, paymentPreimage: ByteVector32): Transactions.TransactionWithInputInfo.HtlcTx.HtlcSuccessTx
fun addSigs(closingTx: Transactions.TransactionWithInputInfo.ClosingTx, localFundingPubkey: PublicKey, remoteFundingPubkey: PublicKey, localSig: ByteVector64, remoteSig: ByteVector64): Transactions.TransactionWithInputInfo.ClosingTx
fun addSigs(commitTx: Transactions.TransactionWithInputInfo.CommitTx, localFundingPubkey: PublicKey, remoteFundingPubkey: PublicKey, localSig: ByteVector64, remoteSig: ByteVector64): Transactions.TransactionWithInputInfo.CommitTx
checkSig
Link copied to clipboard
common
fun checkSig(txinfo: Transactions.TransactionWithInputInfo, sig: ByteVector64, pubKey: PublicKey, sigHash: Int = SigHash.SIGHASH_ALL): Boolean
checkSpendable
Link copied to clipboard
common
fun checkSpendable(txinfo: Transactions.TransactionWithInputInfo): Try<Unit>
commitTxFee
Link copied to clipboard
common
fun commitTxFee(dustLimit: Satoshi, spec: CommitmentSpec): Satoshi
commitTxFeeMsat
Link copied to clipboard
common
fun commitTxFeeMsat(dustLimit: Satoshi, spec: CommitmentSpec): MilliSatoshi

While fees are generally computed in Satoshis (since this is the smallest on-chain unit), it may be useful in some cases to calculate it in MilliSatoshi to avoid rounding issues. If you are adding multiple fees together for example, you should always add them in MilliSatoshi and then round down to Satoshi.

decodeTxNumber
Link copied to clipboard
common
fun decodeTxNumber(sequence: Long, locktime: Long): Long
encodeTxNumber
Link copied to clipboard
common
fun encodeTxNumber(txnumber: Long): Pair<Long, Long>

This is a trick to split and encode a 48-bit txnumber into the sequence and locktime fields of a tx

fee2rate
Link copied to clipboard
common
fun fee2rate(fee: Satoshi, weight: Int): FeeratePerKw
getCommitTxNumber
Link copied to clipboard
common
fun getCommitTxNumber(commitTx: Transaction, isFunder: Boolean, localPaymentBasePoint: PublicKey, remotePaymentBasePoint: PublicKey): Long
htlcOutputFee
Link copied to clipboard
common
fun htlcOutputFee(feerate: FeeratePerKw): MilliSatoshi

Fee for an un-trimmed HTLC.

makeClaimDelayedOutputPenaltyTxs
Link copied to clipboard
common
fun makeClaimDelayedOutputPenaltyTxs(delayedOutputTx: Transaction, localDustLimit: Satoshi, localRevocationPubkey: PublicKey, toLocalDelay: CltvExpiryDelta, localDelayedPaymentPubkey: PublicKey, localFinalScriptPubKey: ByteArray, feerate: FeeratePerKw): List<Transactions.TxResult<Transactions.TransactionWithInputInfo.ClaimHtlcDelayedOutputPenaltyTx>>
makeClaimHtlcSuccessTx
Link copied to clipboard
common
fun makeClaimHtlcSuccessTx(commitTx: Transaction, outputs: TransactionsCommitmentOutputs, localDustLimit: Satoshi, localHtlcPubkey: PublicKey, remoteHtlcPubkey: PublicKey, remoteRevocationPubkey: PublicKey, localFinalScriptPubKey: ByteArray, htlc: UpdateAddHtlc, feerate: FeeratePerKw): Transactions.TxResult<Transactions.TransactionWithInputInfo.ClaimHtlcTx.ClaimHtlcSuccessTx>
makeClaimHtlcTimeoutTx
Link copied to clipboard
common
fun makeClaimHtlcTimeoutTx(commitTx: Transaction, outputs: TransactionsCommitmentOutputs, localDustLimit: Satoshi, localHtlcPubkey: PublicKey, remoteHtlcPubkey: PublicKey, remoteRevocationPubkey: PublicKey, localFinalScriptPubKey: ByteArray, htlc: UpdateAddHtlc, feerate: FeeratePerKw): Transactions.TxResult<Transactions.TransactionWithInputInfo.ClaimHtlcTx.ClaimHtlcTimeoutTx>
makeClaimLocalDelayedOutputTx
Link copied to clipboard
common
fun makeClaimLocalDelayedOutputTx(delayedOutputTx: Transaction, localDustLimit: Satoshi, localRevocationPubkey: PublicKey, toLocalDelay: CltvExpiryDelta, localDelayedPaymentPubkey: PublicKey, localFinalScriptPubKey: ByteArray, feerate: FeeratePerKw): Transactions.TxResult<Transactions.TransactionWithInputInfo.ClaimLocalDelayedOutputTx>
makeClaimP2WPKHOutputTx
Link copied to clipboard
common
fun makeClaimP2WPKHOutputTx(delayedOutputTx: Transaction, localDustLimit: Satoshi, localPaymentPubkey: PublicKey, localFinalScriptPubKey: ByteArray, feerate: FeeratePerKw): Transactions.TxResult<Transactions.TransactionWithInputInfo.ClaimRemoteCommitMainOutputTx.ClaimP2WPKHOutputTx>
makeClaimRemoteDelayedOutputTx
Link copied to clipboard
common
fun makeClaimRemoteDelayedOutputTx(commitTx: Transaction, localDustLimit: Satoshi, localPaymentPubkey: PublicKey, localFinalScriptPubKey: ByteVector, feerate: FeeratePerKw): Transactions.TxResult<Transactions.TransactionWithInputInfo.ClaimRemoteCommitMainOutputTx.ClaimRemoteDelayedOutputTx>
makeClosingTx
Link copied to clipboard
common
fun makeClosingTx(commitTxInput: Transactions.InputInfo, localScriptPubKey: ByteArray, remoteScriptPubKey: ByteArray, localIsFunder: Boolean, dustLimit: Satoshi, closingFee: Satoshi, spec: CommitmentSpec): Transactions.TransactionWithInputInfo.ClosingTx
makeCommitTx
Link copied to clipboard
common
fun makeCommitTx(commitTxInput: Transactions.InputInfo, commitTxNumber: Long, localPaymentBasePoint: PublicKey, remotePaymentBasePoint: PublicKey, localIsFunder: Boolean, outputs: TransactionsCommitmentOutputs): Transactions.TransactionWithInputInfo.CommitTx
makeCommitTxOutputs
Link copied to clipboard
common
fun makeCommitTxOutputs(localFundingPubkey: PublicKey, remoteFundingPubkey: PublicKey, localIsFunder: Boolean, localDustLimit: Satoshi, localRevocationPubkey: PublicKey, toLocalDelay: CltvExpiryDelta, localDelayedPaymentPubkey: PublicKey, remotePaymentPubkey: PublicKey, localHtlcPubkey: PublicKey, remoteHtlcPubkey: PublicKey, spec: CommitmentSpec): TransactionsCommitmentOutputs
makeHtlcPenaltyTx
Link copied to clipboard
common
fun makeHtlcPenaltyTx(commitTx: Transaction, htlcOutputIndex: Int, redeemScript: ByteArray, localDustLimit: Satoshi, localFinalScriptPubKey: ByteArray, feerate: FeeratePerKw): Transactions.TxResult<Transactions.TransactionWithInputInfo.HtlcPenaltyTx>

We already have the redeemScript, no need to build it

makeHtlcTxs
Link copied to clipboard
common
fun makeHtlcTxs(commitTx: Transaction, localDustLimit: Satoshi, localRevocationPubkey: PublicKey, toLocalDelay: CltvExpiryDelta, localDelayedPaymentPubkey: PublicKey, feerate: FeeratePerKw, outputs: TransactionsCommitmentOutputs): List<Transactions.TransactionWithInputInfo.HtlcTx>
makeMainPenaltyTx
Link copied to clipboard
common
fun makeMainPenaltyTx(commitTx: Transaction, localDustLimit: Satoshi, remoteRevocationPubkey: PublicKey, localFinalScriptPubKey: ByteArray, toRemoteDelay: CltvExpiryDelta, remoteDelayedPaymentPubkey: PublicKey, feerate: FeeratePerKw): Transactions.TxResult<Transactions.TransactionWithInputInfo.MainPenaltyTx>
obscuredCommitTxNumber
Link copied to clipboard
common
fun obscuredCommitTxNumber(commitTxNumber: Long, isFunder: Boolean, localPaymentBasePoint: PublicKey, remotePaymentBasePoint: PublicKey): Long
offeredHtlcTrimThreshold
Link copied to clipboard
common
fun offeredHtlcTrimThreshold(dustLimit: Satoshi, spec: CommitmentSpec): Satoshi

Offered HTLCs below this amount will be trimmed.

receivedHtlcTrimThreshold
Link copied to clipboard
common
fun receivedHtlcTrimThreshold(dustLimit: Satoshi, spec: CommitmentSpec): Satoshi

Received HTLCs below this amount will be trimmed.

sign
Link copied to clipboard
common
fun sign(txinfo: Transactions.TransactionWithInputInfo, key: PrivateKey, sigHash: Int = SigHash.SIGHASH_ALL): ByteVector64
fun sign(tx: Transaction, inputIndex: Int, redeemScript: ByteArray, amount: Satoshi, key: PrivateKey, sigHash: Int = SigHash.SIGHASH_ALL): ByteVector64
trimOfferedHtlcs
Link copied to clipboard
common
fun trimOfferedHtlcs(dustLimit: Satoshi, spec: CommitmentSpec): List<OutgoingHtlc>
trimReceivedHtlcs
Link copied to clipboard
common
fun trimReceivedHtlcs(dustLimit: Satoshi, spec: CommitmentSpec): List<IncomingHtlc>
weight2fee
Link copied to clipboard
common
fun weight2fee(feerate: FeeratePerKw, weight: Int): Satoshi

Properties

claimAnchorOutputWeight
Link copied to clipboard
common
val claimAnchorOutputWeight: Int = 321
claimHtlcDelayedWeight
Link copied to clipboard
common
val claimHtlcDelayedWeight: Int = 483
claimHtlcSuccessWeight
Link copied to clipboard
common
val claimHtlcSuccessWeight: Int = 574
claimHtlcTimeoutWeight
Link copied to clipboard
common
val claimHtlcTimeoutWeight: Int = 548
claimP2WPKHOutputWeight
Link copied to clipboard
common
val claimP2WPKHOutputWeight: Int = 438

these values are specific to us and used to estimate fees

htlcPenaltyWeight
Link copied to clipboard
common
val htlcPenaltyWeight: Int = 581
mainPenaltyWeight
Link copied to clipboard
common
val mainPenaltyWeight: Int = 484
PlaceHolderPubKey
Link copied to clipboard
common
val PlaceHolderPubKey: PublicKey

Default public key used for fee estimation

PlaceHolderSig
Link copied to clipboard
common
val PlaceHolderSig: ByteVector64

This default sig takes 72B when encoded in DER (incl. 1B for the trailing sig hash), it is used for fee estimation It is 72 bytes because our signatures are normalized (low-s) and will take up 72 bytes at most in DER format