Changeset View
Changeset View
Standalone View
Standalone View
src/dstencode.cpp
| // Copyright (c) 2017 The Bitcoin developers | // Copyright (c) 2017 The Bitcoin developers | ||||
| // Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
| // file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
| #include "dstencode.h" | #include "dstencode.h" | ||||
| #include "base58.h" | #include "base58.h" | ||||
| #include "cashaddrenc.h" | #include "cashaddrenc.h" | ||||
| #include "chainparams.h" | |||||
| #include "config.h" | #include "config.h" | ||||
| #include "script/standard.h" | #include "script/standard.h" | ||||
| std::string EncodeDestination(const CTxDestination &dest, | std::string EncodeDestination(const CTxDestination &dest, | ||||
| const Config &config) { | const Config &config) { | ||||
| const CChainParams ¶ms = config.GetChainParams(); | const CChainParams ¶ms = config.GetChainParams(); | ||||
| return config.UseCashAddrEncoding() ? EncodeCashAddr(dest, params) | return config.UseCashAddrEncoding() ? EncodeCashAddr(dest, params) | ||||
| : EncodeLegacyAddr(dest, params); | : EncodeLegacyAddr(dest, params); | ||||
| } | } | ||||
| CTxDestination DecodeDestination(const std::string &addr, | CTxDestination DecodeDestination(const std::string &addr, | ||||
| const CChainParams ¶ms) { | const Config &config) { | ||||
| const CChainParams ¶ms = config.GetChainParams(); | |||||
| CTxDestination dst = DecodeCashAddr(addr, params); | CTxDestination dst = DecodeCashAddr(addr, params); | ||||
| if (IsValidDestination(dst)) { | if (IsValidDestination(dst)) { | ||||
| return dst; | return dst; | ||||
| } | } | ||||
| return DecodeLegacyAddr(addr, params); | return DecodeLegacyAddr(addr, params); | ||||
| } | } | ||||
| bool IsValidDestinationString(const std::string &addr, | bool IsValidDestinationString(const std::string &addr, const Config &config) { | ||||
| const CChainParams ¶ms) { | return IsValidDestination(DecodeDestination(addr, config)); | ||||
| return IsValidDestination(DecodeDestination(addr, params)); | |||||
| } | |||||
| std::string EncodeDestination(const CTxDestination &dst) { | |||||
| return EncodeDestination(dst, GetConfig()); | |||||
| } | } | ||||