swap

package
v0.1.2-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 3, 2019 License: MIT Imports: 11 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// FeeRateTotalParts defines the granularity of the fee rate.
	// Throughout the codebase, we'll use fix based arithmetic to compute
	// fees.
	FeeRateTotalParts = 1e6
)

Variables

View Source
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)
)
View Source
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(
		^int32(0), quoteKey, quoteKey, quoteHash, HtlcP2WSH,
		&chaincfg.MainNetParams,
	)
)

Functions

func CalcFee

func CalcFee(amount, feeBase btcutil.Amount, feeRate int64) btcutil.Amount

CalcFee returns the swap fee for a given swap amount.

func ChainParamsFromNetwork

func ChainParamsFromNetwork(network string) (*chaincfg.Params, error)

ChainParamsFromNetwork returns chain parameters based on a network name.

func DecodeTx

func DecodeTx(rawTx []byte) (*wire.MsgTx, error)

DecodeTx decodes raw tx bytes.

func EncodeTx

func EncodeTx(tx *wire.MsgTx) ([]byte, error)

EncodeTx encodes a tx to raw bytes.

func FeeRateAsPercentage

func FeeRateAsPercentage(feeRate int64) float64

FeeRateAsPercentage converts a feerate to a percentage.

func GetInvoiceAmt

func GetInvoiceAmt(params *chaincfg.Params,
	payReq string) (btcutil.Amount, error)

GetInvoiceAmt gets the invoice amount. It requires an amount to be specified.

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

func GetTxInputByOutpoint(tx *wire.MsgTx, input *wire.OutPoint) (
	*wire.TxIn, error)

GetTxInputByOutpoint returns a tx input based on a given input outpoint.

Types

type Htlc

type Htlc struct {
	Script      []byte
	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(cltvExpiry int32, senderKey, receiverKey [33]byte,
	hash lntypes.Hash, outputType HtlcOutputType,
	chainParams *chaincfg.Params) (*Htlc, error)

NewHtlc returns a new instance.

func (*Htlc) AddSuccessToEstimator

func (h *Htlc) AddSuccessToEstimator(estimator *input.TxWeightEstimator)

AddSuccessToEstimator adds a successful spend to a weight estimator.

func (*Htlc) AddTimeoutToEstimator

func (h *Htlc) AddTimeoutToEstimator(estimator *input.TxWeightEstimator)

AddTimeoutToEstimator adds a timeout spend to a weight estimator.

func (*Htlc) GenSuccessWitness

func (h *Htlc) GenSuccessWitness(receiverSig []byte,
	preimage lntypes.Preimage) (wire.TxWitness, error)

GenSuccessWitness returns the success script to spend this htlc with the preimage.

func (*Htlc) GenTimeoutWitness

func (h *Htlc) GenTimeoutWitness(senderSig []byte) (wire.TxWitness, error)

GenTimeoutWitness returns the timeout script to spend this htlc after timeout.

func (*Htlc) IsSuccessWitness

func (h *Htlc) IsSuccessWitness(witness wire.TxWitness) bool

IsSuccessWitness checks whether the given stack is valid for redeeming the htlc.

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
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL