Documentation ¶
Index ¶
- Constants
- Variables
- func EstimateSignedTxNetworkFee(tx *wire.MsgTx, prevTxOuts []*wire.TxOut, feeRate int64) (int64, error)
- func GetNetParams(network string) *chaincfg.Params
- func IsAddress(address string, defaultNet ...*chaincfg.Params) bool
- func IsSupportType(t txscript.ScriptClass) bool
- func IsSupportedNetwork(network string) bool
- func NewPkScript(address string, defaultNet ...*chaincfg.Params) ([]byte, error)
- func SignTxInput(tx *wire.MsgTx, privateKey *btcec.PrivateKey, prevTxOut *wire.TxOut, ...) (*wire.MsgTx, error)
- func SignTxInputTapScript(tx *wire.MsgTx, privateKey *btcec.PrivateKey, prevTxOut *wire.TxOut, ...) (*wire.MsgTx, error)
- func VerifySignature(address string, message string, sigBase64 string, ...) error
- func WitnessFromHex(witnesses []string) (wire.TxWitness, error)
- func WitnessFromString(witnesses string) (wire.TxWitness, error)
- func WitnessToHex(witness wire.TxWitness) []string
- func WitnessToString(witness wire.TxWitness) string
- type Address
- func (a Address) Decoded() btcutil.Address
- func (a Address) DustLimit() int64
- func (a Address) Equal(b Address) bool
- func (a Address) IsForNet(net *chaincfg.Params) bool
- func (a Address) MarshalJSON() ([]byte, error)
- func (a Address) MarshalText() ([]byte, error)
- func (a Address) Net() *chaincfg.Params
- func (a Address) NetworkName() string
- func (a Address) ScriptAddress() []byte
- func (a Address) ScriptPubKey() []byte
- func (a Address) String() string
- func (a Address) Type() AddressType
- func (a *Address) UnmarshalJSON(input []byte) error
- func (a *Address) UnmarshalText(input []byte) error
- type AddressType
- type SignTxInputOptions
- type TransactionType
Constants ¶
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
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
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 )
const (
// MaxSupportedPkScriptSize is the maximum supported size of a pkScript.
MaxSupportedPkScriptSize = 40
)
Variables ¶
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
GetNetParams returns the *chaincfg.Params for the given network.
func IsAddress ¶ added in v0.2.4
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
IsSupportedNetwork returns true if the given network is supported.
TODO: create enum for network
func NewPkScript ¶ added in v0.2.4
NewPkScript creates a pubkey script(or witness program) from the given address string
func SignTxInput ¶ added in v0.4.2
func SignTxInputTapScript ¶ added in v0.4.2
func VerifySignature ¶ added in v0.2.4
func WitnessFromHex ¶
WitnessFromHex parses the passed slice of hex-encoded strings into a witness stack.
func WitnessFromString ¶
WitnessFromString parses the passed space-separated string of hex-encoded strings into a witness stack.
func WitnessToHex ¶
WitnessToHex formats the passed witness stack as a slice of hex-encoded strings.
func WitnessToString ¶
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
ExtractAddressFromPkScript extracts address from the given pubkey script/script pubkey. multi-signature script not supported
func NewAddress ¶ added in v0.2.4
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
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) DustLimit ¶ added in v0.4.2
DustLimit returns the output dust limit (lowest possible satoshis in a UTXO) for the address type.
func (Address) IsForNet ¶ added in v0.2.4
IsForNet returns whether or not the address is associated with the passed bitcoin network.
func (Address) MarshalJSON ¶ added in v0.2.4
MarshalJSON implements the json.Marshaler interface.
func (Address) MarshalText ¶ added in v0.2.4
MarshalText implements the encoding.TextMarshaler interface.
func (Address) ScriptAddress ¶ added in v0.2.4
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
ScriptPubKey or pubkey script
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
UnmarshalJSON parses a hash in hex syntax.
func (*Address) UnmarshalText ¶ added in v0.2.4
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