mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-12 04:42:36 -03:00
e89b9f6a2a
This introduces two new source files, keystore.cpp and wallet.cpp with corresponding headers. Code is moved from main and db, in a preparation for a follow-up commit which introduces the classes CWallet and CKeyStore.
33 lines
842 B
C++
33 lines
842 B
C++
// Copyright (c) 2009-2011 Satoshi Nakamoto & Bitcoin developers
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#include "headers.h"
|
|
#include "db.h"
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// mapKeys
|
|
//
|
|
|
|
std::vector<unsigned char> GenerateNewKey()
|
|
{
|
|
RandAddSeedPerfmon();
|
|
CKey key;
|
|
key.MakeNewKey();
|
|
if (!AddKey(key))
|
|
throw std::runtime_error("GenerateNewKey() : AddKey failed");
|
|
return key.GetPubKey();
|
|
}
|
|
|
|
bool AddKey(const CKey& key)
|
|
{
|
|
CRITICAL_BLOCK(cs_mapKeys)
|
|
{
|
|
mapKeys[key.GetPubKey()] = key.GetPrivKey();
|
|
mapPubKeys[Hash160(key.GetPubKey())] = key.GetPubKey();
|
|
}
|
|
return CWalletDB().WriteKey(key.GetPubKey(), key.GetPrivKey());
|
|
}
|