dash/src/evo/specialtx.h
Kittywhiskers Van Gogh 80777646d8
tests: (in)valid unit test vectors against IsTriviallyValid() evo calls (#4660)
* evo: resolve suggestions given in dash#4696

* evo: add known-good mainnet vectors for IsTriviallyValid()

* evo: add artificially malformed vectors for IsTriviallyValid()

* evo: add IsTriviallyValid() tests

Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>

* Make sure we deserialize the right type of a special tx in GetTxPayload, and debug assert

Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-03-06 00:54:26 -06:00

51 lines
1.4 KiB
C++

// Copyright (c) 2018-2021 The Dash Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_EVO_SPECIALTX_H
#define BITCOIN_EVO_SPECIALTX_H
#include <primitives/transaction.h>
#include <serialize.h>
#include <streams.h>
#include <uint256.h>
#include <version.h>
#include <vector>
template <typename T>
inline bool GetTxPayload(const std::vector<unsigned char>& payload, T& obj)
{
CDataStream ds(payload, SER_NETWORK, PROTOCOL_VERSION);
try {
ds >> obj;
} catch (std::exception& e) {
return false;
}
return ds.empty();
}
template <typename T>
inline bool GetTxPayload(const CMutableTransaction& tx, T& obj)
{
ASSERT_IF_DEBUG(tx.nType == obj.SPECIALTX_TYPE);
return tx.nType == obj.SPECIALTX_TYPE && GetTxPayload(tx.vExtraPayload, obj);
}
template <typename T>
inline bool GetTxPayload(const CTransaction& tx, T& obj)
{
ASSERT_IF_DEBUG(tx.nType == obj.SPECIALTX_TYPE);
return tx.nType == obj.SPECIALTX_TYPE && GetTxPayload(tx.vExtraPayload, obj);
}
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());
}
uint256 CalcTxInputsHash(const CTransaction& tx);
#endif // BITCOIN_EVO_SPECIALTX_H