#include "util.h"
#include "utiltime.h"
#include "wallet/wallet.h"
+#include "zcash/Proof.hpp"
#include <boost/filesystem.hpp>
#include <boost/foreach.hpp>
return true;
}
+bool CWalletDB::WriteCryptedZKey(const libzcash::PaymentAddress & addr,
+ const libzcash::ReceivingKey &rk,
+ const std::vector<unsigned char>& vchCryptedSecret,
+ const CKeyMetadata &keyMeta)
+{
+ const bool fEraseUnencryptedKey = true;
+ nWalletDBUpdated++;
+
+ if (!Write(std::make_pair(std::string("zkeymeta"), addr), keyMeta))
+ return false;
+
+ if (!Write(std::make_pair(std::string("czkey"), addr), std::make_pair(rk, vchCryptedSecret), false))
+ return false;
+ if (fEraseUnencryptedKey)
+ {
+ Erase(std::make_pair(std::string("zkey"), addr));
+ }
+ return true;
+}
+
bool CWalletDB::WriteMasterKey(unsigned int nID, const CMasterKey& kMasterKey)
{
nWalletDBUpdated++;
return Write(std::string("defaultkey"), vchPubKey);
}
+bool CWalletDB::WriteWitnessCacheSize(int64_t nWitnessCacheSize)
+{
+ nWalletDBUpdated++;
+ return Write(std::string("witnesscachesize"), nWitnessCacheSize);
+}
+
bool CWalletDB::ReadPool(int64_t nPool, CKeyPool& keypool)
{
return Read(std::make_pair(std::string("pool"), nPool), keypool);
if (pwtx)
{
- if (!WriteTx(pwtx->GetTxid(), *pwtx))
+ if (!WriteTx(pwtx->GetHash(), *pwtx))
return DB_LOAD_FAIL;
}
else
// Since we're changing the order, write it back
if (pwtx)
{
- if (!WriteTx(pwtx->GetTxid(), *pwtx))
+ if (!WriteTx(pwtx->GetHash(), *pwtx))
return DB_LOAD_FAIL;
}
else
unsigned int nCKeys;
unsigned int nKeyMeta;
unsigned int nZKeys;
+ unsigned int nCZKeys;
unsigned int nZKeyMeta;
bool fIsEncrypted;
bool fAnyUnordered;
vector<uint256> vWalletUpgrade;
CWalletScanState() {
- nKeys = nCKeys = nKeyMeta = nZKeys = nZKeyMeta = 0;
+ nKeys = nCKeys = nKeyMeta = nZKeys = nCZKeys = nZKeyMeta = 0;
fIsEncrypted = false;
fAnyUnordered = false;
nFileVersion = 0;
CWalletTx wtx;
ssValue >> wtx;
CValidationState state;
- if (!(CheckTransaction(wtx, state) && (wtx.GetTxid() == hash) && state.IsValid()))
+ auto verifier = libzcash::ProofVerifier::Strict();
+ if (!(CheckTransaction(wtx, state, verifier) && (wtx.GetHash() == hash) && state.IsValid()))
return false;
// Undo serialize changes in 31600
}
wss.fIsEncrypted = true;
}
+ else if (strType == "czkey")
+ {
+ libzcash::PaymentAddress addr;
+ ssKey >> addr;
+ // Deserialization of a pair is just one item after another
+ uint256 rkValue;
+ ssValue >> rkValue;
+ libzcash::ReceivingKey rk(rkValue);
+ vector<unsigned char> vchCryptedSecret;
+ ssValue >> vchCryptedSecret;
+ wss.nCKeys++;
+
+ if (!pwallet->LoadCryptedZKey(addr, rk, vchCryptedSecret))
+ {
+ strErr = "Error reading wallet database: LoadCryptedZKey failed";
+ return false;
+ }
+ wss.fIsEncrypted = true;
+ }
else if (strType == "keymeta")
{
CPubKey vchPubKey;
return false;
}
}
+ else if (strType == "witnesscachesize")
+ {
+ ssValue >> pwallet->nWitnessCacheSize;
+ }
} catch (...)
{
return false;
static bool IsKeyType(string strType)
{
return (strType== "key" || strType == "wkey" ||
+ strType == "zkey" || strType == "czkey" ||
strType == "mkey" || strType == "ckey");
}
LogPrintf("Keys: %u plaintext, %u encrypted, %u w/ metadata, %u total\n",
wss.nKeys, wss.nCKeys, wss.nKeyMeta, wss.nKeys + wss.nCKeys);
- // TODO: Keep track of encrypted ZKeys
- LogPrintf("ZKeys: %u plaintext, -- encrypted, %u w/metadata, %u total\n",
- wss.nZKeys, wss.nZKeyMeta, wss.nZKeys + 0);
+ LogPrintf("ZKeys: %u plaintext, %u encrypted, %u w/metadata, %u total\n",
+ wss.nZKeys, wss.nCZKeys, wss.nZKeyMeta, wss.nZKeys + wss.nCZKeys);
// nTimeFirstKey is only reliable if all keys have metadata
if ((wss.nKeys + wss.nCKeys) != wss.nKeyMeta)
void ThreadFlushWalletDB(const string& strFile)
{
// Make this thread recognisable as the wallet flushing thread
- RenameThread("bitcoin-wallet");
+ RenameThread("zcash-wallet");
static bool fOneThread;
if (fOneThread)
pathDest /= wallet.strWalletFile;
try {
-#if BOOST_VERSION >= 104000
boost::filesystem::copy_file(pathSrc, pathDest, boost::filesystem::copy_option::overwrite_if_exists);
-#else
- boost::filesystem::copy_file(pathSrc, pathDest);
-#endif
LogPrintf("copied wallet.dat to %s\n", pathDest.string());
return true;
} catch (const boost::filesystem::filesystem_error& e) {