bitcoin

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeriveAddress

func DeriveAddress(
	extendedPublicKey string,
	addressIndex uint32,
	chainParams *chaincfg.Params,
) (string, error)

DeriveAddress uses the specified extended public key and address index to derive an address string in the appropriate format at the specified address index. The extended public key can be at any level. deriveAddress will take the first child `/0` until a depth of 4 is reached, and then produce the address at the supplied index. Thus, calling deriveAddress with an xpub generated at m/44'/0' and passing the address index 5 will produce the address at path m/44'/0'/0/0/5.

In cases where the extended public key is at depth 4, meaning the external or internal chain is already included, deriveAddress will directly derive the address index at the existing depth.

deriveAddress does not support hardened child indexes (anything greater than or equal to 2147483648, abbreviated as 0')

The returned address will be a p2pkh/p2sh address for prefixes xpub and tpub, (i.e. prefixed by 1, m, or n), a p2wpkh-in-p2sh address for prefixes ypub or upub (i.e., prefixed by 3 or 2), and a bech32 p2wpkh address for prefixes zpub or vpub (i.e., prefixed by bc1 or tb1).

See BIP32, BIP44, BIP49, and BIP84 for more on address derivation, particular paths, etc.

func ValidateAddress

func ValidateAddress(btcAddress string, chainParams *chaincfg.Params) error

ValidateAddress checks to see if the btc address is valid on the supplied chain. It is expected that final bitcoin address is provided, *pub extended key will fail the validation.

func ValidateAddressOrKey

func ValidateAddressOrKey(btcAddress string, chainParams *chaincfg.Params) error

ValidateAddressOrKey checks to see if the supplied btc address is valid on the supplied chain. We check both raw btc addresses and *pub extended keys.

Types

type Config

type Config struct {
	BeneficiaryAddress string
	MaxFeePerVByte     int32
	BitcoinChainName   string
	ElectrsURL         *string
}

Config stores configuration related to recovering BTC from a closed keep.

func (Config) ChainParams

func (c Config) ChainParams() (*chaincfg.Params, error)

ChainParams parses the net param name into the associated chaincfg.Params

func (Config) ElectrsURLWithDefault

func (c Config) ElectrsURLWithDefault() string

ElectrsURLWithDefault dereferences ElectrsURL in the following way: if there is a configured value, use it. Otherwise, default to https://blockstream.info/api/. This allows us to add bitcoin connection functionality to nodes that haven't made config changes yet while also letting a user connect to the node of their choice.

func (Config) Validate

func (c Config) Validate() error

Validate returns nil if the configuration is suitable for bitcoin recovery, and an error detailing what went wrong if not.

type Handle

type Handle interface {
	Broadcast(transaction string) error
	VbyteFeeFor25Blocks() (int32, error)
	IsAddressUnused(btcAddress string) (bool, error)
}

Handle serves as an interface abstraction around bitcoin network queries

func Connect

func Connect(apiURL string) Handle

Connect is a constructor for electrsConnection.

Jump to

Keyboard shortcuts

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