bitcoin

package
v0.0.0-...-2da98db Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OutboundBytesMin = uint64(239)  // 239vB == EstimateSegWitTxSize(2, 2, toP2WPKH)
	OutboundBytesMax = uint64(1543) // 1543v == EstimateSegWitTxSize(21, 2, toP2TR)
	OutboundBytesAvg = uint64(245)  // 245vB is a suggested gas limit for zetacore

	DynamicDepositorFeeHeight = 834500 // DynamicDepositorFeeHeight contains the starting height (Bitcoin mainnet) from which dynamic depositor fee will take effect
)
View Source
const (
	// LengthScriptP2TR is the lenth of P2TR script [OP_1 0x20 <32-byte-hash>]
	LengthScriptP2TR = 34

	// LengthScriptP2WSH is the length of P2WSH script [OP_0 0x20 <32-byte-hash>]
	LengthScriptP2WSH = 34

	// LengthScriptP2WPKH is the length of P2WPKH script [OP_0 0x14 <20-byte-hash>]
	LengthScriptP2WPKH = 22

	// LengthScriptP2SH is the length of P2SH script [OP_HASH160 0x14 <20-byte-hash> OP_EQUAL]
	LengthScriptP2SH = 23

	// LengthScriptP2PKH is the length of P2PKH script [OP_DUP OP_HASH160 0x14 <20-byte-hash> OP_EQUALVERIFY OP_CHECKSIG]
	LengthScriptP2PKH = 25
)

Variables

View Source
var (
	// BtcOutboundBytesDepositor is the outbound size incurred by the depositor: 68vB
	BtcOutboundBytesDepositor = OutboundSizeDepositor()

	// BtcOutboundBytesWithdrawer is the outbound size incurred by the withdrawer: 177vB
	BtcOutboundBytesWithdrawer = OutboundSizeWithdrawer()

	// DefaultDepositorFee is the default depositor fee is 0.00001360 BTC (20 * 68vB / 100000000)
	// default depositor fee calculation is based on a fixed fee rate of 20 sat/byte just for simplicity.
	DefaultDepositorFee = DepositorFee(defaultDepositorFeeRate)
)

Functions

func CalcBlockAvgFeeRate

func CalcBlockAvgFeeRate(blockVb *btcjson.GetBlockVerboseTxResult, netParams *chaincfg.Params) (int64, error)

CalcBlockAvgFeeRate calculates the average gas rate (in sat/vByte) for a given block

func CalcDepositorFee

func CalcDepositorFee(
	blockVb *btcjson.GetBlockVerboseTxResult,
	chainID int64,
	netParams *chaincfg.Params,
	logger zerolog.Logger,
) float64

CalcDepositorFee calculates the depositor fee for a given block

func DecodeOpReturnMemo

func DecodeOpReturnMemo(scriptHex string, txid string) ([]byte, bool, error)

DecodeOpReturnMemo decodes memo from OP_RETURN script returns (memo, found, error)

func DecodeScriptP2PKH

func DecodeScriptP2PKH(scriptHex string, net *chaincfg.Params) (string, error)

DecodeScriptP2PKH decodes address from P2PKH script

func DecodeScriptP2SH

func DecodeScriptP2SH(scriptHex string, net *chaincfg.Params) (string, error)

DecodeScriptP2SH decodes address from P2SH script

func DecodeScriptP2TR

func DecodeScriptP2TR(scriptHex string, net *chaincfg.Params) (string, error)

DecodeScriptP2TR decodes address from P2TR script

func DecodeScriptP2WPKH

func DecodeScriptP2WPKH(scriptHex string, net *chaincfg.Params) (string, error)

DecodeScriptP2WPKH decodes address from P2WPKH script

func DecodeScriptP2WSH

func DecodeScriptP2WSH(scriptHex string, net *chaincfg.Params) (string, error)

DecodeScriptP2WSH decodes address from P2WSH script

func DecodeTSSVout

func DecodeTSSVout(vout btcjson.Vout, receiverExpected string, chain chains.Chain) (string, int64, error)

DecodeTSSVout decodes receiver and amount from a given TSS vout

func DepositorFee

func DepositorFee(satPerByte int64) float64

DepositorFee calculates the depositor fee in BTC for a given sat/byte fee rate Note: the depositor fee is charged in order to cover the cost of spending the deposited UTXO in the future

func EncodeAddress

func EncodeAddress(hash160 []byte, netID byte) string

EncodeAddress returns a human-readable payment address given a ripemd160 hash and netID which encodes the bitcoin network and address type. It is used in both pay-to-pubkey-hash (P2PKH) and pay-to-script-hash (P2SH) address encoding. Note: this function is a copy of the function in btcutil/address.go

func EstimateOutboundSize

func EstimateOutboundSize(numInputs uint64, payees []btcutil.Address) (uint64, error)

EstimateOutboundSize estimates the size of an outbound in vBytes

func FeeRateToSatPerByte

func FeeRateToSatPerByte(rate float64) *big.Int

FeeRateToSatPerByte converts a fee rate in BTC/KB to sat/byte.

func GetOutputSizeByAddress

func GetOutputSizeByAddress(to btcutil.Address) (uint64, error)

GetOutputSizeByAddress returns the size of a tx output in bytes by the given address

func GetSatoshis

func GetSatoshis(btc float64) (int64, error)

GetSatoshis converts a bitcoin amount to satoshis

func IsPkScriptP2PKH

func IsPkScriptP2PKH(script []byte) bool

IsPkScriptP2PKH checks if the given script is a P2PKH script

func IsPkScriptP2SH

func IsPkScriptP2SH(script []byte) bool

IsPkScriptP2SH checks if the given script is a P2SH script

func IsPkScriptP2TR

func IsPkScriptP2TR(script []byte) bool

IsPkScriptP2TR checks if the given script is a P2TR script

func IsPkScriptP2WPKH

func IsPkScriptP2WPKH(script []byte) bool

IsPkScriptP2WPKH checks if the given script is a P2WPKH script

func IsPkScriptP2WSH

func IsPkScriptP2WSH(script []byte) bool

IsPkScriptP2WSH checks if the given script is a P2WSH script

func OutboundSizeDepositor

func OutboundSizeDepositor() uint64

OutboundSizeDepositor returns outbound size (68vB) incurred by the depositor

func OutboundSizeWithdrawer

func OutboundSizeWithdrawer() uint64

OutboundSizeWithdrawer returns outbound size (177vB) incurred by the withdrawer (1 input, 3 outputs)

func PayToAddrScript

func PayToAddrScript(addr btcutil.Address) ([]byte, error)

PayToAddrScript creates a new script to pay a transaction output to a the specified address.

func PrettyPrintStruct

func PrettyPrintStruct(val interface{}) (string, error)

PrettyPrintStruct returns a pretty-printed string representation of a struct

func WiredTxSize

func WiredTxSize(numInputs uint64, numOutputs uint64) uint64

WiredTxSize calculates the wired tx size in bytes

Types

This section is empty.

Directories

Path Synopsis
Package observer implements the Bitcoin chain observer
Package observer implements the Bitcoin chain observer
Package signer implements the ChainSigner interface for BTC
Package signer implements the ChainSigner interface for BTC

Jump to

Keyboard shortcuts

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