Rename map to include sprout

This commit is contained in:
Eirik Ogilvie-Wigley 2018-08-27 15:26:52 -06:00
parent 0e0f5e4ea7
commit d6b31d59b5
4 changed files with 15 additions and 15 deletions

View File

@ -116,7 +116,7 @@ TEST(wallet_zkeys_tests, store_and_load_zkeys) {
ASSERT_TRUE(wallet.LoadZKeyMetadata(addr, meta)); ASSERT_TRUE(wallet.LoadZKeyMetadata(addr, meta));
// check metadata is the same // check metadata is the same
CKeyMetadata m= wallet.mapZKeyMetadata[addr]; CKeyMetadata m= wallet.mapSproutZKeyMetadata[addr];
ASSERT_EQ(m.nCreateTime, now); ASSERT_EQ(m.nCreateTime, now);
} }
@ -215,7 +215,7 @@ TEST(wallet_zkeys_tests, write_zkey_direct_to_db) {
ASSERT_EQ(1, addrs.size()); ASSERT_EQ(1, addrs.size());
// wallet should have default metadata for addr with null createtime // wallet should have default metadata for addr with null createtime
CKeyMetadata m = wallet.mapZKeyMetadata[addr]; CKeyMetadata m = wallet.mapSproutZKeyMetadata[addr];
ASSERT_EQ(m.nCreateTime, 0); ASSERT_EQ(m.nCreateTime, 0);
ASSERT_NE(m.nCreateTime, now); ASSERT_NE(m.nCreateTime, now);
@ -235,7 +235,7 @@ TEST(wallet_zkeys_tests, write_zkey_direct_to_db) {
ASSERT_EQ(2, addrs.size()); ASSERT_EQ(2, addrs.size());
// check metadata is now the same // check metadata is now the same
m = wallet.mapZKeyMetadata[addr]; m = wallet.mapSproutZKeyMetadata[addr];
ASSERT_EQ(m.nCreateTime, now); ASSERT_EQ(m.nCreateTime, now);
} }

View File

@ -314,7 +314,7 @@ UniValue importwallet_impl(const UniValue& params, bool fHelp, bool fImportZKeys
continue; continue;
} }
// Successfully imported zaddr. Now import the metadata. // Successfully imported zaddr. Now import the metadata.
pwalletMain->mapZKeyMetadata[addr].nCreateTime = nTime; pwalletMain->mapSproutZKeyMetadata[addr].nCreateTime = nTime;
continue; continue;
} else { } else {
LogPrint("zrpc", "Importing detected an error: invalid spending key. Trying as a transparent key...\n"); LogPrint("zrpc", "Importing detected an error: invalid spending key. Trying as a transparent key...\n");
@ -537,7 +537,7 @@ UniValue dumpwallet_impl(const UniValue& params, bool fHelp, bool fDumpZKeys)
for (auto addr : addresses ) { for (auto addr : addresses ) {
libzcash::SproutSpendingKey key; libzcash::SproutSpendingKey key;
if (pwalletMain->GetSproutSpendingKey(addr, key)) { if (pwalletMain->GetSproutSpendingKey(addr, key)) {
std::string strTime = EncodeDumpTime(pwalletMain->mapZKeyMetadata[addr].nCreateTime); std::string strTime = EncodeDumpTime(pwalletMain->mapSproutZKeyMetadata[addr].nCreateTime);
file << strprintf("%s %s # zaddr=%s\n", EncodeSpendingKey(key), strTime, EncodePaymentAddress(addr)); file << strprintf("%s %s # zaddr=%s\n", EncodeSpendingKey(key), strTime, EncodePaymentAddress(addr));
} }
} }
@ -571,7 +571,7 @@ public:
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding spending key to wallet"); throw JSONRPCError(RPC_WALLET_ERROR, "Error adding spending key to wallet");
} }
m_wallet->mapZKeyMetadata[addr].nCreateTime = 1; m_wallet->mapSproutZKeyMetadata[addr].nCreateTime = 1;
return false; return false;
} }

View File

@ -83,7 +83,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
libzcash::PaymentAddress CWallet::GenerateNewZKey() libzcash::PaymentAddress CWallet::GenerateNewZKey()
{ {
AssertLockHeld(cs_wallet); // mapZKeyMetadata AssertLockHeld(cs_wallet); // mapSproutZKeyMetadata
// TODO: Add Sapling support // TODO: Add Sapling support
auto k = SproutSpendingKey::random(); auto k = SproutSpendingKey::random();
auto addr = k.address(); auto addr = k.address();
@ -94,7 +94,7 @@ libzcash::PaymentAddress CWallet::GenerateNewZKey()
// Create new metadata // Create new metadata
int64_t nCreationTime = GetTime(); int64_t nCreationTime = GetTime();
mapZKeyMetadata[addr] = CKeyMetadata(nCreationTime); mapSproutZKeyMetadata[addr] = CKeyMetadata(nCreationTime);
if (!AddZKey(k)) if (!AddZKey(k))
throw std::runtime_error("CWallet::GenerateNewZKey(): AddZKey failed"); throw std::runtime_error("CWallet::GenerateNewZKey(): AddZKey failed");
@ -171,7 +171,7 @@ bool CWallet::AddSaplingZKey(
// Add spending key to keystore and persist to disk // Add spending key to keystore and persist to disk
bool CWallet::AddZKey(const libzcash::SproutSpendingKey &key) bool CWallet::AddZKey(const libzcash::SproutSpendingKey &key)
{ {
AssertLockHeld(cs_wallet); // mapZKeyMetadata AssertLockHeld(cs_wallet); // mapSproutZKeyMetadata
auto addr = key.address(); auto addr = key.address();
if (!CCryptoKeyStore::AddSproutSpendingKey(key)) if (!CCryptoKeyStore::AddSproutSpendingKey(key))
@ -187,7 +187,7 @@ bool CWallet::AddZKey(const libzcash::SproutSpendingKey &key)
if (!IsCrypted()) { if (!IsCrypted()) {
return CWalletDB(strWalletFile).WriteZKey(addr, return CWalletDB(strWalletFile).WriteZKey(addr,
key, key,
mapZKeyMetadata[addr]); mapSproutZKeyMetadata[addr]);
} }
return true; return true;
} }
@ -278,12 +278,12 @@ bool CWallet::AddCryptedSproutSpendingKey(
return pwalletdbEncryption->WriteCryptedZKey(address, return pwalletdbEncryption->WriteCryptedZKey(address,
rk, rk,
vchCryptedSecret, vchCryptedSecret,
mapZKeyMetadata[address]); mapSproutZKeyMetadata[address]);
} else { } else {
return CWalletDB(strWalletFile).WriteCryptedZKey(address, return CWalletDB(strWalletFile).WriteCryptedZKey(address,
rk, rk,
vchCryptedSecret, vchCryptedSecret,
mapZKeyMetadata[address]); mapSproutZKeyMetadata[address]);
} }
} }
return false; return false;
@ -315,8 +315,8 @@ bool CWallet::LoadKeyMetadata(const CPubKey &pubkey, const CKeyMetadata &meta)
bool CWallet::LoadZKeyMetadata(const SproutPaymentAddress &addr, const CKeyMetadata &meta) bool CWallet::LoadZKeyMetadata(const SproutPaymentAddress &addr, const CKeyMetadata &meta)
{ {
AssertLockHeld(cs_wallet); // mapZKeyMetadata AssertLockHeld(cs_wallet); // mapSproutZKeyMetadata
mapZKeyMetadata[addr] = meta; mapSproutZKeyMetadata[addr] = meta;
return true; return true;
} }

View File

@ -845,7 +845,7 @@ public:
std::set<int64_t> setKeyPool; std::set<int64_t> setKeyPool;
std::map<CKeyID, CKeyMetadata> mapKeyMetadata; std::map<CKeyID, CKeyMetadata> mapKeyMetadata;
std::map<libzcash::SproutPaymentAddress, CKeyMetadata> mapZKeyMetadata; std::map<libzcash::SproutPaymentAddress, CKeyMetadata> mapSproutZKeyMetadata;
std::map<libzcash::SaplingIncomingViewingKey, CKeyMetadata> mapSaplingZKeyMetadata; std::map<libzcash::SaplingIncomingViewingKey, CKeyMetadata> mapSaplingZKeyMetadata;
typedef std::map<unsigned int, CMasterKey> MasterKeyMap; typedef std::map<unsigned int, CMasterKey> MasterKeyMap;