aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/script/script.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/script/script.h b/src/script/script.h
index c722374113..3b799ad637 100644
--- a/src/script/script.h
+++ b/src/script/script.h
@@ -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