Changeset View
Changeset View
Standalone View
Standalone View
src/keystore.cpp
Show First 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | bool CBasicKeyStore::GetKey(const CKeyID &address, CKey &keyOut) const { | ||||
keyOut = mi->second; | keyOut = mi->second; | ||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
bool CBasicKeyStore::AddCScript(const CScript &redeemScript) { | bool CBasicKeyStore::AddCScript(const CScript &redeemScript) { | ||||
if (redeemScript.size() > MAX_SCRIPT_ELEMENT_SIZE) | if (redeemScript.size() > MAX_SCRIPT_ELEMENT_SIZE) { | ||||
return error("CBasicKeyStore::AddCScript(): redeemScripts > %i bytes " | return error("CBasicKeyStore::AddCScript(): redeemScripts > %i bytes " | ||||
"are invalid", | "are invalid", | ||||
MAX_SCRIPT_ELEMENT_SIZE); | MAX_SCRIPT_ELEMENT_SIZE); | ||||
} | |||||
LOCK(cs_KeyStore); | LOCK(cs_KeyStore); | ||||
mapScripts[CScriptID(redeemScript)] = redeemScript; | mapScripts[CScriptID(redeemScript)] = redeemScript; | ||||
return true; | return true; | ||||
} | } | ||||
bool CBasicKeyStore::HaveCScript(const CScriptID &hash) const { | bool CBasicKeyStore::HaveCScript(const CScriptID &hash) const { | ||||
LOCK(cs_KeyStore); | LOCK(cs_KeyStore); | ||||
Show All 20 Lines | bool CBasicKeyStore::GetCScript(const CScriptID &hash, | ||||
return false; | return false; | ||||
} | } | ||||
static bool ExtractPubKey(const CScript &dest, CPubKey &pubKeyOut) { | static bool ExtractPubKey(const CScript &dest, CPubKey &pubKeyOut) { | ||||
// TODO: Use Solver to extract this? | // TODO: Use Solver to extract this? | ||||
CScript::const_iterator pc = dest.begin(); | CScript::const_iterator pc = dest.begin(); | ||||
opcodetype opcode; | opcodetype opcode; | ||||
std::vector<uint8_t> vch; | std::vector<uint8_t> vch; | ||||
if (!dest.GetOp(pc, opcode, vch) || vch.size() < 33 || vch.size() > 65) | if (!dest.GetOp(pc, opcode, vch) || vch.size() < 33 || vch.size() > 65) { | ||||
return false; | return false; | ||||
} | |||||
pubKeyOut = CPubKey(vch); | pubKeyOut = CPubKey(vch); | ||||
if (!pubKeyOut.IsFullyValid()) return false; | if (!pubKeyOut.IsFullyValid()) { | ||||
return false; | |||||
} | |||||
if (!dest.GetOp(pc, opcode, vch) || opcode != OP_CHECKSIG || | if (!dest.GetOp(pc, opcode, vch) || opcode != OP_CHECKSIG || | ||||
dest.GetOp(pc, opcode, vch)) | dest.GetOp(pc, opcode, vch)) { | ||||
return false; | return false; | ||||
} | |||||
return true; | 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; | CPubKey pubKey; | ||||
if (ExtractPubKey(dest, pubKey)) mapWatchKeys[pubKey.GetID()] = pubKey; | if (ExtractPubKey(dest, pubKey)) { | ||||
mapWatchKeys[pubKey.GetID()] = pubKey; | |||||
} | |||||
return true; | return true; | ||||
} | } | ||||
bool CBasicKeyStore::RemoveWatchOnly(const CScript &dest) { | bool CBasicKeyStore::RemoveWatchOnly(const CScript &dest) { | ||||
LOCK(cs_KeyStore); | LOCK(cs_KeyStore); | ||||
setWatchOnly.erase(dest); | setWatchOnly.erase(dest); | ||||
CPubKey pubKey; | CPubKey pubKey; | ||||
if (ExtractPubKey(dest, pubKey)) mapWatchKeys.erase(pubKey.GetID()); | if (ExtractPubKey(dest, pubKey)) { | ||||
mapWatchKeys.erase(pubKey.GetID()); | |||||
} | |||||
return true; | return true; | ||||
} | } | ||||
bool CBasicKeyStore::HaveWatchOnly(const CScript &dest) const { | bool CBasicKeyStore::HaveWatchOnly(const CScript &dest) const { | ||||
LOCK(cs_KeyStore); | LOCK(cs_KeyStore); | ||||
return setWatchOnly.count(dest) > 0; | return setWatchOnly.count(dest) > 0; | ||||
} | } | ||||
bool CBasicKeyStore::HaveWatchOnly() const { | bool CBasicKeyStore::HaveWatchOnly() const { | ||||
LOCK(cs_KeyStore); | LOCK(cs_KeyStore); | ||||
return (!setWatchOnly.empty()); | return (!setWatchOnly.empty()); | ||||
} | } |