Skip to content

Commit ab8d525

Browse files
committed
wip
1 parent 29cdcc1 commit ab8d525

18 files changed

+123
-113
lines changed

src/gridcoin/contract/message.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "amount.h"
66
#include "gridcoin/contract/message.h"
77
#include "gridcoin/contract/contract.h"
8+
#include <key_io.h>
89
#include "script.h"
910
#include "wallet/wallet.h"
1011

@@ -85,7 +86,7 @@ bool CreateContractTx(CWalletTx& wtx_out, CReserveKey& reserve_key, CAmount burn
8586
coin_control_out.destChange = out_address;
8687

8788
LogPrintf("INFO: %s: Change sent to %s for contract transaction per contractchangetoinputaddress setting.",
88-
__func__, CBitcoinAddress(coin_control_out.destChange).ToString());
89+
__func__, EncodeDestination(coin_control_out.destChange));
8990
}
9091

9192
for (const auto& contract : wtx_out.vContracts) {

src/gridcoin/scraper/scraper_net.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
#include "rpc/server.h"
1313
#include "rpc/protocol.h"
1414
#ifdef SCRAPER_NET_PK_AS_ADDRESS
15-
#include "base58.h"
15+
#include <base58.h>
16+
#include <key_io.h>
1617
#endif
1718
#include "gridcoin/appcache.h"
1819
#include "gridcoin/project.h"
@@ -855,7 +856,7 @@ UniValue CScraperManifest::ToJson() const EXCLUSIVE_LOCKS_REQUIRED(CSplitBlob::c
855856
UniValue r(UniValue::VOBJ);
856857

857858
#ifdef SCRAPER_NET_PK_AS_ADDRESS
858-
r.pushKV("pubkey", CBitcoinAddress(pubkey.GetID()).ToString());
859+
r.pushKV("pubkey", EncodeDestination(pubkey.GetID()));
859860
#else
860861
r.pushKV("pubkey", pubkey.GetID().ToString());
861862
#endif
@@ -948,7 +949,7 @@ UniValue listmanifests(const UniValue& params, bool fHelp)
948949
else
949950
{
950951
#ifdef SCRAPER_NET_PK_AS_ADDRESS
951-
subset.pushKV("scraper (manifest) address", CBitcoinAddress(manifest.pubkey.GetID()).ToString());
952+
subset.pushKV("scraper (manifest) address", EncodeDestination(manifest.pubkey.GetID()));
952953
#else
953954
subset.pushKV("scraper (manifest) pubkey", manifest.pubkey.GetID().ToString());
954955
#endif
@@ -971,7 +972,7 @@ UniValue listmanifests(const UniValue& params, bool fHelp)
971972
else
972973
{
973974
#ifdef SCRAPER_NET_PK_AS_ADDRESS
974-
subset.pushKV("scraper (manifest) address", CBitcoinAddress(manifest.pubkey.GetID()).ToString());
975+
subset.pushKV("scraper (manifest) address", EncodeDestination(manifest.pubkey.GetID()));
975976
#else
976977
subset.pushKV("scraper (manifest) pubkey", manifest.pubkey.GetID().ToString());
977978
#endif

src/key_io.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <chainparams.h>
1010
#include <key.h>
1111
#include <pubkey.h>
12+
#include <script.h>
1213

1314
#include <string>
1415

@@ -20,4 +21,10 @@ std::string EncodeExtKey(const CExtKey& extkey);
2021
CExtPubKey DecodeExtPubKey(const std::string& str);
2122
std::string EncodeExtPubKey(const CExtPubKey& extpubkey);
2223

24+
std::string EncodeDestination(const CTxDestination& dest);
25+
CTxDestination DecodeDestination(const std::string& str);
26+
CTxDestination DecodeDestination(const std::string& str, std::string& error_msg, std::vector<int>* error_locations = nullptr);
27+
bool IsValidDestinationString(const std::string& str);
28+
bool IsValidDestinationString(const std::string& str, const CChainParams& params);
29+
2330
#endif // BITCOIN_KEY_IO_H

src/miner.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "amount.h"
88
#include "consensus/merkle.h"
99
#include "txdb.h"
10+
#include <key_io.h>
1011
#include "miner.h"
1112
#include "main.h"
1213
#include "gridcoin/beacon.h"
@@ -921,8 +922,8 @@ void SplitCoinStakeOutput(CBlock &blocknew, int64_t &nReward, bool &fEnableStake
921922
(iterSideStake != vSideStakeAlloc.end()) && (nOutputsUsed <= nMaxSideStakeOutputs);
922923
++iterSideStake)
923924
{
924-
CBitcoinAddress address(iterSideStake->first);
925-
if (!address.IsValid())
925+
CTxDestination dest = DecodeDestination(iterSideStake->first);
926+
if (std::holds_alternative<CNoDestination>(dest))
926927
{
927928
LogPrintf("WARN: SplitCoinStakeOutput: ignoring sidestake invalid address %s.",
928929
iterSideStake->first.c_str());
@@ -948,7 +949,7 @@ void SplitCoinStakeOutput(CBlock &blocknew, int64_t &nReward, bool &fEnableStake
948949
// Push to an output the (reward times the allocation) to the address, increment the accumulator for allocation,
949950
// decrement the remaining stake output value, and increment outputs used.
950951

951-
SideStakeScriptPubKey.SetDestination(address.Get());
952+
SideStakeScriptPubKey.SetDestination(dest);
952953

953954
// It is entirely possible that the coinstake could be from an address that is specified in one of the sidestake
954955
// entries if the sidestake address(es) are local to the staking wallet. There is no reason to sidestake in that
@@ -1305,8 +1306,8 @@ SideStakeAlloc GetSideStakingStatusAndAlloc()
13051306

13061307
sAddress = entry.first;
13071308

1308-
CBitcoinAddress address(sAddress);
1309-
if (!address.IsValid())
1309+
// TODO: Use IsValidDestinationString here.
1310+
if (std::holds_alternative<CNoDestination>(DecodeDestination(sAddress)))
13101311
{
13111312
LogPrintf("WARN: %s: ignoring sidestake invalid address %s.", __func__, sAddress);
13121313
continue;

src/qt/addresstablemodel.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
#include "guiutil.h"
33
#include "walletmodel.h"
44

5+
#include <key_io.h>
56
#include "wallet/wallet.h"
6-
#include "base58.h"
77
#include "util.h"
88

99
#include <QFont>
@@ -62,12 +62,12 @@ class AddressTablePriv
6262
LOCK(wallet->cs_wallet);
6363
for (auto const &item : wallet->mapAddressBook)
6464
{
65-
const CBitcoinAddress& address = item.first;
65+
const std::string& address = EncodeDestination(item.first);
6666
const std::string& strName = item.second;
67-
isminetype fMine = IsMine(*wallet, address.Get());
67+
isminetype fMine = IsMine(*wallet, item.first);
6868
cachedAddressTable.append(AddressTableEntry((fMine != ISMINE_NO) ? AddressTableEntry::Receiving : AddressTableEntry::Sending,
6969
QString::fromStdString(strName),
70-
QString::fromStdString(address.ToString())));
70+
QString::fromStdString(address)));
7171
}
7272
}
7373
// std::lower_bound() and std::upper_bound() require our cachedAddressTable list to be sorted in asc order
@@ -222,7 +222,7 @@ bool AddressTableModel::setData(const QModelIndex &index, const QVariant &value,
222222
auto address_count = [this](const QVariant &value) {
223223
LOCK(wallet->cs_wallet);
224224

225-
return wallet->mapAddressBook.count(CBitcoinAddress(value.toString().toStdString()).Get());
225+
return wallet->mapAddressBook.count(DecodeDestination(value.toString().toStdString()));
226226
};
227227

228228
if (role == Qt::EditRole)
@@ -236,11 +236,11 @@ bool AddressTableModel::setData(const QModelIndex &index, const QVariant &value,
236236
editStatus = NO_CHANGES;
237237
return false;
238238
}
239-
wallet->SetAddressBookName(CBitcoinAddress(rec->address.toStdString()).Get(), value.toString().toStdString());
239+
wallet->SetAddressBookName(DecodeDestination(rec->address.toStdString()), value.toString().toStdString());
240240
break;
241241
case Address:
242242
// Do nothing, if old address == new address
243-
if(CBitcoinAddress(rec->address.toStdString()) == CBitcoinAddress(value.toString().toStdString()))
243+
if(DecodeDestination(rec->address.toStdString()) == DecodeDestination(value.toString().toStdString()))
244244
{
245245
editStatus = NO_CHANGES;
246246
return false;
@@ -264,9 +264,9 @@ bool AddressTableModel::setData(const QModelIndex &index, const QVariant &value,
264264
{
265265
LOCK(wallet->cs_wallet);
266266
// Remove old entry
267-
wallet->DelAddressBookName(CBitcoinAddress(rec->address.toStdString()).Get());
267+
wallet->DelAddressBookName(DecodeDestination(rec->address.toStdString()));
268268
// Add new entry with new address
269-
wallet->SetAddressBookName(CBitcoinAddress(value.toString().toStdString()).Get(), rec->label.toStdString());
269+
wallet->SetAddressBookName(DecodeDestination(value.toString().toStdString()), rec->label.toStdString());
270270
}
271271
}
272272
break;
@@ -342,7 +342,7 @@ QString AddressTableModel::addRow(const QString &type, const QString &label, con
342342
// Check for duplicate addresses
343343
{
344344
LOCK(wallet->cs_wallet);
345-
if(wallet->mapAddressBook.count(CBitcoinAddress(strAddress).Get()))
345+
if(wallet->mapAddressBook.count(DecodeDestination(strAddress)))
346346
{
347347
editStatus = DUPLICATE_ADDRESS;
348348
return QString();
@@ -365,7 +365,7 @@ QString AddressTableModel::addRow(const QString &type, const QString &label, con
365365
editStatus = KEY_GENERATION_FAILURE;
366366
return QString();
367367
}
368-
strAddress = CBitcoinAddress(newKey.GetID()).ToString();
368+
strAddress = EncodeDestination(newKey.GetID());
369369
}
370370
else
371371
{
@@ -375,7 +375,7 @@ QString AddressTableModel::addRow(const QString &type, const QString &label, con
375375
// Add entry
376376
{
377377
LOCK(wallet->cs_wallet);
378-
wallet->SetAddressBookName(CBitcoinAddress(strAddress).Get(), strLabel);
378+
wallet->SetAddressBookName(DecodeDestination(strAddress), strLabel);
379379
}
380380
return QString::fromStdString(strAddress);
381381
}
@@ -392,7 +392,7 @@ bool AddressTableModel::removeRows(int row, int count, const QModelIndex &parent
392392
}
393393
{
394394
LOCK(wallet->cs_wallet);
395-
wallet->DelAddressBookName(CBitcoinAddress(rec->address.toStdString()).Get());
395+
wallet->DelAddressBookName(DecodeDestination(rec->address.toStdString()));
396396
}
397397
return true;
398398
}
@@ -403,8 +403,7 @@ QString AddressTableModel::labelForAddress(const QString &address) const
403403
{
404404
{
405405
LOCK(wallet->cs_wallet);
406-
CBitcoinAddress address_parsed(address.toStdString());
407-
std::map<CTxDestination, std::string>::iterator mi = wallet->mapAddressBook.find(address_parsed.Get());
406+
std::map<CTxDestination, std::string>::iterator mi = wallet->mapAddressBook.find(DecodeDestination(address.toStdString()));
408407
if (mi != wallet->mapAddressBook.end())
409408
{
410409
return QString::fromStdString(mi->second);

src/qt/coincontroldialog.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "init.h"
55
#include "bitcoinunits.h"
66
#include "addresstablemodel.h"
7+
#include <key_io.h>
78
#include "optionsmodel.h"
89
#include "policy/policy.h"
910
#include "policy/fees.h"
@@ -821,7 +822,7 @@ void CoinControlDialog::updateView()
821822
QString sAddress = "";
822823
if (ExtractDestination(out.tx->vout[out.i].scriptPubKey, outputAddress))
823824
{
824-
sAddress = CBitcoinAddress(outputAddress).ToString().c_str();
825+
sAddress = EncodeDestination(outputAddress).c_str();
825826

826827
// if listMode or change => show bitcoin address. In tree mode, address is not shown again for direct wallet address outputs
827828
if (!treeMode || (!(sAddress == sWalletAddress)))

src/qt/consolidateunspentwizardselectinputspage.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "init.h"
66
#include "bitcoinunits.h"
77
#include "addresstablemodel.h"
8+
#include <key_io.h>
89
#include "optionsmodel.h"
910
#include "policy/policy.h"
1011
#include "policy/fees.h"
@@ -582,7 +583,7 @@ void ConsolidateUnspentWizardSelectInputsPage::updateView()
582583
QString sAddress = "";
583584
if (ExtractDestination(out.tx->vout[out.i].scriptPubKey, outputAddress))
584585
{
585-
sAddress = CBitcoinAddress(outputAddress).ToString().c_str();
586+
sAddress = EncodeDestination(outputAddress).c_str();
586587

587588
// if listMode or change => show bitcoin address. In tree mode, address is not shown again for direct wallet address outputs
588589
if (!treeMode || (!(sAddress == sWalletAddress)))

src/qt/researcher/researcherwizardpoolpage.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Distributed under the MIT/X11 software license, see the accompanying
33
// file COPYING or https://opensource.org/licenses/mit-license.php.
44

5-
#include "base58.h"
65
#include "key.h"
6+
#include <key_io.h>
77
#include "qt/decoration.h"
88
#include "qt/forms/ui_researcherwizardpoolpage.h"
99
#include "qt/guiutil.h"
@@ -105,7 +105,7 @@ void ResearcherWizardPoolPage::getNewAddress()
105105
}
106106

107107
ui->addressLabel->setText(
108-
QString::fromStdString(CBitcoinAddress(public_key.GetID()).ToString()));
108+
QString::fromStdString(EncodeDestination(public_key.GetID())));
109109
ui->copyToClipboardButton->setVisible(true);
110110
}
111111

src/qt/sendcoinsdialog.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "init.h"
55
#include "addresstablemodel.h"
66
#include "addressbookpage.h"
7+
#include <key_io.h>
78

89
#include "bitcoinunits.h"
910
#include "optionsmodel.h"
@@ -349,8 +350,8 @@ bool SendCoinsDialog::handleURI(const QString &uri)
349350
// URI has to be valid
350351
if (GUIUtil::parseBitcoinURI(uri, &rv))
351352
{
352-
CBitcoinAddress address(rv.address.toStdString());
353-
if (!address.IsValid())
353+
CTxDestination dest = DecodeDestination(rv.address.toStdString());
354+
if (std::holds_alternative<CNoDestination>(dest))
354355
return false;
355356
pasteEntry(rv);
356357
return true;
@@ -509,7 +510,7 @@ void SendCoinsDialog::coinControlChangeChecked(int state)
509510
if (model)
510511
{
511512
if (state == Qt::Checked)
512-
coinControl->destChange = CBitcoinAddress(ui->coinControlChangeEdit->text().toStdString()).Get();
513+
coinControl->destChange = DecodeDestination(ui->coinControlChangeEdit->text().toStdString());
513514
else
514515
coinControl->destChange = CNoDestination();
515516
}
@@ -525,13 +526,13 @@ void SendCoinsDialog::coinControlChangeEdited(const QString & text)
525526
{
526527
if (model)
527528
{
528-
coinControl->destChange = CBitcoinAddress(text.toStdString()).Get();
529+
coinControl->destChange = DecodeDestination(text.toStdString());
529530

530531
// label for the change address
531532
ui->coinControlChangeAddressLabel->setStyleSheet(QString());
532533
if (text.isEmpty())
533534
ui->coinControlChangeAddressLabel->setText(QString());
534-
else if (!CBitcoinAddress(text.toStdString()).IsValid())
535+
else if (std::holds_alternative<CNoDestination>(coinControl->destChange))
535536
{
536537
ui->coinControlChangeAddressLabel->setStyleSheet("QLabel{color:red;}");
537538
ui->coinControlChangeAddressLabel->setText(tr("WARNING: Invalid Gridcoin address"));

src/qt/transactiondesc.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
#include "guiutil.h"
44
#include "gridcoin/tx_message.h"
55
#include "bitcoinunits.h"
6+
#include <key_io.h>
67
#include "main.h"
78
#include "wallet/wallet.h"
89
#include "txdb.h"
910
#include "node/ui_interface.h"
10-
#include "base58.h"
1111
#include "bitcoingui.h"
1212
#include "util.h"
1313

@@ -71,7 +71,7 @@ std::string PubKeyToGRCAddress(const CScript& scriptPubKey)
7171
std::string grcaddress = "";
7272

7373
for (auto const& addr : addresses)
74-
grcaddress = CBitcoinAddress(addr).ToString();
74+
grcaddress = EncodeDestination(addr);
7575

7676
return grcaddress;
7777
}
@@ -177,7 +177,7 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, unsigned int vo
177177
{
178178
strHTML += "<b>" + tr("From") + ":</b> " + tr("unknown") + "<br>";
179179
strHTML += "<b>" + tr("To") + ":</b> ";
180-
strHTML += GUIUtil::HtmlEscape(CBitcoinAddress(address).ToString());
180+
strHTML += GUIUtil::HtmlEscape(EncodeDestination(address));
181181

182182
if (!wallet->mapAddressBook[address].empty())
183183
strHTML += " (" + tr("own address") + ", " + tr("label") + ": " + GUIUtil::HtmlEscape(wallet->mapAddressBook[address]) + ")";
@@ -203,7 +203,7 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, unsigned int vo
203203

204204
strHTML += "<b>" + tr("To") + ":</b> ";
205205

206-
CTxDestination dest = CBitcoinAddress(strAddress).Get();
206+
CTxDestination dest = DecodeDestination(strAddress);
207207

208208
if (wallet->mapAddressBook.count(dest) && !wallet->mapAddressBook[dest].empty())
209209
strHTML += GUIUtil::HtmlEscape(wallet->mapAddressBook[dest]) + " ";
@@ -269,7 +269,7 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, unsigned int vo
269269
if (wallet->mapAddressBook.count(address) && !wallet->mapAddressBook[address].empty())
270270
strHTML += GUIUtil::HtmlEscape(wallet->mapAddressBook[address]) + " ";
271271

272-
strHTML += GUIUtil::HtmlEscape(CBitcoinAddress(address).ToString());
272+
strHTML += GUIUtil::HtmlEscape(EncodeDestination(address));
273273
strHTML += "<br>";
274274
}
275275
}
@@ -395,7 +395,7 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, unsigned int vo
395395
CTxDestination address;
396396

397397
if (ExtractDestination(vout.scriptPubKey, address))
398-
strHTML += QString::fromStdString(CBitcoinAddress(address).ToString());
398+
strHTML += QString::fromStdString(EncodeDestination(address));
399399

400400
strHTML += " " + tr("Amount") + "=" + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, vout.nValue);
401401
strHTML += " IsMine=" + ((wallet->IsMine(vout) != ISMINE_NO) ? tr("true") : tr("false")) + "</li>";

0 commit comments

Comments
 (0)