CWallet class
[novacoin.git] / src / keystore.cpp
1 // Copyright (c) 2009-2011 Satoshi Nakamoto & Bitcoin developers
2 // Distributed under the MIT/X11 software license, see the accompanying
3 // file license.txt or http://www.opensource.org/licenses/mit-license.php.
4
5 #include "headers.h"
6 #include "db.h"
7
8
9
10 //////////////////////////////////////////////////////////////////////////////
11 //
12 // mapKeys
13 //
14
15 std::vector<unsigned char> CKeyStore::GenerateNewKey()
16 {
17     RandAddSeedPerfmon();
18     CKey key;
19     key.MakeNewKey();
20     if (!AddKey(key))
21         throw std::runtime_error("GenerateNewKey() : AddKey failed");
22     return key.GetPubKey();
23 }
24
25 bool CKeyStore::AddKey(const CKey& key)
26 {
27     CRITICAL_BLOCK(cs_mapKeys)
28     {
29         mapKeys[key.GetPubKey()] = key.GetPrivKey();
30         mapPubKeys[Hash160(key.GetPubKey())] = key.GetPubKey();
31     }
32 }
33