mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-11 12:22:39 -03:00
script: expose getter for CScriptNum, add a BuildScript helper
Some prep work for Miniscript. BuildScript is an efficient way to build Scripts in a generic manner (by concatenating OPs, data, and other Scripts). Co-Authored-By: Pieter Wuille <pieter@wuille.net>
This commit is contained in:
parent
f4e289f384
commit
4fe29368c0
1 changed files with 27 additions and 0 deletions
|
@ -335,6 +335,8 @@ public:
|
|||
return m_value;
|
||||
}
|
||||
|
||||
int64_t GetInt64() const { return m_value; }
|
||||
|
||||
std::vector<unsigned char> getvch() const
|
||||
{
|
||||
return serialize(m_value);
|
||||
|
@ -578,4 +580,29 @@ bool IsOpSuccess(const opcodetype& opcode);
|
|||
|
||||
bool CheckMinimalPush(const std::vector<unsigned char>& data, opcodetype opcode);
|
||||
|
||||
/** Build a script by concatenating other scripts, or any argument accepted by CScript::operator<<. */
|
||||
template<typename... Ts>
|
||||
CScript BuildScript(Ts&&... inputs)
|
||||
{
|
||||
CScript ret;
|
||||
int cnt{0};
|
||||
|
||||
([&ret, &cnt] (Ts&& input) {
|
||||
cnt++;
|
||||
if constexpr (std::is_same_v<std::remove_cv_t<std::remove_reference_t<Ts>>, CScript>) {
|
||||
// If it is a CScript, extend ret with it. Move or copy the first element instead.
|
||||
if (cnt == 0) {
|
||||
ret = std::forward<Ts>(input);
|
||||
} else {
|
||||
ret.insert(ret.end(), input.begin(), input.end());
|
||||
}
|
||||
} else {
|
||||
// Otherwise invoke CScript::operator<<.
|
||||
ret << input;
|
||||
}
|
||||
} (std::forward<Ts>(inputs)), ...);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif // BITCOIN_SCRIPT_SCRIPT_H
|
||||
|
|
Loading…
Reference in a new issue