2023-12-31 01:00:00 +01:00
|
|
|
// Copyright (c) 2018-2024 The Dash Core developers
|
2018-02-13 13:34:35 +01:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2018-04-02 00:30:17 +02:00
|
|
|
#ifndef BITCOIN_EVO_SPECIALTX_H
|
|
|
|
#define BITCOIN_EVO_SPECIALTX_H
|
2018-02-13 13:34:35 +01:00
|
|
|
|
2021-10-25 15:55:34 +02:00
|
|
|
#include <primitives/transaction.h>
|
2022-01-24 15:20:50 +01:00
|
|
|
#include <serialize.h>
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <streams.h>
|
2022-01-24 15:20:50 +01:00
|
|
|
#include <uint256.h>
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <version.h>
|
2018-02-14 12:05:25 +01:00
|
|
|
|
2023-02-03 06:22:51 +01:00
|
|
|
#include <string_view>
|
2024-01-12 04:43:01 +01:00
|
|
|
#include <optional>
|
2022-01-24 15:20:50 +01:00
|
|
|
#include <vector>
|
2018-02-13 13:34:35 +01:00
|
|
|
|
2018-02-14 12:05:25 +01:00
|
|
|
template <typename T>
|
2024-01-12 04:43:01 +01:00
|
|
|
std::optional<T> GetTxPayload(const std::vector<unsigned char>& payload)
|
2018-02-14 12:05:25 +01:00
|
|
|
{
|
|
|
|
CDataStream ds(payload, SER_NETWORK, PROTOCOL_VERSION);
|
|
|
|
try {
|
2024-01-12 04:43:01 +01:00
|
|
|
T obj;
|
2018-02-14 12:05:25 +01:00
|
|
|
ds >> obj;
|
2024-01-12 04:43:01 +01:00
|
|
|
return ds.empty() ? std::make_optional(std::move(obj)) : std::nullopt;
|
2022-10-18 12:24:00 +02:00
|
|
|
} catch (const std::exception& e) {
|
2024-01-12 04:43:01 +01:00
|
|
|
return std::nullopt;
|
2018-02-14 12:05:25 +01:00
|
|
|
}
|
|
|
|
}
|
2024-01-12 04:43:01 +01:00
|
|
|
template <typename T, typename TxType>
|
|
|
|
std::optional<T> GetTxPayload(const TxType& tx, bool assert_type = true)
|
2018-02-14 12:05:25 +01:00
|
|
|
{
|
2024-01-12 04:43:01 +01:00
|
|
|
if (assert_type) { ASSERT_IF_DEBUG(tx.nType == T::SPECIALTX_TYPE); }
|
|
|
|
if (tx.nType != T::SPECIALTX_TYPE) return std::nullopt;
|
|
|
|
return GetTxPayload<T>(tx.vExtraPayload);
|
2018-02-14 12:05:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void SetTxPayload(CMutableTransaction& tx, const T& payload)
|
|
|
|
{
|
|
|
|
CDataStream ds(SER_NETWORK, PROTOCOL_VERSION);
|
|
|
|
ds << payload;
|
2024-02-24 08:36:25 +01:00
|
|
|
tx.vExtraPayload.assign(UCharCast(ds.data()), UCharCast(ds.data() + ds.size()));
|
2018-02-14 12:05:25 +01:00
|
|
|
}
|
|
|
|
|
2018-02-13 13:34:35 +01:00
|
|
|
uint256 CalcTxInputsHash(const CTransaction& tx);
|
|
|
|
|
2018-04-02 00:30:17 +02:00
|
|
|
#endif // BITCOIN_EVO_SPECIALTX_H
|