forked from Bitcoin-ABC/bitcoin-abc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable decoding and optional encoding of cashaddr
Summary: Wraps both cashaddr and base58 addresses into EncodeDestination and DecodeDestination. Test Plan: Added unittest Reviewers: #bitcoin_abc, deadalnix Reviewed By: #bitcoin_abc, deadalnix Subscribers: deadalnix Differential Revision: https://reviews.bitcoinabc.org/D660
- Loading branch information
Showing
31 changed files
with
202 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright (c) 2017 The Bitcoin developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
#include "dstencode.h" | ||
#include "base58.h" | ||
#include "cashaddrenc.h" | ||
#include "chainparams.h" | ||
#include "config.h" | ||
#include "script/standard.h" | ||
|
||
std::string EncodeDestination(const CTxDestination &dst, | ||
const CChainParams ¶ms, const Config &cfg) { | ||
return cfg.UseCashAddrEncoding() ? EncodeCashAddr(dst, params) | ||
: EncodeLegacyAddr(dst, params); | ||
} | ||
|
||
CTxDestination DecodeDestination(const std::string &addr, | ||
const CChainParams ¶ms) { | ||
CTxDestination dst = DecodeCashAddr(addr, params); | ||
if (IsValidDestination(dst)) { | ||
return dst; | ||
} | ||
return DecodeLegacyAddr(addr, params); | ||
} | ||
|
||
bool IsValidDestinationString(const std::string &addr, | ||
const CChainParams ¶ms) { | ||
return IsValidDestination(DecodeDestination(addr, params)); | ||
} | ||
|
||
std::string EncodeDestination(const CTxDestination &dst) { | ||
return EncodeDestination(dst, Params(), GetConfig()); | ||
} | ||
|
||
CTxDestination DecodeDestination(const std::string &addr) { | ||
return DecodeDestination(addr, Params()); | ||
} | ||
|
||
bool IsValidDestinationString(const std::string &addr) { | ||
return IsValidDestinationString(addr, Params()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#ifndef BITCOIN_DSTENCODE_H | ||
#define BITCOIN_DSTENCODE_H | ||
|
||
// key.h and pubkey.h are not used here, but gcc doesn't want to instantiate | ||
// CTxDestination if types are unknown | ||
#include "key.h" | ||
#include "pubkey.h" | ||
#include "script/standard.h" | ||
#include <string> | ||
|
||
class Config; | ||
class CChainParams; | ||
|
||
std::string EncodeDestination(const CTxDestination &, const CChainParams &, | ||
const Config &); | ||
CTxDestination DecodeDestination(const std::string &addr, const CChainParams &); | ||
bool IsValidDestinationString(const std::string &addr, | ||
const CChainParams ¶ms); | ||
|
||
// Temporary workaround. Don't rely on global state, pass all parameters in new | ||
// code. | ||
std::string EncodeDestination(const CTxDestination &); | ||
CTxDestination DecodeDestination(const std::string &addr); | ||
bool IsValidDestinationString(const std::string &addr); | ||
|
||
#endif // BITCOIN_DSTENCODE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1574,6 +1574,7 @@ bool AppInitParameterInteraction(Config &config) { | |
} | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.