diff --git a/src/script/sign.h b/src/script/sign.h --- a/src/script/sign.h +++ b/src/script/sign.h @@ -49,6 +49,19 @@ bool GetPubKey(const CKeyID &address, CPubKey &pubkey) const; }; +struct FlatSigningProvider final : public SigningProvider { + std::map scripts; + std::map pubkeys; + std::map keys; + + bool GetCScript(const CScriptID &scriptid, CScript &script) const override; + bool GetPubKey(const CKeyID &keyid, CPubKey &pubkey) const override; + bool GetKey(const CKeyID &keyid, CKey &key) const override; +}; + +FlatSigningProvider Merge(const FlatSigningProvider &a, + const FlatSigningProvider &b); + /** Interface for signature creators. */ class BaseSignatureCreator { public: diff --git a/src/script/sign.cpp b/src/script/sign.cpp --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -428,6 +428,17 @@ return true; } }; + +template +bool LookupHelper(const M &map, const K &key, V &value) { + auto it = map.find(key); + if (it != map.end()) { + value = it->second; + return true; + } + return false; +} + } // namespace const BaseSignatureCreator &DUMMY_SIGNATURE_CREATOR = DummySignatureCreator(); @@ -554,3 +565,27 @@ CPubKey &pubkey) const { return m_provider->GetPubKey(address, pubkey); } + +bool FlatSigningProvider::GetCScript(const CScriptID &scriptid, + CScript &script) const { + return LookupHelper(scripts, scriptid, script); +} +bool FlatSigningProvider::GetPubKey(const CKeyID &keyid, + CPubKey &pubkey) const { + return LookupHelper(pubkeys, keyid, pubkey); +} +bool FlatSigningProvider::GetKey(const CKeyID &keyid, CKey &key) const { + return LookupHelper(keys, keyid, key); +} + +FlatSigningProvider Merge(const FlatSigningProvider &a, + const FlatSigningProvider &b) { + FlatSigningProvider ret; + ret.scripts = a.scripts; + ret.scripts.insert(b.scripts.begin(), b.scripts.end()); + ret.pubkeys = a.pubkeys; + ret.pubkeys.insert(b.pubkeys.begin(), b.pubkeys.end()); + ret.keys = a.keys; + ret.keys.insert(b.keys.begin(), b.keys.end()); + return ret; +}