15 assert(
HaveKey(key_id) || mapWatchKeys.count(key_id));
31 mapScripts[id] = std::move(script);
38 if (!
GetKey(address, key)) {
40 WatchKeyMap::const_iterator it = mapWatchKeys.find(address);
41 if (it != mapWatchKeys.end()) {
42 vchPubKeyOut = it->second;
54 mapKeys[pubkey.
GetID()] = key;
62 return mapKeys.count(address) > 0;
68 std::set<CKeyID> set_address;
69 for (
const auto& mi : mapKeys) {
70 set_address.insert(mi.first);
78 KeyMap::const_iterator mi = mapKeys.find(address);
79 if (mi != mapKeys.end()) {
88 if (redeemScript.
size() > MAX_SCRIPT_ELEMENT_SIZE)
89 return error(
"CBasicKeyStore::AddCScript(): redeemScripts > %i bytes are invalid", MAX_SCRIPT_ELEMENT_SIZE);
92 mapScripts[
CScriptID(redeemScript)] = redeemScript;
99 return mapScripts.count(hash) > 0;
105 std::set<CScriptID> set_script;
106 for (
const auto& mi : mapScripts) {
107 set_script.insert(mi.first);
115 ScriptMap::const_iterator mi = mapScripts.find(hash);
116 if (mi != mapScripts.end())
118 redeemScriptOut = (*mi).second;
124 static bool ExtractPubKey(
const CScript &dest,
CPubKey& pubKeyOut)
129 std::vector<unsigned char> vch;
143 setWatchOnly.insert(dest);
145 if (ExtractPubKey(dest, pubKey)) {
146 mapWatchKeys[pubKey.
GetID()] = pubKey;
155 setWatchOnly.erase(dest);
157 if (ExtractPubKey(dest, pubKey)) {
158 mapWatchKeys.erase(pubKey.
GetID());
168 return setWatchOnly.count(dest) > 0;
174 return (!setWatchOnly.empty());
181 if (
auto id = boost::get<CKeyID>(&dest)) {
184 if (
auto witness_id = boost::get<WitnessV0KeyHash>(&dest)) {
185 return CKeyID(*witness_id);
187 if (
auto script_id = boost::get<CScriptID>(&dest)) {
191 if (
auto inner_witness_id = boost::get<WitnessV0KeyHash>(&inner_dest)) {
192 return CKeyID(*inner_witness_id);
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a standard scriptPubKey for the destination address.
bool GetOp(const_iterator &pc, opcodetype &opcodeRet, std::vector< unsigned char > &vchRet) const
bool HaveKey(const CKeyStore &store, const CKey &key)
Checks if a CKey is in the given CKeyStore compressed or otherwise.
CPubKey GetPubKey() const
Compute the public key from a private key.
bool GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const override
CCriticalSection cs_KeyStore
bool HaveCScript(const CScriptID &hash) const override
std::set< CScriptID > GetCScripts() const override
bool GetCScript(const CScriptID &hash, CScript &redeemScriptOut) const override
void ImplicitlyLearnRelatedKeyScripts(const CPubKey &pubkey) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore)
std::set< CKeyID > GetKeys() const override
bool AddCScript(const CScript &redeemScript) override
Support for BIP 0013 : see https://github.com/bitcoin/bips/blob/master/bip-0013.mediawiki.
CKeyID GetKeyForDestination(const CKeyStore &store, const CTxDestination &dest)
Return the CKeyID of the key involved in a script (if there is a unique one).
const unsigned char * begin() const
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
#define AssertLockHeld(cs)
static bool ValidSize(const std::vector< unsigned char > &vch)
opcodetype
Script opcodes.
bool IsFullyValid() const
fully validate whether this is a valid public key (more expensive than IsValid()) ...
boost::variant< CNoDestination, CKeyID, CScriptID, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
virtual bool HaveKey(const CKeyID &address) const =0
Check whether a key corresponding to a given address is present in the store.
An encapsulated public key.
bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey) override
Add a key to the store.
bool GetKey(const CKeyID &address, CKey &keyOut) const override
bool IsCompressed() const
Check whether the public key corresponding to this private key is (to be) compressed.
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
void Set(const T pbegin, const T pend, bool fCompressedIn)
Initialize using begin and end iterators to byte data.
bool RemoveWatchOnly(const CScript &dest) override
virtual bool GetCScript(const CScriptID &scriptid, CScript &script) const
Serialized script, used inside transaction inputs and outputs.
const unsigned char * end() const
A virtual base class for key stores.
A reference to a CKey: the Hash360 of its serialized public key.
bool error(const char *fmt, const Args &... args)
A reference to a CScript: the Hash360 of its serialization (see script.h)
An encapsulated private key.
bool HaveWatchOnly() const override
bool HaveKey(const CKeyID &address) const override
Check whether a key corresponding to a given address is present in the store.
bool AddWatchOnly(const CScript &dest) override
Support for Watch-only addresses.
bool IsCompressed() const
Check whether this is a compressed public key.