Rename *SpendingKey -> *SproutSpendingKey

Also GetPaymentAddresses -> GetSproutPaymentAddresses
This commit is contained in:
Jack Grigg
2018-08-03 10:10:26 +01:00
parent f84cf5f817
commit 25d5e80cbe
15 changed files with 149 additions and 143 deletions

View File

@@ -89,7 +89,7 @@ AsyncRPCOperation_sendmany::AsyncRPCOperation_sendmany(
// We don't need to lock on the wallet as spending key related methods are thread-safe
SproutSpendingKey key;
if (!pwalletMain->GetSpendingKey(addr, key)) {
if (!pwalletMain->GetSproutSpendingKey(addr, key)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid from address, no spending key found for zaddr");
}

View File

@@ -330,12 +330,12 @@ bool CCryptoKeyStore::GetPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) co
return false;
}
bool CCryptoKeyStore::AddSpendingKey(const libzcash::SproutSpendingKey &sk)
bool CCryptoKeyStore::AddSproutSpendingKey(const libzcash::SproutSpendingKey &sk)
{
{
LOCK(cs_SpendingKeyStore);
if (!IsCrypted())
return CBasicKeyStore::AddSpendingKey(sk);
return CBasicKeyStore::AddSproutSpendingKey(sk);
if (IsLocked())
return false;
@@ -348,7 +348,7 @@ bool CCryptoKeyStore::AddSpendingKey(const libzcash::SproutSpendingKey &sk)
if (!EncryptSecret(vMasterKey, vchSecret, address.GetHash(), vchCryptedSecret))
return false;
if (!AddCryptedSpendingKey(address, sk.receiving_key(), vchCryptedSecret))
if (!AddCryptedSproutSpendingKey(address, sk.receiving_key(), vchCryptedSecret))
return false;
}
return true;
@@ -384,9 +384,10 @@ bool CCryptoKeyStore::AddSaplingSpendingKey(
return true;
}
bool CCryptoKeyStore::AddCryptedSpendingKey(const libzcash::SproutPaymentAddress &address,
const libzcash::ReceivingKey &rk,
const std::vector<unsigned char> &vchCryptedSecret)
bool CCryptoKeyStore::AddCryptedSproutSpendingKey(
const libzcash::SproutPaymentAddress &address,
const libzcash::ReceivingKey &rk,
const std::vector<unsigned char> &vchCryptedSecret)
{
{
LOCK(cs_SpendingKeyStore);
@@ -420,12 +421,12 @@ bool CCryptoKeyStore::AddCryptedSaplingSpendingKey(
return true;
}
bool CCryptoKeyStore::GetSpendingKey(const libzcash::SproutPaymentAddress &address, libzcash::SproutSpendingKey &skOut) const
bool CCryptoKeyStore::GetSproutSpendingKey(const libzcash::SproutPaymentAddress &address, libzcash::SproutSpendingKey &skOut) const
{
{
LOCK(cs_SpendingKeyStore);
if (!IsCrypted())
return CBasicKeyStore::GetSpendingKey(address, skOut);
return CBasicKeyStore::GetSproutSpendingKey(address, skOut);
CryptedSproutSpendingKeyMap::const_iterator mi = mapCryptedSproutSpendingKeys.find(address);
if (mi != mapCryptedSproutSpendingKeys.end())
@@ -487,7 +488,7 @@ bool CCryptoKeyStore::EncryptKeys(CKeyingMaterial& vMasterKeyIn)
if (!EncryptSecret(vMasterKeyIn, vchSecret, address.GetHash(), vchCryptedSecret)) {
return false;
}
if (!AddCryptedSpendingKey(address, sk.receiving_key(), vchCryptedSecret)) {
if (!AddCryptedSproutSpendingKey(address, sk.receiving_key(), vchCryptedSecret)) {
return false;
}
}

View File

@@ -201,26 +201,27 @@ public:
mi++;
}
}
virtual bool AddCryptedSpendingKey(const libzcash::SproutPaymentAddress &address,
const libzcash::ReceivingKey &rk,
const std::vector<unsigned char> &vchCryptedSecret);
bool AddSpendingKey(const libzcash::SproutSpendingKey &sk);
bool HaveSpendingKey(const libzcash::SproutPaymentAddress &address) const
virtual bool AddCryptedSproutSpendingKey(
const libzcash::SproutPaymentAddress &address,
const libzcash::ReceivingKey &rk,
const std::vector<unsigned char> &vchCryptedSecret);
bool AddSproutSpendingKey(const libzcash::SproutSpendingKey &sk);
bool HaveSproutSpendingKey(const libzcash::SproutPaymentAddress &address) const
{
{
LOCK(cs_SpendingKeyStore);
if (!IsCrypted())
return CBasicKeyStore::HaveSpendingKey(address);
return CBasicKeyStore::HaveSproutSpendingKey(address);
return mapCryptedSproutSpendingKeys.count(address) > 0;
}
return false;
}
bool GetSpendingKey(const libzcash::SproutPaymentAddress &address, libzcash::SproutSpendingKey &skOut) const;
void GetPaymentAddresses(std::set<libzcash::SproutPaymentAddress> &setAddress) const
bool GetSproutSpendingKey(const libzcash::SproutPaymentAddress &address, libzcash::SproutSpendingKey &skOut) const;
void GetSproutPaymentAddresses(std::set<libzcash::SproutPaymentAddress> &setAddress) const
{
if (!IsCrypted())
{
CBasicKeyStore::GetPaymentAddresses(setAddress);
CBasicKeyStore::GetSproutPaymentAddresses(setAddress);
return;
}
setAddress.clear();

View File

@@ -166,7 +166,7 @@ TEST(wallet_tests, find_unspent_notes) {
SelectParams(CBaseChainParams::TESTNET);
CWallet wallet;
auto sk = libzcash::SproutSpendingKey::random();
wallet.AddSpendingKey(sk);
wallet.AddSproutSpendingKey(sk);
auto wtx = GetValidReceive(sk, 10, true);
auto note = GetNote(sk, wtx, 0, 1);
@@ -371,7 +371,7 @@ TEST(wallet_tests, GetNoteNullifier) {
hSig, 1);
EXPECT_NE(nullifier, ret);
wallet.AddSpendingKey(sk);
wallet.AddSproutSpendingKey(sk);
ret = wallet.GetNoteNullifier(
wtx.vjoinsplit[0],
@@ -386,7 +386,7 @@ TEST(wallet_tests, FindMyNotes) {
auto sk = libzcash::SproutSpendingKey::random();
auto sk2 = libzcash::SproutSpendingKey::random();
wallet.AddSpendingKey(sk2);
wallet.AddSproutSpendingKey(sk2);
auto wtx = GetValidReceive(sk, 10, true);
auto note = GetNote(sk, wtx, 0, 1);
@@ -395,7 +395,7 @@ TEST(wallet_tests, FindMyNotes) {
auto noteMap = wallet.FindMyNotes(wtx);
EXPECT_EQ(0, noteMap.size());
wallet.AddSpendingKey(sk);
wallet.AddSproutSpendingKey(sk);
noteMap = wallet.FindMyNotes(wtx);
EXPECT_EQ(2, noteMap.size());
@@ -412,7 +412,7 @@ TEST(wallet_tests, FindMyNotesInEncryptedWallet) {
CKeyingMaterial vMasterKey (r.begin(), r.end());
auto sk = libzcash::SproutSpendingKey::random();
wallet.AddSpendingKey(sk);
wallet.AddSproutSpendingKey(sk);
ASSERT_TRUE(wallet.EncryptKeys(vMasterKey));
@@ -440,7 +440,7 @@ TEST(wallet_tests, get_conflicted_notes) {
CWallet wallet;
auto sk = libzcash::SproutSpendingKey::random();
wallet.AddSpendingKey(sk);
wallet.AddSproutSpendingKey(sk);
auto wtx = GetValidReceive(sk, 10, true);
auto note = GetNote(sk, wtx, 0, 1);
@@ -471,7 +471,7 @@ TEST(wallet_tests, nullifier_is_spent) {
CWallet wallet;
auto sk = libzcash::SproutSpendingKey::random();
wallet.AddSpendingKey(sk);
wallet.AddSproutSpendingKey(sk);
auto wtx = GetValidReceive(sk, 10, true);
auto note = GetNote(sk, wtx, 0, 1);
@@ -511,7 +511,7 @@ TEST(wallet_tests, navigate_from_nullifier_to_note) {
CWallet wallet;
auto sk = libzcash::SproutSpendingKey::random();
wallet.AddSpendingKey(sk);
wallet.AddSproutSpendingKey(sk);
auto wtx = GetValidReceive(sk, 10, true);
auto note = GetNote(sk, wtx, 0, 1);
@@ -537,7 +537,7 @@ TEST(wallet_tests, spent_note_is_from_me) {
CWallet wallet;
auto sk = libzcash::SproutSpendingKey::random();
wallet.AddSpendingKey(sk);
wallet.AddSproutSpendingKey(sk);
auto wtx = GetValidReceive(sk, 10, true);
auto note = GetNote(sk, wtx, 0, 1);
@@ -565,7 +565,7 @@ TEST(wallet_tests, cached_witnesses_empty_chain) {
TestWallet wallet;
auto sk = libzcash::SproutSpendingKey::random();
wallet.AddSpendingKey(sk);
wallet.AddSproutSpendingKey(sk);
auto wtx = GetValidReceive(sk, 10, true, 4);
auto note = GetNote(sk, wtx, 0, 0);
@@ -628,7 +628,7 @@ TEST(wallet_tests, cached_witnesses_chain_tip) {
SaplingMerkleTree saplingTree;
auto sk = libzcash::SproutSpendingKey::random();
wallet.AddSpendingKey(sk);
wallet.AddSproutSpendingKey(sk);
{
// First block (case tested in _empty_chain)
@@ -728,7 +728,7 @@ TEST(wallet_tests, CachedWitnessesDecrementFirst) {
SaplingMerkleTree saplingTree;
auto sk = libzcash::SproutSpendingKey::random();
wallet.AddSpendingKey(sk);
wallet.AddSproutSpendingKey(sk);
{
// First block (case tested in _empty_chain)
@@ -818,7 +818,7 @@ TEST(wallet_tests, CachedWitnessesCleanIndex) {
std::vector<boost::optional<SaplingWitness>> saplingWitnesses;
auto sk = libzcash::SproutSpendingKey::random();
wallet.AddSpendingKey(sk);
wallet.AddSproutSpendingKey(sk);
// Generate a chain
size_t numBlocks = WITNESS_CACHE_SIZE + 10;
@@ -893,7 +893,7 @@ TEST(wallet_tests, ClearNoteWitnessCache) {
TestWallet wallet;
auto sk = libzcash::SproutSpendingKey::random();
wallet.AddSpendingKey(sk);
wallet.AddSproutSpendingKey(sk);
auto wtx = GetValidReceive(sk, 10, true, 4);
auto hash = wtx.GetHash();
@@ -953,7 +953,7 @@ TEST(wallet_tests, WriteWitnessCache) {
CBlockLocator loc;
auto sk = libzcash::SproutSpendingKey::random();
wallet.AddSpendingKey(sk);
wallet.AddSproutSpendingKey(sk);
auto wtx = GetValidReceive(sk, 10, true);
wallet.AddToWallet(wtx, true, NULL);
@@ -1030,7 +1030,7 @@ TEST(wallet_tests, UpdateNullifierNoteMap) {
CKeyingMaterial vMasterKey (r.begin(), r.end());
auto sk = libzcash::SproutSpendingKey::random();
wallet.AddSpendingKey(sk);
wallet.AddSproutSpendingKey(sk);
ASSERT_TRUE(wallet.EncryptKeys(vMasterKey));
@@ -1063,7 +1063,7 @@ TEST(wallet_tests, UpdatedNoteData) {
TestWallet wallet;
auto sk = libzcash::SproutSpendingKey::random();
wallet.AddSpendingKey(sk);
wallet.AddSproutSpendingKey(sk);
auto wtx = GetValidReceive(sk, 10, true);
auto note = GetNote(sk, wtx, 0, 0);
@@ -1110,7 +1110,7 @@ TEST(wallet_tests, MarkAffectedTransactionsDirty) {
TestWallet wallet;
auto sk = libzcash::SproutSpendingKey::random();
wallet.AddSpendingKey(sk);
wallet.AddSproutSpendingKey(sk);
auto wtx = GetValidReceive(sk, 10, true);
auto hash = wtx.GetHash();
@@ -1141,7 +1141,7 @@ TEST(wallet_tests, NoteLocking) {
TestWallet wallet;
auto sk = libzcash::SproutSpendingKey::random();
wallet.AddSpendingKey(sk);
wallet.AddSproutSpendingKey(sk);
auto wtx = GetValidReceive(sk, 10, true);
auto wtx2 = GetValidReceive(sk, 10, true);

View File

@@ -63,18 +63,18 @@ TEST(wallet_zkeys_tests, store_and_load_zkeys) {
// wallet should be empty
std::set<libzcash::SproutPaymentAddress> addrs;
wallet.GetPaymentAddresses(addrs);
wallet.GetSproutPaymentAddresses(addrs);
ASSERT_EQ(0, addrs.size());
// wallet should have one key
auto address = wallet.GenerateNewZKey();
ASSERT_NE(boost::get<libzcash::SproutPaymentAddress>(&address), nullptr);
auto addr = boost::get<libzcash::SproutPaymentAddress>(address);
wallet.GetPaymentAddresses(addrs);
wallet.GetSproutPaymentAddresses(addrs);
ASSERT_EQ(1, addrs.size());
// verify wallet has spending key for the address
ASSERT_TRUE(wallet.HaveSpendingKey(addr));
ASSERT_TRUE(wallet.HaveSproutSpendingKey(addr));
// manually add new spending key to wallet
auto sk = libzcash::SproutSpendingKey::random();
@@ -82,15 +82,15 @@ TEST(wallet_zkeys_tests, store_and_load_zkeys) {
// verify wallet did add it
addr = sk.address();
ASSERT_TRUE(wallet.HaveSpendingKey(addr));
ASSERT_TRUE(wallet.HaveSproutSpendingKey(addr));
// verify spending key stored correctly
libzcash::SproutSpendingKey keyOut;
wallet.GetSpendingKey(addr, keyOut);
wallet.GetSproutSpendingKey(addr, keyOut);
ASSERT_EQ(sk, keyOut);
// verify there are two keys
wallet.GetPaymentAddresses(addrs);
wallet.GetSproutPaymentAddresses(addrs);
ASSERT_EQ(2, addrs.size());
ASSERT_EQ(1, addrs.count(addr));
@@ -122,7 +122,7 @@ TEST(wallet_zkeys_tests, StoreAndLoadViewingKeys) {
// wallet should be empty
std::set<libzcash::SproutPaymentAddress> addrs;
wallet.GetPaymentAddresses(addrs);
wallet.GetSproutPaymentAddresses(addrs);
ASSERT_EQ(0, addrs.size());
// manually add new viewing key to wallet
@@ -134,7 +134,7 @@ TEST(wallet_zkeys_tests, StoreAndLoadViewingKeys) {
auto addr = sk.address();
ASSERT_TRUE(wallet.HaveSproutViewingKey(addr));
// and that we don't have the corresponding spending key
ASSERT_FALSE(wallet.HaveSpendingKey(addr));
ASSERT_FALSE(wallet.HaveSproutSpendingKey(addr));
// verify viewing key stored correctly
libzcash::SproutViewingKey vkOut;
@@ -148,7 +148,7 @@ TEST(wallet_zkeys_tests, StoreAndLoadViewingKeys) {
// verify wallet did add it
auto addr2 = sk2.address();
ASSERT_TRUE(wallet.HaveSproutViewingKey(addr2));
ASSERT_FALSE(wallet.HaveSpendingKey(addr2));
ASSERT_FALSE(wallet.HaveSproutSpendingKey(addr2));
// Remove the first viewing key
ASSERT_TRUE(wallet.RemoveSproutViewingKey(vk));
@@ -178,14 +178,14 @@ TEST(wallet_zkeys_tests, write_zkey_direct_to_db) {
// wallet should be empty
std::set<libzcash::SproutPaymentAddress> addrs;
wallet.GetPaymentAddresses(addrs);
wallet.GetSproutPaymentAddresses(addrs);
ASSERT_EQ(0, addrs.size());
// Add random key to the wallet
auto paymentAddress = wallet.GenerateNewZKey();
// wallet should have one key
wallet.GetPaymentAddresses(addrs);
wallet.GetSproutPaymentAddresses(addrs);
ASSERT_EQ(1, addrs.size());
// create random key and add it to database directly, bypassing wallet
@@ -197,10 +197,10 @@ TEST(wallet_zkeys_tests, write_zkey_direct_to_db) {
db.WriteZKey(addr, sk, meta);
// wallet should not be aware of key
ASSERT_FALSE(wallet.HaveSpendingKey(addr));
ASSERT_FALSE(wallet.HaveSproutSpendingKey(addr));
// wallet sees one key
wallet.GetPaymentAddresses(addrs);
wallet.GetSproutPaymentAddresses(addrs);
ASSERT_EQ(1, addrs.size());
// wallet should have default metadata for addr with null createtime
@@ -212,15 +212,15 @@ TEST(wallet_zkeys_tests, write_zkey_direct_to_db) {
ASSERT_EQ(DB_LOAD_OK, wallet.LoadWallet(fFirstRun));
// wallet can now see the spending key
ASSERT_TRUE(wallet.HaveSpendingKey(addr));
ASSERT_TRUE(wallet.HaveSproutSpendingKey(addr));
// check key is the same
libzcash::SproutSpendingKey keyOut;
wallet.GetSpendingKey(addr, keyOut);
wallet.GetSproutSpendingKey(addr, keyOut);
ASSERT_EQ(sk, keyOut);
// wallet should have two keys
wallet.GetPaymentAddresses(addrs);
wallet.GetSproutPaymentAddresses(addrs);
ASSERT_EQ(2, addrs.size());
// check metadata is now the same
@@ -295,7 +295,7 @@ TEST(wallet_zkeys_tests, write_cryptedzkey_direct_to_db) {
// wallet should be empty
std::set<libzcash::SproutPaymentAddress> addrs;
wallet.GetPaymentAddresses(addrs);
wallet.GetSproutPaymentAddresses(addrs);
ASSERT_EQ(0, addrs.size());
// Add random key to the wallet
@@ -304,7 +304,7 @@ TEST(wallet_zkeys_tests, write_cryptedzkey_direct_to_db) {
auto paymentAddress = boost::get<libzcash::SproutPaymentAddress>(address);
// wallet should have one key
wallet.GetPaymentAddresses(addrs);
wallet.GetSproutPaymentAddresses(addrs);
ASSERT_EQ(1, addrs.size());
// encrypt wallet
@@ -330,7 +330,7 @@ TEST(wallet_zkeys_tests, write_cryptedzkey_direct_to_db) {
ASSERT_TRUE(&wallet != &wallet2);
// wallet should have two keys
wallet2.GetPaymentAddresses(addrs);
wallet2.GetSproutPaymentAddresses(addrs);
ASSERT_EQ(2, addrs.size());
// check we have entries for our payment addresses
@@ -339,16 +339,16 @@ TEST(wallet_zkeys_tests, write_cryptedzkey_direct_to_db) {
// spending key is crypted, so we can't extract valid payment address
libzcash::SproutSpendingKey keyOut;
wallet2.GetSpendingKey(paymentAddress, keyOut);
wallet2.GetSproutSpendingKey(paymentAddress, keyOut);
ASSERT_FALSE(paymentAddress == keyOut.address());
// unlock wallet to get spending keys and verify payment addresses
wallet2.Unlock(strWalletPass);
wallet2.GetSpendingKey(paymentAddress, keyOut);
wallet2.GetSproutSpendingKey(paymentAddress, keyOut);
ASSERT_EQ(paymentAddress, keyOut.address());
wallet2.GetSpendingKey(paymentAddress2, keyOut);
wallet2.GetSproutSpendingKey(paymentAddress2, keyOut);
ASSERT_EQ(paymentAddress2, keyOut.address());
}

View File

@@ -302,7 +302,7 @@ UniValue importwallet_impl(const UniValue& params, bool fHelp, bool fImportZKeys
assert(boost::get<libzcash::SproutSpendingKey>(&spendingkey) != nullptr);
auto key = boost::get<libzcash::SproutSpendingKey>(spendingkey);
auto addr = key.address();
if (pwalletMain->HaveSpendingKey(addr)) {
if (pwalletMain->HaveSproutSpendingKey(addr)) {
LogPrint("zrpc", "Skipping import of zaddr %s (key already present)\n", EncodePaymentAddress(addr));
continue;
}
@@ -530,13 +530,13 @@ UniValue dumpwallet_impl(const UniValue& params, bool fHelp, bool fDumpZKeys)
if (fDumpZKeys) {
std::set<libzcash::SproutPaymentAddress> addresses;
pwalletMain->GetPaymentAddresses(addresses);
pwalletMain->GetSproutPaymentAddresses(addresses);
file << "\n";
file << "# Zkeys\n";
file << "\n";
for (auto addr : addresses ) {
libzcash::SproutSpendingKey key;
if (pwalletMain->GetSpendingKey(addr, key)) {
if (pwalletMain->GetSproutSpendingKey(addr, key)) {
std::string strTime = EncodeDumpTime(pwalletMain->mapZKeyMetadata[addr].nCreateTime);
file << strprintf("%s %s # zaddr=%s\n", EncodeSpendingKey(key), strTime, EncodePaymentAddress(addr));
}
@@ -560,7 +560,7 @@ public:
bool operator()(const libzcash::SproutSpendingKey &sk) const {
auto addr = sk.address();
// Don't throw error in case a key is already there
if (m_wallet->HaveSpendingKey(addr)) {
if (m_wallet->HaveSproutSpendingKey(addr)) {
return true;
} else {
m_wallet->MarkDirty();
@@ -758,7 +758,7 @@ UniValue z_importviewingkey(const UniValue& params, bool fHelp)
auto addr = vkey.address();
{
if (pwalletMain->HaveSpendingKey(addr)) {
if (pwalletMain->HaveSproutSpendingKey(addr)) {
throw JSONRPCError(RPC_WALLET_ERROR, "The wallet already contains the private key for this viewing key");
}
@@ -794,7 +794,7 @@ public:
libzcash::SpendingKey operator()(const libzcash::SproutPaymentAddress &zaddr) const
{
libzcash::SproutSpendingKey k;
if (!pwalletMain->GetSpendingKey(zaddr, k)) {
if (!pwalletMain->GetSproutSpendingKey(zaddr, k)) {
throw JSONRPCError(RPC_WALLET_ERROR, "Wallet does not hold private zkey for this zaddr");
}
return k;
@@ -891,7 +891,7 @@ UniValue z_exportviewingkey(const UniValue& params, bool fHelp)
libzcash::SproutViewingKey vk;
if (!pwalletMain->GetSproutViewingKey(addr, vk)) {
libzcash::SproutSpendingKey k;
if (!pwalletMain->GetSpendingKey(addr, k)) {
if (!pwalletMain->GetSproutSpendingKey(addr, k)) {
throw JSONRPCError(RPC_WALLET_ERROR, "Wallet does not hold private key or viewing key for this zaddr");
}
vk = k.viewing_key();

View File

@@ -2531,7 +2531,7 @@ UniValue z_listunspent(const UniValue& params, bool fHelp)
// TODO: Add Sapling support. For now, ensure we can freely convert.
assert(boost::get<libzcash::SproutPaymentAddress>(&zaddr) != nullptr);
libzcash::SproutPaymentAddress addr = boost::get<libzcash::SproutPaymentAddress>(zaddr);
if (!fIncludeWatchonly && !pwalletMain->HaveSpendingKey(addr)) {
if (!fIncludeWatchonly && !pwalletMain->HaveSproutSpendingKey(addr)) {
throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, spending key for address does not belong to wallet: ") + address);
}
zaddrs.insert(addr);
@@ -2549,7 +2549,7 @@ UniValue z_listunspent(const UniValue& params, bool fHelp)
// User did not provide zaddrs, so use default i.e. all addresses
// TODO: Add Sapling support
std::set<libzcash::SproutPaymentAddress> sproutzaddrs = {};
pwalletMain->GetPaymentAddresses(sproutzaddrs);
pwalletMain->GetSproutPaymentAddresses(sproutzaddrs);
zaddrs.insert(sproutzaddrs.begin(), sproutzaddrs.end());
}
@@ -2565,7 +2565,7 @@ UniValue z_listunspent(const UniValue& params, bool fHelp)
obj.push_back(Pair("jsindex", (int)entry.jsop.js ));
obj.push_back(Pair("jsoutindex", (int)entry.jsop.n));
obj.push_back(Pair("confirmations", entry.nHeight));
obj.push_back(Pair("spendable", pwalletMain->HaveSpendingKey(boost::get<libzcash::SproutPaymentAddress>(entry.address))));
obj.push_back(Pair("spendable", pwalletMain->HaveSproutSpendingKey(boost::get<libzcash::SproutPaymentAddress>(entry.address))));
obj.push_back(Pair("address", EncodePaymentAddress(entry.address)));
obj.push_back(Pair("amount", ValueFromAmount(CAmount(entry.plaintext.value()))));
std::string data(entry.plaintext.memo().begin(), entry.plaintext.memo().end());
@@ -3171,9 +3171,9 @@ UniValue z_listaddresses(const UniValue& params, bool fHelp)
UniValue ret(UniValue::VARR);
{
std::set<libzcash::SproutPaymentAddress> addresses;
pwalletMain->GetPaymentAddresses(addresses);
pwalletMain->GetSproutPaymentAddresses(addresses);
for (auto addr : addresses) {
if (fIncludeWatchonly || pwalletMain->HaveSpendingKey(addr)) {
if (fIncludeWatchonly || pwalletMain->HaveSproutSpendingKey(addr)) {
ret.push_back(EncodePaymentAddress(addr));
}
}
@@ -3296,7 +3296,7 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp)
assert(boost::get<libzcash::SproutPaymentAddress>(&zaddr) != nullptr);
auto sproutzaddr = boost::get<libzcash::SproutPaymentAddress>(zaddr);
if (!(pwalletMain->HaveSpendingKey(sproutzaddr) || pwalletMain->HaveSproutViewingKey(sproutzaddr))) {
if (!(pwalletMain->HaveSproutSpendingKey(sproutzaddr) || pwalletMain->HaveSproutViewingKey(sproutzaddr))) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "From address does not belong to this node, zaddr spending key or viewing key not found.");
}
@@ -3368,7 +3368,7 @@ UniValue z_getbalance(const UniValue& params, bool fHelp)
// TODO: Add Sapling support. For now, ensure we can freely convert.
assert(boost::get<libzcash::SproutPaymentAddress>(&res) != nullptr);
auto zaddr = boost::get<libzcash::SproutPaymentAddress>(res);
if (!(pwalletMain->HaveSpendingKey(zaddr) || pwalletMain->HaveSproutViewingKey(zaddr))) {
if (!(pwalletMain->HaveSproutSpendingKey(zaddr) || pwalletMain->HaveSproutViewingKey(zaddr))) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "From address does not belong to this node, zaddr spending key or viewing key not found.");
}
}
@@ -3610,7 +3610,7 @@ UniValue z_sendmany(const UniValue& params, bool fHelp)
// Check that we have the spending key
if (!fromTaddr) {
if (!pwalletMain->HaveSpendingKey(zaddr)) {
if (!pwalletMain->HaveSproutSpendingKey(zaddr)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "From address does not belong to this node, zaddr spending key not found.");
}
}
@@ -4259,7 +4259,7 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp)
// TODO: Add Sapling support
auto zaddr = boost::get<SproutPaymentAddress>(entry.address);
SproutSpendingKey zkey;
pwalletMain->GetSpendingKey(zaddr, zkey);
pwalletMain->GetSproutSpendingKey(zaddr, zkey);
noteInputs.emplace_back(entry.jsop, entry.plaintext.note(zaddr), nValue, zkey);
mergedNoteValue += nValue;
}

View File

@@ -88,7 +88,7 @@ libzcash::PaymentAddress CWallet::GenerateNewZKey()
auto addr = k.address();
// Check for collision, even though it is unlikely to ever occur
if (CCryptoKeyStore::HaveSpendingKey(addr))
if (CCryptoKeyStore::HaveSproutSpendingKey(addr))
throw std::runtime_error("CWallet::GenerateNewZKey(): Collision detected");
// Create new metadata
@@ -152,7 +152,7 @@ bool CWallet::AddZKey(const libzcash::SproutSpendingKey &key)
AssertLockHeld(cs_wallet); // mapZKeyMetadata
auto addr = key.address();
if (!CCryptoKeyStore::AddSpendingKey(key))
if (!CCryptoKeyStore::AddSproutSpendingKey(key))
return false;
// check if we need to remove from viewing keys
@@ -241,11 +241,12 @@ bool CWallet::AddCryptedKey(const CPubKey &vchPubKey,
}
bool CWallet::AddCryptedSpendingKey(const libzcash::SproutPaymentAddress &address,
const libzcash::ReceivingKey &rk,
const std::vector<unsigned char> &vchCryptedSecret)
bool CWallet::AddCryptedSproutSpendingKey(
const libzcash::SproutPaymentAddress &address,
const libzcash::ReceivingKey &rk,
const std::vector<unsigned char> &vchCryptedSecret)
{
if (!CCryptoKeyStore::AddCryptedSpendingKey(address, rk, vchCryptedSecret))
if (!CCryptoKeyStore::AddCryptedSproutSpendingKey(address, rk, vchCryptedSecret))
return false;
if (!fFileBacked)
return true;
@@ -304,12 +305,12 @@ bool CWallet::LoadCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigne
bool CWallet::LoadCryptedZKey(const libzcash::SproutPaymentAddress &addr, const libzcash::ReceivingKey &rk, const std::vector<unsigned char> &vchCryptedSecret)
{
return CCryptoKeyStore::AddCryptedSpendingKey(addr, rk, vchCryptedSecret);
return CCryptoKeyStore::AddCryptedSproutSpendingKey(addr, rk, vchCryptedSecret);
}
bool CWallet::LoadZKey(const libzcash::SproutSpendingKey &key)
{
return CCryptoKeyStore::AddSpendingKey(key);
return CCryptoKeyStore::AddSproutSpendingKey(key);
}
bool CWallet::AddSproutViewingKey(const libzcash::SproutViewingKey &vk)
@@ -1420,7 +1421,7 @@ boost::optional<uint256> CWallet::GetNoteNullifier(const JSDescription& jsdesc,
// - We have them (this isn't a viewing key)
// - The wallet is unlocked
libzcash::SproutSpendingKey key;
if (GetSpendingKey(address, key)) {
if (GetSproutSpendingKey(address, key)) {
ret = note.nullifier(key);
}
return ret;
@@ -3951,7 +3952,7 @@ void CWallet::GetFilteredNotes(
}
// skip notes which cannot be spent
if (ignoreUnspendable && !HaveSpendingKey(pa)) {
if (ignoreUnspendable && !HaveSproutSpendingKey(pa)) {
continue;
}
@@ -4032,7 +4033,7 @@ void CWallet::GetUnspentFilteredNotes(
}
// skip notes where the spending key is not available
if (requireSpendingKey && !HaveSpendingKey(pa)) {
if (requireSpendingKey && !HaveSproutSpendingKey(pa)) {
continue;
}

View File

@@ -992,7 +992,10 @@ public:
//! Adds an encrypted spending key to the store, without saving it to disk (used by LoadWallet)
bool LoadCryptedZKey(const libzcash::SproutPaymentAddress &addr, const libzcash::ReceivingKey &rk, const std::vector<unsigned char> &vchCryptedSecret);
//! Adds an encrypted spending key to the store, and saves it to disk (virtual method, declared in crypter.h)
bool AddCryptedSpendingKey(const libzcash::SproutPaymentAddress &address, const libzcash::ReceivingKey &rk, const std::vector<unsigned char> &vchCryptedSecret);
bool AddCryptedSproutSpendingKey(
const libzcash::SproutPaymentAddress &address,
const libzcash::ReceivingKey &rk,
const std::vector<unsigned char> &vchCryptedSecret);
//! Adds a Sprout viewing key to the store, and saves it to disk.
bool AddSproutViewingKey(const libzcash::SproutViewingKey &vk);