btcutils

package
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2024 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TransactionP2WPKH  = txscript.WitnessV0PubKeyHashTy
	TransactionP2TR    = txscript.WitnessV1TaprootTy
	TransactionTaproot = TransactionP2TR // Alias of P2TR
	TransactionP2SH    = txscript.ScriptHashTy
	TransactionP2PKH   = txscript.PubKeyHashTy
	TransactionP2WSH   = txscript.WitnessV0ScriptHashTy
)

Types of bitcoin transaction

View Source
const (
	AddressP2WPKH  = txscript.WitnessV0PubKeyHashTy
	AddressP2TR    = txscript.WitnessV1TaprootTy
	AddressTaproot = AddressP2TR // Alias of P2TR
	AddressP2SH    = txscript.ScriptHashTy
	AddressP2PKH   = txscript.PubKeyHashTy
	AddressP2WSH   = txscript.WitnessV0ScriptHashTy
)

Types of bitcoin address

View Source
const (
	// TxVersion is the current latest supported transaction version.
	TxVersion = 2

	// MaxTxInSequenceNum is the maximum sequence number the sequence field
	// of a transaction input can be.
	MaxTxInSequenceNum uint32 = 0xffffffff
)
View Source
const (
	// MaxSupportedPkScriptSize is the maximum supported size of a pkScript.
	MaxSupportedPkScriptSize = 40
)

Variables

View Source
var (
	// NullAddress is an address that script address is all zeros.
	NullAddress = NewAddress("1111111111111111111114oLvT2", &chaincfg.MainNetParams)

	// NullHash is a hash that all bytes are zero.
	NullHash = utils.Must(chainhash.NewHashFromStr("0000000000000000000000000000000000000000000000000000000000000000"))
)

Functions

func EstimateSignedTxNetworkFee added in v0.4.2

func EstimateSignedTxNetworkFee(tx *wire.MsgTx, prevTxOuts []*wire.TxOut, feeRate int64) (int64, error)

EstimateSignedTxNetworkFee estimates the network fee for the given transaction. "prevTxOuts" should be list of all outputs used as inputs in the transaction. If the transaction has unsigned inputs, the fee will be calculated as if those inputs were signed.

func GetNetParams added in v0.2.4

func GetNetParams(network string) *chaincfg.Params

GetNetParams returns the *chaincfg.Params for the given network.

func IsAddress added in v0.2.4

func IsAddress(address string, defaultNet ...*chaincfg.Params) bool

IsAddress returns whether or not the passed string is a valid bitcoin address and valid supported type.

NetParams is optional. If provided, we only check for that network, otherwise, we check for all supported networks.

func IsSupportType added in v0.2.4

func IsSupportType(t txscript.ScriptClass) bool

IsSupportType returns true if the given tx/address type is supported.

func IsSupportedNetwork added in v0.2.4

func IsSupportedNetwork(network string) bool

IsSupportedNetwork returns true if the given network is supported.

TODO: create enum for network

func NewPkScript added in v0.2.4

func NewPkScript(address string, defaultNet ...*chaincfg.Params) ([]byte, error)

NewPkScript creates a pubkey script(or witness program) from the given address string

see: https://en.bitcoin.it/wiki/Script

func SignTxInput added in v0.4.2

func SignTxInput(tx *wire.MsgTx, privateKey *btcec.PrivateKey, prevTxOut *wire.TxOut, inputIndex int, options ...SignTxInputOptions) (*wire.MsgTx, error)

func SignTxInputTapScript added in v0.4.2

func SignTxInputTapScript(tx *wire.MsgTx, privateKey *btcec.PrivateKey, prevTxOut *wire.TxOut, inputIndex int) (*wire.MsgTx, error)

func VerifySignature added in v0.2.4

func VerifySignature(address string, message string, sigBase64 string, defaultNet ...*chaincfg.Params) error

func WitnessFromHex

func WitnessFromHex(witnesses []string) (wire.TxWitness, error)

WitnessFromHex parses the passed slice of hex-encoded strings into a witness stack.

func WitnessFromString

func WitnessFromString(witnesses string) (wire.TxWitness, error)

WitnessFromString parses the passed space-separated string of hex-encoded strings into a witness stack.

func WitnessToHex

func WitnessToHex(witness wire.TxWitness) []string

WitnessToHex formats the passed witness stack as a slice of hex-encoded strings.

func WitnessToString

func WitnessToString(witness wire.TxWitness) string

WitnessToString formats the passed witness stack as a space-separated string of hex-encoded strings.

Types

type Address added in v0.2.4

type Address struct {
	// contains filtered or unexported fields
}

func ExtractAddressFromPkScript added in v0.2.4

func ExtractAddressFromPkScript(pkScript []byte, defaultNet ...*chaincfg.Params) (Address, error)

ExtractAddressFromPkScript extracts address from the given pubkey script/script pubkey. multi-signature script not supported

func NewAddress added in v0.2.4

func NewAddress(address string, defaultNet ...*chaincfg.Params) Address

NewAddress creates a new address from the given address string.

defaultNet is required if your address is P2SH or P2PKH (legacy or nested segwit) If your address is P2WSH, P2WPKH or P2TR, defaultNet is not required.

func SafeNewAddress added in v0.2.4

func SafeNewAddress(address string, defaultNet ...*chaincfg.Params) (Address, error)

SafeNewAddress creates a new address from the given address string. It returns an error if the address is invalid.

defaultNet is required if your address is P2SH or P2PKH (legacy or nested segwit) If your address is P2WSH, P2WPKH or P2TR, defaultNet is not required.

func (Address) Decoded added in v0.2.4

func (a Address) Decoded() btcutil.Address

Decoded returns the btcutil.Address

func (Address) DustLimit added in v0.4.2

func (a Address) DustLimit() int64

DustLimit returns the output dust limit (lowest possible satoshis in a UTXO) for the address type.

func (Address) Equal added in v0.2.4

func (a Address) Equal(b Address) bool

Equal return true if addresses are equal

func (Address) IsForNet added in v0.2.4

func (a Address) IsForNet(net *chaincfg.Params) bool

IsForNet returns whether or not the address is associated with the passed bitcoin network.

func (Address) MarshalJSON added in v0.2.4

func (a Address) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (Address) MarshalText added in v0.2.4

func (a Address) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (Address) Net added in v0.2.4

func (a Address) Net() *chaincfg.Params

Net returns the address network params.

func (Address) NetworkName added in v0.2.4

func (a Address) NetworkName() string

NetworkName

func (Address) ScriptAddress added in v0.2.4

func (a Address) ScriptAddress() []byte

ScriptAddress returns the raw bytes of the address to be used when inserting the address into a txout's script.

func (Address) ScriptPubKey added in v0.2.4

func (a Address) ScriptPubKey() []byte

ScriptPubKey or pubkey script

func (Address) String added in v0.2.4

func (a Address) String() string

String returns the address string.

func (Address) Type added in v0.2.4

func (a Address) Type() AddressType

Type returns the address type.

func (*Address) UnmarshalJSON added in v0.2.4

func (a *Address) UnmarshalJSON(input []byte) error

UnmarshalJSON parses a hash in hex syntax.

func (*Address) UnmarshalText added in v0.2.4

func (a *Address) UnmarshalText(input []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

type AddressType added in v0.2.4

type AddressType = txscript.ScriptClass

AddressType is the type of bitcoin address. It's an alias of txscript.ScriptClass

func GetAddressType added in v0.2.4

func GetAddressType(address string, net *chaincfg.Params) (AddressType, error)

GetAddressType returns the address type of the passed address.

func GetAddressTypeFromPkScript added in v0.2.4

func GetAddressTypeFromPkScript(pkScript []byte, defaultNet ...*chaincfg.Params) (AddressType, error)

GetAddressTypeFromPkScript returns the address type from the given pubkey script/script pubkey.

type SignTxInputOptions added in v0.4.4

type SignTxInputOptions struct {
	SigHashType txscript.SigHashType
}

type TransactionType added in v0.2.4

type TransactionType = txscript.ScriptClass

TransactionType is the type of bitcoin transaction It's an alias of txscript.ScriptClass

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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