mirror of
https://github.com/LBRYFoundation/lbcwallet.git
synced 2025-09-02 10:15:15 +00:00
wallet: add address type param to NewChangeAddress+NewAddress
This commit is contained in:
parent
beb3231a03
commit
d88739df8f
1 changed files with 17 additions and 6 deletions
|
@ -300,6 +300,7 @@ func (w *Wallet) SetChainSynced(synced bool) {
|
||||||
// rescan request.
|
// rescan request.
|
||||||
func (w *Wallet) activeData() ([]btcutil.Address, []wtxmgr.Credit, error) {
|
func (w *Wallet) activeData() ([]btcutil.Address, []wtxmgr.Credit, error) {
|
||||||
var addrs []btcutil.Address
|
var addrs []btcutil.Address
|
||||||
|
// TODO(roasbeef): lookahead?
|
||||||
err := w.Manager.ForEachActiveAddress(func(addr btcutil.Address) error {
|
err := w.Manager.ForEachActiveAddress(func(addr btcutil.Address) error {
|
||||||
addrs = append(addrs, addr)
|
addrs = append(addrs, addr)
|
||||||
return nil
|
return nil
|
||||||
|
@ -336,6 +337,7 @@ func (w *Wallet) syncWithChain() error {
|
||||||
|
|
||||||
// Request notifications for transactions sending to all wallet
|
// Request notifications for transactions sending to all wallet
|
||||||
// addresses.
|
// addresses.
|
||||||
|
// TODO(roasbeef): need to check 3 versions of each key?
|
||||||
addrs, unspent, err := w.activeData()
|
addrs, unspent, err := w.activeData()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -719,7 +721,8 @@ func (w *Wallet) CurrentAddress(account uint32) (btcutil.Address, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// If no address exists yet, create the first external address
|
// If no address exists yet, create the first external address
|
||||||
if waddrmgr.IsError(err, waddrmgr.ErrAddressNotFound) {
|
if waddrmgr.IsError(err, waddrmgr.ErrAddressNotFound) {
|
||||||
return w.NewAddress(account)
|
// TODO(roasbeef): what to default to ?
|
||||||
|
return w.NewAddress(account, waddrmgr.WitnessPubKey)
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -730,7 +733,7 @@ func (w *Wallet) CurrentAddress(account uint32) (btcutil.Address, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if used {
|
if used {
|
||||||
return w.NewAddress(account)
|
return w.NewAddress(account, waddrmgr.WitnessPubKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
return addr.Address(), nil
|
return addr.Address(), nil
|
||||||
|
@ -1401,6 +1404,8 @@ func (w *Wallet) ListUnspent(minconf, maxconf int32,
|
||||||
spendable = true
|
spendable = true
|
||||||
case txscript.PubKeyTy:
|
case txscript.PubKeyTy:
|
||||||
spendable = true
|
spendable = true
|
||||||
|
case txscript.WitnessPubKeyHashTy:
|
||||||
|
spendable = true
|
||||||
case txscript.ScriptHashTy:
|
case txscript.ScriptHashTy:
|
||||||
spendable = true
|
spendable = true
|
||||||
case txscript.MultiSigTy:
|
case txscript.MultiSigTy:
|
||||||
|
@ -1695,9 +1700,11 @@ func (w *Wallet) SortedActivePaymentAddresses() ([]string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewAddress returns the next external chained address for a wallet.
|
// NewAddress returns the next external chained address for a wallet.
|
||||||
func (w *Wallet) NewAddress(account uint32) (btcutil.Address, error) {
|
func (w *Wallet) NewAddress(account uint32,
|
||||||
|
addrType waddrmgr.AddressType) (btcutil.Address, error) {
|
||||||
|
|
||||||
// Get next address from wallet.
|
// Get next address from wallet.
|
||||||
addrs, err := w.Manager.NextExternalAddresses(account, 1)
|
addrs, err := w.Manager.NextExternalAddresses(account, 1, addrType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -1729,9 +1736,11 @@ func (w *Wallet) NewAddress(account uint32) (btcutil.Address, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewChangeAddress returns a new change address for a wallet.
|
// NewChangeAddress returns a new change address for a wallet.
|
||||||
func (w *Wallet) NewChangeAddress(account uint32) (btcutil.Address, error) {
|
func (w *Wallet) NewChangeAddress(account uint32,
|
||||||
|
addrType waddrmgr.AddressType) (btcutil.Address, error) {
|
||||||
|
|
||||||
// Get next chained change address from wallet for account.
|
// Get next chained change address from wallet for account.
|
||||||
addrs, err := w.Manager.NextInternalAddresses(account, 1)
|
addrs, err := w.Manager.NextInternalAddresses(account, 1, addrType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -2006,6 +2015,8 @@ func (w *Wallet) SignTransaction(tx *wire.MsgTx, hashType txscript.SigHashType,
|
||||||
if (hashType&txscript.SigHashSingle) !=
|
if (hashType&txscript.SigHashSingle) !=
|
||||||
txscript.SigHashSingle || i < len(tx.TxOut) {
|
txscript.SigHashSingle || i < len(tx.TxOut) {
|
||||||
|
|
||||||
|
// TODO(roasbeef): make aware of witness, and nested p2sh
|
||||||
|
|
||||||
script, err := txscript.SignTxOutput(w.ChainParams(),
|
script, err := txscript.SignTxOutput(w.ChainParams(),
|
||||||
tx, i, prevOutScript, hashType, getKey,
|
tx, i, prevOutScript, hashType, getKey,
|
||||||
getScript, txIn.SignatureScript)
|
getScript, txIn.SignatureScript)
|
||||||
|
|
Loading…
Add table
Reference in a new issue