Documentation
¶
Index ¶
- Constants
- Variables
- func CalcFee(amount, feeBase btcutil.Amount, feeRate int64) btcutil.Amount
- func DecodeInvoice(params *chaincfg.Params, payReq string) (route.Vertex, [][]zpay32.HopHint, lntypes.Hash, btcutil.Amount, error)
- func FeeRateAsPercentage(feeRate int64) float64
- func GenSuccessPathScript(receiverHtlcKey [32]byte, swapHash lntypes.Hash) ([]byte, error)
- func GenTimeoutPathScript(senderHtlcKey [32]byte, cltvExpiry int64) ([]byte, error)
- func GetScriptOutput(htlcTx *wire.MsgTx, scriptHash []byte) (*wire.OutPoint, btcutil.Amount, error)
- func GetTxInputByOutpoint(tx *wire.MsgTx, input *wire.OutPoint) (*wire.TxIn, error)
- func ShortHash(hash *lntypes.Hash) string
- type Htlc
- type HtlcOutputType
- type HtlcScript
- type HtlcScriptV1
- func (h *HtlcScriptV1) GenTimeoutWitness(senderSig []byte) (wire.TxWitness, error)
- func (h *HtlcScriptV1) IsSuccessWitness(witness wire.TxWitness) bool
- func (h *HtlcScriptV1) MaxSuccessWitnessSize() int
- func (h *HtlcScriptV1) MaxTimeoutWitnessSize() int
- func (h *HtlcScriptV1) Script() []byte
- func (h *HtlcScriptV1) SuccessSequence() uint32
- type HtlcScriptV2
- func (h *HtlcScriptV2) GenTimeoutWitness(senderSig []byte) (wire.TxWitness, error)
- func (h *HtlcScriptV2) IsSuccessWitness(witness wire.TxWitness) bool
- func (h *HtlcScriptV2) MaxSuccessWitnessSize() int
- func (h *HtlcScriptV2) MaxTimeoutWitnessSize() int
- func (h *HtlcScriptV2) Script() []byte
- func (h *HtlcScriptV2) SuccessSequence() uint32
- type HtlcScriptV3
- func (h *HtlcScriptV3) GenTimeoutWitness(senderSig []byte) (wire.TxWitness, error)
- func (h *HtlcScriptV3) IsSuccessWitness(witness wire.TxWitness) bool
- func (h *HtlcScriptV3) MaxSuccessWitnessSize() int
- func (h *HtlcScriptV3) MaxTimeoutWitnessSize() int
- func (h *HtlcScriptV3) Script() []byte
- func (h *HtlcScriptV3) SuccessSequence() uint32
- type PrefixLog
- type ScriptVersion
- type Type
Constants ¶
const ( // FeeRateTotalParts defines the granularity of the fee rate. // Throughout the codebase, we'll use fix based arithmetic to compute // fees. FeeRateTotalParts = 1e6 )
Variables ¶
var (
// QuoteHtlc is a template script just used for fee estimation. It uses
// the maximum value for cltv expiry to get the maximum (worst case)
// script size.
QuoteHtlc, _ = NewHtlc(
HtlcV2,
^int32(0), quoteKey, quoteKey, nil, quoteHash, HtlcP2WSH,
&chaincfg.MainNetParams,
)
// ErrInvalidScriptVersion is returned when an unknown htlc version
// is provided to NewHtlc. The supported version are HtlcV1, HtlcV2,
// HtlcV3 as enums.
ErrInvalidScriptVersion = fmt.Errorf("invalid script version")
// ErrInvalidOutputSelected is returned when a taproot output is
// selected for a v1 or v2 script.
ErrInvalidOutputSelected = fmt.Errorf("taproot output selected for " +
"non taproot htlc")
// either the v1 or v2 script. Shared key is only necessary for the v3
// script.
ErrSharedKeyNotNeeded = fmt.Errorf("shared key not supported for " +
"script version")
// shared key.
ErrSharedKeyRequired = fmt.Errorf("shared key required for script " +
"version")
)
var ( // KeyFamily is the key family used to generate keys that allow // spending of the htlc. // // TODO(joost): decide on actual value KeyFamily = int32(99) )
Functions ¶
func DecodeInvoice ¶
func DecodeInvoice(params *chaincfg.Params, payReq string) (route.Vertex, [][]zpay32.HopHint, lntypes.Hash, btcutil.Amount, error)
DecodeInvoice gets the destination, hash and the amount of an invoice. It requires an amount to be specified.
func FeeRateAsPercentage ¶
FeeRateAsPercentage converts a feerate to a percentage.
func GenSuccessPathScript ¶
GenSuccessPathScript constructs an HtlcScript for the success payment path. Largest possible bytesize of the script is 32 + 5*1 + 20 + 3*1 = 60.
<receiverHtlcKey> OP_CHECKSIGVERIFY OP_SIZE 32 OP_EQUALVERIFY OP_HASH160 <ripemd160h(swapHash)> OP_EQUALVERIFY 1 OP_CHECKSEQUENCEVERIFY
func GenTimeoutPathScript ¶
GenTimeoutPathScript constructs an HtlcScript for the timeout payment path. Largest possible bytesize of the script is 32 + 1 + 2 + 1 = 36.
<senderHtlcKey> OP_CHECKSIGVERIFY <cltvExpiry> OP_CHECKLOCKTIMEVERIFY
func GetScriptOutput ¶
func GetScriptOutput(htlcTx *wire.MsgTx, scriptHash []byte) ( *wire.OutPoint, btcutil.Amount, error)
GetScriptOutput locates the given script in the outputs of a transaction and returns its outpoint and value.
func GetTxInputByOutpoint ¶
GetTxInputByOutpoint returns a tx input based on a given input outpoint.
Types ¶
type Htlc ¶
type Htlc struct { HtlcScript Version ScriptVersion PkScript []byte Hash lntypes.Hash OutputType HtlcOutputType ChainParams *chaincfg.Params Address btcutil.Address SigScript []byte }
Htlc contains relevant htlc information from the receiver perspective.
func NewHtlc ¶
func NewHtlc(version ScriptVersion, cltvExpiry int32, senderKey, receiverKey [33]byte, sharedKey *btcec.PublicKey, hash lntypes.Hash, outputType HtlcOutputType, chainParams *chaincfg.Params) (*Htlc, error)
NewHtlc returns a new instance. For v3 scripts, an internal pubkey generated by both participants must be provided.
func (*Htlc) AddSuccessToEstimator ¶
func (h *Htlc) AddSuccessToEstimator(estimator *input.TxWeightEstimator) error
AddSuccessToEstimator adds a successful spend to a weight estimator.
func (*Htlc) AddTimeoutToEstimator ¶
func (h *Htlc) AddTimeoutToEstimator(estimator *input.TxWeightEstimator) error
AddTimeoutToEstimator adds a timeout spend to a weight estimator.
type HtlcOutputType ¶
type HtlcOutputType uint8
HtlcOutputType defines the output type of the htlc that is published.
const ( // HtlcP2WSH is a pay-to-witness-script-hash output (segwit only) HtlcP2WSH HtlcOutputType = iota // HtlcNP2WSH is a nested pay-to-witness-script-hash output that can be // paid to be legacy wallets. HtlcNP2WSH // HtlcP2TR is a pay-to-taproot output with three separate spend paths. HtlcP2TR )
func (HtlcOutputType) String ¶
func (h HtlcOutputType) String() string
String returns the string value of HtlcOutputType.
type HtlcScript ¶
type HtlcScript interface { // GenTimeoutWitness returns the timeout script to spend this htlc after // timeout. GenTimeoutWitness(senderSig []byte) (wire.TxWitness, error) // IsSuccessWitness checks whether the given stack is valid for // redeeming the htlc. IsSuccessWitness(witness wire.TxWitness) bool // Script returns the htlc script. Script() []byte // MaxSuccessWitnessSize returns the maximum witness size for the // success case witness. MaxSuccessWitnessSize() int // MaxTimeoutWitnessSize returns the maximum witness size for the // timeout case witness. MaxTimeoutWitnessSize() int // SuccessSequence returns the sequence to spend this htlc in the // success case. SuccessSequence() uint32 // contains filtered or unexported methods }
htlcScript defines an interface for the different HTLC implementations.
type HtlcScriptV1 ¶
type HtlcScriptV1 struct {
// contains filtered or unexported fields
}
HtlcScriptV1 encapsulates the htlc v1 script.
func (*HtlcScriptV1) GenTimeoutWitness ¶
func (h *HtlcScriptV1) GenTimeoutWitness( senderSig []byte) (wire.TxWitness, error)
GenTimeoutWitness returns the timeout script to spend this htlc after timeout.
func (*HtlcScriptV1) IsSuccessWitness ¶
func (h *HtlcScriptV1) IsSuccessWitness(witness wire.TxWitness) bool
IsSuccessWitness checks whether the given stack is valid for redeeming the htlc.
func (*HtlcScriptV1) MaxSuccessWitnessSize ¶
func (h *HtlcScriptV1) MaxSuccessWitnessSize() int
MaxSuccessWitnessSize returns the maximum success witness size.
func (*HtlcScriptV1) MaxTimeoutWitnessSize ¶
func (h *HtlcScriptV1) MaxTimeoutWitnessSize() int
MaxTimeoutWitnessSize return the maximum timeout witness size.
func (*HtlcScriptV1) Script ¶
func (h *HtlcScriptV1) Script() []byte
Script returns the htlc script.
func (*HtlcScriptV1) SuccessSequence ¶
func (h *HtlcScriptV1) SuccessSequence() uint32
SuccessSequence returns the sequence to spend this htlc in the success case.
type HtlcScriptV2 ¶
type HtlcScriptV2 struct {
// contains filtered or unexported fields
}
HtlcScriptV2 encapsulates the htlc v2 script.
func (*HtlcScriptV2) GenTimeoutWitness ¶
func (h *HtlcScriptV2) GenTimeoutWitness( senderSig []byte) (wire.TxWitness, error)
GenTimeoutWitness returns the timeout script to spend this htlc after timeout.
func (*HtlcScriptV2) IsSuccessWitness ¶
func (h *HtlcScriptV2) IsSuccessWitness(witness wire.TxWitness) bool
IsSuccessWitness checks whether the given stack is valid for redeeming the htlc.
func (*HtlcScriptV2) MaxSuccessWitnessSize ¶
func (h *HtlcScriptV2) MaxSuccessWitnessSize() int
MaxSuccessWitnessSize returns maximum success witness size.
func (*HtlcScriptV2) MaxTimeoutWitnessSize ¶
func (h *HtlcScriptV2) MaxTimeoutWitnessSize() int
MaxTimeoutWitnessSize returns maximum timeout witness size.
func (*HtlcScriptV2) Script ¶
func (h *HtlcScriptV2) Script() []byte
Script returns the htlc script.
func (*HtlcScriptV2) SuccessSequence ¶
func (h *HtlcScriptV2) SuccessSequence() uint32
SuccessSequence returns the sequence to spend this htlc in the success case.
type HtlcScriptV3 ¶
type HtlcScriptV3 struct { // The final locking script for the timeout path which is available to // the sender after the set blockheight. TimeoutScript []byte // The final locking script for the success path in which the receiver // reveals the preimage. SuccessScript []byte // The public key for the keyspend path which bypasses the above two // locking scripts. InternalPubKey *btcec.PublicKey // The taproot public key which is created with the above 3 inputs. TaprootKey *btcec.PublicKey }
HtlcScriptV3 encapsulates the htlc v3 script.
func (*HtlcScriptV3) GenTimeoutWitness ¶
func (h *HtlcScriptV3) GenTimeoutWitness( senderSig []byte) (wire.TxWitness, error)
GenTimeoutWitness returns the timeout script to spend this htlc after timeout.
func (*HtlcScriptV3) IsSuccessWitness ¶
func (h *HtlcScriptV3) IsSuccessWitness(witness wire.TxWitness) bool
IsSuccessWitness checks whether the given stack is valid for redeeming the htlc.
func (*HtlcScriptV3) MaxSuccessWitnessSize ¶
func (h *HtlcScriptV3) MaxSuccessWitnessSize() int
MaxSuccessWitnessSize returns the maximum witness size for the success case witness.
func (*HtlcScriptV3) MaxTimeoutWitnessSize ¶
func (h *HtlcScriptV3) MaxTimeoutWitnessSize() int
MaxTimeoutWitnessSize returns the maximum witness size for the timeout case witness.
func (*HtlcScriptV3) Script ¶
func (h *HtlcScriptV3) Script() []byte
Script is not implemented, but necessary to conform to interface.
func (*HtlcScriptV3) SuccessSequence ¶
func (h *HtlcScriptV3) SuccessSequence() uint32
SuccessSequence returns the sequence to spend this htlc in the success case.
type PrefixLog ¶
type PrefixLog struct { // Logger is the underlying based logger. Logger btclog.Logger // Hash is the hash the identifies the target swap. Hash lntypes.Hash }
PrefixLog logs with a short swap hash prefix.
func (*PrefixLog) Errorf ¶
Errorf formats message according to format specifier and writes to to log with LevelError.
type ScriptVersion ¶
type ScriptVersion uint8
ScriptVersion defines the HTLC script version.
const ( // HtlcV1 refers to the original version of the HTLC script. HtlcV1 ScriptVersion = iota // HtlcV2 refers to the improved version of the HTLC script. HtlcV2 // HtlcV3 refers to an upgraded version of HtlcV2 implemented with // tapscript. HtlcV3 )