LCOV - code coverage report
Current view: top level - src/evo - assetlocktx.h (source / functions) Hit Total Coverage
Test: test_dash_coverage.info Lines: 42 44 95.5 %
Date: 2026-06-25 07:23:51 Functions: 37 38 97.4 %

          Line data    Source code
       1             : // Copyright (c) 2023-2025 The Dash Core developers
       2             : // Distributed under the MIT software license, see the accompanying
       3             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       4             : 
       5             : #ifndef BITCOIN_EVO_ASSETLOCKTX_H
       6             : #define BITCOIN_EVO_ASSETLOCKTX_H
       7             : 
       8             : #include <bls/bls.h>
       9             : #include <consensus/amount.h>
      10             : #include <gsl/pointers.h>
      11             : #include <primitives/transaction.h>
      12             : #include <serialize.h>
      13             : #include <univalue.h>
      14             : 
      15             : #include <optional>
      16             : 
      17             : class CBlockIndex;
      18             : class CRangesSet;
      19             : class TxValidationState;
      20             : struct RPCResult;
      21             : namespace llmq {
      22             : class CQuorumManager;
      23             : } // namespace llmq
      24             : namespace node {
      25             : class BlockManager;
      26             : } // namespace node
      27             : 
      28             : class CAssetLockPayload
      29             : {
      30             : public:
      31             :     static constexpr uint8_t CURRENT_VERSION = 1;
      32             :     static constexpr auto SPECIALTX_TYPE = TRANSACTION_ASSET_LOCK;
      33             : 
      34             : private:
      35          24 :     uint8_t nVersion{CURRENT_VERSION};
      36             :     std::vector<CTxOut> creditOutputs;
      37             : 
      38             : public:
      39          18 :     explicit CAssetLockPayload(const std::vector<CTxOut>& creditOutputs) :
      40           9 :         creditOutputs(creditOutputs)
      41          18 :     {}
      42             : 
      43          45 :     CAssetLockPayload() = default;
      44             : 
      45          66 :     SERIALIZE_METHODS(CAssetLockPayload, obj)
      46             :     {
      47          22 :         READWRITE(
      48             :             obj.nVersion,
      49             :             obj.creditOutputs
      50             :         );
      51          22 :     }
      52             : 
      53             :     std::string ToString() const;
      54             : 
      55             :     [[nodiscard]] static RPCResult GetJsonHelp(const std::string& key, bool optional);
      56             :     [[nodiscard]] UniValue ToJson() const;
      57             : 
      58             :     // getters
      59          19 :     uint8_t getVersion() const
      60             :     {
      61          19 :         return nVersion;
      62             :     }
      63             : 
      64          21 :     const std::vector<CTxOut>& getCreditOutputs() const
      65             :     {
      66          21 :         return creditOutputs;
      67             :     }
      68             : };
      69             : 
      70             : class CAssetUnlockPayload
      71             : {
      72             : public:
      73             :     static constexpr uint8_t CURRENT_VERSION = 1;
      74             :     static constexpr auto SPECIALTX_TYPE = TRANSACTION_ASSET_UNLOCK;
      75             : 
      76             :     static constexpr size_t MAXIMUM_WITHDRAWALS = 32;
      77             : 
      78             : private:
      79           9 :     uint8_t nVersion{CURRENT_VERSION};
      80           9 :     uint64_t index{0};
      81           9 :     uint32_t fee{0};
      82           9 :     uint32_t requestedHeight{0};
      83           9 :     uint256 quorumHash{0};
      84           9 :     CBLSSignature quorumSig{};
      85             : 
      86             : public:
      87          10 :     CAssetUnlockPayload(uint8_t nVersion, uint64_t index, uint32_t fee, uint32_t requestedHeight,
      88             :             uint256 quorumHash, CBLSSignature quorumSig) :
      89           5 :         nVersion(nVersion),
      90           5 :         index(index),
      91           5 :         fee(fee),
      92           5 :         requestedHeight(requestedHeight),
      93           5 :         quorumHash(quorumHash),
      94           5 :         quorumSig(quorumSig)
      95          10 :     {}
      96             : 
      97          27 :     CAssetUnlockPayload() = default;
      98             : 
      99          42 :     SERIALIZE_METHODS(CAssetUnlockPayload, obj)
     100             :     {
     101          14 :         READWRITE(
     102             :             obj.nVersion,
     103             :             obj.index,
     104             :             obj.fee,
     105             :             obj.requestedHeight,
     106             :             obj.quorumHash,
     107             :             obj.quorumSig
     108             :         );
     109          14 :     }
     110             : 
     111             :     std::string ToString() const;
     112             : 
     113             :     [[nodiscard]] static RPCResult GetJsonHelp(const std::string& key, bool optional);
     114             :     [[nodiscard]] UniValue ToJson() const;
     115             : 
     116             :     bool VerifySig(const llmq::CQuorumManager& qman, const uint256& msgHash, gsl::not_null<const CBlockIndex*> pindexTip, TxValidationState& state) const;
     117             : 
     118             :     // getters
     119          16 :     uint8_t getVersion() const
     120             :     {
     121          16 :         return nVersion;
     122             :     }
     123             : 
     124           7 :     uint64_t getIndex() const
     125             :     {
     126           7 :         return index;
     127             :     }
     128             : 
     129           5 :     uint32_t getFee() const
     130             :     {
     131           5 :         return fee;
     132             :     }
     133             : 
     134           5 :     uint32_t getRequestedHeight() const
     135             :     {
     136           5 :         return requestedHeight;
     137             :     }
     138             : 
     139           8 :     const uint256& getQuorumHash() const
     140             :     {
     141           8 :         return quorumHash;
     142             :     }
     143             : 
     144           4 :     const CBLSSignature& getQuorumSig() const
     145             :     {
     146           4 :         return quorumSig;
     147             :     }
     148             : 
     149             :     // used by mempool to know when possible to drop a transaction as expired
     150             :     static constexpr int HEIGHT_DIFF_EXPIRING = 48;
     151           0 :     int getHeightToExpiry() const
     152             :     {
     153           0 :         return requestedHeight + HEIGHT_DIFF_EXPIRING;
     154             :     }
     155             : };
     156             : 
     157             : bool CheckAssetLockTx(const CTransaction& tx, TxValidationState& state);
     158             : bool CheckAssetUnlockTx(const node::BlockManager& blockman, const llmq::CQuorumManager& qman, const CTransaction& tx, gsl::not_null<const CBlockIndex*> pindexPrev, const std::optional<CRangesSet>& indexes, TxValidationState& state);
     159             : bool GetAssetUnlockFee(const CTransaction& tx, CAmount& txfee, TxValidationState& state);
     160             : 
     161             : #endif // BITCOIN_EVO_ASSETLOCKTX_H

Generated by: LCOV version 1.16