2011-08-09 13:27:58 +02:00
|
|
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
2014-12-17 02:47:57 +01:00
|
|
|
// Copyright (c) 2009-2014 The Bitcoin Core developers
|
2014-10-26 09:35:06 +01:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2012-05-18 16:02:28 +02:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2011-06-01 18:27:05 +02:00
|
|
|
|
2012-04-15 22:10:54 +02:00
|
|
|
#include "keystore.h"
|
2013-04-13 07:13:08 +02:00
|
|
|
|
|
|
|
#include "crypter.h"
|
|
|
|
#include "key.h"
|
2014-08-20 17:37:40 +02:00
|
|
|
#include "script/script.h"
|
2014-09-25 04:24:46 +02:00
|
|
|
#include "script/standard.h"
|
Split up util.cpp/h
Split up util.cpp/h into:
- string utilities (hex, base32, base64): no internal dependencies, no dependency on boost (apart from foreach)
- money utilities (parsesmoney, formatmoney)
- time utilities (gettime*, sleep, format date):
- and the rest (logging, argument parsing, config file parsing)
The latter is basically the environment and OS handling,
and is stripped of all utility functions, so we may want to
rename it to something else than util.cpp/h for clarity (Matt suggested
osinterface).
Breaks dependency of sha256.cpp on all the things pulled in by util.
2014-08-21 16:11:09 +02:00
|
|
|
#include "util.h"
|
2011-06-01 18:27:05 +02:00
|
|
|
|
2013-04-13 07:13:08 +02:00
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
|
2012-05-14 23:44:52 +02:00
|
|
|
bool CKeyStore::GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const
|
2011-07-05 16:42:32 +02:00
|
|
|
{
|
|
|
|
CKey key;
|
2011-07-05 20:53:43 +02:00
|
|
|
if (!GetKey(address, key))
|
2011-07-05 16:42:32 +02:00
|
|
|
return false;
|
|
|
|
vchPubKeyOut = key.GetPubKey();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-05-01 06:52:05 +02:00
|
|
|
bool CKeyStore::AddKey(const CKey &key) {
|
|
|
|
return AddKeyPubKey(key, key.GetPubKey());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CBasicKeyStore::AddKeyPubKey(const CKey& key, const CPubKey &pubkey)
|
2011-06-01 18:27:05 +02:00
|
|
|
{
|
2013-05-01 06:52:05 +02:00
|
|
|
LOCK(cs_KeyStore);
|
|
|
|
mapKeys[pubkey.GetID()] = key;
|
2011-06-25 14:57:32 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-01-05 03:40:52 +01:00
|
|
|
bool CBasicKeyStore::AddCScript(const CScript& redeemScript)
|
2011-10-03 19:05:43 +02:00
|
|
|
{
|
2014-03-11 03:43:15 +01:00
|
|
|
if (redeemScript.size() > MAX_SCRIPT_ELEMENT_SIZE)
|
|
|
|
return error("CBasicKeyStore::AddCScript() : redeemScripts > %i bytes are invalid", MAX_SCRIPT_ELEMENT_SIZE);
|
|
|
|
|
2013-05-01 06:52:05 +02:00
|
|
|
LOCK(cs_KeyStore);
|
2014-09-25 04:24:46 +02:00
|
|
|
mapScripts[CScriptID(redeemScript)] = redeemScript;
|
2011-10-03 19:05:43 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-05-14 23:44:52 +02:00
|
|
|
bool CBasicKeyStore::HaveCScript(const CScriptID& hash) const
|
2011-10-03 19:05:43 +02:00
|
|
|
{
|
2013-05-01 06:52:05 +02:00
|
|
|
LOCK(cs_KeyStore);
|
|
|
|
return mapScripts.count(hash) > 0;
|
2011-10-03 19:05:43 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 23:44:52 +02:00
|
|
|
bool CBasicKeyStore::GetCScript(const CScriptID &hash, CScript& redeemScriptOut) const
|
2011-10-03 19:05:43 +02:00
|
|
|
{
|
2013-05-01 06:52:05 +02:00
|
|
|
LOCK(cs_KeyStore);
|
|
|
|
ScriptMap::const_iterator mi = mapScripts.find(hash);
|
|
|
|
if (mi != mapScripts.end())
|
2011-10-03 19:05:43 +02:00
|
|
|
{
|
2013-05-01 06:52:05 +02:00
|
|
|
redeemScriptOut = (*mi).second;
|
|
|
|
return true;
|
2011-10-03 19:05:43 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-06-09 21:11:59 +02:00
|
|
|
bool CBasicKeyStore::AddWatchOnly(const CScript &dest)
|
2013-07-26 01:06:01 +02:00
|
|
|
{
|
|
|
|
LOCK(cs_KeyStore);
|
|
|
|
setWatchOnly.insert(dest);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-07-26 21:05:11 +02:00
|
|
|
bool CBasicKeyStore::RemoveWatchOnly(const CScript &dest)
|
|
|
|
{
|
|
|
|
LOCK(cs_KeyStore);
|
|
|
|
setWatchOnly.erase(dest);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-06-09 21:11:59 +02:00
|
|
|
bool CBasicKeyStore::HaveWatchOnly(const CScript &dest) const
|
2013-07-26 01:06:01 +02:00
|
|
|
{
|
|
|
|
LOCK(cs_KeyStore);
|
|
|
|
return setWatchOnly.count(dest) > 0;
|
|
|
|
}
|
2014-07-26 21:05:11 +02:00
|
|
|
|
|
|
|
bool CBasicKeyStore::HaveWatchOnly() const
|
|
|
|
{
|
|
|
|
LOCK(cs_KeyStore);
|
|
|
|
return (!setWatchOnly.empty());
|
|
|
|
}
|