diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp --- a/src/bitcoin-tx.cpp +++ b/src/bitcoin-tx.cpp @@ -266,7 +266,8 @@ } static void MutateTxAddOutAddr(CMutableTransaction &tx, - const std::string &strInput) { + const std::string &strInput, + const CChainParams &chainParams) { // Separate into VALUE:ADDRESS std::vector vStrInputParts; boost::split(vStrInputParts, strInput, boost::is_any_of(":")); @@ -280,7 +281,7 @@ // extract and validate ADDRESS std::string strAddr = vStrInputParts[1]; - CTxDestination destination = DecodeDestination(strAddr); + CTxDestination destination = DecodeDestination(strAddr, chainParams); if (!IsValidDestination(destination)) { throw std::runtime_error("invalid TX output address"); } @@ -714,7 +715,8 @@ }; static void MutateTx(CMutableTransaction &tx, const std::string &command, - const std::string &commandVal) { + const std::string &commandVal, + const CChainParams &chainParams) { std::unique_ptr ecc; if (command == "nversion") { @@ -728,7 +730,7 @@ } else if (command == "delout") { MutateTxDelOutput(tx, commandVal); } else if (command == "outaddr") { - MutateTxAddOutAddr(tx, commandVal); + MutateTxAddOutAddr(tx, commandVal, chainParams); } else if (command == "outpubkey") { MutateTxAddOutPubKey(tx, commandVal); } else if (command == "outmultisig") { @@ -804,7 +806,8 @@ return ret; } -static int CommandLineRawTx(int argc, char *argv[]) { +static int CommandLineRawTx(int argc, char *argv[], + const CChainParams &chainParams) { std::string strPrint; int nRet = 0; try { @@ -851,7 +854,7 @@ value = arg.substr(eqpos + 1); } - MutateTx(tx, key, value); + MutateTx(tx, key, value, chainParams); } OutputTx(CTransaction(tx)); @@ -890,7 +893,7 @@ int ret = EXIT_FAILURE; try { - ret = CommandLineRawTx(argc, argv); + ret = CommandLineRawTx(argc, argv, Params()); } catch (const std::exception &e) { PrintExceptionContinue(&e, "CommandLineRawTx()"); } catch (...) { diff --git a/src/dstencode.h b/src/dstencode.h --- a/src/dstencode.h +++ b/src/dstencode.h @@ -19,7 +19,6 @@ // Temporary workaround. Don't rely on global state, pass all parameters in new // code. std::string EncodeDestination(const CTxDestination &); -CTxDestination DecodeDestination(const std::string &addr); bool IsValidDestinationString(const std::string &addr); #endif // BITCOIN_DSTENCODE_H diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h --- a/src/qt/guiutil.h +++ b/src/qt/guiutil.h @@ -64,7 +64,8 @@ QString formatBitcoinURI(const Config &config, const SendCoinsRecipient &info); // Returns true if given address+amount meets "dust" definition -bool isDust(const QString &address, const Amount amount); +bool isDust(const QString &address, const Amount amount, + const CChainParams &chainParams); // HTML escaping for rich text controls QString HtmlEscape(const QString &str, bool fMultiLine = false); diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -303,8 +303,9 @@ return ret; } -bool isDust(const QString &address, const Amount amount) { - CTxDestination dest = DecodeDestination(address.toStdString()); +bool isDust(const QString &address, const Amount amount, + const CChainParams &chainParams) { + CTxDestination dest = DecodeDestination(address.toStdString(), chainParams); CScript script = GetScriptForDestination(dest); CTxOut txOut(amount, script); return txOut.IsDust(dustRelayFee); diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp --- a/src/qt/sendcoinsdialog.cpp +++ b/src/qt/sendcoinsdialog.cpp @@ -673,7 +673,8 @@ // show the estimated required time for confirmation ui->confirmationTargetLabel->setText( GUIUtil::formatDurationStr( - nConfirmTarget * Params().GetConsensus().nPowTargetSpacing) + + nConfirmTarget * + model->getChainParams().GetConsensus().nPowTargetSpacing) + " / " + tr("%n block(s)", "", nConfirmTarget)); } else { payTxFee = CFeeRate(Amount(ui->customFee->value())); @@ -832,7 +833,8 @@ CoinControlDialog::coinControl->destChange = CNoDestination(); ui->labelCoinControlChangeLabel->setStyleSheet("QLabel{color:red;}"); - const CTxDestination dest = DecodeDestination(text.toStdString()); + const CTxDestination dest = + DecodeDestination(text.toStdString(), model->getChainParams()); if (text.isEmpty()) { // Nothing entered diff --git a/src/qt/sendcoinsentry.cpp b/src/qt/sendcoinsentry.cpp --- a/src/qt/sendcoinsentry.cpp +++ b/src/qt/sendcoinsentry.cpp @@ -147,7 +147,8 @@ } // Reject dust outputs: - if (retval && GUIUtil::isDust(ui->payTo->text(), ui->payAmount->value())) { + if (retval && GUIUtil::isDust(ui->payTo->text(), ui->payAmount->value(), + model->getChainParams())) { ui->payAmount->setValid(false); retval = false; } diff --git a/src/qt/signverifymessagedialog.cpp b/src/qt/signverifymessagedialog.cpp --- a/src/qt/signverifymessagedialog.cpp +++ b/src/qt/signverifymessagedialog.cpp @@ -112,8 +112,8 @@ * old signature displayed */ ui->signatureOut_SM->clear(); - CTxDestination destination = - DecodeDestination(ui->addressIn_SM->text().toStdString()); + CTxDestination destination = DecodeDestination( + ui->addressIn_SM->text().toStdString(), model->getChainParams()); if (!IsValidDestination(destination)) { ui->statusLabel_SM->setStyleSheet("QLabel { color: red; }"); ui->statusLabel_SM->setText( @@ -192,8 +192,8 @@ } void SignVerifyMessageDialog::on_verifyMessageButton_VM_clicked() { - CTxDestination destination = - DecodeDestination(ui->addressIn_VM->text().toStdString()); + CTxDestination destination = DecodeDestination( + ui->addressIn_VM->text().toStdString(), model->getChainParams()); if (!IsValidDestination(destination)) { ui->statusLabel_VM->setStyleSheet("QLabel { color: red; }"); ui->statusLabel_VM->setText( diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h --- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -5,6 +5,7 @@ #ifndef BITCOIN_QT_WALLETMODEL_H #define BITCOIN_QT_WALLETMODEL_H +#include "chainparams.h" #include "paymentrequestplus.h" #include "walletmodeltransaction.h" @@ -229,6 +230,7 @@ bool hdEnabled() const; int getDefaultConfirmTarget() const; + const CChainParams &getChainParams() const; private: CWallet *wallet; diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -683,3 +683,7 @@ int WalletModel::getDefaultConfirmTarget() const { return nTxConfirmTarget; } + +const CChainParams &WalletModel::getChainParams() const { + return wallet->chainParams; +} diff --git a/src/test/key_tests.cpp b/src/test/key_tests.cpp --- a/src/test/key_tests.cpp +++ b/src/test/key_tests.cpp @@ -102,10 +102,15 @@ BOOST_CHECK(!key2C.VerifyPubKey(pubkey2)); BOOST_CHECK(key2C.VerifyPubKey(pubkey2C)); - BOOST_CHECK(DecodeDestination(addr1) == CTxDestination(pubkey1.GetID())); - BOOST_CHECK(DecodeDestination(addr2) == CTxDestination(pubkey2.GetID())); - BOOST_CHECK(DecodeDestination(addr1C) == CTxDestination(pubkey1C.GetID())); - BOOST_CHECK(DecodeDestination(addr2C) == CTxDestination(pubkey2C.GetID())); + const CChainParams &chainParams = Params(); + BOOST_CHECK(DecodeDestination(addr1, chainParams) == + CTxDestination(pubkey1.GetID())); + BOOST_CHECK(DecodeDestination(addr2, chainParams) == + CTxDestination(pubkey2.GetID())); + BOOST_CHECK(DecodeDestination(addr1C, chainParams) == + CTxDestination(pubkey1C.GetID())); + BOOST_CHECK(DecodeDestination(addr2C, chainParams) == + CTxDestination(pubkey2C.GetID())); for (int n = 0; n < 16; n++) { std::string strMsg = strprintf("Very secret message %i: 11", n);