LCOV - code coverage report
Current view: top level - src - destination_io.cpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 30 44 68.2 %
Date: 2025-02-23 09:33:43 Functions: 7 10 70.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 https://www.opensource.org/licenses/mit-license.php.
       4             : 
       5             : #include "destination_io.h"
       6             : #include "key_io.h"
       7             : #include "sapling/key_io_sapling.h"
       8             : 
       9             : namespace Standard {
      10             : 
      11        3802 :     std::string EncodeDestination(const CWDestination &address, const CChainParams::Base58Type addrType) {
      12        3802 :         const CTxDestination *dest = boost::get<CTxDestination>(&address);
      13        3802 :         if (!dest) {
      14        2566 :             return KeyIO::EncodePaymentAddress(*boost::get<libzcash::SaplingPaymentAddress>(&address));
      15             :         }
      16        2519 :         return EncodeDestination(*dest, addrType);
      17             :     };
      18             : 
      19        1070 :     CWDestination DecodeDestination(const std::string& strAddress)
      20             :     {
      21        1070 :         bool isStaking = false;
      22        1070 :         bool isExchange = false;
      23        1070 :         return DecodeDestination(strAddress, isStaking, isExchange);
      24             :     }
      25             : 
      26        1070 :     CWDestination DecodeDestination(const std::string& strAddress, bool& isStaking, bool& isExchange)
      27             :     {
      28        1070 :         bool isShielded = false;
      29        1070 :         return DecodeDestination(strAddress, isStaking, isExchange, isShielded);
      30             :     }
      31             : 
      32             :     // agregar isShielded
      33        1693 :     CWDestination DecodeDestination(const std::string& strAddress, bool& isStaking, bool& isExchange, bool& isShielded)
      34             :     {
      35        3386 :         CWDestination dest;
      36        3386 :         CTxDestination regDest = ::DecodeDestination(strAddress, isStaking, isExchange);
      37        1693 :         if (!IsValidDestination(regDest)) {
      38         162 :             const auto sapDest = KeyIO::DecodeSaplingPaymentAddress(strAddress);
      39         158 :             if (sapDest) {
      40         154 :                 isShielded = true;
      41         154 :                 return *sapDest;
      42             :             }
      43             :         }
      44        3232 :         return regDest;
      45             : 
      46             :     }
      47             : 
      48         887 :     bool IsValidDestination(const CWDestination& address)
      49             :     {
      50             :         // Only regular base58 addresses and shielded addresses accepted here for now
      51         887 :         const libzcash::SaplingPaymentAddress *dest1 = boost::get<libzcash::SaplingPaymentAddress>(&address);
      52         887 :         if (dest1) return true;
      53             : 
      54         809 :         const CTxDestination *dest = boost::get<CTxDestination>(&address);
      55         809 :         return dest && ::IsValidDestination(*dest);
      56             :     }
      57             : 
      58          58 :     const libzcash::SaplingPaymentAddress* GetShieldedDestination(const CWDestination& dest)
      59             :     {
      60          58 :         return boost::get<libzcash::SaplingPaymentAddress>(&dest);
      61             :     }
      62             : 
      63        1123 :     const CTxDestination* GetTransparentDestination(const CWDestination& dest)
      64             :     {
      65        1123 :         return boost::get<CTxDestination>(&dest);
      66             :     }
      67             : 
      68             : } // End Standard namespace
      69             : 
      70           0 : Destination& Destination::operator=(const Destination& from)
      71             : {
      72           0 :     this->dest = from.dest;
      73           0 :     this->isP2CS = from.isP2CS;
      74           0 :     this->isExchange = from.isExchange;
      75           0 :     return *this;
      76             : }
      77             : 
      78             : // Returns the key ID if Destination is a transparent "regular" destination
      79           0 : const CKeyID* Destination::getKeyID()
      80             : {
      81           0 :     const CTxDestination* regDest = Standard::GetTransparentDestination(dest);
      82           0 :     return (regDest) ? boost::get<CKeyID>(regDest) : nullptr;
      83             : }
      84             : 
      85           0 : std::string Destination::ToString() const
      86             : {
      87           0 :     if (!Standard::IsValidDestination(dest)) {
      88             :         // Invalid address
      89           0 :         return "";
      90             :     }
      91           0 :     CChainParams::Base58Type addrType = isP2CS ? CChainParams::STAKING_ADDRESS
      92           0 :                                  : (isExchange ? CChainParams::EXCHANGE_ADDRESS
      93             :                                  : CChainParams::PUBKEY_ADDRESS);
      94           0 :     return Standard::EncodeDestination(dest, addrType);
      95             : }
      96             : 

Generated by: LCOV version 1.14