Add simple FlatSigningProvider

This commit is contained in:
Pieter Wuille 2018-07-12 15:03:55 -07:00
parent 29943a904a
commit e54d76044b
2 changed files with 41 additions and 2 deletions

View file

@ -11,7 +11,6 @@
#include <script/standard.h> #include <script/standard.h>
#include <uint256.h> #include <uint256.h>
typedef std::vector<unsigned char> valtype; typedef std::vector<unsigned char> valtype;
MutableTransactionSignatureCreator::MutableTransactionSignatureCreator(const CMutableTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn, int nHashTypeIn) : txTo(txToIn), nIn(nInIn), nHashType(nHashTypeIn), amount(amountIn), checker(txTo, nIn, amountIn) {} MutableTransactionSignatureCreator::MutableTransactionSignatureCreator(const CMutableTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn, int nHashTypeIn) : txTo(txToIn), nIn(nInIn), nHashType(nHashTypeIn), amount(amountIn), checker(txTo, nIn, amountIn) {}
@ -437,6 +436,18 @@ public:
return true; return true;
} }
}; };
template<typename M, typename K, typename V>
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;
}
} }
const BaseSignatureCreator& DUMMY_SIGNATURE_CREATOR = DummySignatureCreator(); const BaseSignatureCreator& DUMMY_SIGNATURE_CREATOR = DummySignatureCreator();
@ -460,7 +471,6 @@ bool IsSolvable(const SigningProvider& provider, const CScript& script)
return false; return false;
} }
bool PartiallySignedTransaction::IsNull() const bool PartiallySignedTransaction::IsNull() const
{ {
return !tx && inputs.empty() && outputs.empty() && unknown.empty(); return !tx && inputs.empty() && outputs.empty() && unknown.empty();
@ -618,3 +628,19 @@ bool PublicOnlySigningProvider::GetPubKey(const CKeyID &address, CPubKey& pubkey
{ {
return m_provider->GetPubKey(address, pubkey); 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;
}

View file

@ -43,6 +43,19 @@ public:
bool GetPubKey(const CKeyID &address, CPubKey& pubkey) const; bool GetPubKey(const CKeyID &address, CPubKey& pubkey) const;
}; };
struct FlatSigningProvider final : public SigningProvider
{
std::map<CScriptID, CScript> scripts;
std::map<CKeyID, CPubKey> pubkeys;
std::map<CKeyID, CKey> 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. */ /** Interface for signature creators. */
class BaseSignatureCreator { class BaseSignatureCreator {
public: public: