Allow spending from the waddrmgr.ImportedAddrAccount via wallet.SpendPairs.

Previously, when creating a change address during the process of
creating a new transaction an error case would be hit in the waddrmgr
triggered by attempting to derive a new internal address from under a
waddrmgr.ImportedAddrAccount. To remedy this error, we now use the
default account for change when spending outputs from an imported
key. This approach allows funds under the control of imported
private keys to be protected under the wallet's seed as soon as
they've been partially spent.
This commit is contained in:
Olaoluwa Osuntokun 2016-01-29 21:10:10 -08:00
parent b480a0a09d
commit 32ca19322a

View file

@ -216,6 +216,13 @@ func createTx(eligible []wtxmgr.Credit,
feeEst = minimumFee(feeIncrement, szEst, msgtx.TxOut, inputs, bs.Height, disallowFree) feeEst = minimumFee(feeIncrement, szEst, msgtx.TxOut, inputs, bs.Height, disallowFree)
} }
// If we're spending the outputs of an imported address, we default
// to generating change addresses from the default account.
prevAccount := account
if account == waddrmgr.ImportedAddrAccount {
account = waddrmgr.DefaultAccountNum
}
var changeAddr btcutil.Address var changeAddr btcutil.Address
// changeIdx is -1 unless there's a change output. // changeIdx is -1 unless there's a change output.
changeIdx := -1 changeIdx := -1
@ -241,6 +248,11 @@ func createTx(eligible []wtxmgr.Credit,
} }
if feeForSize(feeIncrement, msgtx.SerializeSize()) <= feeEst { if feeForSize(feeIncrement, msgtx.SerializeSize()) <= feeEst {
if change > 0 && prevAccount == waddrmgr.ImportedAddrAccount {
log.Warnf("Spend from imported account produced change: moving"+
" %v from imported account into default account.", change)
}
// The required fee for this size is less than or equal to what // The required fee for this size is less than or equal to what
// we guessed, so we're done. // we guessed, so we're done.
break break