Skip to content

Commit 548f828

Browse files
committed
Final migration from CBitcoinAddress to the destionation wrapper
1 parent 0724bbb commit 548f828

File tree

7 files changed

+55
-56
lines changed

7 files changed

+55
-56
lines changed

src/qt/paymentserver.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,9 @@ void PaymentServer::ipcParseCommandLine(int argc, char* argv[])
193193

194194
SendCoinsRecipient r;
195195
if (GUIUtil::parseBitcoinURI(arg, &r) && !r.address.isEmpty()) {
196-
CBitcoinAddress address(r.address.toStdString());
197-
198-
if (address.IsValid(Params(CBaseChainParams::MAIN))) {
196+
if (IsValidDestinationString(r.address.toStdString(), false, Params(CBaseChainParams::MAIN))) {
199197
SelectParams(CBaseChainParams::MAIN);
200-
} else if (address.IsValid(Params(CBaseChainParams::TESTNET))) {
198+
} else if (IsValidDestinationString(r.address.toStdString(), false, Params(CBaseChainParams::TESTNET))) {
201199
SelectParams(CBaseChainParams::TESTNET);
202200
}
203201
}
@@ -385,8 +383,7 @@ void PaymentServer::handleURIOrFile(const QString& s)
385383
{
386384
SendCoinsRecipient recipient;
387385
if (GUIUtil::parseBitcoinURI(s, &recipient)) {
388-
CBitcoinAddress address(recipient.address.toStdString());
389-
if (!address.IsValid()) {
386+
if (!IsValidDestinationString(recipient.address.toStdString())) {
390387
Q_EMIT message(tr("URI handling"), tr("Invalid payment address %1").arg(recipient.address),
391388
CClientUIInterface::MSG_ERROR);
392389
} else
@@ -505,7 +502,7 @@ bool PaymentServer::processPaymentRequest(PaymentRequestPlus& request, SendCoins
505502
CTxDestination dest;
506503
if (ExtractDestination(sendingTo.first, dest)) {
507504
// Append destination address
508-
addresses.append(QString::fromStdString(CBitcoinAddress(dest).ToString()));
505+
addresses.append(QString::fromStdString(EncodeDestination(dest)));
509506
} else if (!recipient.authenticatedMerchant.isEmpty()) {
510507
// Insecure payments to custom pivx addresses are not supported
511508
// (there is no good way to tell the user where they are paying in a way

src/qt/walletmodel.cpp

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -578,10 +578,11 @@ WalletModel::SendCoinsReturn WalletModel::sendCoins(WalletModelTransaction& tran
578578
Q_FOREACH (const SendCoinsRecipient& rcp, transaction.getRecipients()) {
579579
// Don't touch the address book when we have a payment request
580580
if (!rcp.paymentRequest.IsInitialized()) {
581-
CBitcoinAddress address = CBitcoinAddress(rcp.address.toStdString());
582-
std::string purpose = address.IsStakingAddress() ? AddressBook::AddressBookPurpose::COLD_STAKING_SEND : AddressBook::AddressBookPurpose::SEND;
581+
bool isStaking = false;
582+
CTxDestination address = DecodeDestination(rcp.address.toStdString(), isStaking);
583+
std::string purpose = isStaking ? AddressBook::AddressBookPurpose::COLD_STAKING_SEND : AddressBook::AddressBookPurpose::SEND;
583584
std::string strLabel = rcp.label.toStdString();
584-
updateAddressBookLabels(address.Get(), strLabel, purpose);
585+
updateAddressBookLabels(address, strLabel, purpose);
585586
}
586587
Q_EMIT coinsSent(wallet, rcp, transaction_array);
587588
}
@@ -699,7 +700,7 @@ static void NotifyKeyStoreStatusChanged(WalletModel* walletmodel, CCryptoKeyStor
699700

700701
static void NotifyAddressBookChanged(WalletModel* walletmodel, CWallet* wallet, const CTxDestination& address, const std::string& label, bool isMine, const std::string& purpose, ChangeType status)
701702
{
702-
QString strAddress = QString::fromStdString(pwalletMain->ParseIntoAddress(address, purpose).ToString());
703+
QString strAddress = QString::fromStdString(pwalletMain->ParseIntoAddress(address, purpose));
703704
QString strLabel = QString::fromStdString(label);
704705
QString strPurpose = QString::fromStdString(purpose);
705706

@@ -879,32 +880,35 @@ bool WalletModel::blacklistAddressFromColdStaking(const QString &addressStr)
879880

880881
bool WalletModel::updateAddressBookPurpose(const QString &addressStr, const std::string& purpose)
881882
{
882-
CBitcoinAddress address(addressStr.toStdString());
883-
if (address.IsStakingAddress())
883+
bool isStaking = false;
884+
CTxDestination address = DecodeDestination(addressStr.toStdString(), isStaking);
885+
if (isStaking)
884886
return error("Invalid PIVX address, cold staking address");
885887
CKeyID keyID;
886888
if (!getKeyId(address, keyID))
887889
return false;
888890
return pwalletMain->SetAddressBook(keyID, getLabelForAddress(address), purpose);
889891
}
890892

891-
bool WalletModel::getKeyId(const CBitcoinAddress& address, CKeyID& keyID)
893+
bool WalletModel::getKeyId(const CTxDestination& address, CKeyID& keyID)
892894
{
893-
if (!address.IsValid())
895+
if (!IsValidDestination(address))
894896
return error("Invalid PIVX address");
895897

896-
if (!address.GetKeyID(keyID))
898+
const CKeyID* inKeyID = boost::get<CKeyID>(&address);
899+
if (!inKeyID)
897900
return error("Unable to get KeyID from PIVX address");
898901

902+
keyID = *inKeyID;
899903
return true;
900904
}
901905

902-
std::string WalletModel::getLabelForAddress(const CBitcoinAddress& address)
906+
std::string WalletModel::getLabelForAddress(const CTxDestination& address)
903907
{
904908
std::string label = "";
905909
{
906910
LOCK(wallet->cs_wallet);
907-
std::map<CTxDestination, AddressBook::CAddressBookData>::iterator mi = wallet->mapAddressBook.find(address.Get());
911+
std::map<CTxDestination, AddressBook::CAddressBookData>::iterator mi = wallet->mapAddressBook.find(address);
908912
if (mi != wallet->mapAddressBook.end()) {
909913
label = mi->second.name;
910914
}
@@ -980,7 +984,7 @@ void WalletModel::listCoins(std::map<QString, std::vector<COutput> >& mapCoins)
980984
CTxDestination address;
981985
if (!out.fSpendable || !ExtractDestination(cout.tx->vout[cout.i].scriptPubKey, address))
982986
continue;
983-
mapCoins[QString::fromStdString(CBitcoinAddress(address).ToString())].push_back(out);
987+
mapCoins[QString::fromStdString(EncodeDestination(address))].push_back(out);
984988
}
985989
}
986990

@@ -1039,11 +1043,10 @@ bool WalletModel::isMine(const CTxDestination& address)
10391043

10401044
bool WalletModel::isMine(const QString& addressStr)
10411045
{
1042-
CBitcoinAddress address(addressStr.toStdString());
1043-
return IsMine(*wallet, address.Get());
1046+
return IsMine(*wallet, DecodeDestination(addressStr.toStdString()));
10441047
}
10451048

1046-
bool WalletModel::isUsed(CBitcoinAddress address)
1049+
bool WalletModel::isUsed(CTxDestination address)
10471050
{
10481051
return wallet->IsUsed(address);
10491052
}

src/qt/walletmodel.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,12 @@ class WalletModel : public QObject
263263
bool whitelistAddressFromColdStaking(const QString &addressStr);
264264
bool blacklistAddressFromColdStaking(const QString &address);
265265
bool updateAddressBookPurpose(const QString &addressStr, const std::string& purpose);
266-
std::string getLabelForAddress(const CBitcoinAddress& address);
267-
bool getKeyId(const CBitcoinAddress& address, CKeyID& keyID);
266+
std::string getLabelForAddress(const CTxDestination& address);
267+
bool getKeyId(const CTxDestination& address, CKeyID& keyID);
268268

269269
bool isMine(const CTxDestination& address);
270270
bool isMine(const QString& addressStr);
271-
bool isUsed(CBitcoinAddress address);
271+
bool isUsed(CTxDestination address);
272272
void getOutputs(const std::vector<COutPoint>& vOutpoints, std::vector<COutput>& vOutputs);
273273
bool getMNCollateralCandidate(COutPoint& outPoint);
274274
bool isSpent(const COutPoint& outpoint) const;

src/rpc/blockchain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,7 @@ UniValue getserials(const UniValue& params, bool fHelp) {
12381238
if (!ExtractDestinations(tx.vout[0].scriptPubKey, type, addresses, nRequired)) {
12391239
spentTo = strprintf("type: %d", GetTxnOutputType(type));
12401240
} else {
1241-
spentTo = CBitcoinAddress(addresses[0]).ToString();
1241+
spentTo = EncodeDestination(addresses[0]);
12421242
}
12431243
}
12441244
}

src/wallet/wallet.cpp

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,12 @@ int64_t CWallet::GetKeyCreationTime(CPubKey pubkey)
141141
return mapKeyMetadata[pubkey.GetID()].nCreateTime;
142142
}
143143

144-
int64_t CWallet::GetKeyCreationTime(const CBitcoinAddress& address)
144+
int64_t CWallet::GetKeyCreationTime(const CTxDestination& address)
145145
{
146-
CKeyID keyID;
147-
if (address.GetKeyID(keyID)) {
146+
const CKeyID* keyID = boost::get<CKeyID>(&address);
147+
if (keyID) {
148148
CPubKey keyRet;
149-
if (GetPubKey(keyID, keyRet)) {
149+
if (GetPubKey(*keyID, keyRet)) {
150150
return GetKeyCreationTime(keyRet);
151151
}
152152
}
@@ -681,15 +681,14 @@ bool CWallet::GetVinAndKeysFromOutput(COutput out, CTxIn& txinRet, CPubKey& pubK
681681

682682
CTxDestination address1;
683683
ExtractDestination(pubScript, address1, fColdStake);
684-
CBitcoinAddress address2(address1);
685684

686-
CKeyID keyID;
687-
if (!address2.GetKeyID(keyID)) {
685+
CKeyID* keyID = boost::get<CKeyID>(&address1);
686+
if (!keyID) {
688687
LogPrintf("CWallet::GetVinAndKeysFromOutput -- Address does not refer to a key\n");
689688
return false;
690689
}
691690

692-
if (!GetKey(keyID, keyRet)) {
691+
if (!GetKey(*keyID, keyRet)) {
693692
LogPrintf("CWallet::GetVinAndKeysFromOutput -- Private key for address is not known\n");
694693
return false;
695694
}
@@ -1098,10 +1097,10 @@ isminetype CWallet::IsMine(const CTxIn& txin) const
10981097
return ISMINE_NO;
10991098
}
11001099

1101-
bool CWallet::IsUsed(const CBitcoinAddress address) const
1100+
bool CWallet::IsUsed(const CTxDestination address) const
11021101
{
11031102
LOCK(cs_wallet);
1104-
CScript scriptPubKey = GetScriptForDestination(address.Get());
1103+
CScript scriptPubKey = GetScriptForDestination(address);
11051104
if (!::IsMine(*this, scriptPubKey)) {
11061105
return false;
11071106
}
@@ -2091,7 +2090,7 @@ bool CWallet::AvailableCoins(std::vector<COutput>* pCoins, // --> populates
20912090
}
20922091
}
20932092

2094-
std::map<CBitcoinAddress, std::vector<COutput> > CWallet::AvailableCoinsByAddress(bool fConfirmed, CAmount maxCoinValue)
2093+
std::map<CTxDestination , std::vector<COutput> > CWallet::AvailableCoinsByAddress(bool fConfirmed, CAmount maxCoinValue)
20952094
{
20962095
std::vector<COutput> vCoins;
20972096
// include cold
@@ -2102,8 +2101,8 @@ std::map<CBitcoinAddress, std::vector<COutput> > CWallet::AvailableCoinsByAddres
21022101
ALL_COINS, // coin type
21032102
fConfirmed); // only confirmed
21042103

2105-
std::map<CBitcoinAddress, std::vector<COutput> > mapCoins;
2106-
for (COutput out : vCoins) {
2104+
std::map<CTxDestination, std::vector<COutput> > mapCoins;
2105+
for (COutput& out : vCoins) {
21072106
if (maxCoinValue > 0 && out.tx->vout[out.i].nValue > maxCoinValue)
21082107
continue;
21092108

@@ -2117,7 +2116,7 @@ std::map<CBitcoinAddress, std::vector<COutput> > CWallet::AvailableCoinsByAddres
21172116
continue;
21182117
}
21192118

2120-
mapCoins[CBitcoinAddress(address, fColdStakeAddr ? CChainParams::STAKING_ADDRESS : CChainParams::PUBKEY_ADDRESS)].push_back(out);
2119+
mapCoins[address].push_back(out);
21212120
}
21222121

21232122
return mapCoins;
@@ -3026,7 +3025,7 @@ DBErrors CWallet::ZapWalletTx(std::vector<CWalletTx>& vWtx)
30263025
return DB_LOAD_OK;
30273026
}
30283027

3029-
CBitcoinAddress CWallet::ParseIntoAddress(const CTxDestination& dest, const std::string& purpose) {
3028+
std::string CWallet::ParseIntoAddress(const CTxDestination& dest, const std::string& purpose) {
30303029
const CChainParams::Base58Type addrType =
30313030
AddressBook::IsColdStakingPurpose(purpose) ?
30323031
CChainParams::STAKING_ADDRESS : CChainParams::PUBKEY_ADDRESS;
@@ -3046,7 +3045,7 @@ bool CWallet::SetAddressBook(const CTxDestination& address, const std::string& s
30463045
mapAddressBook.at(address).purpose, (fUpdated ? CT_UPDATED : CT_NEW));
30473046
if (!fFileBacked)
30483047
return false;
3049-
std::string addressStr = ParseIntoAddress(address, mapAddressBook.at(address).purpose).ToString();
3048+
std::string addressStr = ParseIntoAddress(address, mapAddressBook.at(address).purpose);
30503049
if (!strPurpose.empty() && !CWalletDB(strWalletFile).WritePurpose(addressStr, strPurpose))
30513050
return false;
30523051
return CWalletDB(strWalletFile).WriteName(addressStr, strName);
@@ -3488,7 +3487,7 @@ bool CWallet::AddDestData(const CTxDestination& dest, const std::string& key, co
34883487
mapAddressBook[dest].destdata.insert(std::make_pair(key, value));
34893488
if (!fFileBacked)
34903489
return true;
3491-
return CWalletDB(strWalletFile).WriteDestData(CBitcoinAddress(dest).ToString(), key, value);
3490+
return CWalletDB(strWalletFile).WriteDestData(EncodeDestination(dest), key, value);
34923491
}
34933492

34943493
bool CWallet::EraseDestData(const CTxDestination& dest, const std::string& key)
@@ -3497,7 +3496,7 @@ bool CWallet::EraseDestData(const CTxDestination& dest, const std::string& key)
34973496
return false;
34983497
if (!fFileBacked)
34993498
return true;
3500-
return CWalletDB(strWalletFile).EraseDestData(CBitcoinAddress(dest).ToString(), key);
3499+
return CWalletDB(strWalletFile).EraseDestData(EncodeDestination(dest), key);
35013500
}
35023501

35033502
bool CWallet::LoadDestData(const CTxDestination& dest, const std::string& key, const std::string& value)
@@ -3514,10 +3513,10 @@ void CWallet::AutoCombineDust()
35143513
return;
35153514
}
35163515

3517-
std::map<CBitcoinAddress, std::vector<COutput> > mapCoinsByAddress = AvailableCoinsByAddress(true, nAutoCombineThreshold * COIN);
3516+
std::map<CTxDestination, std::vector<COutput> > mapCoinsByAddress = AvailableCoinsByAddress(true, nAutoCombineThreshold * COIN);
35183517

35193518
//coins are sectioned by address. This combination code only wants to combine inputs that belong to the same address
3520-
for (std::map<CBitcoinAddress, std::vector<COutput> >::iterator it = mapCoinsByAddress.begin(); it != mapCoinsByAddress.end(); it++) {
3519+
for (std::map<CTxDestination, std::vector<COutput> >::iterator it = mapCoinsByAddress.begin(); it != mapCoinsByAddress.end(); it++) {
35213520
std::vector<COutput> vCoins, vRewardCoins;
35223521
bool maxSize = false;
35233522
vCoins = it->second;
@@ -3566,7 +3565,7 @@ void CWallet::AutoCombineDust()
35663565
continue;
35673566

35683567
std::vector<CRecipient> vecSend;
3569-
CScript scriptPubKey = GetScriptForDestination(it->first.Get());
3568+
CScript scriptPubKey = GetScriptForDestination(it->first);
35703569
vecSend.push_back(CRecipient{scriptPubKey, nTotalRewardsValue, false});
35713570

35723571
//Send change to same address

src/wallet/wallet.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
362362
//! >> Available coins (P2CS)
363363
void GetAvailableP2CSCoins(std::vector<COutput>& vCoins) const;
364364

365-
std::map<CBitcoinAddress, std::vector<COutput> > AvailableCoinsByAddress(bool fConfirmed = true, CAmount maxCoinValue = 0);
365+
std::map<CTxDestination, std::vector<COutput> > AvailableCoinsByAddress(bool fConfirmed = true, CAmount maxCoinValue = 0);
366366

367367
/// Get 10000 PIV output and keys which can be used for the Masternode
368368
bool GetMasternodeVinAndKeys(CTxIn& txinRet, CPubKey& pubKeyRet, CKey& keyRet, std::string strTxHash = "", std::string strOutputIndex = "");
@@ -383,7 +383,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
383383
PairResult getNewAddress(CTxDestination& ret, std::string label);
384384
PairResult getNewStakingAddress(CTxDestination& ret, std::string label);
385385
int64_t GetKeyCreationTime(CPubKey pubkey);
386-
int64_t GetKeyCreationTime(const CBitcoinAddress& address);
386+
int64_t GetKeyCreationTime(const CTxDestination& address);
387387

388388
//! Adds a key to the store, and saves it to disk.
389389
bool AddKeyPubKey(const CKey& key, const CPubKey& pubkey);
@@ -529,7 +529,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
529529
bool GetBudgetSystemCollateralTX(CWalletTx& tx, uint256 hash, bool useIX);
530530
bool GetBudgetFinalizationCollateralTX(CWalletTx& tx, uint256 hash, bool useIX); // Only used for budget finalization
531531

532-
bool IsUsed(const CBitcoinAddress address) const;
532+
bool IsUsed(const CTxDestination address) const;
533533

534534
isminetype IsMine(const CTxIn& txin) const;
535535
CAmount GetDebit(const CTxIn& txin, const isminefilter& filter) const;
@@ -548,7 +548,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
548548
DBErrors LoadWallet(bool& fFirstRunRet);
549549
DBErrors ZapWalletTx(std::vector<CWalletTx>& vWtx);
550550

551-
static CBitcoinAddress ParseIntoAddress(const CTxDestination& dest, const std::string& purpose);
551+
static std::string ParseIntoAddress(const CTxDestination& dest, const std::string& purpose);
552552

553553
bool SetAddressBook(const CTxDestination& address, const std::string& strName, const std::string& purpose);
554554
bool DelAddressBook(const CTxDestination& address, const CChainParams::Base58Type addrType = CChainParams::PUBKEY_ADDRESS);
@@ -618,7 +618,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
618618
const CCoinControl* coinControl = NULL);
619619

620620
// - ZC PublicSpends
621-
bool SpendZerocoin(CAmount nAmount, CWalletTx& wtxNew, CZerocoinSpendReceipt& receipt, std::vector<CZerocoinMint>& vMintsSelected, std::list<std::pair<CTxDestination,CAmount>> addressesTo, CBitcoinAddress* changeAddress = nullptr);
621+
bool SpendZerocoin(CAmount nAmount, CWalletTx& wtxNew, CZerocoinSpendReceipt& receipt, std::vector<CZerocoinMint>& vMintsSelected, std::list<std::pair<CTxDestination,CAmount>> addressesTo, CTxDestination* changeAddress = nullptr);
622622
bool MintsToInputVectorPublicSpend(std::map<CBigNum, CZerocoinMint>& mapMintsSelected, const uint256& hashTxOut, std::vector<CTxIn>& vin, CZerocoinSpendReceipt& receipt, libzerocoin::SpendType spendType, CBlockIndex* pindexCheckpoint = nullptr);
623623
bool CreateZCPublicSpendTransaction(
624624
CAmount nValue,
@@ -628,7 +628,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
628628
std::vector<CZerocoinMint>& vSelectedMints,
629629
std::vector<CDeterministicMint>& vNewMints,
630630
std::list<std::pair<CTxDestination,CAmount>> addressesTo,
631-
CBitcoinAddress* changeAddress = nullptr);
631+
CTxDestination* changeAddress = nullptr);
632632

633633
// - ZC Balances
634634
CAmount GetZerocoinBalance(bool fMatureOnly) const;

src/wallet/wallet_zerocoin.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ bool CWallet::CreateZerocoinMintTransaction(const CAmount nValue,
293293
// - ZC PublicSpends
294294

295295
bool CWallet::SpendZerocoin(CAmount nAmount, CWalletTx& wtxNew, CZerocoinSpendReceipt& receipt, std::vector<CZerocoinMint>& vMintsSelected,
296-
std::list<std::pair<CTxDestination, CAmount>> addressesTo, CBitcoinAddress* changeAddress)
296+
std::list<std::pair<CTxDestination, CAmount>> addressesTo, CTxDestination* changeAddress)
297297
{
298298
// Default: assume something goes wrong. Depending on the problem this gets more specific below
299299
int nStatus = ZPIV_SPEND_ERROR;
@@ -454,7 +454,7 @@ bool CWallet::CreateZCPublicSpendTransaction(
454454
std::vector<CZerocoinMint>& vSelectedMints,
455455
std::vector<CDeterministicMint>& vNewMints,
456456
std::list<std::pair<CTxDestination,CAmount>> addressesTo,
457-
CBitcoinAddress* changeAddress)
457+
CTxDestination * changeAddress)
458458
{
459459
// Check available funds
460460
int nStatus = ZPIV_TRX_FUNDS_PROBLEMS;
@@ -622,7 +622,7 @@ bool CWallet::CreateZCPublicSpendTransaction(
622622
CScript scriptChange;
623623
// Change address
624624
if(changeAddress){
625-
scriptChange = GetScriptForDestination(changeAddress->Get());
625+
scriptChange = GetScriptForDestination(*changeAddress);
626626
} else {
627627
// Reserve a new key pair from key pool
628628
CPubKey vchPubKey;

0 commit comments

Comments
 (0)