... so it recogizes SegWit change addresses.
Fixes #11137.
788 | @@ -789,9 +789,7 @@ void SendCoinsDialog::coinControlChangeEdited(const QString& text) 789 | } 790 | else // Valid address 791 | { 792 | - CKeyID keyid; 793 | - addr.GetKeyID(keyid); 794 | - if (!model->havePrivKey(keyid)) // Unknown change address 795 | + if (model->isMine(addr.Get()) != ISMINE_SPENDABLE) // Unknown change address
IMO remove the comment, the code is more expressive.
Move { to this line.
if you feel like it, you might add a const CTxDestination dest = addr.Get(); before that line and then use if (!bool(model->IsMine(dest) & ISMINE_SPENDABLE)).
Though, it shouldn't make a difference.
560 | @@ -561,9 +561,9 @@ bool WalletModel::getPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const 561 | return wallet->GetPubKey(address, vchPubKeyOut); 562 | } 563 | 564 | -bool WalletModel::havePrivKey(const CKeyID &address) const 565 | +isminetype WalletModel::isMine(const CTxDestination &dest) const
const CTxDestination& dest.
function names are PascalCase.
Where can I find guidelines about where to put the whitespace? I went with the existing layout. See how the line I replaced had (const CKeyID &address)?
This is mentioned in the developer notes. Though, you could always just run clang format (also mentioned in the developer notes)
Check src/qt/walletmodel.h - they're all lowerThenUpper
Yes but it's outdated.
So what's the plan? Shouldn't we go through the code fixing all the outdated style at once rather than fixing one at a time?
I mean, I can change just the one I touched if that's preferable.
6 | @@ -7,6 +7,7 @@ 7 | 8 | #include "paymentrequestplus.h" 9 | #include "walletmodeltransaction.h" 10 | +#include "script/ismine.h"
Sort include.
190 | @@ -190,7 +191,7 @@ class WalletModel : public QObject 191 | UnlockContext requestUnlock(); 192 | 193 | bool getPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const; 194 | - bool havePrivKey(const CKeyID &address) const; 195 | + isminetype isMine(const CTxDestination &dest) const;
const CTxDestination& dest.
For the record, another option, that doesn't require to include in this header script/ismine.h, is bool isSpendable(const CKeyID& address).
I don't see bool isSpendable(const CKeyID& address) anywhere. And the point is that we want to be able to check the spendability of general addresses, not only CKeyIDs.
utACK 89daeb84915d7fd21230771ed266dde1f7d7afda
BTW, squash and reword, commit message is too long.
788 | @@ -789,10 +789,8 @@ void SendCoinsDialog::coinControlChangeEdited(const QString& text) 789 | } 790 | else // Valid address 791 | { 792 | - CKeyID keyid; 793 | - addr.GetKeyID(keyid); 794 | - if (!model->havePrivKey(keyid)) // Unknown change address 795 | - { 796 | + const CTxDestination dest = addr.Get(); 797 | + if (!bool(model->isMine(dest) & ISMINE_SPENDABLE)) {
The bool(..) is unnecessary.
Removed period from commit message
Removed bool
Squashed again
It appears that calling the function IsMine instead of isMine caused an error:
CXX qt/qt_libbitcoinqt_a-walletmodeltransaction.o
qt/walletmodel.cpp:566:12: error: too many arguments to function call, expected 1, have 2; did you mean '::IsMine'?
return IsMine(*wallet, dest);
^~~~~~
::IsMine
./script/ismine.h:39:12: note: '::IsMine' declared here
isminetype IsMine(const CKeyStore& keystore, const CTxDestination& dest, SigVersion = SIGVERSION_BASE);
^
I'll call it 'IsSpendable()` instead.
utACK 848ef973d7ecb054e0d6d6952fd69a0816f3b7cd
@promag title is still correct I believe, because it still uses IsMine() to check
@MeshCollider it's too long 🙄.
I finally understood what you meant about IsSpendable(), so did it that way. IsSpendable() calls IsMine(), so the commit log is correct. I've used the same string for the PR title.
Should change to a watch-only address be permitted?
Change to any address is permitted. The warning is for if you do not have control of the address.
I'd like to see a warning if I accidentally try to send change to a watchonly address. Because maybe I accidentally copied the wrong address and am about to lose my coins.
788 | @@ -789,10 +789,8 @@ void SendCoinsDialog::coinControlChangeEdited(const QString& text) 789 | } 790 | else // Valid address 791 | { 792 | - CKeyID keyid; 793 | - addr.GetKeyID(keyid); 794 | - if (!model->havePrivKey(keyid)) // Unknown change address 795 | - { 796 | + const CTxDestination dest = addr.Get(); 797 | + if (!model->IsSpendable(dest)) {
Wouldn't if (!model->IsSpendable(addr.Get())) { be simpler?
Yes it would, and that's how I had it until @MarcoFalke made this comment.
Is there a style guide that tells me how such things should be? Lots of people seem to have ideas about what's right, but I'd like to see something in writing, as it were.
dest can be used in a few places below, but as I mentioned above this is just personal preference for one style over another. Just use what you feel makes more sense, no need to discuss.
Good point. I use it in the few places below now too.
utACK 848ef973d7ecb054e0d6d6952fd69a0816f3b7cd
utACK c41224d.
Concept ACK! Solves also the issue discussed in my PR #10972 which I've now closed.
Ouch, did no one notice that this was filed against 0.15? Had to revert it, because otherwise it would mess up the release process for 0.15.0. We need a new PR for master.