Documentation ¶
Index ¶
- Constants
- Variables
- func CalcBlockAvgFeeRate(blockVb *btcjson.GetBlockVerboseTxResult, netParams *chaincfg.Params) (int64, error)
- func CalcDepositorFee(rpcClient interfaces.BTCRPCClient, rawResult *btcjson.TxRawResult, ...) (float64, error)
- func DecodeOpReturnMemo(scriptHex string) ([]byte, bool, error)
- func DecodeScript(script []byte) ([]byte, bool, error)
- func DecodeScriptP2PKH(scriptHex string, net *chaincfg.Params) (string, error)
- func DecodeScriptP2SH(scriptHex string, net *chaincfg.Params) (string, error)
- func DecodeScriptP2TR(scriptHex string, net *chaincfg.Params) (string, error)
- func DecodeScriptP2WPKH(scriptHex string, net *chaincfg.Params) (string, error)
- func DecodeScriptP2WSH(scriptHex string, net *chaincfg.Params) (string, error)
- func DecodeSenderFromScript(pkScript []byte, net *chaincfg.Params) (string, error)
- func DecodeTSSVout(vout btcjson.Vout, receiverExpected string, chain chains.Chain) (string, int64, error)
- func DepositorFee(satPerByte int64) float64
- func EncodeAddress(hash160 []byte, netID byte) string
- func EstimateOutboundSize(numInputs uint64, payees []btcutil.Address) (uint64, error)
- func FeeRateToSatPerByte(rate float64) *big.Int
- func GetOutputSizeByAddress(to btcutil.Address) (uint64, error)
- func GetRecentFeeRate(rpcClient interfaces.BTCRPCClient, netParams *chaincfg.Params) (uint64, error)
- func GetSatoshis(btc float64) (int64, error)
- func IsPkScriptP2PKH(script []byte) bool
- func IsPkScriptP2SH(script []byte) bool
- func IsPkScriptP2TR(script []byte) bool
- func IsPkScriptP2WPKH(script []byte) bool
- func IsPkScriptP2WSH(script []byte) bool
- func OutboundSizeDepositor() uint64
- func OutboundSizeWithdrawer() uint64
- func PrettyPrintStruct(val interface{}) (string, error)
- func WiredTxSize(numInputs uint64, numOutputs uint64) uint64
- type DepositorFeeCalculator
Constants ¶
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 )
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 ¶
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) )
var ErrBitcoinNotEnabled = errors.New("bitcoin is not enabled")
ErrBitcoinNotEnabled is the error returned when bitcoin is not enabled
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( rpcClient interfaces.BTCRPCClient, rawResult *btcjson.TxRawResult, netParams *chaincfg.Params, ) (float64, error)
CalcDepositorFee calculates the depositor fee for a given tx result
func DecodeOpReturnMemo ¶
DecodeOpReturnMemo decodes memo from OP_RETURN script returns (memo, found, error)
func DecodeScript ¶
DecodeScript decodes memo wrapped in an inscription like script in witness returns (memo, found, error)
Note: the format of the script is following that of "inscription" defined in ordinal theory. However, to separate from inscription (as this use case is not an NFT), simplifications are made. The bitcoin envelope script is as follows: OP_DATA_32 <32 byte of public key> OP_CHECKSIG OP_FALSE OP_IF
OP_PUSH 0x... OP_PUSH 0x...
OP_ENDIF There are no content-type or any other attributes, it's just raw bytes.
func DecodeScriptP2PKH ¶
DecodeScriptP2PKH decodes address from P2PKH script
func DecodeScriptP2SH ¶
DecodeScriptP2SH decodes address from P2SH script
func DecodeScriptP2TR ¶
DecodeScriptP2TR decodes address from P2TR script
func DecodeScriptP2WPKH ¶
DecodeScriptP2WPKH decodes address from P2WPKH script
func DecodeScriptP2WSH ¶
DecodeScriptP2WSH decodes address from P2WSH script
func DecodeSenderFromScript ¶
DecodeSenderFromScript decodes sender from a given 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 ¶
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 ¶
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 ¶
EstimateOutboundSize estimates the size of an outbound in vBytes
func FeeRateToSatPerByte ¶
FeeRateToSatPerByte converts a fee rate in BTC/KB to sat/byte.
func GetOutputSizeByAddress ¶
GetOutputSizeByAddress returns the size of a tx output in bytes by the given address
func GetRecentFeeRate ¶
func GetRecentFeeRate(rpcClient interfaces.BTCRPCClient, netParams *chaincfg.Params) (uint64, error)
GetRecentFeeRate gets the highest fee rate from recent blocks Note: this method should be used for testnet ONLY
func GetSatoshis ¶
GetSatoshis converts a bitcoin amount to satoshis
func IsPkScriptP2PKH ¶
IsPkScriptP2PKH checks if the given script is a P2PKH script
func IsPkScriptP2SH ¶
IsPkScriptP2SH checks if the given script is a P2SH script
func IsPkScriptP2TR ¶
IsPkScriptP2TR checks if the given script is a P2TR script
func IsPkScriptP2WPKH ¶
IsPkScriptP2WPKH checks if the given script is a P2WPKH script
func IsPkScriptP2WSH ¶
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 PrettyPrintStruct ¶
PrettyPrintStruct returns a pretty-printed string representation of a struct
func WiredTxSize ¶
WiredTxSize calculates the wired tx size in bytes
Types ¶
type DepositorFeeCalculator ¶
type DepositorFeeCalculator func(interfaces.BTCRPCClient, *btcjson.TxRawResult, *chaincfg.Params) (float64, error)
DepositorFeeCalculator is a function type to calculate the Bitcoin depositor fee