Update to use new API in CCryptoKeyStore and store a viewing key in walletdb.
This commit is contained in:
parent
73699ceaf6
commit
2aa9c0253a
|
@ -191,9 +191,10 @@ bool CWallet::AddCryptedKey(const CPubKey &vchPubKey,
|
||||||
|
|
||||||
|
|
||||||
bool CWallet::AddCryptedSpendingKey(const libzcash::PaymentAddress &address,
|
bool CWallet::AddCryptedSpendingKey(const libzcash::PaymentAddress &address,
|
||||||
|
const libzcash::ViewingKey &vk,
|
||||||
const std::vector<unsigned char> &vchCryptedSecret)
|
const std::vector<unsigned char> &vchCryptedSecret)
|
||||||
{
|
{
|
||||||
if (!CCryptoKeyStore::AddCryptedSpendingKey(address, vchCryptedSecret))
|
if (!CCryptoKeyStore::AddCryptedSpendingKey(address, vk, vchCryptedSecret))
|
||||||
return false;
|
return false;
|
||||||
if (!fFileBacked)
|
if (!fFileBacked)
|
||||||
return true;
|
return true;
|
||||||
|
@ -201,10 +202,12 @@ bool CWallet::AddCryptedSpendingKey(const libzcash::PaymentAddress &address,
|
||||||
LOCK(cs_wallet);
|
LOCK(cs_wallet);
|
||||||
if (pwalletdbEncryption)
|
if (pwalletdbEncryption)
|
||||||
return pwalletdbEncryption->WriteCryptedZKey(address,
|
return pwalletdbEncryption->WriteCryptedZKey(address,
|
||||||
|
vk,
|
||||||
vchCryptedSecret,
|
vchCryptedSecret,
|
||||||
mapZKeyMetadata[address]);
|
mapZKeyMetadata[address]);
|
||||||
else
|
else
|
||||||
return CWalletDB(strWalletFile).WriteCryptedZKey(address,
|
return CWalletDB(strWalletFile).WriteCryptedZKey(address,
|
||||||
|
vk,
|
||||||
vchCryptedSecret,
|
vchCryptedSecret,
|
||||||
mapZKeyMetadata[address]);
|
mapZKeyMetadata[address]);
|
||||||
}
|
}
|
||||||
|
@ -233,9 +236,9 @@ bool CWallet::LoadCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigne
|
||||||
return CCryptoKeyStore::AddCryptedKey(vchPubKey, vchCryptedSecret);
|
return CCryptoKeyStore::AddCryptedKey(vchPubKey, vchCryptedSecret);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CWallet::LoadCryptedZKey(const libzcash::PaymentAddress &addr, const std::vector<unsigned char> &vchCryptedSecret)
|
bool CWallet::LoadCryptedZKey(const libzcash::PaymentAddress &addr, const libzcash::ViewingKey &vk, const std::vector<unsigned char> &vchCryptedSecret)
|
||||||
{
|
{
|
||||||
return CCryptoKeyStore::AddCryptedSpendingKey(addr, vchCryptedSecret);
|
return CCryptoKeyStore::AddCryptedSpendingKey(addr, vk, vchCryptedSecret);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CWallet::LoadZKey(const libzcash::SpendingKey &key)
|
bool CWallet::LoadZKey(const libzcash::SpendingKey &key)
|
||||||
|
|
|
@ -753,9 +753,9 @@ public:
|
||||||
//! Load spending key metadata (used by LoadWallet)
|
//! Load spending key metadata (used by LoadWallet)
|
||||||
bool LoadZKeyMetadata(const libzcash::PaymentAddress &addr, const CKeyMetadata &meta);
|
bool LoadZKeyMetadata(const libzcash::PaymentAddress &addr, const CKeyMetadata &meta);
|
||||||
//! Adds an encrypted spending key to the store, without saving it to disk (used by LoadWallet)
|
//! Adds an encrypted spending key to the store, without saving it to disk (used by LoadWallet)
|
||||||
bool LoadCryptedZKey(const libzcash::PaymentAddress &addr, const std::vector<unsigned char> &vchCryptedSecret);
|
bool LoadCryptedZKey(const libzcash::PaymentAddress &addr, const libzcash::ViewingKey &vk, 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)
|
//! Adds an encrypted spending key to the store, and saves it to disk (virtual method, declared in crypter.h)
|
||||||
bool AddCryptedSpendingKey(const libzcash::PaymentAddress &address, const std::vector<unsigned char> &vchCryptedSecret);
|
bool AddCryptedSpendingKey(const libzcash::PaymentAddress &address, const libzcash::ViewingKey &vk, const std::vector<unsigned char> &vchCryptedSecret);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Increment the next transaction order id
|
* Increment the next transaction order id
|
||||||
|
|
|
@ -105,6 +105,7 @@ bool CWalletDB::WriteCryptedKey(const CPubKey& vchPubKey,
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CWalletDB::WriteCryptedZKey(const libzcash::PaymentAddress & addr,
|
bool CWalletDB::WriteCryptedZKey(const libzcash::PaymentAddress & addr,
|
||||||
|
const libzcash::ViewingKey &vk,
|
||||||
const std::vector<unsigned char>& vchCryptedSecret,
|
const std::vector<unsigned char>& vchCryptedSecret,
|
||||||
const CKeyMetadata &keyMeta)
|
const CKeyMetadata &keyMeta)
|
||||||
{
|
{
|
||||||
|
@ -114,7 +115,7 @@ bool CWalletDB::WriteCryptedZKey(const libzcash::PaymentAddress & addr,
|
||||||
if (!Write(std::make_pair(std::string("zkeymeta"), addr), keyMeta))
|
if (!Write(std::make_pair(std::string("zkeymeta"), addr), keyMeta))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!Write(std::make_pair(std::string("czkey"), addr), vchCryptedSecret, false))
|
if (!Write(std::make_pair(std::string("czkey"), addr), std::make_pair(vk, vchCryptedSecret), false))
|
||||||
return false;
|
return false;
|
||||||
if (fEraseUnencryptedKey)
|
if (fEraseUnencryptedKey)
|
||||||
{
|
{
|
||||||
|
@ -581,11 +582,15 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
|
||||||
{
|
{
|
||||||
libzcash::PaymentAddress addr;
|
libzcash::PaymentAddress addr;
|
||||||
ssKey >> addr;
|
ssKey >> addr;
|
||||||
|
// Deserialization of a pair is just one item after another
|
||||||
|
uint256 vkValue;
|
||||||
|
ssValue >> vkValue;
|
||||||
|
libzcash::ViewingKey vk(vkValue);
|
||||||
vector<unsigned char> vchCryptedSecret;
|
vector<unsigned char> vchCryptedSecret;
|
||||||
ssValue >> vchCryptedSecret;
|
ssValue >> vchCryptedSecret;
|
||||||
wss.nCKeys++;
|
wss.nCKeys++;
|
||||||
|
|
||||||
if (!pwallet->LoadCryptedZKey(addr, vchCryptedSecret))
|
if (!pwallet->LoadCryptedZKey(addr, vk, vchCryptedSecret))
|
||||||
{
|
{
|
||||||
strErr = "Error reading wallet database: LoadCryptedZKey failed";
|
strErr = "Error reading wallet database: LoadCryptedZKey failed";
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -136,6 +136,7 @@ public:
|
||||||
/// Write spending key to wallet database, where key is payment address and value is spending key.
|
/// Write spending key to wallet database, where key is payment address and value is spending key.
|
||||||
bool WriteZKey(const libzcash::PaymentAddress& addr, const libzcash::SpendingKey& key, const CKeyMetadata &keyMeta);
|
bool WriteZKey(const libzcash::PaymentAddress& addr, const libzcash::SpendingKey& key, const CKeyMetadata &keyMeta);
|
||||||
bool WriteCryptedZKey(const libzcash::PaymentAddress & addr,
|
bool WriteCryptedZKey(const libzcash::PaymentAddress & addr,
|
||||||
|
const libzcash::ViewingKey & vk,
|
||||||
const std::vector<unsigned char>& vchCryptedSecret,
|
const std::vector<unsigned char>& vchCryptedSecret,
|
||||||
const CKeyMetadata &keyMeta);
|
const CKeyMetadata &keyMeta);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue