vMasterKey.resize(WALLET_CRYPTO_KEY_SIZE);
RAND_bytes(&vMasterKey[0], WALLET_CRYPTO_KEY_SIZE);
- CMasterKey kMasterKey(nDerivationMethodIndex);
+ CMasterKey kMasterKey;
RandAddSeedPerfmon();
kMasterKey.vchSalt.resize(WALLET_CRYPTO_SALT_SIZE);
bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey)
{
{
- LOCK2(cs_main, cs_wallet);
printf("CommitTransaction:\n%s", wtxNew.ToString().c_str());
+
+ // Track how many getdata requests our transaction gets
+ mapRequestCount[wtxNew.GetHash()] = 0;
+
+ // Try to broadcast before saving
+ if (!wtxNew.AcceptToMemoryPool())
+ {
+ // This must not fail. The transaction has already been signed.
+ printf("CommitTransaction() : Error: Transaction not valid");
+ return false;
+ }
+
+ wtxNew.RelayWalletTransaction();
+
{
+ LOCK2(cs_main, cs_wallet);
+
// This is only to keep the database open to defeat the auto-flush for the
// duration of this scope. This is the only place where this optimization
// maybe makes sense; please don't do it anywhere else.
if (fFileBacked)
delete pwalletdb;
}
-
- // Track how many getdata requests our transaction gets
- mapRequestCount[wtxNew.GetHash()] = 0;
-
- // Broadcast
- if (!wtxNew.AcceptToMemoryPool())
- {
- // This must not fail. The transaction has already been signed and recorded.
- printf("CommitTransaction() : Error: Transaction not valid");
- return false;
- }
- wtxNew.RelayWalletTransaction();
}
return true;
}
// Mark old keypool keys as used,
// and generate all new keys
//
-bool CWallet::NewKeyPool()
+bool CWallet::NewKeyPool(unsigned int nSize)
{
{
LOCK(cs_wallet);
if (IsLocked())
return false;
- int64_t nKeys = max(GetArg("-keypool", 100), (int64_t)0);
- for (int i = 0; i < nKeys; i++)
+ uint64_t nKeys;
+ if (nSize > 0)
+ nKeys = nSize;
+ else
+ nKeys = max<uint64_t>(GetArg("-keypool", 100), 0);
+
+ for (uint64_t i = 0; i < nKeys; i++)
{
- int64_t nIndex = i+1;
+ uint64_t nIndex = i+1;
walletdb.WritePool(nIndex, CKeyPool(GenerateNewKey()));
setKeyPool.insert(nIndex);
}
- printf("CWallet::NewKeyPool wrote %" PRId64 " new keys\n", nKeys);
+ printf("CWallet::NewKeyPool wrote %" PRIu64 " new keys\n", nKeys);
}
return true;
}
CWalletDB walletdb(strWalletFile);
// Top up key pool
- unsigned int nTargetSize;
+ uint64_t nTargetSize;
if (nSize > 0)
nTargetSize = nSize;
else
- nTargetSize = max<unsigned int>(GetArg("-keypool", 100), 0LL);
+ nTargetSize = max<uint64_t>(GetArg("-keypool", 100), 0);
while (setKeyPool.size() < (nTargetSize + 1))
{
- int64_t nEnd = 1;
+ uint64_t nEnd = 1;
if (!setKeyPool.empty())
nEnd = *(--setKeyPool.end()) + 1;
if (!walletdb.WritePool(nEnd, CKeyPool(GenerateNewKey())))
throw runtime_error("TopUpKeyPool() : writing generated key failed");
setKeyPool.insert(nEnd);
- printf("keypool added key %" PRId64 ", size=%" PRIszu "\n", nEnd, setKeyPool.size());
+ printf("keypool added key %" PRIu64 ", size=%" PRIszu "\n", nEnd, setKeyPool.size());
}
}
return true;