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

          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        7350 :     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       22023 :     CAssetLockPayload() = default;
      44             : 
      45       22044 :     SERIALIZE_METHODS(CAssetLockPayload, obj)
      46             :     {
      47        7348 :         READWRITE(
      48             :             obj.nVersion,
      49             :             obj.creditOutputs
      50             :         );
      51        7348 :     }
      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        7326 :     uint8_t getVersion() const
      60             :     {
      61        7326 :         return nVersion;
      62             :     }
      63             : 
      64        6671 :     const std::vector<CTxOut>& getCreditOutputs() const
      65             :     {
      66        6671 :         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        5901 :     uint8_t nVersion{CURRENT_VERSION};
      80        5901 :     uint64_t index{0};
      81        5901 :     uint32_t fee{0};
      82        5901 :     uint32_t requestedHeight{0};
      83        5901 :     uint256 quorumHash{0};
      84        5901 :     CBLSSignature quorumSig{};
      85             : 
      86             : public:
      87        2310 :     CAssetUnlockPayload(uint8_t nVersion, uint64_t index, uint32_t fee, uint32_t requestedHeight,
      88             :             uint256 quorumHash, CBLSSignature quorumSig) :
      89        1155 :         nVersion(nVersion),
      90        1155 :         index(index),
      91        1155 :         fee(fee),
      92        1155 :         requestedHeight(requestedHeight),
      93        1155 :         quorumHash(quorumHash),
      94        1155 :         quorumSig(quorumSig)
      95        2310 :     {}
      96             : 
      97       17703 :     CAssetUnlockPayload() = default;
      98             : 
      99       21168 :     SERIALIZE_METHODS(CAssetUnlockPayload, obj)
     100             :     {
     101        7056 :         READWRITE(
     102             :             obj.nVersion,
     103             :             obj.index,
     104             :             obj.fee,
     105             :             obj.requestedHeight,
     106             :             obj.quorumHash,
     107             :             obj.quorumSig
     108             :         );
     109        7056 :     }
     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        3490 :     uint8_t getVersion() const
     120             :     {
     121        3490 :         return nVersion;
     122             :     }
     123             : 
     124        3113 :     uint64_t getIndex() const
     125             :     {
     126        3113 :         return index;
     127             :     }
     128             : 
     129        5618 :     uint32_t getFee() const
     130             :     {
     131        5618 :         return fee;
     132             :     }
     133             : 
     134        1155 :     uint32_t getRequestedHeight() const
     135             :     {
     136        1155 :         return requestedHeight;
     137             :     }
     138             : 
     139        2308 :     const uint256& getQuorumHash() const
     140             :     {
     141        2308 :         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        1372 :     int getHeightToExpiry() const
     152             :     {
     153        1372 :         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