Skip to content

Commit c7b2618

Browse files
Add IsMyAddressSpendable function and use it for send dialogs
1 parent 010457c commit c7b2618

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

src/omnicore/omnicore.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2101,17 +2101,29 @@ int mastercore_handler_tx(const CTransaction &tx, int nBlock, unsigned int idx,
21012101
}
21022102

21032103
// IsMine wrapper to determine whether the address is in our local wallet
2104-
bool IsMyAddress(const std::string &address)
2104+
bool IsMyAddress(const std::string &address)
21052105
{
21062106
if (!pwalletMain) return false;
21072107

21082108
const CBitcoinAddress& mscaddress = address;
2109-
2110-
CTxDestination lookupaddress = mscaddress.Get();
2109+
CTxDestination lookupaddress = mscaddress.Get();
21112110

21122111
return (IsMine(*pwalletMain, lookupaddress));
21132112
}
21142113

2114+
// IsMine wrapper to determine whether the address is spendable
2115+
bool IsMyAddressSpendable(const std::string &address)
2116+
{
2117+
if (!pwalletMain) return false;
2118+
2119+
const CBitcoinAddress& mscaddress = address;
2120+
CTxDestination destination = mscaddress.Get();
2121+
isminetype mineType = pwalletMain ? IsMine(*pwalletMain, destination) : ISMINE_NO;
2122+
if (mineType & ISMINE_SPENDABLE) return true;
2123+
2124+
return false; // eg (mineType & ISMINE_NO) (mineType & ISMINE_WATCH_ONLY) and so on, not considered spendable
2125+
}
2126+
21152127
// gets a label for a Bitcoin address from the wallet, mainly to the UI (used in demo)
21162128
string getLabel(const string &address)
21172129
{

src/omnicore/omnicore.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ extern std::map<uint32_t, int64_t> global_balance_reserved_testeco;
394394
int64_t getMPbalance(const string &Address, unsigned int property, TallyType ttype);
395395
int64_t getUserAvailableMPbalance(const string &Address, unsigned int property);
396396
bool IsMyAddress(const std::string &address);
397+
bool IsMyAddressSpendable(const std::string &address);
397398

398399
string getLabel(const string &address);
399400

src/qt/metadexdialog.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,10 @@ void MetaDExDialog::FullRefresh()
402402
(my_it->second).init();
403403
while (0 != (id = (my_it->second).next())) {
404404
if(id==propertyId) {
405-
if (IsMyAddress(address)) ui->sellAddressCombo->addItem((my_it->first).c_str()); // only include wallet addresses
405+
if (IsMyAddressSpendable(address)) ui->sellAddressCombo->addItem((my_it->first).c_str()); // only include wallet addresses
406406
}
407407
if (((id==OMNI_PROPERTY_MSC) && (!testeco)) || ((id==OMNI_PROPERTY_TMSC) && (testeco))) {
408-
if (IsMyAddress(address)) ui->buyAddressCombo->addItem((my_it->first).c_str());
408+
if (IsMyAddressSpendable(address)) ui->buyAddressCombo->addItem((my_it->first).c_str());
409409
}
410410
}
411411
}

src/qt/sendmpdialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ void SendMPDialog::updateProperty()
178178
if(id == propertyId) { includeAddress=true; break; }
179179
}
180180
if (!includeAddress) continue; //ignore this address, has never transacted in this propertyId
181-
if (!IsMyAddress(address)) continue; //ignore this address, it's not ours
181+
if (!IsMyAddressSpendable(address)) continue; //ignore this address, it's not ours
182182
if ((address.substr(0,1)=="2") || (address.substr(0,3)=="3")) continue; //quick hack to not show P2SH addresses in from selector (can't be sent from UI)
183183
ui->sendFromComboBox->addItem(QString::fromStdString(address + " \t" + FormatMP(propertyId, getUserAvailableMPbalance(address, propertyId)) + getTokenLabel(propertyId)));
184184
}

0 commit comments

Comments
 (0)