LCOV - code coverage report
Current view: top level - src/wallet - hdchain.h (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 14 16 87.5 %
Date: 2025-02-23 09:33:43 Functions: 3 3 100.0 %

          Line data    Source code
       1             : // Copyright (c) 2020-2021 The PIVX 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 PIVX_WALLET_HDCHAIN_H
       6             : #define PIVX_WALLET_HDCHAIN_H
       7             : 
       8             : #include "key.h"
       9             : 
      10             : namespace HDChain {
      11             :     namespace ChangeType {
      12             :         static const uint8_t EXTERNAL = 0;
      13             :         static const uint8_t INTERNAL = 1;
      14             :         static const uint8_t STAKING = 2;
      15             :     };
      16             : 
      17             :     namespace ChainCounterType {
      18             :         static const uint8_t Standard  = 0;
      19             :         static const uint8_t Sapling   = 1;
      20             :     };
      21             : }
      22             : 
      23             : /* Simple HD chain data model for regular and sapling addresses */
      24             : class CHDChain
      25             : {
      26             : private:
      27             :     int nVersion;
      28             :     CKeyID seed_id;
      29             : 
      30             : public:
      31             :     // Standard/Sapling hd chain
      32             :     static const int CURRENT_VERSION = 2;
      33             :     // Single account counters.
      34             :     uint32_t nExternalChainCounter{0};
      35             :     uint32_t nInternalChainCounter{0};
      36             :     uint32_t nStakingChainCounter{0};
      37             :     // Chain counter type
      38             :     uint8_t chainType{HDChain::ChainCounterType::Standard};
      39             : 
      40        3632 :     explicit CHDChain(const uint8_t& _chainType = HDChain::ChainCounterType::Standard) : chainType(_chainType) { SetNull(); }
      41             : 
      42       27096 :     SERIALIZE_METHODS(CHDChain, obj)
      43             :     {
      44       13548 :         READWRITE(obj.nVersion, obj.seed_id, obj.nExternalChainCounter, obj.nInternalChainCounter, obj.nStakingChainCounter);
      45       13548 :         if (obj.nVersion > 1) READWRITE(obj.chainType);
      46       13548 :     }
      47             : 
      48             :     bool SetNull();
      49             :     bool IsNull() const;
      50             : 
      51             :     bool SetSeed(const CKeyID& seedId);
      52       26859 :     CKeyID GetID() const { return seed_id; }
      53             : 
      54       11506 :     uint32_t& GetChainCounter(const uint8_t& type = HDChain::ChangeType::EXTERNAL) {
      55       11506 :         switch (type) {
      56        6559 :             case HDChain::ChangeType::EXTERNAL:
      57        6559 :                 return nExternalChainCounter;
      58        3228 :             case HDChain::ChangeType::INTERNAL:
      59        3228 :                 return nInternalChainCounter;
      60        1719 :             case HDChain::ChangeType::STAKING:
      61        1719 :                 return nStakingChainCounter;
      62           0 :             default:
      63           0 :                 throw std::runtime_error("HD chain type doesn't exist.");
      64             :         }
      65             :     }
      66             : };
      67             : 
      68             : #endif // PIVX_WALLET_HDCHAIN_H

Generated by: LCOV version 1.14