Documentation ¶
Index ¶
- Constants
- func GetCooperativeWitness(takerSig, makerSig, redeemScript []byte) [][]byte
- func GetCsvWitness(signature, redeemScript []byte) [][]byte
- func GetOpeningTxScript(takerPubkeyHash []byte, makerPubkeyHash []byte, pHash []byte, csv uint32) ([]byte, error)
- func GetPreimageWitness(signature, preimage, redeemScript []byte) [][]byte
- func ParamsToTxScript(p *swap.OpeningParams, locktimeHeight uint32) ([]byte, error)
- type BitcoinOnChain
- func (b *BitcoinOnChain) CreateOpeningAddress(params *swap.OpeningParams, csv uint32) (string, error)
- func (b *BitcoinOnChain) GetCSVHeight() uint32
- func (b *BitcoinOnChain) GetChain() *chaincfg.Params
- func (b *BitcoinOnChain) GetFee(txSize int64) (uint64, error)
- func (b *BitcoinOnChain) GetFeeSatsFromTx(psbtString, txHex string) (uint64, error)
- func (b *BitcoinOnChain) GetOutputScript(params *swap.OpeningParams) ([]byte, error)
- func (b *BitcoinOnChain) GetVoutAndVerify(txHex string, params *swap.OpeningParams) (bool, uint32, error)
- func (b *BitcoinOnChain) PrepareSpendingTransaction(swapParams *swap.OpeningParams, claimParams *swap.ClaimParams, ...) (tx *wire.MsgTx, sigHash, redeemScript []byte, err error)
- func (b *BitcoinOnChain) TxIdFromHex(txHex string) (string, error)
- func (b *BitcoinOnChain) ValidateTx(swapParams *swap.OpeningParams, openingTxHex string) (bool, error)
- type Estimator
- type GBitcoindBackend
- type GBitcoindEstimator
- type LiquidOnChain
- func (l *LiquidOnChain) AddBlindingRandomFactors(claimParams *swap.ClaimParams) (err error)
- func (l *LiquidOnChain) Blech32ToScript(blech32Addr string) ([]byte, error)
- func (l *LiquidOnChain) BroadcastOpeningTx(unpreparedTxHex string) (string, string, error)
- func (l *LiquidOnChain) CreateBlindedOpeningAddress(redeemScript []byte, blindingPubkey *btcec.PublicKey) (string, error)
- func (l *LiquidOnChain) CreateCoopSpendingTransaction(swapParams *swap.OpeningParams, claimParams *swap.ClaimParams, ...) (txId, txHex string, error error)
- func (l *LiquidOnChain) CreateCsvSpendingTransaction(swapParams *swap.OpeningParams, claimParams *swap.ClaimParams) (txId, txHex string, error error)
- func (l *LiquidOnChain) CreateOpeningAddress(redeemScript []byte) (string, error)
- func (l *LiquidOnChain) CreateOpeningTransaction(swapParams *swap.OpeningParams) (unpreparedTxHex string, fee uint64, vout uint32, err error)
- func (l *LiquidOnChain) CreatePreimageSpendingTransaction(swapParams *swap.OpeningParams, claimParams *swap.ClaimParams) (string, string, error)
- func (l *LiquidOnChain) FindVout(outputs []*transaction.TxOutput, redeemScript []byte) (uint32, error)
- func (l *LiquidOnChain) GetAsset() string
- func (l *LiquidOnChain) GetCSVHeight() uint32
- func (l *LiquidOnChain) GetFlatSwapOutFee() (uint64, error)
- func (l *LiquidOnChain) GetNetwork() string
- func (l *LiquidOnChain) GetOnchainBalance() (uint64, error)
- func (b *LiquidOnChain) GetOutputScript(params *swap.OpeningParams) ([]byte, error)
- func (l *LiquidOnChain) GetRefundFee() (uint64, error)
- func (l *LiquidOnChain) NewAddress() (string, error)
- func (l *LiquidOnChain) TxIdFromHex(txHex string) (string, error)
- func (l *LiquidOnChain) ValidateTx(openingParams *swap.OpeningParams, txHex string) (bool, error)
- func (l *LiquidOnChain) VoutFromTxHex(txHex string, redeemScript []byte) (uint32, error)
- type LndEstimator
- type RegtestFeeEstimator
Constants ¶
const ( // BitcoinCsv is the amount of blocks that is set to the script OP_CSV. It // is the time in blocks after which the swap opening on-chain transaction // can be reclaimed by the maker. With an average time to mine a block of // 10m this value converts to 7 days. BitcoinCsv = 1008 // BitcoinMinConfs is the amount of blocks after which it is assumed to be // reasonably safe to pay the claim invoice. BitcoinMinConfs = 3 // BitcoinFeeTargetBlocks is the amount of blocks that is used to estimate // the on-chain fee. BitcoinFeeTargetBlocks = 6 // BitcoinCsvSafetyLimit is the amount of blocks until which we assume it // to be safe to pay for the claim invoice. After this time we assume that // it is too close to the csv limit to pay the invoice. BitcoinCsvSafetyLimit = BitcoinCsv / 2 // EstimatedOpeningTxSize in vByte is the estimated size of a swap opening // transaction with a security margin. The estimate is meant to express the // fees for most, but not all swap out opening tx fees. This is calculated // as follows: The average amount of inputs is 3 with an expected type of // P2WPKH that has a size of 68 vByte. The outputs are a P2WSH and a P2WPKH // output with a total size of 84 vByte including the tx overhead. This // leads to an expected size for the opening tx of (3*68 + 84) = 288 vByte. // We add a security margin to this which leads to the size of 350 vByte. EstimatedOpeningTxSize = 350 )
const ( // FeePerKwFloor is the lowest fee rate in sat/kw that we should use for // estimating transaction fees before signing. FeePerKwFloor btcutil.Amount = 253 // DefaultBitcoinStaticFeePerKW is the default fee rate of 50 sat/vb // expressed in sat/kw DefaultBitcoinStaticFeePerKW = btcutil.Amount(12500) )
const ( LiquidCsv = 60 LiquidConfs = 2 LiquidTargetBlocks = 7 )
Variables ¶
This section is empty.
Functions ¶
func GetCooperativeWitness ¶
func GetCsvWitness ¶
GetCsvWitness returns the witness for spending the transaction with a passed csv
func GetOpeningTxScript ¶
func GetOpeningTxScript(takerPubkeyHash []byte, makerPubkeyHash []byte, pHash []byte, csv uint32) ([]byte, error)
GetOpeningTxScript returns the script for the opening transaction of a swap, where the taker is the peer paying the invoice and the maker the peer providing the lbtc
func GetPreimageWitness ¶
GetPreimageWitness returns the witness for spending the transaction with the preimage
func ParamsToTxScript ¶
func ParamsToTxScript(p *swap.OpeningParams, locktimeHeight uint32) ([]byte, error)
Types ¶
type BitcoinOnChain ¶
type BitcoinOnChain struct {
// contains filtered or unexported fields
}
func NewBitcoinOnChain ¶
func (*BitcoinOnChain) CreateOpeningAddress ¶
func (b *BitcoinOnChain) CreateOpeningAddress(params *swap.OpeningParams, csv uint32) (string, error)
func (*BitcoinOnChain) GetCSVHeight ¶
func (b *BitcoinOnChain) GetCSVHeight() uint32
func (*BitcoinOnChain) GetChain ¶
func (b *BitcoinOnChain) GetChain() *chaincfg.Params
func (*BitcoinOnChain) GetFee ¶
func (b *BitcoinOnChain) GetFee(txSize int64) (uint64, error)
GetFee returns the estimated fee in sat for a transaction of size txSize. It fetches the fee estimation from the Estimator in sat/kw and converts the returned fee estimation into sat/vb. The return value is in sat.
func (*BitcoinOnChain) GetFeeSatsFromTx ¶
func (b *BitcoinOnChain) GetFeeSatsFromTx(psbtString, txHex string) (uint64, error)
func (*BitcoinOnChain) GetOutputScript ¶
func (b *BitcoinOnChain) GetOutputScript(params *swap.OpeningParams) ([]byte, error)
func (*BitcoinOnChain) GetVoutAndVerify ¶
func (b *BitcoinOnChain) GetVoutAndVerify(txHex string, params *swap.OpeningParams) (bool, uint32, error)
func (*BitcoinOnChain) PrepareSpendingTransaction ¶
func (b *BitcoinOnChain) PrepareSpendingTransaction(swapParams *swap.OpeningParams, claimParams *swap.ClaimParams, spendingAddr string, vout uint32, csv uint32, preparedFee uint64) (tx *wire.MsgTx, sigHash, redeemScript []byte, err error)
func (*BitcoinOnChain) TxIdFromHex ¶
func (b *BitcoinOnChain) TxIdFromHex(txHex string) (string, error)
func (*BitcoinOnChain) ValidateTx ¶
func (b *BitcoinOnChain) ValidateTx(swapParams *swap.OpeningParams, openingTxHex string) (bool, error)
type Estimator ¶
type Estimator interface { // EstimateFeePerKw returns the estimated fee in sat/kw for a transaction // that should be confirmed in targetBlocks. EstimateFeePerKW(targetBlocks uint32) (btcutil.Amount, error) Start() error }
Estimator is used to estimate on-chain fees for transactions.
type GBitcoindBackend ¶
type GBitcoindBackend interface { GetMempoolInfo() (*gbitcoin.MempoolInfo, error) EstimateFee(blocks uint32, mode string) (*gbitcoin.FeeResponse, error) Ping() (bool, error) }
type GBitcoindEstimator ¶
type GBitcoindEstimator struct {
// contains filtered or unexported fields
}
GBitcoindEstimator uses the Bitcoin client from glightning to estimate the transaction fee.
func NewGBitcoindEstimator ¶
func NewGBitcoindEstimator(bitcoindRpc GBitcoindBackend, estimateMode string, fallBackFeeRate btcutil.Amount) (*GBitcoindEstimator, error)
NewGBitcoindEstimator creates a new BitcoindEstimator given a fully populated rpc config that is able to successfully connect and authenticate with the bitcoind node, and also a fall back fee rate. The fallback fee rate is used in the occasion that the estimator has insufficient data, or returns zero for a fee estimate.
func (*GBitcoindEstimator) EstimateFeePerKW ¶
func (g *GBitcoindEstimator) EstimateFeePerKW(targetBlocks uint32) (btcutil.Amount, error)
func (*GBitcoindEstimator) Start ¶
func (g *GBitcoindEstimator) Start() error
Start signals the Estimator to start any processes or goroutines it needs to perform its duty.
NOTE: This method is part of the Estimator interface.
type LiquidOnChain ¶
type LiquidOnChain struct {
// contains filtered or unexported fields
}
func NewLiquidOnChain ¶
func (*LiquidOnChain) AddBlindingRandomFactors ¶
func (l *LiquidOnChain) AddBlindingRandomFactors(claimParams *swap.ClaimParams) (err error)
func (*LiquidOnChain) Blech32ToScript ¶
func (l *LiquidOnChain) Blech32ToScript(blech32Addr string) ([]byte, error)
Blech32ToScript returns an elements script from a Blech32 Address
func (*LiquidOnChain) BroadcastOpeningTx ¶
func (l *LiquidOnChain) BroadcastOpeningTx(unpreparedTxHex string) (string, string, error)
func (*LiquidOnChain) CreateBlindedOpeningAddress ¶
func (l *LiquidOnChain) CreateBlindedOpeningAddress(redeemScript []byte, blindingPubkey *btcec.PublicKey) (string, error)
creatOpeningAddress returns the address for the opening tx
func (*LiquidOnChain) CreateCoopSpendingTransaction ¶
func (l *LiquidOnChain) CreateCoopSpendingTransaction(swapParams *swap.OpeningParams, claimParams *swap.ClaimParams, takerSigner swap.Signer) (txId, txHex string, error error)
func (*LiquidOnChain) CreateCsvSpendingTransaction ¶
func (l *LiquidOnChain) CreateCsvSpendingTransaction(swapParams *swap.OpeningParams, claimParams *swap.ClaimParams) (txId, txHex string, error error)
func (*LiquidOnChain) CreateOpeningAddress ¶
func (l *LiquidOnChain) CreateOpeningAddress(redeemScript []byte) (string, error)
creatOpeningAddress returns the address for the opening tx
func (*LiquidOnChain) CreateOpeningTransaction ¶
func (l *LiquidOnChain) CreateOpeningTransaction(swapParams *swap.OpeningParams) (unpreparedTxHex string, fee uint64, vout uint32, err error)
func (*LiquidOnChain) CreatePreimageSpendingTransaction ¶
func (l *LiquidOnChain) CreatePreimageSpendingTransaction(swapParams *swap.OpeningParams, claimParams *swap.ClaimParams) (string, string, error)
func (*LiquidOnChain) FindVout ¶
func (l *LiquidOnChain) FindVout(outputs []*transaction.TxOutput, redeemScript []byte) (uint32, error)
func (*LiquidOnChain) GetAsset ¶
func (l *LiquidOnChain) GetAsset() string
func (*LiquidOnChain) GetCSVHeight ¶
func (l *LiquidOnChain) GetCSVHeight() uint32
func (*LiquidOnChain) GetFlatSwapOutFee ¶
func (l *LiquidOnChain) GetFlatSwapOutFee() (uint64, error)
GetFlatSwapOutFee returns a fee that is the size of an opening transaction with 2 inputs and 3 ouputs (blinded p2wpkh, blinded p2wsh, feeoutput): 2587 bytes
func (*LiquidOnChain) GetNetwork ¶
func (l *LiquidOnChain) GetNetwork() string
func (*LiquidOnChain) GetOnchainBalance ¶
func (l *LiquidOnChain) GetOnchainBalance() (uint64, error)
func (*LiquidOnChain) GetOutputScript ¶
func (b *LiquidOnChain) GetOutputScript(params *swap.OpeningParams) ([]byte, error)
func (*LiquidOnChain) GetRefundFee ¶
func (l *LiquidOnChain) GetRefundFee() (uint64, error)
func (*LiquidOnChain) NewAddress ¶
func (l *LiquidOnChain) NewAddress() (string, error)
func (*LiquidOnChain) TxIdFromHex ¶
func (l *LiquidOnChain) TxIdFromHex(txHex string) (string, error)
func (*LiquidOnChain) ValidateTx ¶
func (l *LiquidOnChain) ValidateTx(openingParams *swap.OpeningParams, txHex string) (bool, error)
func (*LiquidOnChain) VoutFromTxHex ¶
func (l *LiquidOnChain) VoutFromTxHex(txHex string, redeemScript []byte) (uint32, error)
type LndEstimator ¶
type LndEstimator struct {
// contains filtered or unexported fields
}
LndEstimator uses the WalletKitClient to estimate the fee.
func NewLndEstimator ¶
func NewLndEstimator( walletkit walletrpc.WalletKitClient, fallbackFeeRate btcutil.Amount, timeout time.Duration, ) (*LndEstimator, error)
func (*LndEstimator) EstimateFeePerKW ¶
func (l *LndEstimator) EstimateFeePerKW(targetBlocks uint32) (btcutil.Amount, error)
EstimateFeePerKw returns the estimated fee in sat/kw for a transaction that should be confirmed in targetBlocks. It uses lnds internal fee estimation.
func (*LndEstimator) Start ¶
func (l *LndEstimator) Start() error
Start is necessary to implement the Estimator interface but is noop for the LndEstimator.
type RegtestFeeEstimator ¶
type RegtestFeeEstimator struct{}
RegtestFeeEstimator is used as the Estimator when the bitcoin network is set to "regtest". We need this fee estimator for cln as lnd uses a static fee estimator on regtest that uses a constant fee rate of 12500 sat/kw. See "DefaultBitcoinStaticFeePerKW" on chainregistry: https://github.com/lightningnetwork/lnd/blob/5c36d96c9cbe8b27c29f9682dcbdab7928ae870f/chainreg/chainregistry.go
func NewRegtestFeeEstimator ¶
func NewRegtestFeeEstimator() (*RegtestFeeEstimator, error)
func (*RegtestFeeEstimator) EstimateFeePerKW ¶
func (r *RegtestFeeEstimator) EstimateFeePerKW(targetBlocks uint32) (btcutil.Amount, error)
EstimateFeePerKw returns the estimated fee in sat/kw for a transaction that should be confirmed in targetBlocks. RegtestFeeEstimator uses the DefaultBitcoindStaticFeePerKw.
func (*RegtestFeeEstimator) Start ¶
func (r *RegtestFeeEstimator) Start() error
Start returns nil as we only need it to implement Estimator interface.