2022-06-08 01:36:46 +02:00
|
|
|
// Copyright (c) 2018-2022 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
|
|
|
|
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>
|
|
|
|
inline bool GetTxPayload(const std::vector<unsigned char>& payload, T& obj)
|
|
|
|
{
|
|
|
|
CDataStream ds(payload, SER_NETWORK, PROTOCOL_VERSION);
|
|
|
|
try {
|
|
|
|
ds >> obj;
|
2022-10-18 12:24:00 +02:00
|
|
|
} catch (const std::exception& e) {
|
2018-02-14 12:05:25 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return ds.empty();
|
|
|
|
}
|
|
|
|
template <typename T>
|
2022-03-30 01:56:30 +02:00
|
|
|
inline bool GetTxPayload(const CMutableTransaction& tx, T& obj, bool assert_type = true)
|
2018-02-14 12:05:25 +01:00
|
|
|
{
|
2022-03-30 01:56:30 +02:00
|
|
|
if (assert_type) { ASSERT_IF_DEBUG(tx.nType == obj.SPECIALTX_TYPE); }
|
2022-03-06 07:54:26 +01:00
|
|
|
return tx.nType == obj.SPECIALTX_TYPE && GetTxPayload(tx.vExtraPayload, obj);
|
2018-02-14 12:05:25 +01:00
|
|
|
}
|
|
|
|
template <typename T>
|
2022-03-30 01:56:30 +02:00
|
|
|
inline bool GetTxPayload(const CTransaction& tx, T& obj, bool assert_type = true)
|
2018-02-14 12:05:25 +01:00
|
|
|
{
|
2022-03-30 01:56:30 +02:00
|
|
|
if (assert_type) { ASSERT_IF_DEBUG(tx.nType == obj.SPECIALTX_TYPE); }
|
2022-03-06 07:54:26 +01:00
|
|
|
return tx.nType == obj.SPECIALTX_TYPE && GetTxPayload(tx.vExtraPayload, obj);
|
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;
|
|
|
|
tx.vExtraPayload.assign(ds.begin(), ds.end());
|
|
|
|
}
|
|
|
|
|
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
|