PIVX Core  5.6.99
P2P Digital Currency
destination_io.cpp
Go to the documentation of this file.
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"
8 
9 namespace Standard {
10 
11  std::string EncodeDestination(const CWDestination &address, const CChainParams::Base58Type addrType) {
12  const CTxDestination *dest = boost::get<CTxDestination>(&address);
13  if (!dest) {
14  return KeyIO::EncodePaymentAddress(*boost::get<libzcash::SaplingPaymentAddress>(&address));
15  }
16  return EncodeDestination(*dest, addrType);
17  };
18 
19  CWDestination DecodeDestination(const std::string& strAddress)
20  {
21  bool isStaking = false;
22  bool isExchange = false;
23  return DecodeDestination(strAddress, isStaking, isExchange);
24  }
25 
26  CWDestination DecodeDestination(const std::string& strAddress, bool& isStaking, bool& isExchange)
27  {
28  bool isShielded = false;
29  return DecodeDestination(strAddress, isStaking, isExchange, isShielded);
30  }
31 
32  // agregar isShielded
33  CWDestination DecodeDestination(const std::string& strAddress, bool& isStaking, bool& isExchange, bool& isShielded)
34  {
35  CWDestination dest;
36  CTxDestination regDest = ::DecodeDestination(strAddress, isStaking, isExchange);
37  if (!IsValidDestination(regDest)) {
38  const auto sapDest = KeyIO::DecodeSaplingPaymentAddress(strAddress);
39  if (sapDest) {
40  isShielded = true;
41  return *sapDest;
42  }
43  }
44  return regDest;
45 
46  }
47 
48  bool IsValidDestination(const CWDestination& address)
49  {
50  // Only regular base58 addresses and shielded addresses accepted here for now
51  const libzcash::SaplingPaymentAddress *dest1 = boost::get<libzcash::SaplingPaymentAddress>(&address);
52  if (dest1) return true;
53 
54  const CTxDestination *dest = boost::get<CTxDestination>(&address);
55  return dest && ::IsValidDestination(*dest);
56  }
57 
59  {
60  return boost::get<libzcash::SaplingPaymentAddress>(&dest);
61  }
62 
64  {
65  return boost::get<CTxDestination>(&dest);
66  }
67 
68 } // End Standard namespace
69 
71 {
72  this->dest = from.dest;
73  this->isP2CS = from.isP2CS;
74  this->isExchange = from.isExchange;
75  return *this;
76 }
77 
78 // Returns the key ID if Destination is a transparent "regular" destination
80 {
82  return (regDest) ? boost::get<CKeyID>(regDest) : nullptr;
83 }
84 
85 std::string Destination::ToString() const
86 {
88  // Invalid address
89  return "";
90  }
94  return Standard::EncodeDestination(dest, addrType);
95 }
96 
A reference to a CKey: the Hash160 of its serialized public key.
Definition: pubkey.h:21
Wrapper class for every supported address.
const CKeyID * getKeyID()
Destination & operator=(const Destination &from)
CWDestination dest
std::string ToString() const
Sapling functions.
Definition: address.h:30
boost::variant< CTxDestination, libzcash::SaplingPaymentAddress > CWDestination
std::string EncodePaymentAddress(const libzcash::PaymentAddress &zaddr)
Optional< libzcash::SaplingPaymentAddress > DecodeSaplingPaymentAddress(const std::string &strAddress)
const CTxDestination * GetTransparentDestination(const CWDestination &dest)
bool IsValidDestination(const CWDestination &address)
std::string EncodeDestination(const CWDestination &address, const CChainParams::Base58Type addrType)
CWDestination DecodeDestination(const std::string &strAddress)
const libzcash::SaplingPaymentAddress * GetShieldedDestination(const CWDestination &dest)
boost::variant< CNoDestination, CKeyID, CScriptID, CExchangeKeyID > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:72