Use CBitcoinAddress wrappers in Zcash-specific code

This commit is contained in:
Jack Grigg
2018-04-20 15:09:23 +01:00
parent 07444da1db
commit b6be3e88bb
12 changed files with 78 additions and 80 deletions

View File

@@ -502,10 +502,10 @@ std::string CChainParams::GetFoundersRewardAddressAtHeight(int nHeight) const {
CScript CChainParams::GetFoundersRewardScriptAtHeight(int nHeight) const { CScript CChainParams::GetFoundersRewardScriptAtHeight(int nHeight) const {
assert(nHeight > 0 && nHeight <= consensus.GetLastFoundersRewardBlockHeight()); assert(nHeight > 0 && nHeight <= consensus.GetLastFoundersRewardBlockHeight());
CBitcoinAddress address(GetFoundersRewardAddressAtHeight(nHeight).c_str()); CTxDestination address = DecodeDestination(GetFoundersRewardAddressAtHeight(nHeight).c_str());
assert(address.IsValid()); assert(IsValidDestination(address));
assert(address.IsScript()); assert(boost::get<CScriptID>(&address) != nullptr);
CScriptID scriptID = boost::get<CScriptID>(address.Get()); // Get() returns a boost variant CScriptID scriptID = boost::get<CScriptID>(address); // address is a boost variant
CScript script = CScript() << OP_HASH160 << ToByteVector(scriptID) << OP_EQUAL; CScript script = CScript() << OP_HASH160 << ToByteVector(scriptID) << OP_EQUAL;
return script; return script;
} }

View File

@@ -59,7 +59,7 @@ TEST(founders_reward_test, create_testnet_2of3multisig) {
pWallet->AddCScript(result); pWallet->AddCScript(result);
pWallet->SetAddressBook(innerID, "", "receive"); pWallet->SetAddressBook(innerID, "", "receive");
std::string address = CBitcoinAddress(innerID).ToString(); std::string address = EncodeDestination(innerID);
addresses.push_back(address); addresses.push_back(address);
} }

View File

@@ -1079,8 +1079,8 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
#ifdef ENABLE_MINING #ifdef ENABLE_MINING
if (mapArgs.count("-mineraddress")) { if (mapArgs.count("-mineraddress")) {
CBitcoinAddress addr; CTxDestination addr = DecodeDestination(mapArgs["-mineraddress"]);
if (!addr.SetString(mapArgs["-mineraddress"])) { if (!IsValidDestination(addr)) {
return InitError(strprintf( return InitError(strprintf(
_("Invalid address for -mineraddress=<addr>: '%s' (must be a transparent address)"), _("Invalid address for -mineraddress=<addr>: '%s' (must be a transparent address)"),
mapArgs["-mineraddress"])); mapArgs["-mineraddress"]));
@@ -1717,9 +1717,8 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
bool minerAddressInLocalWallet = false; bool minerAddressInLocalWallet = false;
if (pwalletMain) { if (pwalletMain) {
// Address has alreday been validated // Address has alreday been validated
CBitcoinAddress addr(mapArgs["-mineraddress"]); CTxDestination addr = DecodeDestination(mapArgs["-mineraddress"]);
CKeyID keyID; CKeyID keyID = boost::get<CKeyID>(addr);
addr.GetKeyID(keyID);
minerAddressInLocalWallet = pwalletMain->HaveKey(keyID); minerAddressInLocalWallet = pwalletMain->HaveKey(keyID);
} }
if (GetBoolArg("-minetolocalwallet", true) && !minerAddressInLocalWallet) { if (GetBoolArg("-minetolocalwallet", true) && !minerAddressInLocalWallet) {

View File

@@ -395,9 +395,9 @@ boost::optional<CScript> GetMinerScriptPubKey()
#endif #endif
{ {
CKeyID keyID; CKeyID keyID;
CBitcoinAddress addr; CTxDestination addr = DecodeDestination(GetArg("-mineraddress", ""));
if (addr.SetString(GetArg("-mineraddress", ""))) { if (IsValidDestination(addr)) {
addr.GetKeyID(keyID); keyID = boost::get<CKeyID>(addr);
} else { } else {
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
CPubKey pubkey; CPubKey pubkey;

View File

@@ -55,7 +55,7 @@ void dumpKeyInfo(uint256 privkey)
key.SetSecret(secret, fCompressed); key.SetSecret(secret, fCompressed);
vector<unsigned char> vchPubKey = key.GetPubKey(); vector<unsigned char> vchPubKey = key.GetPubKey();
printf(" * pubkey (hex): %s\n", HexStr(vchPubKey).c_str()); printf(" * pubkey (hex): %s\n", HexStr(vchPubKey).c_str());
printf(" * address (base58): %s\n", CBitcoinAddress(vchPubKey).ToString().c_str()); printf(" * address (base58): %s\n", EncodeDestination(vchPubKey).c_str());
} }
} }
#endif #endif

View File

@@ -68,18 +68,18 @@ BOOST_AUTO_TEST_CASE(rpc_addmultisig)
const char address2Hex[] = "0388c2037017c62240b6b72ac1a2a5f94da790596ebd06177c8572752922165cb4"; const char address2Hex[] = "0388c2037017c62240b6b72ac1a2a5f94da790596ebd06177c8572752922165cb4";
UniValue v; UniValue v;
CBitcoinAddress address; CTxDestination address;
BOOST_CHECK_NO_THROW(v = addmultisig(createArgs(1, address1Hex), false)); BOOST_CHECK_NO_THROW(v = addmultisig(createArgs(1, address1Hex), false));
address.SetString(v.get_str()); address = DecodeDestination(v.get_str());
BOOST_CHECK(address.IsValid() && address.IsScript()); BOOST_CHECK(IsValidDestination(address) && boost::get<CScriptID>(&address) != nullptr);
BOOST_CHECK_NO_THROW(v = addmultisig(createArgs(1, address1Hex, address2Hex), false)); BOOST_CHECK_NO_THROW(v = addmultisig(createArgs(1, address1Hex, address2Hex), false));
address.SetString(v.get_str()); address = DecodeDestination(v.get_str());
BOOST_CHECK(address.IsValid() && address.IsScript()); BOOST_CHECK(IsValidDestination(address) && boost::get<CScriptID>(&address) != nullptr);
BOOST_CHECK_NO_THROW(v = addmultisig(createArgs(2, address1Hex, address2Hex), false)); BOOST_CHECK_NO_THROW(v = addmultisig(createArgs(2, address1Hex, address2Hex), false));
address.SetString(v.get_str()); address = DecodeDestination(v.get_str());
BOOST_CHECK(address.IsValid() && address.IsScript()); BOOST_CHECK(IsValidDestination(address) && boost::get<CScriptID>(&address) != nullptr);
BOOST_CHECK_THROW(addmultisig(createArgs(0), false), runtime_error); BOOST_CHECK_THROW(addmultisig(createArgs(0), false), runtime_error);
BOOST_CHECK_THROW(addmultisig(createArgs(1), false), runtime_error); BOOST_CHECK_THROW(addmultisig(createArgs(1), false), runtime_error);
@@ -103,7 +103,7 @@ BOOST_AUTO_TEST_CASE(rpc_wallet)
LOCK2(cs_main, pwalletMain->cs_wallet); LOCK2(cs_main, pwalletMain->cs_wallet);
CPubKey demoPubkey = pwalletMain->GenerateNewKey(); CPubKey demoPubkey = pwalletMain->GenerateNewKey();
CBitcoinAddress demoAddress = CBitcoinAddress(CTxDestination(demoPubkey.GetID())); CTxDestination demoAddress(CTxDestination(demoPubkey.GetID()));
UniValue retValue; UniValue retValue;
string strAccount = ""; string strAccount = "";
string strPurpose = "receive"; string strPurpose = "receive";
@@ -116,14 +116,14 @@ BOOST_AUTO_TEST_CASE(rpc_wallet)
}); });
CPubKey setaccountDemoPubkey = pwalletMain->GenerateNewKey(); CPubKey setaccountDemoPubkey = pwalletMain->GenerateNewKey();
CBitcoinAddress setaccountDemoAddress = CBitcoinAddress(CTxDestination(setaccountDemoPubkey.GetID())); CTxDestination setaccountDemoAddress(CTxDestination(setaccountDemoPubkey.GetID()));
/********************************* /*********************************
* setaccount * setaccount
*********************************/ *********************************/
BOOST_CHECK_NO_THROW(CallRPC("setaccount " + setaccountDemoAddress.ToString() + " \"\"")); BOOST_CHECK_NO_THROW(CallRPC("setaccount " + EncodeDestination(setaccountDemoAddress) + " \"\""));
/* Accounts are disabled */ /* Accounts are disabled */
BOOST_CHECK_THROW(CallRPC("setaccount " + setaccountDemoAddress.ToString() + " nullaccount"), runtime_error); BOOST_CHECK_THROW(CallRPC("setaccount " + EncodeDestination(setaccountDemoAddress) + " nullaccount"), runtime_error);
/* t1VtArtnn1dGPiD2WFfMXYXW5mHM3q1GpgV is not owned by the test wallet. */ /* t1VtArtnn1dGPiD2WFfMXYXW5mHM3q1GpgV is not owned by the test wallet. */
BOOST_CHECK_THROW(CallRPC("setaccount t1VtArtnn1dGPiD2WFfMXYXW5mHM3q1GpgV nullaccount"), runtime_error); BOOST_CHECK_THROW(CallRPC("setaccount t1VtArtnn1dGPiD2WFfMXYXW5mHM3q1GpgV nullaccount"), runtime_error);
BOOST_CHECK_THROW(CallRPC("setaccount"), runtime_error); BOOST_CHECK_THROW(CallRPC("setaccount"), runtime_error);
@@ -135,7 +135,7 @@ BOOST_AUTO_TEST_CASE(rpc_wallet)
* getbalance * getbalance
*********************************/ *********************************/
BOOST_CHECK_NO_THROW(CallRPC("getbalance")); BOOST_CHECK_NO_THROW(CallRPC("getbalance"));
BOOST_CHECK_THROW(CallRPC("getbalance " + demoAddress.ToString()), runtime_error); BOOST_CHECK_THROW(CallRPC("getbalance " + EncodeDestination(demoAddress)), runtime_error);
/********************************* /*********************************
* listunspent * listunspent
@@ -177,10 +177,10 @@ BOOST_AUTO_TEST_CASE(rpc_wallet)
* listtransactions * listtransactions
*********************************/ *********************************/
BOOST_CHECK_NO_THROW(CallRPC("listtransactions")); BOOST_CHECK_NO_THROW(CallRPC("listtransactions"));
BOOST_CHECK_NO_THROW(CallRPC("listtransactions " + demoAddress.ToString())); BOOST_CHECK_NO_THROW(CallRPC("listtransactions " + EncodeDestination(demoAddress)));
BOOST_CHECK_NO_THROW(CallRPC("listtransactions " + demoAddress.ToString() + " 20")); BOOST_CHECK_NO_THROW(CallRPC("listtransactions " + EncodeDestination(demoAddress) + " 20"));
BOOST_CHECK_NO_THROW(CallRPC("listtransactions " + demoAddress.ToString() + " 20 0")); BOOST_CHECK_NO_THROW(CallRPC("listtransactions " + EncodeDestination(demoAddress) + " 20 0"));
BOOST_CHECK_THROW(CallRPC("listtransactions " + demoAddress.ToString() + " not_int"), runtime_error); BOOST_CHECK_THROW(CallRPC("listtransactions " + EncodeDestination(demoAddress) + " not_int"), runtime_error);
/********************************* /*********************************
* listlockunspent * listlockunspent
@@ -217,33 +217,33 @@ BOOST_AUTO_TEST_CASE(rpc_wallet)
/* Accounts are deprecated */ /* Accounts are deprecated */
BOOST_CHECK_THROW(CallRPC("getaccountaddress accountThatDoesntExists"), runtime_error); BOOST_CHECK_THROW(CallRPC("getaccountaddress accountThatDoesntExists"), runtime_error);
BOOST_CHECK_NO_THROW(retValue = CallRPC("getaccountaddress " + strAccount)); BOOST_CHECK_NO_THROW(retValue = CallRPC("getaccountaddress " + strAccount));
BOOST_CHECK(CBitcoinAddress(retValue.get_str()).Get() == demoAddress.Get()); BOOST_CHECK(DecodeDestination(retValue.get_str()) == demoAddress);
/********************************* /*********************************
* getaccount * getaccount
*********************************/ *********************************/
BOOST_CHECK_THROW(CallRPC("getaccount"), runtime_error); BOOST_CHECK_THROW(CallRPC("getaccount"), runtime_error);
BOOST_CHECK_NO_THROW(CallRPC("getaccount " + demoAddress.ToString())); BOOST_CHECK_NO_THROW(CallRPC("getaccount " + EncodeDestination(demoAddress)));
/********************************* /*********************************
* signmessage + verifymessage * signmessage + verifymessage
*********************************/ *********************************/
BOOST_CHECK_NO_THROW(retValue = CallRPC("signmessage " + demoAddress.ToString() + " mymessage")); BOOST_CHECK_NO_THROW(retValue = CallRPC("signmessage " + EncodeDestination(demoAddress) + " mymessage"));
BOOST_CHECK_THROW(CallRPC("signmessage"), runtime_error); BOOST_CHECK_THROW(CallRPC("signmessage"), runtime_error);
/* Should throw error because this address is not loaded in the wallet */ /* Should throw error because this address is not loaded in the wallet */
BOOST_CHECK_THROW(CallRPC("signmessage t1h8SqgtM3QM5e2M8EzhhT1yL2PXXtA6oqe mymessage"), runtime_error); BOOST_CHECK_THROW(CallRPC("signmessage t1h8SqgtM3QM5e2M8EzhhT1yL2PXXtA6oqe mymessage"), runtime_error);
/* missing arguments */ /* missing arguments */
BOOST_CHECK_THROW(CallRPC("verifymessage " + demoAddress.ToString()), runtime_error); BOOST_CHECK_THROW(CallRPC("verifymessage " + EncodeDestination(demoAddress)), runtime_error);
BOOST_CHECK_THROW(CallRPC("verifymessage " + demoAddress.ToString() + " " + retValue.get_str()), runtime_error); BOOST_CHECK_THROW(CallRPC("verifymessage " + EncodeDestination(demoAddress) + " " + retValue.get_str()), runtime_error);
/* Illegal address */ /* Illegal address */
BOOST_CHECK_THROW(CallRPC("verifymessage t1VtArtnn1dGPiD2WFfMXYXW5mHM3q1Gpg " + retValue.get_str() + " mymessage"), runtime_error); BOOST_CHECK_THROW(CallRPC("verifymessage t1VtArtnn1dGPiD2WFfMXYXW5mHM3q1Gpg " + retValue.get_str() + " mymessage"), runtime_error);
/* wrong address */ /* wrong address */
BOOST_CHECK(CallRPC("verifymessage t1VtArtnn1dGPiD2WFfMXYXW5mHM3q1GpgV " + retValue.get_str() + " mymessage").get_bool() == false); BOOST_CHECK(CallRPC("verifymessage t1VtArtnn1dGPiD2WFfMXYXW5mHM3q1GpgV " + retValue.get_str() + " mymessage").get_bool() == false);
/* Correct address and signature but wrong message */ /* Correct address and signature but wrong message */
BOOST_CHECK(CallRPC("verifymessage " + demoAddress.ToString() + " " + retValue.get_str() + " wrongmessage").get_bool() == false); BOOST_CHECK(CallRPC("verifymessage " + EncodeDestination(demoAddress) + " " + retValue.get_str() + " wrongmessage").get_bool() == false);
/* Correct address, message and signature*/ /* Correct address, message and signature*/
BOOST_CHECK(CallRPC("verifymessage " + demoAddress.ToString() + " " + retValue.get_str() + " mymessage").get_bool() == true); BOOST_CHECK(CallRPC("verifymessage " + EncodeDestination(demoAddress) + " " + retValue.get_str() + " mymessage").get_bool() == true);
/********************************* /*********************************
* getaddressesbyaccount * getaddressesbyaccount
@@ -254,7 +254,7 @@ BOOST_AUTO_TEST_CASE(rpc_wallet)
BOOST_CHECK_EQUAL(4, arr.size()); BOOST_CHECK_EQUAL(4, arr.size());
bool notFound = true; bool notFound = true;
for (auto a : arr.getValues()) { for (auto a : arr.getValues()) {
notFound &= CBitcoinAddress(a.get_str()).Get() != demoAddress.Get(); notFound &= DecodeDestination(a.get_str()) != demoAddress;
} }
BOOST_CHECK(!notFound); BOOST_CHECK(!notFound);

View File

@@ -73,8 +73,8 @@ AsyncRPCOperation_mergetoaddress::AsyncRPCOperation_mergetoaddress(
throw JSONRPCError(RPC_INVALID_PARAMETER, "Recipient parameter missing"); throw JSONRPCError(RPC_INVALID_PARAMETER, "Recipient parameter missing");
} }
toTaddr_ = CBitcoinAddress(std::get<0>(recipient)); toTaddr_ = DecodeDestination(std::get<0>(recipient));
isToTaddr_ = toTaddr_.IsValid(); isToTaddr_ = IsValidDestination(toTaddr_);
isToZaddr_ = false; isToZaddr_ = false;
if (!isToTaddr_) { if (!isToTaddr_) {
@@ -246,7 +246,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl()
rawTx.vin.push_back(in); rawTx.vin.push_back(in);
} }
if (isToTaddr_) { if (isToTaddr_) {
CScript scriptPubKey = GetScriptForDestination(toTaddr_.Get()); CScript scriptPubKey = GetScriptForDestination(toTaddr_);
CTxOut out(sendAmount, scriptPubKey); CTxOut out(sendAmount, scriptPubKey);
rawTx.vout.push_back(out); rawTx.vout.push_back(out);
} }

View File

@@ -86,7 +86,7 @@ private:
MergeToAddressRecipient recipient_; MergeToAddressRecipient recipient_;
bool isToTaddr_; bool isToTaddr_;
bool isToZaddr_; bool isToZaddr_;
CBitcoinAddress toTaddr_; CTxDestination toTaddr_;
PaymentAddress toPaymentAddress_; PaymentAddress toPaymentAddress_;
uint256 joinSplitPubKey_; uint256 joinSplitPubKey_;

View File

@@ -74,8 +74,8 @@ AsyncRPCOperation_sendmany::AsyncRPCOperation_sendmany(
throw JSONRPCError(RPC_INVALID_PARAMETER, "No recipients"); throw JSONRPCError(RPC_INVALID_PARAMETER, "No recipients");
} }
fromtaddr_ = CBitcoinAddress(fromAddress); fromtaddr_ = DecodeDestination(fromAddress);
isfromtaddr_ = fromtaddr_.IsValid(); isfromtaddr_ = IsValidDestination(fromtaddr_);
isfromzaddr_ = false; isfromzaddr_ = false;
if (!isfromtaddr_) { if (!isfromtaddr_) {
@@ -829,7 +829,8 @@ void AsyncRPCOperation_sendmany::sign_send_raw_transaction(UniValue obj)
bool AsyncRPCOperation_sendmany::find_utxos(bool fAcceptCoinbase=false) { bool AsyncRPCOperation_sendmany::find_utxos(bool fAcceptCoinbase=false) {
set<CBitcoinAddress> setAddress = {fromtaddr_}; std::set<CTxDestination> destinations;
destinations.insert(fromtaddr_);
vector<COutput> vecOutputs; vector<COutput> vecOutputs;
LOCK2(cs_main, pwalletMain->cs_wallet); LOCK2(cs_main, pwalletMain->cs_wallet);
@@ -845,13 +846,13 @@ bool AsyncRPCOperation_sendmany::find_utxos(bool fAcceptCoinbase=false) {
continue; continue;
} }
if (setAddress.size()) { if (destinations.size()) {
CTxDestination address; CTxDestination address;
if (!ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) { if (!ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) {
continue; continue;
} }
if (!setAddress.count(address)) { if (!destinations.count(address)) {
continue; continue;
} }
} }
@@ -1101,12 +1102,12 @@ void AsyncRPCOperation_sendmany::add_taddr_outputs_to_tx() {
std::string outputAddress = std::get<0>(r); std::string outputAddress = std::get<0>(r);
CAmount nAmount = std::get<1>(r); CAmount nAmount = std::get<1>(r);
CBitcoinAddress address(outputAddress); CTxDestination address = DecodeDestination(outputAddress);
if (!address.IsValid()) { if (!IsValidDestination(address)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid output address, not a valid taddr."); throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid output address, not a valid taddr.");
} }
CScript scriptPubKey = GetScriptForDestination(address.Get()); CScript scriptPubKey = GetScriptForDestination(address);
CTxOut out(nAmount, scriptPubKey); CTxOut out(nAmount, scriptPubKey);
rawTx.vout.push_back(out); rawTx.vout.push_back(out);

View File

@@ -79,7 +79,7 @@ private:
std::string fromaddress_; std::string fromaddress_;
bool isfromtaddr_; bool isfromtaddr_;
bool isfromzaddr_; bool isfromzaddr_;
CBitcoinAddress fromtaddr_; CTxDestination fromtaddr_;
PaymentAddress frompaymentaddress_; PaymentAddress frompaymentaddress_;
SpendingKey spendingkey_; SpendingKey spendingkey_;

View File

@@ -129,7 +129,7 @@ UniValue importprivkey(const UniValue& params, bool fHelp)
// Don't throw error in case a key is already there // Don't throw error in case a key is already there
if (pwalletMain->HaveKey(vchAddress)) { if (pwalletMain->HaveKey(vchAddress)) {
return CBitcoinAddress(vchAddress).ToString(); return EncodeDestination(vchAddress);
} }
pwalletMain->mapKeyMetadata[vchAddress].nCreateTime = 1; pwalletMain->mapKeyMetadata[vchAddress].nCreateTime = 1;
@@ -145,7 +145,7 @@ UniValue importprivkey(const UniValue& params, bool fHelp)
} }
} }
return CBitcoinAddress(vchAddress).ToString(); return EncodeDestination(vchAddress);
} }
UniValue importaddress(const UniValue& params, bool fHelp) UniValue importaddress(const UniValue& params, bool fHelp)

View File

@@ -3138,16 +3138,16 @@ UniValue z_listaddresses(const UniValue& params, bool fHelp)
} }
CAmount getBalanceTaddr(std::string transparentAddress, int minDepth=1, bool ignoreUnspendable=true) { CAmount getBalanceTaddr(std::string transparentAddress, int minDepth=1, bool ignoreUnspendable=true) {
set<CBitcoinAddress> setAddress; std::set<CTxDestination> destinations;
vector<COutput> vecOutputs; vector<COutput> vecOutputs;
CAmount balance = 0; CAmount balance = 0;
if (transparentAddress.length() > 0) { if (transparentAddress.length() > 0) {
CBitcoinAddress taddr = CBitcoinAddress(transparentAddress); CTxDestination taddr = DecodeDestination(transparentAddress);
if (!taddr.IsValid()) { if (!IsValidDestination(taddr)) {
throw std::runtime_error("invalid transparent address"); throw std::runtime_error("invalid transparent address");
} }
setAddress.insert(taddr); destinations.insert(taddr);
} }
LOCK2(cs_main, pwalletMain->cs_wallet); LOCK2(cs_main, pwalletMain->cs_wallet);
@@ -3163,13 +3163,13 @@ CAmount getBalanceTaddr(std::string transparentAddress, int minDepth=1, bool ign
continue; continue;
} }
if (setAddress.size()) { if (destinations.size()) {
CTxDestination address; CTxDestination address;
if (!ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) { if (!ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) {
continue; continue;
} }
if (!setAddress.count(address)) { if (!destinations.count(address)) {
continue; continue;
} }
} }
@@ -3297,8 +3297,8 @@ UniValue z_getbalance(const UniValue& params, bool fHelp)
// Check that the from address is valid. // Check that the from address is valid.
auto fromaddress = params[0].get_str(); auto fromaddress = params[0].get_str();
bool fromTaddr = false; bool fromTaddr = false;
CBitcoinAddress taddr(fromaddress); CTxDestination taddr = DecodeDestination(fromaddress);
fromTaddr = taddr.IsValid(); fromTaddr = IsValidDestination(taddr);
libzcash::PaymentAddress zaddr; libzcash::PaymentAddress zaddr;
if (!fromTaddr) { if (!fromTaddr) {
CZCPaymentAddress address(fromaddress); CZCPaymentAddress address(fromaddress);
@@ -3531,8 +3531,8 @@ UniValue z_sendmany(const UniValue& params, bool fHelp)
// Check that the from address is valid. // Check that the from address is valid.
auto fromaddress = params[0].get_str(); auto fromaddress = params[0].get_str();
bool fromTaddr = false; bool fromTaddr = false;
CBitcoinAddress taddr(fromaddress); CTxDestination taddr = DecodeDestination(fromaddress);
fromTaddr = taddr.IsValid(); fromTaddr = IsValidDestination(taddr);
libzcash::PaymentAddress zaddr; libzcash::PaymentAddress zaddr;
if (!fromTaddr) { if (!fromTaddr) {
CZCPaymentAddress address(fromaddress); CZCPaymentAddress address(fromaddress);
@@ -3577,8 +3577,8 @@ UniValue z_sendmany(const UniValue& params, bool fHelp)
string address = find_value(o, "address").get_str(); string address = find_value(o, "address").get_str();
bool isZaddr = false; bool isZaddr = false;
CBitcoinAddress taddr(address); CTxDestination taddr = DecodeDestination(address);
if (!taddr.IsValid()) { if (!IsValidDestination(taddr)) {
try { try {
CZCPaymentAddress zaddr(address); CZCPaymentAddress zaddr(address);
zaddr.Get(); zaddr.Get();
@@ -3752,10 +3752,10 @@ UniValue z_shieldcoinbase(const UniValue& params, bool fHelp)
// Validate the from address // Validate the from address
auto fromaddress = params[0].get_str(); auto fromaddress = params[0].get_str();
bool isFromWildcard = fromaddress == "*"; bool isFromWildcard = fromaddress == "*";
CBitcoinAddress taddr; CTxDestination taddr;
if (!isFromWildcard) { if (!isFromWildcard) {
taddr = CBitcoinAddress(fromaddress); taddr = DecodeDestination(fromaddress);
if (!taddr.IsValid()) { if (!IsValidDestination(taddr)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid from address, should be a taddr or \"*\"."); throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid from address, should be a taddr or \"*\".");
} }
} }
@@ -3800,9 +3800,9 @@ UniValue z_shieldcoinbase(const UniValue& params, bool fHelp)
size_t mempoolLimit = (nLimit != 0) ? nLimit : (overwinterActive ? 0 : (size_t)GetArg("-mempooltxinputlimit", 0)); size_t mempoolLimit = (nLimit != 0) ? nLimit : (overwinterActive ? 0 : (size_t)GetArg("-mempooltxinputlimit", 0));
// Set of addresses to filter utxos by // Set of addresses to filter utxos by
set<CBitcoinAddress> setAddress = {}; std::set<CTxDestination> destinations = {};
if (!isFromWildcard) { if (!isFromWildcard) {
setAddress.insert(taddr); destinations.insert(taddr);
} }
// Get available utxos // Get available utxos
@@ -3820,7 +3820,7 @@ UniValue z_shieldcoinbase(const UniValue& params, bool fHelp)
continue; continue;
} }
// If taddr is not wildcard "*", filter utxos // If taddr is not wildcard "*", filter utxos
if (setAddress.size()>0 && !setAddress.count(address)) { if (destinations.size() > 0 && !destinations.count(address)) {
continue; continue;
} }
@@ -3832,8 +3832,7 @@ UniValue z_shieldcoinbase(const UniValue& params, bool fHelp)
CAmount nValue = out.tx->vout[out.i].nValue; CAmount nValue = out.tx->vout[out.i].nValue;
if (!maxedOutFlag) { if (!maxedOutFlag) {
CBitcoinAddress ba(address); size_t increase = (boost::get<CScriptID>(&address) != nullptr) ? CTXIN_SPEND_P2SH_SIZE : CTXIN_SPEND_DUST_SIZE;
size_t increase = (ba.IsScript()) ? CTXIN_SPEND_P2SH_SIZE : CTXIN_SPEND_DUST_SIZE;
if (estimatedTxSize + increase >= MAX_TX_SIZE || if (estimatedTxSize + increase >= MAX_TX_SIZE ||
(mempoolLimit > 0 && utxoCounter > mempoolLimit)) (mempoolLimit > 0 && utxoCounter > mempoolLimit))
{ {
@@ -3976,7 +3975,7 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp)
bool useAny = false; bool useAny = false;
bool useAnyUTXO = false; bool useAnyUTXO = false;
bool useAnyNote = false; bool useAnyNote = false;
std::set<CBitcoinAddress> taddrs = {}; std::set<CTxDestination> taddrs = {};
std::set<libzcash::PaymentAddress> zaddrs = {}; std::set<libzcash::PaymentAddress> zaddrs = {};
UniValue addresses = params[0].get_array(); UniValue addresses = params[0].get_array();
@@ -3999,8 +3998,8 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp)
} else if (address == "ANY_ZADDR") { } else if (address == "ANY_ZADDR") {
useAnyNote = true; useAnyNote = true;
} else { } else {
CBitcoinAddress taddr(address); CTxDestination taddr = DecodeDestination(address);
if (taddr.IsValid()) { if (IsValidDestination(taddr)) {
// Ignore any listed t-addrs if we are using all of them // Ignore any listed t-addrs if we are using all of them
if (!(useAny || useAnyUTXO)) { if (!(useAny || useAnyUTXO)) {
taddrs.insert(taddr); taddrs.insert(taddr);
@@ -4028,8 +4027,8 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp)
// Validate the destination address // Validate the destination address
auto destaddress = params[1].get_str(); auto destaddress = params[1].get_str();
bool isToZaddr = false; bool isToZaddr = false;
CBitcoinAddress taddr(destaddress); CTxDestination taddr = DecodeDestination(destaddress);
if (!taddr.IsValid()) { if (!IsValidDestination(taddr)) {
try { try {
CZCPaymentAddress zaddr(destaddress); CZCPaymentAddress zaddr(destaddress);
zaddr.Get(); zaddr.Get();
@@ -4125,8 +4124,7 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp)
CAmount nValue = out.tx->vout[out.i].nValue; CAmount nValue = out.tx->vout[out.i].nValue;
if (!maxedOutUTXOsFlag) { if (!maxedOutUTXOsFlag) {
CBitcoinAddress ba(address); size_t increase = (boost::get<CScriptID>(&address) != nullptr) ? CTXIN_SPEND_P2SH_SIZE : CTXIN_SPEND_DUST_SIZE;
size_t increase = (ba.IsScript()) ? CTXIN_SPEND_P2SH_SIZE : CTXIN_SPEND_DUST_SIZE;
if (estimatedTxSize + increase >= MAX_TX_SIZE || if (estimatedTxSize + increase >= MAX_TX_SIZE ||
(mempoolLimit > 0 && utxoCounter > mempoolLimit)) (mempoolLimit > 0 && utxoCounter > mempoolLimit))
{ {