parent
e2416930ea
commit
a4ac4fc3f4
|
@ -554,8 +554,10 @@ class AddSpendingKeyToWallet : public boost::static_visitor<bool>
|
|||
{
|
||||
private:
|
||||
CWallet *m_wallet;
|
||||
const Consensus::Params ¶ms;
|
||||
public:
|
||||
AddSpendingKeyToWallet(CWallet *wallet) : m_wallet(wallet) {}
|
||||
AddSpendingKeyToWallet(CWallet *wallet, const Consensus::Params ¶ms) :
|
||||
m_wallet(wallet), params(params) {}
|
||||
|
||||
bool operator()(const libzcash::SproutSpendingKey &sk) const {
|
||||
auto addr = sk.address();
|
||||
|
@ -577,6 +579,7 @@ public:
|
|||
|
||||
bool operator()(const libzcash::SaplingSpendingKey &sk) const {
|
||||
auto fvk = sk.full_viewing_key();
|
||||
auto ivk = fvk.in_viewing_key();
|
||||
auto addr = sk.default_address();
|
||||
{
|
||||
// Don't throw error in case a key is already there
|
||||
|
@ -588,9 +591,12 @@ public:
|
|||
if (!m_wallet-> AddSaplingZKey(sk, addr)) {
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding spending key to wallet");
|
||||
}
|
||||
|
||||
m_wallet->mapSaplingZKeyMetadata[addr].nCreateTime = 1;
|
||||
|
||||
|
||||
// Sapling addresses can't have been used in transactions prior to activation.
|
||||
m_wallet->mapSaplingZKeyMetadata[ivk].nCreateTime = std::max(
|
||||
1, // In case a code fork sets Sapling to always be active
|
||||
params.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -672,9 +678,10 @@ UniValue z_importkey(const UniValue& params, bool fHelp)
|
|||
if (!IsValidSpendingKey(spendingkey)) {
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid spending key");
|
||||
}
|
||||
|
||||
|
||||
// Sapling support
|
||||
auto keyAlreadyExists = boost::apply_visitor(AddSpendingKeyToWallet(pwalletMain), spendingkey);
|
||||
auto keyAlreadyExists = boost::apply_visitor(
|
||||
AddSpendingKeyToWallet(pwalletMain, Params().GetConsensus()), spendingkey);
|
||||
if (keyAlreadyExists && fIgnoreExistingKey) {
|
||||
return NullUniValue;
|
||||
}
|
||||
|
|
|
@ -107,6 +107,7 @@ SaplingPaymentAddress CWallet::GenerateNewSaplingZKey()
|
|||
|
||||
auto sk = SaplingSpendingKey::random();
|
||||
auto fvk = sk.full_viewing_key();
|
||||
auto ivk = fvk.in_viewing_key();
|
||||
auto addr = sk.default_address();
|
||||
|
||||
// Check for collision, even though it is unlikely to ever occur
|
||||
|
@ -116,8 +117,8 @@ SaplingPaymentAddress CWallet::GenerateNewSaplingZKey()
|
|||
|
||||
// Create new metadata
|
||||
int64_t nCreationTime = GetTime();
|
||||
mapSaplingZKeyMetadata[addr] = CKeyMetadata(nCreationTime);
|
||||
|
||||
mapSaplingZKeyMetadata[ivk] = CKeyMetadata(nCreationTime);
|
||||
|
||||
if (!AddSaplingZKey(sk, addr)) {
|
||||
throw std::runtime_error("CWallet::GenerateNewSaplingZKey(): AddSaplingZKey failed");
|
||||
}
|
||||
|
|
|
@ -846,7 +846,7 @@ public:
|
|||
std::set<int64_t> setKeyPool;
|
||||
std::map<CKeyID, CKeyMetadata> mapKeyMetadata;
|
||||
std::map<libzcash::SproutPaymentAddress, CKeyMetadata> mapZKeyMetadata;
|
||||
std::map<libzcash::SaplingPaymentAddress, CKeyMetadata> mapSaplingZKeyMetadata;
|
||||
std::map<libzcash::SaplingIncomingViewingKey, CKeyMetadata> mapSaplingZKeyMetadata;
|
||||
|
||||
typedef std::map<unsigned int, CMasterKey> MasterKeyMap;
|
||||
MasterKeyMap mapMasterKeys;
|
||||
|
|
Loading…
Reference in New Issue