|
|
@ -6,23 +6,30 @@ |
|
|
|
#include "keystore.h" |
|
|
|
#include "keystore.h" |
|
|
|
|
|
|
|
|
|
|
|
#include "key.h" |
|
|
|
#include "key.h" |
|
|
|
|
|
|
|
#include "pubkey.h" |
|
|
|
#include "util.h" |
|
|
|
#include "util.h" |
|
|
|
|
|
|
|
|
|
|
|
#include <boost/foreach.hpp> |
|
|
|
#include <boost/foreach.hpp> |
|
|
|
|
|
|
|
|
|
|
|
bool CKeyStore::GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const |
|
|
|
bool CKeyStore::AddKey(const CKey &key) { |
|
|
|
|
|
|
|
return AddKeyPubKey(key, key.GetPubKey()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool CBasicKeyStore::GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
CKey key; |
|
|
|
CKey key; |
|
|
|
if (!GetKey(address, key)) |
|
|
|
if (!GetKey(address, key)) { |
|
|
|
|
|
|
|
WatchKeyMap::const_iterator it = mapWatchKeys.find(address); |
|
|
|
|
|
|
|
if (it != mapWatchKeys.end()) { |
|
|
|
|
|
|
|
vchPubKeyOut = it->second; |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
vchPubKeyOut = key.GetPubKey(); |
|
|
|
vchPubKeyOut = key.GetPubKey(); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool CKeyStore::AddKey(const CKey &key) { |
|
|
|
|
|
|
|
return AddKeyPubKey(key, key.GetPubKey()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool CBasicKeyStore::AddKeyPubKey(const CKey& key, const CPubKey &pubkey) |
|
|
|
bool CBasicKeyStore::AddKeyPubKey(const CKey& key, const CPubKey &pubkey) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LOCK(cs_KeyStore); |
|
|
|
LOCK(cs_KeyStore); |
|
|
@ -58,10 +65,29 @@ bool CBasicKeyStore::GetCScript(const CScriptID &hash, CScript& redeemScriptOut) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static bool ExtractPubKey(const CScript &dest, CPubKey& pubKeyOut) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
//TODO: Use Solver to extract this?
|
|
|
|
|
|
|
|
CScript::const_iterator pc = dest.begin(); |
|
|
|
|
|
|
|
opcodetype opcode; |
|
|
|
|
|
|
|
std::vector<unsigned char> vch; |
|
|
|
|
|
|
|
if (!dest.GetOp(pc, opcode, vch) || vch.size() < 33 || vch.size() > 65) |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
pubKeyOut = CPubKey(vch); |
|
|
|
|
|
|
|
if (!pubKeyOut.IsFullyValid()) |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
if (!dest.GetOp(pc, opcode, vch) || opcode != OP_CHECKSIG || dest.GetOp(pc, opcode, vch)) |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool CBasicKeyStore::AddWatchOnly(const CScript &dest) |
|
|
|
bool CBasicKeyStore::AddWatchOnly(const CScript &dest) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LOCK(cs_KeyStore); |
|
|
|
LOCK(cs_KeyStore); |
|
|
|
setWatchOnly.insert(dest); |
|
|
|
setWatchOnly.insert(dest); |
|
|
|
|
|
|
|
CPubKey pubKey; |
|
|
|
|
|
|
|
if (ExtractPubKey(dest, pubKey)) |
|
|
|
|
|
|
|
mapWatchKeys[pubKey.GetID()] = pubKey; |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -69,6 +95,9 @@ bool CBasicKeyStore::RemoveWatchOnly(const CScript &dest) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LOCK(cs_KeyStore); |
|
|
|
LOCK(cs_KeyStore); |
|
|
|
setWatchOnly.erase(dest); |
|
|
|
setWatchOnly.erase(dest); |
|
|
|
|
|
|
|
CPubKey pubKey; |
|
|
|
|
|
|
|
if (ExtractPubKey(dest, pubKey)) |
|
|
|
|
|
|
|
mapWatchKeys.erase(pubKey.GetID()); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|