|
|
|
|
@@ -119,7 +119,7 @@ CPubKey CWallet::GenerateNewKey()
|
|
|
|
|
|
|
|
|
|
// try to get the master key
|
|
|
|
|
if (!GetKey(hdChain.masterKeyID, key))
|
|
|
|
|
throw std::runtime_error("CWallet::GenerateNewKey(): Master key not found");
|
|
|
|
|
throw std::runtime_error(std::string(__func__) + ": Master key not found");
|
|
|
|
|
|
|
|
|
|
masterKey.SetMaster(key.begin(), key.size());
|
|
|
|
|
|
|
|
|
|
@@ -146,7 +146,7 @@ CPubKey CWallet::GenerateNewKey()
|
|
|
|
|
|
|
|
|
|
// update the chain model in the database
|
|
|
|
|
if (!CWalletDB(strWalletFile).WriteHDChain(hdChain))
|
|
|
|
|
throw std::runtime_error("CWallet::GenerateNewKey(): Writing HD chain model failed");
|
|
|
|
|
throw std::runtime_error(std::string(__func__) + ": Writing HD chain model failed");
|
|
|
|
|
} else {
|
|
|
|
|
secret.MakeNewKey(fCompressed);
|
|
|
|
|
}
|
|
|
|
|
@@ -164,7 +164,7 @@ CPubKey CWallet::GenerateNewKey()
|
|
|
|
|
nTimeFirstKey = nCreationTime;
|
|
|
|
|
|
|
|
|
|
if (!AddKeyPubKey(secret, pubkey))
|
|
|
|
|
throw std::runtime_error("CWallet::GenerateNewKey(): AddKey failed");
|
|
|
|
|
throw std::runtime_error(std::string(__func__) + ": AddKey failed");
|
|
|
|
|
return pubkey;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -1464,7 +1464,7 @@ isminetype CWallet::IsMine(const CTxOut& txout) const
|
|
|
|
|
CAmount CWallet::GetCredit(const CTxOut& txout, const isminefilter& filter) const
|
|
|
|
|
{
|
|
|
|
|
if (!MoneyRange(txout.nValue))
|
|
|
|
|
throw std::runtime_error("CWallet::GetCredit(): value out of range");
|
|
|
|
|
throw std::runtime_error(std::string(__func__) + ": value out of range");
|
|
|
|
|
return ((IsMine(txout) & filter) ? txout.nValue : 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -1493,7 +1493,7 @@ bool CWallet::IsChange(const CTxOut& txout) const
|
|
|
|
|
CAmount CWallet::GetChange(const CTxOut& txout) const
|
|
|
|
|
{
|
|
|
|
|
if (!MoneyRange(txout.nValue))
|
|
|
|
|
throw std::runtime_error("CWallet::GetChange(): value out of range");
|
|
|
|
|
throw std::runtime_error(std::string(__func__) + ": value out of range");
|
|
|
|
|
return (IsChange(txout) ? txout.nValue : 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -1521,7 +1521,7 @@ CPubKey CWallet::GenerateNewHDMasterKey()
|
|
|
|
|
|
|
|
|
|
// write the key&metadata to the database
|
|
|
|
|
if (!AddKeyPubKey(key, pubkey))
|
|
|
|
|
throw std::runtime_error(std::string(__func__)+": AddKeyPubKey failed");
|
|
|
|
|
throw std::runtime_error(std::string(__func__) + ": AddKeyPubKey failed");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pubkey;
|
|
|
|
|
@@ -1548,7 +1548,7 @@ bool CWallet::SetHDChain(const CHDChain& chain, bool memonly)
|
|
|
|
|
{
|
|
|
|
|
LOCK(cs_wallet);
|
|
|
|
|
if (!memonly && !CWalletDB(strWalletFile).WriteHDChain(chain))
|
|
|
|
|
throw runtime_error("AddHDChain(): writing chain failed");
|
|
|
|
|
throw runtime_error(std::string(__func__) + ": writing chain failed");
|
|
|
|
|
|
|
|
|
|
hdChain = chain;
|
|
|
|
|
return true;
|
|
|
|
|
@@ -3159,7 +3159,7 @@ bool CWallet::TopUpKeyPool(unsigned int kpSize)
|
|
|
|
|
if (!setKeyPool.empty())
|
|
|
|
|
nEnd = *(--setKeyPool.end()) + 1;
|
|
|
|
|
if (!walletdb.WritePool(nEnd, CKeyPool(GenerateNewKey())))
|
|
|
|
|
throw runtime_error("TopUpKeyPool(): writing generated key failed");
|
|
|
|
|
throw runtime_error(std::string(__func__) + ": writing generated key failed");
|
|
|
|
|
setKeyPool.insert(nEnd);
|
|
|
|
|
LogPrintf("keypool added key %d, size=%u\n", nEnd, setKeyPool.size());
|
|
|
|
|
}
|
|
|
|
|
@@ -3186,9 +3186,9 @@ void CWallet::ReserveKeyFromKeyPool(int64_t& nIndex, CKeyPool& keypool)
|
|
|
|
|
nIndex = *(setKeyPool.begin());
|
|
|
|
|
setKeyPool.erase(setKeyPool.begin());
|
|
|
|
|
if (!walletdb.ReadPool(nIndex, keypool))
|
|
|
|
|
throw runtime_error("ReserveKeyFromKeyPool(): read failed");
|
|
|
|
|
throw runtime_error(std::string(__func__) + ": read failed");
|
|
|
|
|
if (!HaveKey(keypool.vchPubKey.GetID()))
|
|
|
|
|
throw runtime_error("ReserveKeyFromKeyPool(): unknown key in key pool");
|
|
|
|
|
throw runtime_error(std::string(__func__) + ": unknown key in key pool");
|
|
|
|
|
assert(keypool.vchPubKey.IsValid());
|
|
|
|
|
LogPrintf("keypool reserve %d\n", nIndex);
|
|
|
|
|
}
|
|
|
|
|
@@ -3247,7 +3247,7 @@ int64_t CWallet::GetOldestKeyPoolTime()
|
|
|
|
|
CWalletDB walletdb(strWalletFile);
|
|
|
|
|
int64_t nIndex = *(setKeyPool.begin());
|
|
|
|
|
if (!walletdb.ReadPool(nIndex, keypool))
|
|
|
|
|
throw runtime_error("GetOldestKeyPoolTime(): read oldest key in keypool failed");
|
|
|
|
|
throw runtime_error(std::string(__func__) + ": read oldest key in keypool failed");
|
|
|
|
|
assert(keypool.vchPubKey.IsValid());
|
|
|
|
|
return keypool.nTime;
|
|
|
|
|
}
|
|
|
|
|
@@ -3498,11 +3498,11 @@ void CWallet::GetAllReserveKeys(set<CKeyID>& setAddress) const
|
|
|
|
|
{
|
|
|
|
|
CKeyPool keypool;
|
|
|
|
|
if (!walletdb.ReadPool(id, keypool))
|
|
|
|
|
throw runtime_error("GetAllReserveKeyHashes(): read failed");
|
|
|
|
|
throw runtime_error(std::string(__func__) + ": read failed");
|
|
|
|
|
assert(keypool.vchPubKey.IsValid());
|
|
|
|
|
CKeyID keyID = keypool.vchPubKey.GetID();
|
|
|
|
|
if (!HaveKey(keyID))
|
|
|
|
|
throw runtime_error("GetAllReserveKeyHashes(): unknown key in key pool");
|
|
|
|
|
throw runtime_error(std::string(__func__) + ": unknown key in key pool");
|
|
|
|
|
setAddress.insert(keyID);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|