Rename *ViewingKey* -> *SproutViewingKey*
This commit is contained in:
@@ -111,9 +111,9 @@ TEST(wallet_zkeys_tests, store_and_load_zkeys) {
|
||||
|
||||
/**
|
||||
* This test covers methods on CWallet
|
||||
* AddViewingKey()
|
||||
* RemoveViewingKey()
|
||||
* LoadViewingKey()
|
||||
* AddSproutViewingKey()
|
||||
* RemoveSproutViewingKey()
|
||||
* LoadSproutViewingKey()
|
||||
*/
|
||||
TEST(wallet_zkeys_tests, StoreAndLoadViewingKeys) {
|
||||
SelectParams(CBaseChainParams::MAIN);
|
||||
@@ -128,32 +128,32 @@ TEST(wallet_zkeys_tests, StoreAndLoadViewingKeys) {
|
||||
// manually add new viewing key to wallet
|
||||
auto sk = libzcash::SproutSpendingKey::random();
|
||||
auto vk = sk.viewing_key();
|
||||
ASSERT_TRUE(wallet.AddViewingKey(vk));
|
||||
ASSERT_TRUE(wallet.AddSproutViewingKey(vk));
|
||||
|
||||
// verify wallet did add it
|
||||
auto addr = sk.address();
|
||||
ASSERT_TRUE(wallet.HaveViewingKey(addr));
|
||||
ASSERT_TRUE(wallet.HaveSproutViewingKey(addr));
|
||||
// and that we don't have the corresponding spending key
|
||||
ASSERT_FALSE(wallet.HaveSpendingKey(addr));
|
||||
|
||||
// verify viewing key stored correctly
|
||||
libzcash::SproutViewingKey vkOut;
|
||||
wallet.GetViewingKey(addr, vkOut);
|
||||
wallet.GetSproutViewingKey(addr, vkOut);
|
||||
ASSERT_EQ(vk, vkOut);
|
||||
|
||||
// Load a second viewing key into the wallet
|
||||
auto sk2 = libzcash::SproutSpendingKey::random();
|
||||
ASSERT_TRUE(wallet.LoadViewingKey(sk2.viewing_key()));
|
||||
ASSERT_TRUE(wallet.LoadSproutViewingKey(sk2.viewing_key()));
|
||||
|
||||
// verify wallet did add it
|
||||
auto addr2 = sk2.address();
|
||||
ASSERT_TRUE(wallet.HaveViewingKey(addr2));
|
||||
ASSERT_TRUE(wallet.HaveSproutViewingKey(addr2));
|
||||
ASSERT_FALSE(wallet.HaveSpendingKey(addr2));
|
||||
|
||||
// Remove the first viewing key
|
||||
ASSERT_TRUE(wallet.RemoveViewingKey(vk));
|
||||
ASSERT_FALSE(wallet.HaveViewingKey(addr));
|
||||
ASSERT_TRUE(wallet.HaveViewingKey(addr2));
|
||||
ASSERT_TRUE(wallet.RemoveSproutViewingKey(vk));
|
||||
ASSERT_FALSE(wallet.HaveSproutViewingKey(addr));
|
||||
ASSERT_TRUE(wallet.HaveSproutViewingKey(addr2));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -230,7 +230,7 @@ TEST(wallet_zkeys_tests, write_zkey_direct_to_db) {
|
||||
|
||||
/**
|
||||
* This test covers methods on CWalletDB
|
||||
* WriteViewingKey()
|
||||
* WriteSproutViewingKey()
|
||||
*/
|
||||
TEST(wallet_zkeys_tests, WriteViewingKeyDirectToDB) {
|
||||
SelectParams(CBaseChainParams::TESTNET);
|
||||
@@ -255,20 +255,20 @@ TEST(wallet_zkeys_tests, WriteViewingKeyDirectToDB) {
|
||||
int64_t now = GetTime();
|
||||
CKeyMetadata meta(now);
|
||||
CWalletDB db("wallet-vkey.dat");
|
||||
db.WriteViewingKey(vk);
|
||||
db.WriteSproutViewingKey(vk);
|
||||
|
||||
// wallet should not be aware of viewing key
|
||||
ASSERT_FALSE(wallet.HaveViewingKey(addr));
|
||||
ASSERT_FALSE(wallet.HaveSproutViewingKey(addr));
|
||||
|
||||
// load the wallet again
|
||||
ASSERT_EQ(DB_LOAD_OK, wallet.LoadWallet(fFirstRun));
|
||||
|
||||
// wallet can now see the viewing key
|
||||
ASSERT_TRUE(wallet.HaveViewingKey(addr));
|
||||
ASSERT_TRUE(wallet.HaveSproutViewingKey(addr));
|
||||
|
||||
// check key is the same
|
||||
libzcash::SproutViewingKey vkOut;
|
||||
wallet.GetViewingKey(addr, vkOut);
|
||||
wallet.GetSproutViewingKey(addr, vkOut);
|
||||
ASSERT_EQ(vk, vkOut);
|
||||
}
|
||||
|
||||
|
||||
@@ -763,14 +763,14 @@ UniValue z_importviewingkey(const UniValue& params, bool fHelp)
|
||||
}
|
||||
|
||||
// Don't throw error in case a viewing key is already there
|
||||
if (pwalletMain->HaveViewingKey(addr)) {
|
||||
if (pwalletMain->HaveSproutViewingKey(addr)) {
|
||||
if (fIgnoreExistingKey) {
|
||||
return NullUniValue;
|
||||
}
|
||||
} else {
|
||||
pwalletMain->MarkDirty();
|
||||
|
||||
if (!pwalletMain->AddViewingKey(vkey)) {
|
||||
if (!pwalletMain->AddSproutViewingKey(vkey)) {
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding viewing key to wallet");
|
||||
}
|
||||
}
|
||||
@@ -889,7 +889,7 @@ UniValue z_exportviewingkey(const UniValue& params, bool fHelp)
|
||||
auto addr = boost::get<libzcash::SproutPaymentAddress>(address);
|
||||
|
||||
libzcash::SproutViewingKey vk;
|
||||
if (!pwalletMain->GetViewingKey(addr, vk)) {
|
||||
if (!pwalletMain->GetSproutViewingKey(addr, vk)) {
|
||||
libzcash::SproutSpendingKey k;
|
||||
if (!pwalletMain->GetSpendingKey(addr, k)) {
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, "Wallet does not hold private key or viewing key for this zaddr");
|
||||
|
||||
@@ -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->HaveViewingKey(sproutzaddr))) {
|
||||
if (!(pwalletMain->HaveSpendingKey(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->HaveViewingKey(zaddr))) {
|
||||
if (!(pwalletMain->HaveSpendingKey(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.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,8 +156,8 @@ bool CWallet::AddZKey(const libzcash::SproutSpendingKey &key)
|
||||
return false;
|
||||
|
||||
// check if we need to remove from viewing keys
|
||||
if (HaveViewingKey(addr))
|
||||
RemoveViewingKey(key.viewing_key());
|
||||
if (HaveSproutViewingKey(addr))
|
||||
RemoveSproutViewingKey(key.viewing_key());
|
||||
|
||||
if (!fFileBacked)
|
||||
return true;
|
||||
@@ -312,26 +312,26 @@ bool CWallet::LoadZKey(const libzcash::SproutSpendingKey &key)
|
||||
return CCryptoKeyStore::AddSpendingKey(key);
|
||||
}
|
||||
|
||||
bool CWallet::AddViewingKey(const libzcash::SproutViewingKey &vk)
|
||||
bool CWallet::AddSproutViewingKey(const libzcash::SproutViewingKey &vk)
|
||||
{
|
||||
if (!CCryptoKeyStore::AddViewingKey(vk)) {
|
||||
if (!CCryptoKeyStore::AddSproutViewingKey(vk)) {
|
||||
return false;
|
||||
}
|
||||
nTimeFirstKey = 1; // No birthday information for viewing keys.
|
||||
if (!fFileBacked) {
|
||||
return true;
|
||||
}
|
||||
return CWalletDB(strWalletFile).WriteViewingKey(vk);
|
||||
return CWalletDB(strWalletFile).WriteSproutViewingKey(vk);
|
||||
}
|
||||
|
||||
bool CWallet::RemoveViewingKey(const libzcash::SproutViewingKey &vk)
|
||||
bool CWallet::RemoveSproutViewingKey(const libzcash::SproutViewingKey &vk)
|
||||
{
|
||||
AssertLockHeld(cs_wallet);
|
||||
if (!CCryptoKeyStore::RemoveViewingKey(vk)) {
|
||||
if (!CCryptoKeyStore::RemoveSproutViewingKey(vk)) {
|
||||
return false;
|
||||
}
|
||||
if (fFileBacked) {
|
||||
if (!CWalletDB(strWalletFile).EraseViewingKey(vk)) {
|
||||
if (!CWalletDB(strWalletFile).EraseSproutViewingKey(vk)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -339,9 +339,9 @@ bool CWallet::RemoveViewingKey(const libzcash::SproutViewingKey &vk)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CWallet::LoadViewingKey(const libzcash::SproutViewingKey &vk)
|
||||
bool CWallet::LoadSproutViewingKey(const libzcash::SproutViewingKey &vk)
|
||||
{
|
||||
return CCryptoKeyStore::AddViewingKey(vk);
|
||||
return CCryptoKeyStore::AddSproutViewingKey(vk);
|
||||
}
|
||||
|
||||
bool CWallet::AddCScript(const CScript& redeemScript)
|
||||
|
||||
@@ -994,11 +994,11 @@ public:
|
||||
//! 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);
|
||||
|
||||
//! Adds a viewing key to the store, and saves it to disk.
|
||||
bool AddViewingKey(const libzcash::SproutViewingKey &vk);
|
||||
bool RemoveViewingKey(const libzcash::SproutViewingKey &vk);
|
||||
//! Adds a viewing key to the store, without saving it to disk (used by LoadWallet)
|
||||
bool LoadViewingKey(const libzcash::SproutViewingKey &dest);
|
||||
//! Adds a Sprout viewing key to the store, and saves it to disk.
|
||||
bool AddSproutViewingKey(const libzcash::SproutViewingKey &vk);
|
||||
bool RemoveSproutViewingKey(const libzcash::SproutViewingKey &vk);
|
||||
//! Adds a Sprout viewing key to the store, without saving it to disk (used by LoadWallet)
|
||||
bool LoadSproutViewingKey(const libzcash::SproutViewingKey &dest);
|
||||
|
||||
/**
|
||||
* Sapling ZKeys
|
||||
|
||||
@@ -142,13 +142,13 @@ bool CWalletDB::WriteZKey(const libzcash::SproutPaymentAddress& addr, const libz
|
||||
return Write(std::make_pair(std::string("zkey"), addr), key, false);
|
||||
}
|
||||
|
||||
bool CWalletDB::WriteViewingKey(const libzcash::SproutViewingKey &vk)
|
||||
bool CWalletDB::WriteSproutViewingKey(const libzcash::SproutViewingKey &vk)
|
||||
{
|
||||
nWalletDBUpdated++;
|
||||
return Write(std::make_pair(std::string("vkey"), vk), '1');
|
||||
}
|
||||
|
||||
bool CWalletDB::EraseViewingKey(const libzcash::SproutViewingKey &vk)
|
||||
bool CWalletDB::EraseSproutViewingKey(const libzcash::SproutViewingKey &vk)
|
||||
{
|
||||
nWalletDBUpdated++;
|
||||
return Erase(std::make_pair(std::string("vkey"), vk));
|
||||
@@ -490,7 +490,7 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
|
||||
char fYes;
|
||||
ssValue >> fYes;
|
||||
if (fYes == '1')
|
||||
pwallet->LoadViewingKey(vk);
|
||||
pwallet->LoadSproutViewingKey(vk);
|
||||
|
||||
// Viewing keys have no birthday information for now,
|
||||
// so set the wallet birthday to the beginning of time.
|
||||
|
||||
@@ -139,8 +139,8 @@ public:
|
||||
const std::vector<unsigned char>& vchCryptedSecret,
|
||||
const CKeyMetadata &keyMeta);
|
||||
|
||||
bool WriteViewingKey(const libzcash::SproutViewingKey &vk);
|
||||
bool EraseViewingKey(const libzcash::SproutViewingKey &vk);
|
||||
bool WriteSproutViewingKey(const libzcash::SproutViewingKey &vk);
|
||||
bool EraseSproutViewingKey(const libzcash::SproutViewingKey &vk);
|
||||
|
||||
private:
|
||||
CWalletDB(const CWalletDB&);
|
||||
|
||||
Reference in New Issue
Block a user