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 ¶
- func CreateWallet(params *chaincfg.Params, seed, pubPass, privPass []byte, ...) (wallet.Wallet, error)
- func Open(db walletdb.DB, pubPass []byte, params *chaincfg.Params, rpcclient rpc.Client) (wallet.Wallet, error)
- type Wallet
- func (w *Wallet) Close() error
- func (w *Wallet) ImportAddress(addr btcutil.Address) error
- func (w *Wallet) ListUnspent() (utxos []wallet.Utxo, err error)
- func (w *Wallet) NewAddress() (btcutil.Address, error)
- func (w *Wallet) NewPubkey() (pub *btcec.PublicKey, err error)
- func (w *Wallet) SelectUnspent(amt, feePerTxIn, feePerTxOut btcutil.Amount) (utxos []wallet.Utxo, change btcutil.Amount, err error)
- func (w *Wallet) SendRawTransaction(tx *wire.MsgTx) (*chainhash.Hash, error)
- func (w *Wallet) SetRPCClient(rpc rpc.Client)
- func (w *Wallet) Unlock(privPass []byte) error
- func (w *Wallet) UtxoByTxIn(txin *wire.TxIn) (wallet.Utxo, error)
- func (w *Wallet) WitnessSignTxByIdxs(tx *wire.MsgTx, idxs []int) ([]wire.TxWitness, error)
- func (w *Wallet) WitnessSignature(tx *wire.MsgTx, idx int, amt btcutil.Amount, sc []byte, pub *btcec.PublicKey) ([]byte, error)
- func (w *Wallet) WitnessSignatureWithCallback(tx *wire.MsgTx, idx int, amt btcutil.Amount, sc []byte, pub *btcec.PublicKey, ...) ([]byte, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Wallet ¶
type Wallet struct {
// contains filtered or unexported fields
}
Wallet is hierarchical deterministic Wallet
func (*Wallet) ImportAddress ¶
ImportAddress imports an address by creating addresses until reaching to it It stops after creating 100 addresses to avoid infinite loop
func (*Wallet) ListUnspent ¶
ListUnspent returns unspent transactions. It asks the running bitcoind instance to return all known utxos for addresses managed by the wallet
func (*Wallet) NewAddress ¶
NewAddress creates a new address managed by wallet
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 ¶
SendRawTransaction delegates to RPC client
func (*Wallet) SetRPCClient ¶
SetRPCClient sets rpc client
func (*Wallet) UtxoByTxIn ¶
UtxoByTxIn finds utxo by txin
func (*Wallet) WitnessSignTxByIdxs ¶
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