Introduce wrappers around CZCPaymentAddress

This patch removes the need for the intermediary Base58 type
CZCPaymentAddress, by providing {Encode,Decode}PaymentAddress
functions that directly operate on the conversion between strings
and libzcash::PaymentAddress.
This commit is contained in:
Jack Grigg
2018-04-24 15:01:45 +01:00
parent f146029b0a
commit 80ed13d545
15 changed files with 135 additions and 140 deletions

View File

@@ -363,3 +363,18 @@ template bool CZCEncoding<libzcash::SpendingKey,
template libzcash::SpendingKey CZCEncoding<libzcash::SpendingKey, template libzcash::SpendingKey CZCEncoding<libzcash::SpendingKey,
CChainParams::ZCSPENDING_KEY, CChainParams::ZCSPENDING_KEY,
libzcash::SerializedSpendingKeySize>::Get() const; libzcash::SerializedSpendingKeySize>::Get() const;
std::string EncodePaymentAddress(const libzcash::PaymentAddress& zaddr)
{
return CZCPaymentAddress(zaddr).ToString();
}
boost::optional<libzcash::PaymentAddress> DecodePaymentAddress(const std::string& str)
{
CZCPaymentAddress addr(str);
try {
return addr.Get();
} catch (const std::runtime_error&) {
return boost::none;
}
}

View File

@@ -179,4 +179,7 @@ CTxDestination DecodeDestination(const std::string& str);
bool IsValidDestinationString(const std::string& str); bool IsValidDestinationString(const std::string& str);
bool IsValidDestinationString(const std::string& str, const CChainParams& params); bool IsValidDestinationString(const std::string& str, const CChainParams& params);
std::string EncodePaymentAddress(const libzcash::PaymentAddress& zaddr);
boost::optional<libzcash::PaymentAddress> DecodePaymentAddress(const std::string& str);
#endif // BITCOIN_BASE58_H #endif // BITCOIN_BASE58_H

View File

@@ -7,7 +7,7 @@
std::string PaymentDisclosureInfo::ToString() const { std::string PaymentDisclosureInfo::ToString() const {
return strprintf("PaymentDisclosureInfo(version=%d, esk=%s, joinSplitPrivKey=<omitted>, address=%s)", return strprintf("PaymentDisclosureInfo(version=%d, esk=%s, joinSplitPrivKey=<omitted>, address=%s)",
version, esk.ToString(), CZCPaymentAddress(zaddr).ToString()); version, esk.ToString(), EncodePaymentAddress(zaddr));
} }
std::string PaymentDisclosure::ToString() const { std::string PaymentDisclosure::ToString() const {
@@ -17,7 +17,7 @@ std::string PaymentDisclosure::ToString() const {
std::string PaymentDisclosurePayload::ToString() const { std::string PaymentDisclosurePayload::ToString() const {
return strprintf("PaymentDisclosurePayload(version=%d, esk=%s, txid=%s, js=%d, n=%d, address=%s, message=%s)", return strprintf("PaymentDisclosurePayload(version=%d, esk=%s, txid=%s, js=%d, n=%d, address=%s, message=%s)",
version, esk.ToString(), txid.ToString(), js, n, CZCPaymentAddress(zaddr).ToString(), message); version, esk.ToString(), txid.ToString(), js, n, EncodePaymentAddress(zaddr), message);
} }
PaymentDisclosure::PaymentDisclosure(const uint256 &joinSplitPubKey, const PaymentDisclosureKey &key, const PaymentDisclosureInfo &info, const std::string &message) PaymentDisclosure::PaymentDisclosure(const uint256 &joinSplitPubKey, const PaymentDisclosureKey &key, const PaymentDisclosureInfo &info, const std::string &message)

View File

@@ -235,27 +235,23 @@ UniValue z_validateaddress(const UniValue& params, bool fHelp)
LOCK(cs_main); LOCK(cs_main);
#endif #endif
bool isValid = false;
bool isMine = false; bool isMine = false;
std::string payingKey, transmissionKey; std::string payingKey, transmissionKey;
string strAddress = params[0].get_str(); string strAddress = params[0].get_str();
try { auto isValid = DecodePaymentAddress(strAddress);
CZCPaymentAddress address(strAddress); if (isValid) {
libzcash::PaymentAddress addr = address.Get(); libzcash::PaymentAddress addr = *isValid;
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
isMine = pwalletMain->HaveSpendingKey(addr); isMine = pwalletMain->HaveSpendingKey(addr);
#endif #endif
payingKey = addr.a_pk.GetHex(); payingKey = addr.a_pk.GetHex();
transmissionKey = addr.pk_enc.GetHex(); transmissionKey = addr.pk_enc.GetHex();
isValid = true;
} catch (std::runtime_error e) {
// address is invalid, nop here as isValid is false.
} }
UniValue ret(UniValue::VOBJ); UniValue ret(UniValue::VOBJ);
ret.push_back(Pair("isvalid", isValid)); ret.push_back(Pair("isvalid", static_cast<bool>(isValid)));
if (isValid) if (isValid)
{ {
ret.push_back(Pair("address", strAddress)); ret.push_back(Pair("address", strAddress));

View File

@@ -203,15 +203,15 @@ BOOST_AUTO_TEST_CASE(zc_address_test)
{ {
auto addr = sk.address(); auto addr = sk.address();
CZCPaymentAddress paymentaddr(addr); std::string addr_string = EncodePaymentAddress(addr);
string addr_string = paymentaddr.ToString();
BOOST_CHECK(addr_string[0] == 'z'); BOOST_CHECK(addr_string[0] == 'z');
BOOST_CHECK(addr_string[1] == 'c'); BOOST_CHECK(addr_string[1] == 'c');
CZCPaymentAddress paymentaddr2(addr_string); auto paymentaddr2 = DecodePaymentAddress(addr_string);
BOOST_ASSERT(static_cast<bool>(paymentaddr2));
PaymentAddress addr2 = paymentaddr2.Get(); PaymentAddress addr2 = *paymentaddr2;
BOOST_CHECK(addr.a_pk == addr2.a_pk); BOOST_CHECK(addr.a_pk == addr2.a_pk);
BOOST_CHECK(addr.pk_enc == addr2.pk_enc); BOOST_CHECK(addr.pk_enc == addr2.pk_enc);
} }

View File

@@ -386,7 +386,7 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_z_exportwallet)
BOOST_CHECK(addrs.size()==0); BOOST_CHECK(addrs.size()==0);
// wallet should have one key // wallet should have one key
CZCPaymentAddress paymentAddress = pwalletMain->GenerateNewZKey(); auto addr = pwalletMain->GenerateNewZKey();
pwalletMain->GetPaymentAddresses(addrs); pwalletMain->GetPaymentAddresses(addrs);
BOOST_CHECK(addrs.size()==1); BOOST_CHECK(addrs.size()==1);
@@ -411,11 +411,10 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_z_exportwallet)
BOOST_CHECK_NO_THROW(CallRPC(string("z_exportwallet ") + tmpfilename.string())); BOOST_CHECK_NO_THROW(CallRPC(string("z_exportwallet ") + tmpfilename.string()));
auto addr = paymentAddress.Get();
libzcash::SpendingKey key; libzcash::SpendingKey key;
BOOST_CHECK(pwalletMain->GetSpendingKey(addr, key)); BOOST_CHECK(pwalletMain->GetSpendingKey(addr, key));
std::string s1 = paymentAddress.ToString(); std::string s1 = EncodePaymentAddress(addr);
std::string s2 = CZCSpendingKey(key).ToString(); std::string s2 = CZCSpendingKey(key).ToString();
// There's no way to really delete a private key so we will read in the // There's no way to really delete a private key so we will read in the
@@ -459,7 +458,7 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_z_importwallet)
// create a random key locally // create a random key locally
auto testSpendingKey = libzcash::SpendingKey::random(); auto testSpendingKey = libzcash::SpendingKey::random();
auto testPaymentAddress = testSpendingKey.address(); auto testPaymentAddress = testSpendingKey.address();
std::string testAddr = CZCPaymentAddress(testPaymentAddress).ToString(); std::string testAddr = EncodePaymentAddress(testPaymentAddress);
std::string testKey = CZCSpendingKey(testSpendingKey).ToString(); std::string testKey = CZCSpendingKey(testSpendingKey).ToString();
// create test data using the random key // create test data using the random key
@@ -498,8 +497,7 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_z_importwallet)
BOOST_CHECK(addrs.size()==1); BOOST_CHECK(addrs.size()==1);
// check that we have the spending key for the address // check that we have the spending key for the address
CZCPaymentAddress address(testAddr); auto addr = *DecodePaymentAddress(testAddr);
auto addr = address.Get();
BOOST_CHECK(pwalletMain->HaveSpendingKey(addr)); BOOST_CHECK(pwalletMain->HaveSpendingKey(addr));
// Verify the spending key is the same as the test data // Verify the spending key is the same as the test data
@@ -546,7 +544,7 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_z_importexport)
// create a random key locally // create a random key locally
auto testSpendingKey = libzcash::SpendingKey::random(); auto testSpendingKey = libzcash::SpendingKey::random();
auto testPaymentAddress = testSpendingKey.address(); auto testPaymentAddress = testSpendingKey.address();
std::string testAddr = CZCPaymentAddress(testPaymentAddress).ToString(); std::string testAddr = EncodePaymentAddress(testPaymentAddress);
std::string testKey = CZCSpendingKey(testSpendingKey).ToString(); std::string testKey = CZCSpendingKey(testSpendingKey).ToString();
BOOST_CHECK_NO_THROW(CallRPC(string("z_importkey ") + testKey)); BOOST_CHECK_NO_THROW(CallRPC(string("z_importkey ") + testKey));
BOOST_CHECK_NO_THROW(retValue = CallRPC(string("z_exportkey ") + testAddr)); BOOST_CHECK_NO_THROW(retValue = CallRPC(string("z_exportkey ") + testAddr));
@@ -566,7 +564,7 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_z_importexport)
// Make new addresses for the set // Make new addresses for the set
for (int i=0; i<n2; i++) { for (int i=0; i<n2; i++) {
myaddrs.insert((pwalletMain->GenerateNewZKey()).ToString()); myaddrs.insert(EncodePaymentAddress(pwalletMain->GenerateNewZKey()));
} }
// Verify number of addresses stored in wallet is n1+n2 // Verify number of addresses stored in wallet is n1+n2
@@ -593,8 +591,7 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_z_importexport)
// Add one more address // Add one more address
BOOST_CHECK_NO_THROW(retValue = CallRPC("z_getnewaddress")); BOOST_CHECK_NO_THROW(retValue = CallRPC("z_getnewaddress"));
std::string newaddress = retValue.get_str(); std::string newaddress = retValue.get_str();
CZCPaymentAddress pa(newaddress); auto newAddr = *DecodePaymentAddress(newaddress);
auto newAddr = pa.Get();
BOOST_CHECK(pwalletMain->HaveSpendingKey(newAddr)); BOOST_CHECK(pwalletMain->HaveSpendingKey(newAddr));
// Check if too many args // Check if too many args
@@ -916,8 +913,8 @@ BOOST_AUTO_TEST_CASE(rpc_z_sendmany_parameters)
std::vector<char> v (2 * (ZC_MEMO_SIZE+1)); // x2 for hexadecimal string format std::vector<char> v (2 * (ZC_MEMO_SIZE+1)); // x2 for hexadecimal string format
std::fill(v.begin(),v.end(), 'A'); std::fill(v.begin(),v.end(), 'A');
std::string badmemo(v.begin(), v.end()); std::string badmemo(v.begin(), v.end());
CZCPaymentAddress pa = pwalletMain->GenerateNewZKey(); auto pa = pwalletMain->GenerateNewZKey();
std::string zaddr1 = pa.ToString(); std::string zaddr1 = EncodePaymentAddress(pa);
BOOST_CHECK_THROW(CallRPC(string("z_sendmany tmRr6yJonqGK23UVhrKuyvTpF8qxQQjKigJ ") BOOST_CHECK_THROW(CallRPC(string("z_sendmany tmRr6yJonqGK23UVhrKuyvTpF8qxQQjKigJ ")
+ "[{\"address\":\"" + zaddr1 + "\", \"amount\":123.456}]"), runtime_error); + "[{\"address\":\"" + zaddr1 + "\", \"amount\":123.456}]"), runtime_error);
@@ -952,7 +949,7 @@ BOOST_AUTO_TEST_CASE(rpc_z_sendmany_parameters)
std::vector<SendManyRecipient> recipients = { SendManyRecipient("dummy",1.0, "") }; std::vector<SendManyRecipient> recipients = { SendManyRecipient("dummy",1.0, "") };
std::shared_ptr<AsyncRPCOperation> operation( new AsyncRPCOperation_sendmany(mtx, "INVALID", recipients, {}, 1) ); std::shared_ptr<AsyncRPCOperation> operation( new AsyncRPCOperation_sendmany(mtx, "INVALID", recipients, {}, 1) );
} catch (const UniValue& objError) { } catch (const UniValue& objError) {
BOOST_CHECK( find_error(objError, "payment address is invalid")); BOOST_CHECK( find_error(objError, "Invalid from address"));
} }
// Testnet payment addresses begin with 'zt'. This test detects an incorrect prefix. // Testnet payment addresses begin with 'zt'. This test detects an incorrect prefix.
@@ -960,7 +957,7 @@ BOOST_AUTO_TEST_CASE(rpc_z_sendmany_parameters)
std::vector<SendManyRecipient> recipients = { SendManyRecipient("dummy",1.0, "") }; std::vector<SendManyRecipient> recipients = { SendManyRecipient("dummy",1.0, "") };
std::shared_ptr<AsyncRPCOperation> operation( new AsyncRPCOperation_sendmany(mtx, "zcMuhvq8sEkHALuSU2i4NbNQxshSAYrpCExec45ZjtivYPbuiFPwk6WHy4SvsbeZ4siy1WheuRGjtaJmoD1J8bFqNXhsG6U", recipients, {}, 1) ); std::shared_ptr<AsyncRPCOperation> operation( new AsyncRPCOperation_sendmany(mtx, "zcMuhvq8sEkHALuSU2i4NbNQxshSAYrpCExec45ZjtivYPbuiFPwk6WHy4SvsbeZ4siy1WheuRGjtaJmoD1J8bFqNXhsG6U", recipients, {}, 1) );
} catch (const UniValue& objError) { } catch (const UniValue& objError) {
BOOST_CHECK( find_error(objError, "payment address is for wrong network type")); BOOST_CHECK( find_error(objError, "Invalid from address"));
} }
// Note: The following will crash as a google test because AsyncRPCOperation_sendmany // Note: The following will crash as a google test because AsyncRPCOperation_sendmany
@@ -994,8 +991,8 @@ BOOST_AUTO_TEST_CASE(rpc_z_sendmany_internals)
// add keys manually // add keys manually
BOOST_CHECK_NO_THROW(retValue = CallRPC("getnewaddress")); BOOST_CHECK_NO_THROW(retValue = CallRPC("getnewaddress"));
std::string taddr1 = retValue.get_str(); std::string taddr1 = retValue.get_str();
CZCPaymentAddress pa = pwalletMain->GenerateNewZKey(); auto pa = pwalletMain->GenerateNewZKey();
std::string zaddr1 = pa.ToString(); std::string zaddr1 = EncodePaymentAddress(pa);
// there are no utxos to spend // there are no utxos to spend
{ {
@@ -1392,7 +1389,7 @@ BOOST_AUTO_TEST_CASE(rpc_z_shieldcoinbase_parameters)
std::vector<ShieldCoinbaseUTXO> inputs = { ShieldCoinbaseUTXO{uint256(),0,0} }; std::vector<ShieldCoinbaseUTXO> inputs = { ShieldCoinbaseUTXO{uint256(),0,0} };
std::shared_ptr<AsyncRPCOperation> operation( new AsyncRPCOperation_shieldcoinbase(mtx, inputs, mainnetzaddr, 1) ); std::shared_ptr<AsyncRPCOperation> operation( new AsyncRPCOperation_shieldcoinbase(mtx, inputs, mainnetzaddr, 1) );
} catch (const UniValue& objError) { } catch (const UniValue& objError) {
BOOST_CHECK( find_error(objError, "payment address is for wrong network type")); BOOST_CHECK( find_error(objError, "Invalid to address"));
} }
} }
@@ -1417,8 +1414,8 @@ BOOST_AUTO_TEST_CASE(rpc_z_shieldcoinbase_internals)
mapArgs["-mempooltxinputlimit"] = "1"; mapArgs["-mempooltxinputlimit"] = "1";
// Add keys manually // Add keys manually
CZCPaymentAddress pa = pwalletMain->GenerateNewZKey(); auto pa = pwalletMain->GenerateNewZKey();
std::string zaddr = pa.ToString(); std::string zaddr = EncodePaymentAddress(pa);
// Supply 2 inputs when mempool limit is 1 // Supply 2 inputs when mempool limit is 1
{ {
@@ -1542,8 +1539,8 @@ BOOST_AUTO_TEST_CASE(rpc_z_mergetoaddress_parameters)
std::vector<char> v (2 * (ZC_MEMO_SIZE+1)); // x2 for hexadecimal string format std::vector<char> v (2 * (ZC_MEMO_SIZE+1)); // x2 for hexadecimal string format
std::fill(v.begin(),v.end(), 'A'); std::fill(v.begin(),v.end(), 'A');
std::string badmemo(v.begin(), v.end()); std::string badmemo(v.begin(), v.end());
CZCPaymentAddress pa = pwalletMain->GenerateNewZKey(); auto pa = pwalletMain->GenerateNewZKey();
std::string zaddr1 = pa.ToString(); std::string zaddr1 = EncodePaymentAddress(pa);
BOOST_CHECK_THROW(CallRPC(string("z_mergetoaddress [\"tmRr6yJonqGK23UVhrKuyvTpF8qxQQjKigJ\"] ") BOOST_CHECK_THROW(CallRPC(string("z_mergetoaddress [\"tmRr6yJonqGK23UVhrKuyvTpF8qxQQjKigJ\"] ")
+ zaddr1 + " 0.0001 100 100 " + badmemo), runtime_error); + zaddr1 + " 0.0001 100 100 " + badmemo), runtime_error);
@@ -1590,7 +1587,7 @@ BOOST_AUTO_TEST_CASE(rpc_z_mergetoaddress_parameters)
std::shared_ptr<AsyncRPCOperation> operation( new AsyncRPCOperation_mergetoaddress(mtx, inputs, {}, mainnetzaddr, 1) ); std::shared_ptr<AsyncRPCOperation> operation( new AsyncRPCOperation_mergetoaddress(mtx, inputs, {}, mainnetzaddr, 1) );
BOOST_FAIL("Should have caused an error"); BOOST_FAIL("Should have caused an error");
} catch (const UniValue& objError) { } catch (const UniValue& objError) {
BOOST_CHECK( find_error(objError, "payment address is for wrong network type")); BOOST_CHECK( find_error(objError, "Invalid recipient address"));
} }
} }
@@ -1613,8 +1610,8 @@ BOOST_AUTO_TEST_CASE(rpc_z_mergetoaddress_internals)
// Add keys manually // Add keys manually
BOOST_CHECK_NO_THROW(retValue = CallRPC("getnewaddress")); BOOST_CHECK_NO_THROW(retValue = CallRPC("getnewaddress"));
MergeToAddressRecipient taddr1(retValue.get_str(), ""); MergeToAddressRecipient taddr1(retValue.get_str(), "");
CZCPaymentAddress pa = pwalletMain->GenerateNewZKey(); auto pa = pwalletMain->GenerateNewZKey();
MergeToAddressRecipient zaddr1(pa.ToString(), "DEADBEEF"); MergeToAddressRecipient zaddr1(EncodePaymentAddress(pa), "DEADBEEF");
// Supply 2 inputs when mempool limit is 1 // Supply 2 inputs when mempool limit is 1
{ {

View File

@@ -78,14 +78,12 @@ AsyncRPCOperation_mergetoaddress::AsyncRPCOperation_mergetoaddress(
isToZaddr_ = false; isToZaddr_ = false;
if (!isToTaddr_) { if (!isToTaddr_) {
CZCPaymentAddress address(std::get<0>(recipient)); auto address = DecodePaymentAddress(std::get<0>(recipient));
try { if (address) {
PaymentAddress addr = address.Get();
isToZaddr_ = true; isToZaddr_ = true;
toPaymentAddress_ = addr; toPaymentAddress_ = *address;
} catch (const std::runtime_error& e) { } else {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, string("runtime error: ") + e.what()); throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid recipient address");
} }
} }
@@ -857,8 +855,7 @@ UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit(
PaymentDisclosureInfo pdInfo = {PAYMENT_DISCLOSURE_VERSION_EXPERIMENTAL, esk, joinSplitPrivKey, zaddr}; PaymentDisclosureInfo pdInfo = {PAYMENT_DISCLOSURE_VERSION_EXPERIMENTAL, esk, joinSplitPrivKey, zaddr};
paymentDisclosureData_.push_back(PaymentDisclosureKeyInfo(pdKey, pdInfo)); paymentDisclosureData_.push_back(PaymentDisclosureKeyInfo(pdKey, pdInfo));
CZCPaymentAddress address(zaddr); LogPrint("paymentdisclosure", "%s: Payment Disclosure: js=%d, n=%d, zaddr=%s\n", getId(), js_index, int(mapped_index), EncodePaymentAddress(zaddr));
LogPrint("paymentdisclosure", "%s: Payment Disclosure: js=%d, n=%d, zaddr=%s\n", getId(), js_index, int(mapped_index), address.ToString());
} }
// !!! Payment disclosure END // !!! Payment disclosure END

View File

@@ -79,9 +79,9 @@ AsyncRPCOperation_sendmany::AsyncRPCOperation_sendmany(
isfromzaddr_ = false; isfromzaddr_ = false;
if (!isfromtaddr_) { if (!isfromtaddr_) {
CZCPaymentAddress address(fromAddress); auto address = DecodePaymentAddress(fromAddress);
try { if (address) {
PaymentAddress addr = address.Get(); PaymentAddress addr = *address;
// We don't need to lock on the wallet as spending key related methods are thread-safe // We don't need to lock on the wallet as spending key related methods are thread-safe
SpendingKey key; SpendingKey key;
@@ -92,8 +92,8 @@ AsyncRPCOperation_sendmany::AsyncRPCOperation_sendmany(
isfromzaddr_ = true; isfromzaddr_ = true;
frompaymentaddress_ = addr; frompaymentaddress_ = addr;
spendingkey_ = key; spendingkey_ = key;
} catch (const std::runtime_error& e) { } else {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, string("runtime error: ") + e.what()); throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid from address");
} }
} }
@@ -467,7 +467,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
std::string hexMemo = std::get<2>(smr); std::string hexMemo = std::get<2>(smr);
zOutputsDeque.pop_front(); zOutputsDeque.pop_front();
PaymentAddress pa = CZCPaymentAddress(address).Get(); PaymentAddress pa = *DecodePaymentAddress(address);
JSOutput jso = JSOutput(pa, value); JSOutput jso = JSOutput(pa, value);
if (hexMemo.size() > 0) { if (hexMemo.size() > 0) {
jso.memo = get_memo_from_hex_string(hexMemo); jso.memo = get_memo_from_hex_string(hexMemo);
@@ -726,7 +726,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
assert(value==0); assert(value==0);
info.vjsout.push_back(JSOutput()); // dummy output while we accumulate funds into a change note for vpub_new info.vjsout.push_back(JSOutput()); // dummy output while we accumulate funds into a change note for vpub_new
} else { } else {
PaymentAddress pa = CZCPaymentAddress(address).Get(); PaymentAddress pa = *DecodePaymentAddress(address);
JSOutput jso = JSOutput(pa, value); JSOutput jso = JSOutput(pa, value);
if (hexMemo.size() > 0) { if (hexMemo.size() > 0) {
jso.memo = get_memo_from_hex_string(hexMemo); jso.memo = get_memo_from_hex_string(hexMemo);
@@ -1080,8 +1080,7 @@ UniValue AsyncRPCOperation_sendmany::perform_joinsplit(
PaymentDisclosureInfo pdInfo = {PAYMENT_DISCLOSURE_VERSION_EXPERIMENTAL, esk, joinSplitPrivKey, zaddr}; PaymentDisclosureInfo pdInfo = {PAYMENT_DISCLOSURE_VERSION_EXPERIMENTAL, esk, joinSplitPrivKey, zaddr};
paymentDisclosureData_.push_back(PaymentDisclosureKeyInfo(pdKey, pdInfo)); paymentDisclosureData_.push_back(PaymentDisclosureKeyInfo(pdKey, pdInfo));
CZCPaymentAddress address(zaddr); LogPrint("paymentdisclosure", "%s: Payment Disclosure: js=%d, n=%d, zaddr=%s\n", getId(), js_index, int(mapped_index), EncodePaymentAddress(zaddr));
LogPrint("paymentdisclosure", "%s: Payment Disclosure: js=%d, n=%d, zaddr=%s\n", getId(), js_index, int(mapped_index), address.ToString());
} }
// !!! Payment disclosure END // !!! Payment disclosure END

View File

@@ -71,11 +71,11 @@ AsyncRPCOperation_shieldcoinbase::AsyncRPCOperation_shieldcoinbase(
} }
// Check the destination address is valid for this network i.e. not testnet being used on mainnet // Check the destination address is valid for this network i.e. not testnet being used on mainnet
CZCPaymentAddress address(toAddress); auto address = DecodePaymentAddress(toAddress);
try { if (address) {
tozaddr_ = address.Get(); tozaddr_ = *address;
} catch (const std::runtime_error& e) { } else {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, string("runtime error: ") + e.what()); throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid to address");
} }
// Log the context info // Log the context info
@@ -451,8 +451,7 @@ UniValue AsyncRPCOperation_shieldcoinbase::perform_joinsplit(ShieldCoinbaseJSInf
PaymentDisclosureInfo pdInfo = {PAYMENT_DISCLOSURE_VERSION_EXPERIMENTAL, esk, joinSplitPrivKey, zaddr}; PaymentDisclosureInfo pdInfo = {PAYMENT_DISCLOSURE_VERSION_EXPERIMENTAL, esk, joinSplitPrivKey, zaddr};
paymentDisclosureData_.push_back(PaymentDisclosureKeyInfo(pdKey, pdInfo)); paymentDisclosureData_.push_back(PaymentDisclosureKeyInfo(pdKey, pdInfo));
CZCPaymentAddress address(zaddr); LogPrint("paymentdisclosure", "%s: Payment Disclosure: js=%d, n=%d, zaddr=%s\n", getId(), js_index, int(mapped_index), EncodePaymentAddress(zaddr));
LogPrint("paymentdisclosure", "%s: Payment Disclosure: js=%d, n=%d, zaddr=%s\n", getId(), js_index, int(mapped_index), address.ToString());
} }
// !!! Payment disclosure END // !!! Payment disclosure END

View File

@@ -25,12 +25,11 @@ TEST(wallet_zkeys_tests, store_and_load_zkeys) {
ASSERT_EQ(0, addrs.size()); ASSERT_EQ(0, addrs.size());
// wallet should have one key // wallet should have one key
CZCPaymentAddress paymentAddress = wallet.GenerateNewZKey(); auto addr = wallet.GenerateNewZKey();
wallet.GetPaymentAddresses(addrs); wallet.GetPaymentAddresses(addrs);
ASSERT_EQ(1, addrs.size()); ASSERT_EQ(1, addrs.size());
// verify wallet has spending key for the address // verify wallet has spending key for the address
auto addr = paymentAddress.Get();
ASSERT_TRUE(wallet.HaveSpendingKey(addr)); ASSERT_TRUE(wallet.HaveSpendingKey(addr));
// manually add new spending key to wallet // manually add new spending key to wallet
@@ -289,22 +288,22 @@ TEST(wallet_zkeys_tests, write_cryptedzkey_direct_to_db) {
ASSERT_EQ(2, addrs.size()); ASSERT_EQ(2, addrs.size());
// check we have entries for our payment addresses // check we have entries for our payment addresses
ASSERT_TRUE(addrs.count(paymentAddress.Get())); ASSERT_TRUE(addrs.count(paymentAddress));
ASSERT_TRUE(addrs.count(paymentAddress2.Get())); ASSERT_TRUE(addrs.count(paymentAddress2));
// spending key is crypted, so we can't extract valid payment address // spending key is crypted, so we can't extract valid payment address
libzcash::SpendingKey keyOut; libzcash::SpendingKey keyOut;
wallet2.GetSpendingKey(paymentAddress.Get(), keyOut); wallet2.GetSpendingKey(paymentAddress, keyOut);
ASSERT_FALSE(paymentAddress.Get() == keyOut.address()); ASSERT_FALSE(paymentAddress == keyOut.address());
// unlock wallet to get spending keys and verify payment addresses // unlock wallet to get spending keys and verify payment addresses
wallet2.Unlock(strWalletPass); wallet2.Unlock(strWalletPass);
wallet2.GetSpendingKey(paymentAddress.Get(), keyOut); wallet2.GetSpendingKey(paymentAddress, keyOut);
ASSERT_EQ(paymentAddress.Get(), keyOut.address()); ASSERT_EQ(paymentAddress, keyOut.address());
wallet2.GetSpendingKey(paymentAddress2.Get(), keyOut); wallet2.GetSpendingKey(paymentAddress2, keyOut);
ASSERT_EQ(paymentAddress2.Get(), keyOut.address()); ASSERT_EQ(paymentAddress2, keyOut.address());
ECC_Stop(); ECC_Stop();
} }

View File

@@ -254,11 +254,8 @@ UniValue z_validatepaymentdisclosure(const UniValue& params, bool fHelp)
// Check the payment address is valid // Check the payment address is valid
PaymentAddress zaddr = pd.payload.zaddr; PaymentAddress zaddr = pd.payload.zaddr;
CZCPaymentAddress address; {
if (!address.Set(zaddr)) { o.push_back(Pair("paymentAddress", EncodePaymentAddress(zaddr)));
errs.push_back("Payment disclosure refers to an invalid payment address");
} else {
o.push_back(Pair("paymentAddress", address.ToString()));
try { try {
// Decrypt the note to get value and memo field // Decrypt the note to get value and memo field

View File

@@ -300,11 +300,11 @@ UniValue importwallet_impl(const UniValue& params, bool fHelp, bool fImportZKeys
libzcash::SpendingKey key = spendingkey.Get(); libzcash::SpendingKey key = spendingkey.Get();
libzcash::PaymentAddress addr = key.address(); libzcash::PaymentAddress addr = key.address();
if (pwalletMain->HaveSpendingKey(addr)) { if (pwalletMain->HaveSpendingKey(addr)) {
LogPrint("zrpc", "Skipping import of zaddr %s (key already present)\n", CZCPaymentAddress(addr).ToString()); LogPrint("zrpc", "Skipping import of zaddr %s (key already present)\n", EncodePaymentAddress(addr));
continue; continue;
} }
int64_t nTime = DecodeDumpTime(vstr[1]); int64_t nTime = DecodeDumpTime(vstr[1]);
LogPrint("zrpc", "Importing zaddr %s...\n", CZCPaymentAddress(addr).ToString()); LogPrint("zrpc", "Importing zaddr %s...\n", EncodePaymentAddress(addr));
if (!pwalletMain->AddZKey(key)) { if (!pwalletMain->AddZKey(key)) {
// Something went wrong // Something went wrong
fGood = false; fGood = false;
@@ -536,7 +536,7 @@ UniValue dumpwallet_impl(const UniValue& params, bool fHelp, bool fDumpZKeys)
libzcash::SpendingKey key; libzcash::SpendingKey key;
if (pwalletMain->GetSpendingKey(addr, key)) { if (pwalletMain->GetSpendingKey(addr, key)) {
std::string strTime = EncodeDumpTime(pwalletMain->mapZKeyMetadata[addr].nCreateTime); std::string strTime = EncodeDumpTime(pwalletMain->mapZKeyMetadata[addr].nCreateTime);
file << strprintf("%s %s # zaddr=%s\n", CZCSpendingKey(key).ToString(), strTime, CZCPaymentAddress(addr).ToString()); file << strprintf("%s %s # zaddr=%s\n", CZCSpendingKey(key).ToString(), strTime, EncodePaymentAddress(addr));
} }
} }
file << "\n"; file << "\n";
@@ -760,8 +760,11 @@ UniValue z_exportkey(const UniValue& params, bool fHelp)
string strAddress = params[0].get_str(); string strAddress = params[0].get_str();
CZCPaymentAddress address(strAddress); auto address = DecodePaymentAddress(strAddress);
auto addr = address.Get(); if (!address) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid zaddr");
}
auto addr = *address;
libzcash::SpendingKey k; libzcash::SpendingKey k;
if (!pwalletMain->GetSpendingKey(addr, k)) if (!pwalletMain->GetSpendingKey(addr, k))
@@ -796,8 +799,11 @@ UniValue z_exportviewingkey(const UniValue& params, bool fHelp)
string strAddress = params[0].get_str(); string strAddress = params[0].get_str();
CZCPaymentAddress address(strAddress); auto address = DecodePaymentAddress(strAddress);
auto addr = address.Get(); if (!address) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid zaddr");
}
auto addr = *address;
libzcash::ViewingKey vk; libzcash::ViewingKey vk;
if (!pwalletMain->GetViewingKey(addr, vk)) { if (!pwalletMain->GetViewingKey(addr, vk)) {

View File

@@ -2521,14 +2521,14 @@ UniValue z_listunspent(const UniValue& params, bool fHelp)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected string"); throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected string");
} }
string address = o.get_str(); string address = o.get_str();
try { auto zaddr = DecodePaymentAddress(address);
CZCPaymentAddress zaddr(address); if (zaddr) {
libzcash::PaymentAddress addr = zaddr.Get(); libzcash::PaymentAddress addr = *zaddr;
if (!fIncludeWatchonly && !pwalletMain->HaveSpendingKey(addr)) { if (!fIncludeWatchonly && !pwalletMain->HaveSpendingKey(addr)) {
throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, spending key for address does not belong to wallet: ") + address); throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, spending key for address does not belong to wallet: ") + address);
} }
zaddrs.insert(addr); zaddrs.insert(addr);
} catch (const std::runtime_error&) { } else {
throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, address is not a valid zaddr: ") + address); throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, address is not a valid zaddr: ") + address);
} }
@@ -2555,7 +2555,7 @@ UniValue z_listunspent(const UniValue& params, bool fHelp)
obj.push_back(Pair("jsoutindex", (int)entry.jsop.n)); obj.push_back(Pair("jsoutindex", (int)entry.jsop.n));
obj.push_back(Pair("confirmations", entry.nHeight)); obj.push_back(Pair("confirmations", entry.nHeight));
obj.push_back(Pair("spendable", pwalletMain->HaveSpendingKey(entry.address))); obj.push_back(Pair("spendable", pwalletMain->HaveSpendingKey(entry.address)));
obj.push_back(Pair("address", CZCPaymentAddress(entry.address).ToString())); obj.push_back(Pair("address", EncodePaymentAddress(entry.address)));
obj.push_back(Pair("amount", ValueFromAmount(CAmount(entry.plaintext.value())))); obj.push_back(Pair("amount", ValueFromAmount(CAmount(entry.plaintext.value()))));
std::string data(entry.plaintext.memo().begin(), entry.plaintext.memo().end()); std::string data(entry.plaintext.memo().begin(), entry.plaintext.memo().end());
obj.push_back(Pair("memo", HexStr(data))); obj.push_back(Pair("memo", HexStr(data)));
@@ -2945,11 +2945,13 @@ UniValue zc_raw_joinsplit(const UniValue& params, bool fHelp)
} }
for (const string& name_ : outputs.getKeys()) { for (const string& name_ : outputs.getKeys()) {
CZCPaymentAddress pubaddr(name_); auto addrTo = DecodePaymentAddress(name_);
PaymentAddress addrTo = pubaddr.Get(); if (!addrTo) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid recipient address.");
}
CAmount nAmount = AmountFromValue(outputs[name_]); CAmount nAmount = AmountFromValue(outputs[name_]);
vjsout.push_back(JSOutput(addrTo, nAmount)); vjsout.push_back(JSOutput(*addrTo, nAmount));
} }
while (vjsout.size() < ZC_NUM_JS_OUTPUTS) { while (vjsout.size() < ZC_NUM_JS_OUTPUTS) {
@@ -3059,12 +3061,11 @@ UniValue zc_raw_keygen(const UniValue& params, bool fHelp)
auto addr = k.address(); auto addr = k.address();
auto viewing_key = k.viewing_key(); auto viewing_key = k.viewing_key();
CZCPaymentAddress pubaddr(addr);
CZCSpendingKey spendingkey(k); CZCSpendingKey spendingkey(k);
CZCViewingKey viewingkey(viewing_key); CZCViewingKey viewingkey(viewing_key);
UniValue result(UniValue::VOBJ); UniValue result(UniValue::VOBJ);
result.push_back(Pair("zcaddress", pubaddr.ToString())); result.push_back(Pair("zcaddress", EncodePaymentAddress(addr)));
result.push_back(Pair("zcsecretkey", spendingkey.ToString())); result.push_back(Pair("zcsecretkey", spendingkey.ToString()));
result.push_back(Pair("zcviewingkey", viewingkey.ToString())); result.push_back(Pair("zcviewingkey", viewingkey.ToString()));
return result; return result;
@@ -3092,9 +3093,8 @@ UniValue z_getnewaddress(const UniValue& params, bool fHelp)
EnsureWalletIsUnlocked(); EnsureWalletIsUnlocked();
CZCPaymentAddress pubaddr = pwalletMain->GenerateNewZKey(); auto zaddr = pwalletMain->GenerateNewZKey();
std::string result = pubaddr.ToString(); return EncodePaymentAddress(zaddr);
return result;
} }
@@ -3131,7 +3131,7 @@ UniValue z_listaddresses(const UniValue& params, bool fHelp)
pwalletMain->GetPaymentAddresses(addresses); pwalletMain->GetPaymentAddresses(addresses);
for (auto addr : addresses ) { for (auto addr : addresses ) {
if (fIncludeWatchonly || pwalletMain->HaveSpendingKey(addr)) { if (fIncludeWatchonly || pwalletMain->HaveSpendingKey(addr)) {
ret.push_back(CZCPaymentAddress(addr).ToString()); ret.push_back(EncodePaymentAddress(addr));
} }
} }
return ret; return ret;
@@ -3228,15 +3228,12 @@ UniValue z_listreceivedbyaddress(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();
libzcash::PaymentAddress zaddr; auto zaddr = DecodePaymentAddress(fromaddress);
CZCPaymentAddress address(fromaddress); if (!zaddr) {
try {
zaddr = address.Get();
} catch (const std::runtime_error&) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid zaddr."); throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid zaddr.");
} }
if (!(pwalletMain->HaveSpendingKey(zaddr) || pwalletMain->HaveViewingKey(zaddr))) { if (!(pwalletMain->HaveSpendingKey(*zaddr) || pwalletMain->HaveViewingKey(*zaddr))) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "From address does not belong to this node, zaddr spending key or viewing key not found."); throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "From address does not belong to this node, zaddr spending key or viewing key not found.");
} }
@@ -3301,12 +3298,11 @@ UniValue z_getbalance(const UniValue& params, bool fHelp)
fromTaddr = IsValidDestination(taddr); fromTaddr = IsValidDestination(taddr);
libzcash::PaymentAddress zaddr; libzcash::PaymentAddress zaddr;
if (!fromTaddr) { if (!fromTaddr) {
CZCPaymentAddress address(fromaddress); auto res = DecodePaymentAddress(fromaddress);
try { if (!res) {
zaddr = address.Get();
} catch (const std::runtime_error&) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid from address, should be a taddr or zaddr."); throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid from address, should be a taddr or zaddr.");
} }
zaddr = *res;
if (!(pwalletMain->HaveSpendingKey(zaddr) || pwalletMain->HaveViewingKey(zaddr))) { if (!(pwalletMain->HaveSpendingKey(zaddr) || pwalletMain->HaveViewingKey(zaddr))) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "From address does not belong to this node, zaddr spending key or viewing key not found."); throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "From address does not belong to this node, zaddr spending key or viewing key not found.");
} }
@@ -3537,13 +3533,12 @@ UniValue z_sendmany(const UniValue& params, bool fHelp)
fromTaddr = IsValidDestination(taddr); fromTaddr = IsValidDestination(taddr);
libzcash::PaymentAddress zaddr; libzcash::PaymentAddress zaddr;
if (!fromTaddr) { if (!fromTaddr) {
CZCPaymentAddress address(fromaddress); auto res = DecodePaymentAddress(fromaddress);
try { if (!res) {
zaddr = address.Get();
} catch (const std::runtime_error&) {
// invalid // invalid
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid from address, should be a taddr or zaddr."); throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid from address, should be a taddr or zaddr.");
} }
zaddr = *res;
} }
// Check that we have the spending key // Check that we have the spending key
@@ -3581,11 +3576,9 @@ UniValue z_sendmany(const UniValue& params, bool fHelp)
bool isZaddr = false; bool isZaddr = false;
CTxDestination taddr = DecodeDestination(address); CTxDestination taddr = DecodeDestination(address);
if (!IsValidDestination(taddr)) { if (!IsValidDestination(taddr)) {
try { if (DecodePaymentAddress(address)) {
CZCPaymentAddress zaddr(address);
zaddr.Get();
isZaddr = true; isZaddr = true;
} catch (const std::runtime_error&) { } else {
throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, unknown address format: ")+address ); throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, unknown address format: ")+address );
} }
} }
@@ -3777,10 +3770,7 @@ UniValue z_shieldcoinbase(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();
try { if (!DecodePaymentAddress(destaddress)) {
CZCPaymentAddress pa(destaddress);
libzcash::PaymentAddress zaddr = pa.Get();
} catch (const std::runtime_error&) {
throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, unknown address format: ") + destaddress ); throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, unknown address format: ") + destaddress );
} }
@@ -4021,13 +4011,13 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp)
taddrs.insert(taddr); taddrs.insert(taddr);
} }
} else { } else {
try { auto zaddr = DecodePaymentAddress(address);
CZCPaymentAddress zaddr(address); if (zaddr) {
// Ignore listed z-addrs if we are using all of them // Ignore listed z-addrs if we are using all of them
if (!(useAny || useAnyNote)) { if (!(useAny || useAnyNote)) {
zaddrs.insert(zaddr.Get()); zaddrs.insert(*zaddr);
} }
} catch (const std::runtime_error&) { } else {
throw JSONRPCError( throw JSONRPCError(
RPC_INVALID_PARAMETER, RPC_INVALID_PARAMETER,
string("Invalid parameter, unknown address format: ") + address); string("Invalid parameter, unknown address format: ") + address);
@@ -4045,11 +4035,9 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp)
bool isToZaddr = false; bool isToZaddr = false;
CTxDestination taddr = DecodeDestination(destaddress); CTxDestination taddr = DecodeDestination(destaddress);
if (!IsValidDestination(taddr)) { if (!IsValidDestination(taddr)) {
try { if (DecodePaymentAddress(destaddress)) {
CZCPaymentAddress zaddr(destaddress);
zaddr.Get();
isToZaddr = true; isToZaddr = true;
} catch (const std::runtime_error&) { } else {
throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, unknown address format: ") + destaddress ); throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, unknown address format: ") + destaddress );
} }
} }

View File

@@ -80,7 +80,7 @@ const CWalletTx* CWallet::GetWalletTx(const uint256& hash) const
} }
// Generate a new spending key and return its public payment address // Generate a new spending key and return its public payment address
CZCPaymentAddress CWallet::GenerateNewZKey() libzcash::PaymentAddress CWallet::GenerateNewZKey()
{ {
AssertLockHeld(cs_wallet); // mapZKeyMetadata AssertLockHeld(cs_wallet); // mapZKeyMetadata
auto k = SpendingKey::random(); auto k = SpendingKey::random();
@@ -94,10 +94,9 @@ CZCPaymentAddress CWallet::GenerateNewZKey()
int64_t nCreationTime = GetTime(); int64_t nCreationTime = GetTime();
mapZKeyMetadata[addr] = CKeyMetadata(nCreationTime); mapZKeyMetadata[addr] = CKeyMetadata(nCreationTime);
CZCPaymentAddress pubaddr(addr);
if (!AddZKey(k)) if (!AddZKey(k))
throw std::runtime_error("CWallet::GenerateNewZKey(): AddZKey failed"); throw std::runtime_error("CWallet::GenerateNewZKey(): AddZKey failed");
return pubaddr; return addr;
} }
// Add spending key to keystore and persist to disk // Add spending key to keystore and persist to disk
@@ -3718,7 +3717,7 @@ void CWallet::GetFilteredNotes(std::vector<CSproutNotePlaintextEntry> & outEntri
std::set<PaymentAddress> filterAddresses; std::set<PaymentAddress> filterAddresses;
if (address.length() > 0) { if (address.length() > 0) {
filterAddresses.insert(CZCPaymentAddress(address).Get()); filterAddresses.insert(*DecodePaymentAddress(address));
} }
GetFilteredNotes(outEntries, filterAddresses, minDepth, ignoreSpent, ignoreUnspendable); GetFilteredNotes(outEntries, filterAddresses, minDepth, ignoreSpent, ignoreUnspendable);
@@ -3781,7 +3780,7 @@ void CWallet::GetFilteredNotes(
ZCNoteDecryption decryptor; ZCNoteDecryption decryptor;
if (!GetNoteDecryptor(pa, decryptor)) { if (!GetNoteDecryptor(pa, decryptor)) {
// Note decryptors are created when the wallet is loaded, so it should always exist // Note decryptors are created when the wallet is loaded, so it should always exist
throw std::runtime_error(strprintf("Could not find note decryptor for payment address %s", CZCPaymentAddress(pa).ToString())); throw std::runtime_error(strprintf("Could not find note decryptor for payment address %s", EncodePaymentAddress(pa)));
} }
// determine amount of funds in the note // determine amount of funds in the note
@@ -3798,10 +3797,10 @@ void CWallet::GetFilteredNotes(
} catch (const note_decryption_failed &err) { } catch (const note_decryption_failed &err) {
// Couldn't decrypt with this spending key // Couldn't decrypt with this spending key
throw std::runtime_error(strprintf("Could not decrypt note for payment address %s", CZCPaymentAddress(pa).ToString())); throw std::runtime_error(strprintf("Could not decrypt note for payment address %s", EncodePaymentAddress(pa)));
} catch (const std::exception &exc) { } catch (const std::exception &exc) {
// Unexpected failure // Unexpected failure
throw std::runtime_error(strprintf("Error while decrypting note for payment address %s: %s", CZCPaymentAddress(pa).ToString(), exc.what())); throw std::runtime_error(strprintf("Error while decrypting note for payment address %s: %s", EncodePaymentAddress(pa), exc.what()));
} }
} }
} }
@@ -3857,7 +3856,7 @@ void CWallet::GetUnspentFilteredNotes(
ZCNoteDecryption decryptor; ZCNoteDecryption decryptor;
if (!GetNoteDecryptor(pa, decryptor)) { if (!GetNoteDecryptor(pa, decryptor)) {
// Note decryptors are created when the wallet is loaded, so it should always exist // Note decryptors are created when the wallet is loaded, so it should always exist
throw std::runtime_error(strprintf("Could not find note decryptor for payment address %s", CZCPaymentAddress(pa).ToString())); throw std::runtime_error(strprintf("Could not find note decryptor for payment address %s", EncodePaymentAddress(pa)));
} }
// determine amount of funds in the note // determine amount of funds in the note
@@ -3874,10 +3873,10 @@ void CWallet::GetUnspentFilteredNotes(
} catch (const note_decryption_failed &err) { } catch (const note_decryption_failed &err) {
// Couldn't decrypt with this spending key // Couldn't decrypt with this spending key
throw std::runtime_error(strprintf("Could not decrypt note for payment address %s", CZCPaymentAddress(pa).ToString())); throw std::runtime_error(strprintf("Could not decrypt note for payment address %s", EncodePaymentAddress(pa)));
} catch (const std::exception &exc) { } catch (const std::exception &exc) {
// Unexpected failure // Unexpected failure
throw std::runtime_error(strprintf("Error while decrypting note for payment address %s: %s", CZCPaymentAddress(pa).ToString(), exc.what())); throw std::runtime_error(strprintf("Error while decrypting note for payment address %s: %s", EncodePaymentAddress(pa), exc.what()));
} }
} }
} }

View File

@@ -960,7 +960,7 @@ public:
* ZKeys * ZKeys
*/ */
//! Generates a new zaddr //! Generates a new zaddr
CZCPaymentAddress GenerateNewZKey(); libzcash::PaymentAddress GenerateNewZKey();
//! Adds spending key to the store, and saves it to disk //! Adds spending key to the store, and saves it to disk
bool AddZKey(const libzcash::SpendingKey &key); bool AddZKey(const libzcash::SpendingKey &key);
//! Adds spending key to the store, without saving it to disk (used by LoadWallet) //! Adds spending key to the store, without saving it to disk (used by LoadWallet)