Skip to content

Commit e54d760

Browse files
committed
Add simple FlatSigningProvider
1 parent 29943a9 commit e54d760

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

src/script/sign.cpp

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <script/standard.h>
1212
#include <uint256.h>
1313

14-
1514
typedef std::vector<unsigned char> valtype;
1615

1716
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 @@ class DummySignatureCreator final : public BaseSignatureCreator {
437436
return true;
438437
}
439438
};
439+
440+
template<typename M, typename K, typename V>
441+
bool LookupHelper(const M& map, const K& key, V& value)
442+
{
443+
auto it = map.find(key);
444+
if (it != map.end()) {
445+
value = it->second;
446+
return true;
447+
}
448+
return false;
449+
}
450+
440451
}
441452

442453
const BaseSignatureCreator& DUMMY_SIGNATURE_CREATOR = DummySignatureCreator();
@@ -460,7 +471,6 @@ bool IsSolvable(const SigningProvider& provider, const CScript& script)
460471
return false;
461472
}
462473

463-
464474
bool PartiallySignedTransaction::IsNull() const
465475
{
466476
return !tx && inputs.empty() && outputs.empty() && unknown.empty();
@@ -618,3 +628,19 @@ bool PublicOnlySigningProvider::GetPubKey(const CKeyID &address, CPubKey& pubkey
618628
{
619629
return m_provider->GetPubKey(address, pubkey);
620630
}
631+
632+
bool FlatSigningProvider::GetCScript(const CScriptID& scriptid, CScript& script) const { return LookupHelper(scripts, scriptid, script); }
633+
bool FlatSigningProvider::GetPubKey(const CKeyID& keyid, CPubKey& pubkey) const { return LookupHelper(pubkeys, keyid, pubkey); }
634+
bool FlatSigningProvider::GetKey(const CKeyID& keyid, CKey& key) const { return LookupHelper(keys, keyid, key); }
635+
636+
FlatSigningProvider Merge(const FlatSigningProvider& a, const FlatSigningProvider& b)
637+
{
638+
FlatSigningProvider ret;
639+
ret.scripts = a.scripts;
640+
ret.scripts.insert(b.scripts.begin(), b.scripts.end());
641+
ret.pubkeys = a.pubkeys;
642+
ret.pubkeys.insert(b.pubkeys.begin(), b.pubkeys.end());
643+
ret.keys = a.keys;
644+
ret.keys.insert(b.keys.begin(), b.keys.end());
645+
return ret;
646+
}

src/script/sign.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,19 @@ class PublicOnlySigningProvider : public SigningProvider
4343
bool GetPubKey(const CKeyID &address, CPubKey& pubkey) const;
4444
};
4545

46+
struct FlatSigningProvider final : public SigningProvider
47+
{
48+
std::map<CScriptID, CScript> scripts;
49+
std::map<CKeyID, CPubKey> pubkeys;
50+
std::map<CKeyID, CKey> keys;
51+
52+
bool GetCScript(const CScriptID& scriptid, CScript& script) const override;
53+
bool GetPubKey(const CKeyID& keyid, CPubKey& pubkey) const override;
54+
bool GetKey(const CKeyID& keyid, CKey& key) const override;
55+
};
56+
57+
FlatSigningProvider Merge(const FlatSigningProvider& a, const FlatSigningProvider& b);
58+
4659
/** Interface for signature creators. */
4760
class BaseSignatureCreator {
4861
public:

0 commit comments

Comments
 (0)