wallet

package
v0.0.0-...-1c741c1 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2019 License: MIT Imports: 20 Imported by: 0

README

wallet

This package provides wallet features necessary for implementing DLCs.

This package heavily relies on some of the packages of btcsuite/btcwallet for its core functionality.

Connecting to bitcoind

Until bitcoin rpc parameters can be read automatically from a bitcoin.conf file, your bitcoin rpc parameters need to be entered manually in the wallet.go file, in lines 59-61.

	rpcport     = "localhost: REPLACEME"
	rpcusername = "RENAME!"
	rpcpassword = "RENAME!"

For your convenience, the defualt mainnet port number is 8333, for testnet3 is 18332 , and regnet is 18443.

Documentation

Overview

Package wallet provides the the bitcoin wallet features necessary for implementing DLCs.

It is heavily based on btcsuite's [btcwallet](https://github.com/btcsuite/btcwallet) implementation.

Assumptions

Right now, this library assumes only one cointype will be used (`waddrmgr.KeyScopeBIP0084`)and there will be only one account associated with that cointype. If this is to change, this library will need to be refactored a little (actually a lot).

How address management works

The hierarchical deterministic address manager is provided by btcsuite's waddrmgr(http://godoc.org/github.com/btcsuite/btcwallet/waddrmgr). When a wallet is created, `Manager` is created as part of the wallet. `Manager` is the root manager; it handles the root HD key (m/). A `ScopedKeyManager` is a sub key manager under the main root key manager; each scoped key managagers handles the cointype key for a particular key scope (m/purpose/cointype).

Under each `ScopedKeyManager` are `Account` types associated with that `ScopedKeyManager`.

For more information on address management, please consult the original [godoc](https://godoc.org/github.com/btcsuite/btcwallet/waddrmgr).

How UTXO management works

Right now, to ask about UTXOS, the wallet will query the running `bitcoind` instance by using the rpc command `ListUnspent()`. When a public address is generated, it is also registered to `bitcoind`, so `bitcoind` knows to keep track of transactions associated with that addresss.

Connecting to `bitcoind`

Until bitcoin rpc parameters can be read automatically from a `bitcoin.conf` file, your bitcoin rpc parameters need to be entered manually in the `wallet.go` file, in lines 59-61. ```

rpcport     = "localhost: REPLACEME"
rpcusername = "RENAME!"
rpcpassword = "RENAME!"

``` For your convenience, the default `mainnet` port number is `8333`, for `testnet3` is `18332` , and `regnet` is `18443`.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateWallet

func CreateWallet(
	params *chaincfg.Params,
	seed, pubPass, privPass []byte,
	walletDir, walletName string) (wallet.Wallet, error)

CreateWallet returns a new Wallet, also creates db where wallet resides

func Open

func Open(
	db walletdb.DB, pubPass []byte, params *chaincfg.Params, rpcclient rpc.Client,
) (wallet.Wallet, error)

Open loads a wallet from the passed db and public pass phrase.

Types

type Wallet

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

Wallet is hierarchical deterministic Wallet

func (*Wallet) Close

func (w *Wallet) Close() error

Close closes managers

func (*Wallet) ImportAddress

func (w *Wallet) ImportAddress(addr btcutil.Address) error

ImportAddress imports an address by creating addresses until reaching to it It stops after creating 100 addresses to avoid infinite loop

func (*Wallet) ListUnspent

func (w *Wallet) ListUnspent() (utxos []wallet.Utxo, err error)

ListUnspent returns unspent transactions. It asks the running bitcoind instance to return all known utxos for addresses managed by the wallet

func (*Wallet) NewAddress

func (w *Wallet) NewAddress() (btcutil.Address, error)

NewAddress creates a new address managed by wallet

func (*Wallet) NewPubkey

func (w *Wallet) NewPubkey() (pub *btcec.PublicKey, err error)

NewPubkey returns a new btcec.PublicKey type public key

func (*Wallet) SelectUnspent

func (w *Wallet) SelectUnspent(
	amt, feePerTxIn, feePerTxOut btcutil.Amount,
) (utxos []wallet.Utxo, change btcutil.Amount, err error)

SelectUnspent is an implementation of Wallet.SelectUnspent

func (*Wallet) SendRawTransaction

func (w *Wallet) SendRawTransaction(tx *wire.MsgTx) (*chainhash.Hash, error)

SendRawTransaction delegates to RPC client

func (*Wallet) SetRPCClient

func (w *Wallet) SetRPCClient(rpc rpc.Client)

SetRPCClient sets rpc client

func (*Wallet) Unlock

func (w *Wallet) Unlock(privPass []byte) error

Unlock unlocks address manager with a given private pass phrase

func (*Wallet) UtxoByTxIn

func (w *Wallet) UtxoByTxIn(txin *wire.TxIn) (wallet.Utxo, error)

UtxoByTxIn finds utxo by txin

func (*Wallet) WitnessSignTxByIdxs

func (w *Wallet) WitnessSignTxByIdxs(tx *wire.MsgTx, idxs []int) ([]wire.TxWitness, error)

WitnessSignTxByIdxs returns witnesses associated to txins at given indices

func (*Wallet) WitnessSignature

func (w *Wallet) WitnessSignature(
	tx *wire.MsgTx, idx int, amt btcutil.Amount, sc []byte, pub *btcec.PublicKey,
) ([]byte, error)

WitnessSignature returns witness signature by signing tx with the privkey of given pubkey

func (*Wallet) WitnessSignatureWithCallback

func (w *Wallet) WitnessSignatureWithCallback(
	tx *wire.MsgTx, idx int, amt btcutil.Amount, sc []byte, pub *btcec.PublicKey,
	privkeyConverter wallet.PrivateKeyConverter,
) ([]byte, error)

WitnessSignatureWithCallback does the same with WitnessSignature does, but applying a func PrivateKeyConverter to raw privkey and use the result as privkey for calculating witness signature

Jump to

Keyboard shortcuts

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