Changeset View
Changeset View
Standalone View
Standalone View
src/base58.cpp
Show First 20 Lines • Show All 202 Lines • ▼ Show 20 Lines | int CBase58Data::CompareTo(const CBase58Data &b58) const { | ||||
if (vchVersion < b58.vchVersion) return -1; | if (vchVersion < b58.vchVersion) return -1; | ||||
if (vchVersion > b58.vchVersion) return 1; | if (vchVersion > b58.vchVersion) return 1; | ||||
if (vchData < b58.vchData) return -1; | if (vchData < b58.vchData) return -1; | ||||
if (vchData > b58.vchData) return 1; | if (vchData > b58.vchData) return 1; | ||||
return 0; | return 0; | ||||
} | } | ||||
namespace { | namespace { | ||||
/** base58-encoded Bitcoin addresses. | |||||
deadalnix: While we are at it, could you put the `/**` on its own line ? | |||||
* Public-key-hash-addresses have version 0 (or 111 testnet). | |||||
* The data vector contains RIPEMD160(SHA256(pubkey)), where pubkey is the | |||||
* serialized public key. | |||||
* Script-hash-addresses have version 5 (or 196 testnet). | |||||
* The data vector contains RIPEMD160(SHA256(cscript)), where cscript is the | |||||
* serialized redemption script. | |||||
*/ | |||||
class CBitcoinAddress : public CBase58Data { | |||||
public: | |||||
bool Set(const CKeyID &id); | |||||
bool Set(const CScriptID &id); | |||||
bool Set(const CTxDestination &dest); | |||||
bool IsValid() const; | |||||
bool IsValid(const CChainParams ¶ms) const; | |||||
CBitcoinAddress() {} | |||||
CBitcoinAddress(const CTxDestination &dest) { Set(dest); } | |||||
CBitcoinAddress(const std::string &strAddress) { SetString(strAddress); } | |||||
CBitcoinAddress(const char *pszAddress) { SetString(pszAddress); } | |||||
CTxDestination Get() const; | |||||
bool GetKeyID(CKeyID &keyID) const; | |||||
bool IsScript() const; | |||||
}; | |||||
class CBitcoinAddressVisitor : public boost::static_visitor<bool> { | class CBitcoinAddressVisitor : public boost::static_visitor<bool> { | ||||
private: | private: | ||||
CBitcoinAddress *addr; | CBitcoinAddress *addr; | ||||
public: | public: | ||||
CBitcoinAddressVisitor(CBitcoinAddress *addrIn) : addr(addrIn) {} | CBitcoinAddressVisitor(CBitcoinAddress *addrIn) : addr(addrIn) {} | ||||
bool operator()(const CKeyID &id) const { return addr->Set(id); } | bool operator()(const CKeyID &id) const { return addr->Set(id); } | ||||
▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | |||||
bool CBitcoinSecret::SetString(const char *pszSecret) { | bool CBitcoinSecret::SetString(const char *pszSecret) { | ||||
return CBase58Data::SetString(pszSecret) && IsValid(); | return CBase58Data::SetString(pszSecret) && IsValid(); | ||||
} | } | ||||
bool CBitcoinSecret::SetString(const std::string &strSecret) { | bool CBitcoinSecret::SetString(const std::string &strSecret) { | ||||
return SetString(strSecret.c_str()); | return SetString(strSecret.c_str()); | ||||
} | } | ||||
std::string EncodeDestination(const CTxDestination &dest) { | |||||
CBitcoinAddress addr(dest); | |||||
if (!addr.IsValid()) return ""; | |||||
deadalnixUnsubmitted Done Inline ActionsUse braces or a ternary. deadalnix: Use braces or a ternary. | |||||
return addr.ToString(); | |||||
} | |||||
CTxDestination DecodeDestination(const std::string &str) { | |||||
return CBitcoinAddress(str).Get(); | |||||
} | |||||
bool IsValidDestinationString(const std::string &str, | |||||
const CChainParams ¶ms) { | |||||
return CBitcoinAddress(str).IsValid(params); | |||||
} | |||||
bool IsValidDestinationString(const std::string &str) { | |||||
return CBitcoinAddress(str).IsValid(); | |||||
} |
While we are at it, could you put the /** on its own line ?