2011-08-09 07:27:58 -04:00
|
|
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
2013-10-20 16:25:06 -03:00
|
|
|
// Copyright (c) 2009-2013 The Bitcoin developers
|
2011-06-01 12:27:05 -04:00
|
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
2012-05-18 10:02:28 -04:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2011-06-01 12:27:05 -04:00
|
|
|
|
2012-04-15 17:10:54 -03:00
|
|
|
#include "keystore.h"
|
2013-04-13 02:13:08 -03:00
|
|
|
|
|
|
|
#include "crypter.h"
|
|
|
|
#include "key.h"
|
2011-11-08 15:20:29 -03:00
|
|
|
#include "script.h"
|
2011-06-01 12:27:05 -04:00
|
|
|
|
2013-04-13 02:13:08 -03:00
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
|
2012-05-14 17:44:52 -04:00
|
|
|
bool CKeyStore::GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const
|
2011-07-05 10:42:32 -04:00
|
|
|
{
|
|
|
|
CKey key;
|
2011-07-05 14:53:43 -04:00
|
|
|
if (!GetKey(address, key))
|
2011-07-05 10:42:32 -04:00
|
|
|
return false;
|
|
|
|
vchPubKeyOut = key.GetPubKey();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-05-01 00:52:05 -04:00
|
|
|
bool CKeyStore::AddKey(const CKey &key) {
|
|
|
|
return AddKeyPubKey(key, key.GetPubKey());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CBasicKeyStore::AddKeyPubKey(const CKey& key, const CPubKey &pubkey)
|
2011-06-01 12:27:05 -04:00
|
|
|
{
|
2013-05-01 00:52:05 -04:00
|
|
|
LOCK(cs_KeyStore);
|
|
|
|
mapKeys[pubkey.GetID()] = key;
|
2011-06-25 08:57:32 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-01-04 23:40:52 -03:00
|
|
|
bool CBasicKeyStore::AddCScript(const CScript& redeemScript)
|
2011-10-03 14:05:43 -03:00
|
|
|
{
|
2014-03-10 23:43:15 -03:00
|
|
|
if (redeemScript.size() > MAX_SCRIPT_ELEMENT_SIZE)
|
|
|
|
return error("CBasicKeyStore::AddCScript() : redeemScripts > %i bytes are invalid", MAX_SCRIPT_ELEMENT_SIZE);
|
|
|
|
|
2013-05-01 00:52:05 -04:00
|
|
|
LOCK(cs_KeyStore);
|
|
|
|
mapScripts[redeemScript.GetID()] = redeemScript;
|
2011-10-03 14:05:43 -03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-05-14 17:44:52 -04:00
|
|
|
bool CBasicKeyStore::HaveCScript(const CScriptID& hash) const
|
2011-10-03 14:05:43 -03:00
|
|
|
{
|
2013-05-01 00:52:05 -04:00
|
|
|
LOCK(cs_KeyStore);
|
|
|
|
return mapScripts.count(hash) > 0;
|
2011-10-03 14:05:43 -03:00
|
|
|
}
|
|
|
|
|
2012-05-14 17:44:52 -04:00
|
|
|
bool CBasicKeyStore::GetCScript(const CScriptID &hash, CScript& redeemScriptOut) const
|
2011-10-03 14:05:43 -03:00
|
|
|
{
|
2013-05-01 00:52:05 -04:00
|
|
|
LOCK(cs_KeyStore);
|
|
|
|
ScriptMap::const_iterator mi = mapScripts.find(hash);
|
|
|
|
if (mi != mapScripts.end())
|
2011-10-03 14:05:43 -03:00
|
|
|
{
|
2013-05-01 00:52:05 -04:00
|
|
|
redeemScriptOut = (*mi).second;
|
|
|
|
return true;
|
2011-10-03 14:05:43 -03:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|