diff --git a/src/base58.cpp b/src/base58.cpp index f6e58992480ac..69092bdd5b11f 100644 --- a/src/base58.cpp +++ b/src/base58.cpp @@ -6,15 +6,15 @@ #include "base58.h" #include "hash.h" +#include "script/script.h" #include "uint256.h" -#include #include #include + +#include +#include #include -#include -#include -#include #include /** All alphanumeric characters except for "0", "I", "O", and "l" */ @@ -231,94 +231,64 @@ int CBase58Data::CompareTo(const CBase58Data& b58) const namespace { -class CBitcoinAddressVisitor : public boost::static_visitor +class DestinationEncoder : public boost::static_visitor { private: - CBitcoinAddress* addr; - CChainParams::Base58Type type; + const CChainParams& m_params; + const CChainParams::Base58Type m_addrType; public: - CBitcoinAddressVisitor(CBitcoinAddress* addrIn, - const CChainParams::Base58Type addrType = CChainParams::PUBKEY_ADDRESS) : - addr(addrIn), - type(addrType){}; - - bool operator()(const CKeyID& id) const { return addr->Set(id, type); } - bool operator()(const CScriptID& id) const { return addr->Set(id); } - bool operator()(const CNoDestination& no) const { return false; } -}; - -} // anon namespace + DestinationEncoder(const CChainParams& params, const CChainParams::Base58Type _addrType = CChainParams::PUBKEY_ADDRESS) : m_params(params), m_addrType(_addrType) {} -bool CBitcoinAddress::Set(const CKeyID& id, const CChainParams::Base58Type addrType) -{ - SetData(Params().Base58Prefix(addrType), &id, 20); - return true; -} - -bool CBitcoinAddress::Set(const CScriptID& id) -{ - SetData(Params().Base58Prefix(CChainParams::SCRIPT_ADDRESS), &id, 20); - return true; -} - -bool CBitcoinAddress::Set(const CTxDestination& dest, const CChainParams::Base58Type addrType) -{ - return boost::apply_visitor(CBitcoinAddressVisitor(this, addrType), dest); -} - -bool CBitcoinAddress::IsValid() const -{ - return IsValid(Params()); -} - -bool CBitcoinAddress::IsValid(const CChainParams& params) const -{ - bool fCorrectSize = vchData.size() == 20; - bool fKnownVersion = vchVersion == params.Base58Prefix(CChainParams::PUBKEY_ADDRESS) || - vchVersion == params.Base58Prefix(CChainParams::SCRIPT_ADDRESS) || - vchVersion == params.Base58Prefix(CChainParams::STAKING_ADDRESS); - return fCorrectSize && fKnownVersion; -} + std::string operator()(const CKeyID& id) const + { + std::vector data = m_params.Base58Prefix(m_addrType); + data.insert(data.end(), id.begin(), id.end()); + return EncodeBase58Check(data); + } -CTxDestination CBitcoinAddress::Get() const -{ - if (!IsValid()) - return CNoDestination(); - uint160 id; - memcpy(&id, &vchData[0], 20); - if (vchVersion == Params().Base58Prefix(CChainParams::PUBKEY_ADDRESS) || - vchVersion == Params().Base58Prefix(CChainParams::STAKING_ADDRESS)) - return CKeyID(id); - else if (vchVersion == Params().Base58Prefix(CChainParams::SCRIPT_ADDRESS)) - return CScriptID(id); - else - return CNoDestination(); -} + std::string operator()(const CScriptID& id) const + { + std::vector data = m_params.Base58Prefix(CChainParams::SCRIPT_ADDRESS); + data.insert(data.end(), id.begin(), id.end()); + return EncodeBase58Check(data); + } -bool CBitcoinAddress::GetKeyID(CKeyID& keyID) const -{ - if (!IsValid() || - (vchVersion != Params().Base58Prefix(CChainParams::PUBKEY_ADDRESS) && - vchVersion != Params().Base58Prefix(CChainParams::STAKING_ADDRESS))) - return false; - uint160 id; - memcpy(&id, &vchData[0], 20); - keyID = CKeyID(id); - return true; -} + std::string operator()(const CNoDestination& no) const { return ""; } +}; -bool CBitcoinAddress::IsScript() const +CTxDestination DecodeDestination(const std::string& str, const CChainParams& params, bool& isStaking) { - bool fCorrectSize = vchData.size() == 20; - return fCorrectSize && vchVersion == Params().Base58Prefix(CChainParams::SCRIPT_ADDRESS); + std::vector data; + uint160 hash; + if (DecodeBase58Check(str, data)) { + // base58-encoded PIVX addresses. + // Public-key-hash-addresses have version 30 (or 139 testnet). + // The data vector contains RIPEMD160(SHA256(pubkey)), where pubkey is the serialized public key. + const std::vector& pubkey_prefix = params.Base58Prefix(CChainParams::PUBKEY_ADDRESS); + if (data.size() == hash.size() + pubkey_prefix.size() && std::equal(pubkey_prefix.begin(), pubkey_prefix.end(), data.begin())) { + std::copy(data.begin() + pubkey_prefix.size(), data.end(), hash.begin()); + return CKeyID(hash); + } + // Public-key-hash-coldstaking-addresses have version 63 (or 73 testnet). + const std::vector& staking_prefix = params.Base58Prefix(CChainParams::STAKING_ADDRESS); + if (data.size() == hash.size() + staking_prefix.size() && std::equal(staking_prefix.begin(), staking_prefix.end(), data.begin())) { + isStaking = true; + std::copy(data.begin() + staking_prefix.size(), data.end(), hash.begin()); + return CKeyID(hash); + } + // Script-hash-addresses have version 13 (or 19 testnet). + // The data vector contains RIPEMD160(SHA256(cscript)), where cscript is the serialized redemption script. + const std::vector& script_prefix = params.Base58Prefix(CChainParams::SCRIPT_ADDRESS); + if (data.size() == hash.size() + script_prefix.size() && std::equal(script_prefix.begin(), script_prefix.end(), data.begin())) { + std::copy(data.begin() + script_prefix.size(), data.end(), hash.begin()); + return CScriptID(hash); + } + } + return CNoDestination(); } -bool CBitcoinAddress::IsStakingAddress() const -{ - bool fCorrectSize = vchData.size() == 20; - return fCorrectSize && vchVersion == Params().Base58Prefix(CChainParams::STAKING_ADDRESS); -} +} // anon namespace CKey DecodeSecret(const std::string& str) { @@ -349,13 +319,6 @@ std::string EncodeSecret(const CKey& key) return ret; } -CTxDestination DestinationFor(const CKeyID& keyID, const CChainParams::Base58Type addrType) -{ - CBitcoinAddress addr(keyID, addrType); - if (!addr.IsValid()) throw std::runtime_error("Error, trying to decode an invalid keyID"); - return addr.Get(); -} - std::string EncodeDestination(const CTxDestination& dest, bool isStaking) { return EncodeDestination(dest, isStaking ? CChainParams::STAKING_ADDRESS : CChainParams::PUBKEY_ADDRESS); @@ -363,36 +326,27 @@ std::string EncodeDestination(const CTxDestination& dest, bool isStaking) std::string EncodeDestination(const CTxDestination& dest, const CChainParams::Base58Type addrType) { - CBitcoinAddress addr(dest, addrType); - if (!addr.IsValid()) return ""; - return addr.ToString(); + return boost::apply_visitor(DestinationEncoder(Params(), addrType), dest); } CTxDestination DecodeDestination(const std::string& str) { - return CBitcoinAddress(str).Get(); + bool isStaking; + return DecodeDestination(str, Params(), isStaking); } CTxDestination DecodeDestination(const std::string& str, bool& isStaking) { - CBitcoinAddress addr(str); - isStaking = addr.IsStakingAddress(); - return addr.Get(); + return DecodeDestination(str, Params(), isStaking); } bool IsValidDestinationString(const std::string& str, bool fStaking, const CChainParams& params) { - return IsValidDestinationString(str, fStaking); -} - -bool IsValidDestinationString(const std::string& str) -{ - CBitcoinAddress address(str); - return address.IsValid(); + bool isStaking = false; + return IsValidDestination(DecodeDestination(str, params, isStaking)) && (isStaking == fStaking); } bool IsValidDestinationString(const std::string& str, bool isStaking) { - CBitcoinAddress address(str); - return address.IsValid() && (address.IsStakingAddress() == isStaking); + return IsValidDestinationString(str, isStaking, Params()); } diff --git a/src/base58.h b/src/base58.h index 7d0a996fc1b7c..4ae85ab8fbbc7 100644 --- a/src/base58.h +++ b/src/base58.h @@ -18,7 +18,6 @@ #include "chainparams.h" #include "key.h" #include "pubkey.h" -#include "script/script.h" #include "script/standard.h" #include @@ -101,42 +100,6 @@ class CBase58Data bool operator>(const CBase58Data& b58) const { return CompareTo(b58) > 0; } }; -/** base58-encoded PIVX addresses. - * Public-key-hash-addresses have version 0 (or 111 testnet). - * The data vector contains RIPEMD160(SHA256(pubkey)), where pubkey is the serialized public key. - * Script-hash-addresses have version 5 (or 196 testnet). - * The data vector contains RIPEMD160(SHA256(cscript)), where cscript is the serialized redemption script. - */ -class CBitcoinAddress : public CBase58Data -{ -public: - bool Set(const CKeyID& id, const CChainParams::Base58Type addrType = CChainParams::PUBKEY_ADDRESS); - bool Set(const CScriptID& id); - bool Set(const CTxDestination& dest, const CChainParams::Base58Type addrType = CChainParams::PUBKEY_ADDRESS); - bool IsValid() const; - bool IsValid(const CChainParams& params) const; - - CBitcoinAddress() {} - CBitcoinAddress(const CTxDestination& dest, const CChainParams::Base58Type addrType = CChainParams::PUBKEY_ADDRESS) { Set(dest, addrType); } - CBitcoinAddress(const std::string& strAddress) { SetString(strAddress); } - CBitcoinAddress(const char* pszAddress) { SetString(pszAddress); } - - CTxDestination Get() const; - bool GetKeyID(CKeyID& keyID) const; - bool IsScript() const; - bool IsStakingAddress() const; - - - // Helpers - static const CBitcoinAddress newCSInstance(const CTxDestination& dest) { - return CBitcoinAddress(dest, CChainParams::STAKING_ADDRESS); - } - - static const CBitcoinAddress newInstance(const CTxDestination& dest) { - return CBitcoinAddress(dest, CChainParams::PUBKEY_ADDRESS); - } -}; - CKey DecodeSecret(const std::string& str); std::string EncodeSecret(const CKey& key); @@ -177,7 +140,6 @@ typedef CBitcoinExtKeyBase CBitcoinExtPubKey; -CTxDestination DestinationFor(const CKeyID& keyID, const CChainParams::Base58Type addrType); std::string EncodeDestination(const CTxDestination& dest, bool isStaking); std::string EncodeDestination(const CTxDestination& dest, const CChainParams::Base58Type addrType = CChainParams::PUBKEY_ADDRESS); // DecodeDestinationisStaking flag is set to true when the string arg is from an staking address diff --git a/src/qt/paymentserver.cpp b/src/qt/paymentserver.cpp index 184af12f8cac4..ba353250b44c4 100644 --- a/src/qt/paymentserver.cpp +++ b/src/qt/paymentserver.cpp @@ -193,11 +193,9 @@ void PaymentServer::ipcParseCommandLine(int argc, char* argv[]) SendCoinsRecipient r; if (GUIUtil::parseBitcoinURI(arg, &r) && !r.address.isEmpty()) { - CBitcoinAddress address(r.address.toStdString()); - - if (address.IsValid(Params(CBaseChainParams::MAIN))) { + if (IsValidDestinationString(r.address.toStdString(), false, Params(CBaseChainParams::MAIN))) { SelectParams(CBaseChainParams::MAIN); - } else if (address.IsValid(Params(CBaseChainParams::TESTNET))) { + } else if (IsValidDestinationString(r.address.toStdString(), false, Params(CBaseChainParams::TESTNET))) { SelectParams(CBaseChainParams::TESTNET); } } @@ -385,8 +383,7 @@ void PaymentServer::handleURIOrFile(const QString& s) { SendCoinsRecipient recipient; if (GUIUtil::parseBitcoinURI(s, &recipient)) { - CBitcoinAddress address(recipient.address.toStdString()); - if (!address.IsValid()) { + if (!IsValidDestinationString(recipient.address.toStdString(), false, Params())) { Q_EMIT message(tr("URI handling"), tr("Invalid payment address %1").arg(recipient.address), CClientUIInterface::MSG_ERROR); } else @@ -505,7 +502,7 @@ bool PaymentServer::processPaymentRequest(PaymentRequestPlus& request, SendCoins CTxDestination dest; if (ExtractDestination(sendingTo.first, dest)) { // Append destination address - addresses.append(QString::fromStdString(CBitcoinAddress(dest).ToString())); + addresses.append(QString::fromStdString(EncodeDestination(dest))); } else if (!recipient.authenticatedMerchant.isEmpty()) { // Insecure payments to custom pivx addresses are not supported // (there is no good way to tell the user where they are paying in a way diff --git a/src/qt/pivx/settings/settingsmultisendwidget.cpp b/src/qt/pivx/settings/settingsmultisendwidget.cpp index 97c97775d0ce3..75c56d3d81f76 100644 --- a/src/qt/pivx/settings/settingsmultisendwidget.cpp +++ b/src/qt/pivx/settings/settingsmultisendwidget.cpp @@ -337,7 +337,7 @@ void SettingsMultisendWidget::activate() strRet = tr("Unable to activate MultiSend, no available recipients"); else if (!(ui->checkBoxStake->isChecked() || ui->checkBoxRewards->isChecked())) { strRet = tr("Unable to activate MultiSend\nCheck one or both of the check boxes to send on stake and/or masternode rewards"); - } else if (IsValidDestinationString(pwalletMain->vMultiSend[0].first)) { + } else if (IsValidDestinationString(pwalletMain->vMultiSend[0].first, false, Params())) { pwalletMain->fMultiSendStake = ui->checkBoxStake->isChecked(); pwalletMain->fMultiSendMasternodeReward = ui->checkBoxRewards->isChecked(); diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index ca4765b2f2240..cfc9a3aac5692 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -585,10 +585,11 @@ WalletModel::SendCoinsReturn WalletModel::sendCoins(WalletModelTransaction& tran Q_FOREACH (const SendCoinsRecipient& rcp, transaction.getRecipients()) { // Don't touch the address book when we have a payment request if (!rcp.paymentRequest.IsInitialized()) { - CBitcoinAddress address = CBitcoinAddress(rcp.address.toStdString()); - std::string purpose = address.IsStakingAddress() ? AddressBook::AddressBookPurpose::COLD_STAKING_SEND : AddressBook::AddressBookPurpose::SEND; + bool isStaking = false; + CTxDestination address = DecodeDestination(rcp.address.toStdString(), isStaking); + std::string purpose = isStaking ? AddressBook::AddressBookPurpose::COLD_STAKING_SEND : AddressBook::AddressBookPurpose::SEND; std::string strLabel = rcp.label.toStdString(); - updateAddressBookLabels(address.Get(), strLabel, purpose); + updateAddressBookLabels(address, strLabel, purpose); } Q_EMIT coinsSent(wallet, rcp, transaction_array); } @@ -706,7 +707,7 @@ static void NotifyKeyStoreStatusChanged(WalletModel* walletmodel, CCryptoKeyStor static void NotifyAddressBookChanged(WalletModel* walletmodel, CWallet* wallet, const CTxDestination& address, const std::string& label, bool isMine, const std::string& purpose, ChangeType status) { - QString strAddress = QString::fromStdString(pwalletMain->ParseIntoAddress(address, purpose).ToString()); + QString strAddress = QString::fromStdString(pwalletMain->ParseIntoAddress(address, purpose)); QString strLabel = QString::fromStdString(label); QString strPurpose = QString::fromStdString(purpose); @@ -886,8 +887,9 @@ bool WalletModel::blacklistAddressFromColdStaking(const QString &addressStr) bool WalletModel::updateAddressBookPurpose(const QString &addressStr, const std::string& purpose) { - CBitcoinAddress address(addressStr.toStdString()); - if (address.IsStakingAddress()) + bool isStaking = false; + CTxDestination address = DecodeDestination(addressStr.toStdString(), isStaking); + if (isStaking) return error("Invalid PIVX address, cold staking address"); CKeyID keyID; if (!getKeyId(address, keyID)) @@ -895,23 +897,25 @@ bool WalletModel::updateAddressBookPurpose(const QString &addressStr, const std: return pwalletMain->SetAddressBook(keyID, getLabelForAddress(address), purpose); } -bool WalletModel::getKeyId(const CBitcoinAddress& address, CKeyID& keyID) +bool WalletModel::getKeyId(const CTxDestination& address, CKeyID& keyID) { - if (!address.IsValid()) + if (!IsValidDestination(address)) return error("Invalid PIVX address"); - if (!address.GetKeyID(keyID)) + const CKeyID* inKeyID = boost::get(&address); + if (!inKeyID) return error("Unable to get KeyID from PIVX address"); + keyID = *inKeyID; return true; } -std::string WalletModel::getLabelForAddress(const CBitcoinAddress& address) +std::string WalletModel::getLabelForAddress(const CTxDestination& address) { std::string label = ""; { LOCK(wallet->cs_wallet); - std::map::iterator mi = wallet->mapAddressBook.find(address.Get()); + std::map::iterator mi = wallet->mapAddressBook.find(address); if (mi != wallet->mapAddressBook.end()) { label = mi->second.name; } @@ -987,7 +991,7 @@ void WalletModel::listCoins(std::map >& mapCoins) CTxDestination address; if (!out.fSpendable || !ExtractDestination(cout.tx->vout[cout.i].scriptPubKey, address)) continue; - mapCoins[QString::fromStdString(CBitcoinAddress(address).ToString())].push_back(out); + mapCoins[QString::fromStdString(EncodeDestination(address))].push_back(out); } } @@ -1046,11 +1050,10 @@ bool WalletModel::isMine(const CTxDestination& address) bool WalletModel::isMine(const QString& addressStr) { - CBitcoinAddress address(addressStr.toStdString()); - return IsMine(*wallet, address.Get()); + return IsMine(*wallet, DecodeDestination(addressStr.toStdString())); } -bool WalletModel::isUsed(CBitcoinAddress address) +bool WalletModel::isUsed(CTxDestination address) { return wallet->IsUsed(address); } diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h index 203739e98f86e..40585f0cfdf82 100644 --- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -263,12 +263,12 @@ class WalletModel : public QObject bool whitelistAddressFromColdStaking(const QString &addressStr); bool blacklistAddressFromColdStaking(const QString &address); bool updateAddressBookPurpose(const QString &addressStr, const std::string& purpose); - std::string getLabelForAddress(const CBitcoinAddress& address); - bool getKeyId(const CBitcoinAddress& address, CKeyID& keyID); + std::string getLabelForAddress(const CTxDestination& address); + bool getKeyId(const CTxDestination& address, CKeyID& keyID); bool isMine(const CTxDestination& address); bool isMine(const QString& addressStr); - bool isUsed(CBitcoinAddress address); + bool isUsed(CTxDestination address); void getOutputs(const std::vector& vOutpoints, std::vector& vOutputs); bool getMNCollateralCandidate(COutPoint& outPoint); bool isSpent(const COutPoint& outpoint) const; diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index ea0d1bc5a6ddc..9ec7d88c0ff0c 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1238,7 +1238,7 @@ UniValue getserials(const UniValue& params, bool fHelp) { if (!ExtractDestinations(tx.vout[0].scriptPubKey, type, addresses, nRequired)) { spentTo = strprintf("type: %d", GetTxnOutputType(type)); } else { - spentTo = CBitcoinAddress(addresses[0]).ToString(); + spentTo = EncodeDestination(addresses[0]); } } } diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 7927699a162e9..01422378d4dc4 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -132,7 +132,7 @@ PairResult CWallet::getNewAddress(CTxDestination& ret, const std::string address if (!SetAddressBook(keyID, addressLabel, purpose)) throw std::runtime_error("CWallet::getNewAddress() : SetAddressBook failed"); - ret = DestinationFor(keyID, addrType); + ret = CTxDestination(keyID); return PairResult(true); } @@ -141,12 +141,12 @@ int64_t CWallet::GetKeyCreationTime(CPubKey pubkey) return mapKeyMetadata[pubkey.GetID()].nCreateTime; } -int64_t CWallet::GetKeyCreationTime(const CBitcoinAddress& address) +int64_t CWallet::GetKeyCreationTime(const CTxDestination& address) { - CKeyID keyID; - if (address.GetKeyID(keyID)) { + const CKeyID* keyID = boost::get(&address); + if (keyID) { CPubKey keyRet; - if (GetPubKey(keyID, keyRet)) { + if (GetPubKey(*keyID, keyRet)) { return GetKeyCreationTime(keyRet); } } @@ -641,15 +641,14 @@ bool CWallet::GetVinAndKeysFromOutput(COutput out, CTxIn& txinRet, CPubKey& pubK CTxDestination address1; ExtractDestination(pubScript, address1, fColdStake); - CBitcoinAddress address2(address1); - CKeyID keyID; - if (!address2.GetKeyID(keyID)) { + CKeyID* keyID = boost::get(&address1); + if (!keyID) { LogPrintf("CWallet::GetVinAndKeysFromOutput -- Address does not refer to a key\n"); return false; } - if (!GetKey(keyID, keyRet)) { + if (!GetKey(*keyID, keyRet)) { LogPrintf("CWallet::GetVinAndKeysFromOutput -- Private key for address is not known\n"); return false; } @@ -1058,10 +1057,10 @@ isminetype CWallet::IsMine(const CTxIn& txin) const return ISMINE_NO; } -bool CWallet::IsUsed(const CBitcoinAddress address) const +bool CWallet::IsUsed(const CTxDestination address) const { LOCK(cs_wallet); - CScript scriptPubKey = GetScriptForDestination(address.Get()); + CScript scriptPubKey = GetScriptForDestination(address); if (!::IsMine(*this, scriptPubKey)) { return false; } @@ -2124,7 +2123,7 @@ bool CWallet::AvailableCoins(std::vector* pCoins, // --> populates } } -std::map > CWallet::AvailableCoinsByAddress(bool fConfirmed, CAmount maxCoinValue) +std::map > CWallet::AvailableCoinsByAddress(bool fConfirmed, CAmount maxCoinValue) { std::vector vCoins; // include cold @@ -2135,8 +2134,8 @@ std::map > CWallet::AvailableCoinsByAddres ALL_COINS, // coin type fConfirmed); // only confirmed - std::map > mapCoins; - for (COutput out : vCoins) { + std::map > mapCoins; + for (COutput& out : vCoins) { if (maxCoinValue > 0 && out.tx->vout[out.i].nValue > maxCoinValue) continue; @@ -2150,7 +2149,7 @@ std::map > CWallet::AvailableCoinsByAddres continue; } - mapCoins[CBitcoinAddress(address, fColdStakeAddr ? CChainParams::STAKING_ADDRESS : CChainParams::PUBKEY_ADDRESS)].push_back(out); + mapCoins[address].push_back(out); } return mapCoins; @@ -3059,7 +3058,7 @@ DBErrors CWallet::ZapWalletTx(std::vector& vWtx) return DB_LOAD_OK; } -CBitcoinAddress CWallet::ParseIntoAddress(const CTxDestination& dest, const std::string& purpose) { +std::string CWallet::ParseIntoAddress(const CTxDestination& dest, const std::string& purpose) { const CChainParams::Base58Type addrType = AddressBook::IsColdStakingPurpose(purpose) ? CChainParams::STAKING_ADDRESS : CChainParams::PUBKEY_ADDRESS; @@ -3079,7 +3078,7 @@ bool CWallet::SetAddressBook(const CTxDestination& address, const std::string& s mapAddressBook.at(address).purpose, (fUpdated ? CT_UPDATED : CT_NEW)); if (!fFileBacked) return false; - std::string addressStr = ParseIntoAddress(address, mapAddressBook.at(address).purpose).ToString(); + std::string addressStr = ParseIntoAddress(address, mapAddressBook.at(address).purpose); if (!strPurpose.empty() && !CWalletDB(strWalletFile).WritePurpose(addressStr, strPurpose)) return false; return CWalletDB(strWalletFile).WriteName(addressStr, strName); @@ -3521,7 +3520,7 @@ bool CWallet::AddDestData(const CTxDestination& dest, const std::string& key, co mapAddressBook[dest].destdata.insert(std::make_pair(key, value)); if (!fFileBacked) return true; - return CWalletDB(strWalletFile).WriteDestData(CBitcoinAddress(dest).ToString(), key, value); + return CWalletDB(strWalletFile).WriteDestData(EncodeDestination(dest), key, value); } bool CWallet::EraseDestData(const CTxDestination& dest, const std::string& key) @@ -3530,7 +3529,7 @@ bool CWallet::EraseDestData(const CTxDestination& dest, const std::string& key) return false; if (!fFileBacked) return true; - return CWalletDB(strWalletFile).EraseDestData(CBitcoinAddress(dest).ToString(), key); + return CWalletDB(strWalletFile).EraseDestData(EncodeDestination(dest), key); } bool CWallet::LoadDestData(const CTxDestination& dest, const std::string& key, const std::string& value) @@ -3547,10 +3546,10 @@ void CWallet::AutoCombineDust() return; } - std::map > mapCoinsByAddress = AvailableCoinsByAddress(true, nAutoCombineThreshold * COIN); + std::map > mapCoinsByAddress = AvailableCoinsByAddress(true, nAutoCombineThreshold * COIN); //coins are sectioned by address. This combination code only wants to combine inputs that belong to the same address - for (std::map >::iterator it = mapCoinsByAddress.begin(); it != mapCoinsByAddress.end(); it++) { + for (std::map >::iterator it = mapCoinsByAddress.begin(); it != mapCoinsByAddress.end(); it++) { std::vector vCoins, vRewardCoins; bool maxSize = false; vCoins = it->second; @@ -3599,7 +3598,7 @@ void CWallet::AutoCombineDust() continue; std::vector vecSend; - CScript scriptPubKey = GetScriptForDestination(it->first.Get()); + CScript scriptPubKey = GetScriptForDestination(it->first); vecSend.push_back(CRecipient{scriptPubKey, nTotalRewardsValue, false}); //Send change to same address diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index b6dc0342b0e53..47d50153f0235 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -362,7 +362,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface //! >> Available coins (P2CS) void GetAvailableP2CSCoins(std::vector& vCoins) const; - std::map > AvailableCoinsByAddress(bool fConfirmed = true, CAmount maxCoinValue = 0); + std::map > AvailableCoinsByAddress(bool fConfirmed = true, CAmount maxCoinValue = 0); /// Get 10000 PIV output and keys which can be used for the Masternode bool GetMasternodeVinAndKeys(CTxIn& txinRet, CPubKey& pubKeyRet, CKey& keyRet, std::string strTxHash = "", std::string strOutputIndex = ""); @@ -383,7 +383,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface PairResult getNewAddress(CTxDestination& ret, std::string label); PairResult getNewStakingAddress(CTxDestination& ret, std::string label); int64_t GetKeyCreationTime(CPubKey pubkey); - int64_t GetKeyCreationTime(const CBitcoinAddress& address); + int64_t GetKeyCreationTime(const CTxDestination& address); //! Adds a key to the store, and saves it to disk. bool AddKeyPubKey(const CKey& key, const CPubKey& pubkey); @@ -529,7 +529,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface bool GetBudgetSystemCollateralTX(CWalletTx& tx, uint256 hash, bool useIX); bool GetBudgetFinalizationCollateralTX(CWalletTx& tx, uint256 hash, bool useIX); // Only used for budget finalization - bool IsUsed(const CBitcoinAddress address) const; + bool IsUsed(const CTxDestination address) const; isminetype IsMine(const CTxIn& txin) const; CAmount GetDebit(const CTxIn& txin, const isminefilter& filter) const; @@ -548,7 +548,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface DBErrors LoadWallet(bool& fFirstRunRet); DBErrors ZapWalletTx(std::vector& vWtx); - static CBitcoinAddress ParseIntoAddress(const CTxDestination& dest, const std::string& purpose); + static std::string ParseIntoAddress(const CTxDestination& dest, const std::string& purpose); bool SetAddressBook(const CTxDestination& address, const std::string& strName, const std::string& purpose); bool DelAddressBook(const CTxDestination& address, const CChainParams::Base58Type addrType = CChainParams::PUBKEY_ADDRESS); @@ -618,7 +618,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface const CCoinControl* coinControl = NULL); // - ZC PublicSpends - bool SpendZerocoin(CAmount nAmount, CWalletTx& wtxNew, CZerocoinSpendReceipt& receipt, std::vector& vMintsSelected, std::list> addressesTo, CBitcoinAddress* changeAddress = nullptr); + bool SpendZerocoin(CAmount nAmount, CWalletTx& wtxNew, CZerocoinSpendReceipt& receipt, std::vector& vMintsSelected, std::list> addressesTo, CTxDestination* changeAddress = nullptr); bool MintsToInputVectorPublicSpend(std::map& mapMintsSelected, const uint256& hashTxOut, std::vector& vin, CZerocoinSpendReceipt& receipt, libzerocoin::SpendType spendType, CBlockIndex* pindexCheckpoint = nullptr); bool CreateZCPublicSpendTransaction( CAmount nValue, @@ -628,7 +628,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface std::vector& vSelectedMints, std::vector& vNewMints, std::list> addressesTo, - CBitcoinAddress* changeAddress = nullptr); + CTxDestination* changeAddress = nullptr); // - ZC Balances CAmount GetZerocoinBalance(bool fMatureOnly) const; diff --git a/src/wallet/wallet_zerocoin.cpp b/src/wallet/wallet_zerocoin.cpp index 544231f8e5be2..0db5aaf908ad8 100644 --- a/src/wallet/wallet_zerocoin.cpp +++ b/src/wallet/wallet_zerocoin.cpp @@ -293,7 +293,7 @@ bool CWallet::CreateZerocoinMintTransaction(const CAmount nValue, // - ZC PublicSpends bool CWallet::SpendZerocoin(CAmount nAmount, CWalletTx& wtxNew, CZerocoinSpendReceipt& receipt, std::vector& vMintsSelected, - std::list> addressesTo, CBitcoinAddress* changeAddress) + std::list> addressesTo, CTxDestination* changeAddress) { // Default: assume something goes wrong. Depending on the problem this gets more specific below int nStatus = ZPIV_SPEND_ERROR; @@ -454,7 +454,7 @@ bool CWallet::CreateZCPublicSpendTransaction( std::vector& vSelectedMints, std::vector& vNewMints, std::list> addressesTo, - CBitcoinAddress* changeAddress) + CTxDestination * changeAddress) { // Check available funds int nStatus = ZPIV_TRX_FUNDS_PROBLEMS; @@ -622,7 +622,7 @@ bool CWallet::CreateZCPublicSpendTransaction( CScript scriptChange; // Change address if(changeAddress){ - scriptChange = GetScriptForDestination(changeAddress->Get()); + scriptChange = GetScriptForDestination(*changeAddress); } else { // Reserve a new key pair from key pool CPubKey vchPubKey;