mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-01 08:25:51 +00:00
Have RPC account_info recognize bitcoin addresses.
This commit is contained in:
@@ -79,6 +79,7 @@
|
|||||||
|
|
||||||
Config theConfig;
|
Config theConfig;
|
||||||
const char* ALPHABET = "rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz";
|
const char* ALPHABET = "rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz";
|
||||||
|
const char* ALPHABET_BITCOIN = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
||||||
|
|
||||||
void Config::setup(const std::string& strConf, bool bTestNet, bool bQuiet)
|
void Config::setup(const std::string& strConf, bool bTestNet, bool bQuiet)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -200,6 +200,8 @@ public:
|
|||||||
|
|
||||||
extern Config theConfig;
|
extern Config theConfig;
|
||||||
|
|
||||||
|
extern const char* ALPHABET;
|
||||||
|
extern const char* ALPHABET_BITCOIN;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// vim:ts=4
|
// vim:ts=4
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ Json::Value rpcError(int iError, Json::Value jvResult)
|
|||||||
const char* pToken;
|
const char* pToken;
|
||||||
const char* pMessage;
|
const char* pMessage;
|
||||||
} errorInfoA[] = {
|
} errorInfoA[] = {
|
||||||
|
{ rpcACT_BITCOIN, "actBitcoin", "Account is bitcoin address." },
|
||||||
{ rpcACT_EXISTS, "actExists", "Account already exists." },
|
{ rpcACT_EXISTS, "actExists", "Account already exists." },
|
||||||
{ rpcACT_MALFORMED, "actMalformed", "Account malformed." },
|
{ rpcACT_MALFORMED, "actMalformed", "Account malformed." },
|
||||||
{ rpcACT_NOT_FOUND, "actNotFound", "Account not found." },
|
{ rpcACT_NOT_FOUND, "actNotFound", "Account not found." },
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ enum {
|
|||||||
rpcUNKNOWN_COMMAND,
|
rpcUNKNOWN_COMMAND,
|
||||||
|
|
||||||
// Bad parameter
|
// Bad parameter
|
||||||
|
rpcACT_BITCOIN,
|
||||||
rpcACT_MALFORMED,
|
rpcACT_MALFORMED,
|
||||||
rpcQUALITY_MALFORMED,
|
rpcQUALITY_MALFORMED,
|
||||||
rpcBAD_BLOB,
|
rpcBAD_BLOB,
|
||||||
|
|||||||
@@ -512,7 +512,9 @@ Json::Value RPCHandler::accountFromString(Ledger::ref lrLedger, RippleAddress& n
|
|||||||
}
|
}
|
||||||
else if (bStrict)
|
else if (bStrict)
|
||||||
{
|
{
|
||||||
return rpcError(rpcACT_MALFORMED);
|
return naAccount.setAccountID(strIdent, ALPHABET_BITCOIN)
|
||||||
|
? rpcError(rpcACT_BITCOIN)
|
||||||
|
: rpcError(rpcACT_MALFORMED);
|
||||||
}
|
}
|
||||||
// Must be a seed.
|
// Must be a seed.
|
||||||
else if (!naSeed.setSeedGeneric(strIdent))
|
else if (!naSeed.setSeedGeneric(strIdent))
|
||||||
|
|||||||
@@ -328,7 +328,7 @@ std::string RippleAddress::humanAccountID() const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RippleAddress::setAccountID(const std::string& strAccountID)
|
bool RippleAddress::setAccountID(const std::string& strAccountID, const char* pAlphabet)
|
||||||
{
|
{
|
||||||
if (strAccountID.empty())
|
if (strAccountID.empty())
|
||||||
{
|
{
|
||||||
@@ -338,7 +338,7 @@ bool RippleAddress::setAccountID(const std::string& strAccountID)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mIsValid = SetString(strAccountID.c_str(), VER_ACCOUNT_ID);
|
mIsValid = SetString(strAccountID.c_str(), VER_ACCOUNT_ID, pAlphabet);
|
||||||
}
|
}
|
||||||
|
|
||||||
return mIsValid;
|
return mIsValid;
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ public:
|
|||||||
|
|
||||||
std::string humanAccountID() const;
|
std::string humanAccountID() const;
|
||||||
|
|
||||||
bool setAccountID(const std::string& strAccountID);
|
bool setAccountID(const std::string& strAccountID, const char* pAlphabet=0);
|
||||||
void setAccountID(const uint160& hash160In);
|
void setAccountID(const uint160& hash160In);
|
||||||
|
|
||||||
static RippleAddress createAccountID(const std::string& strAccountID)
|
static RippleAddress createAccountID(const std::string& strAccountID)
|
||||||
|
|||||||
@@ -69,8 +69,10 @@ inline std::string EncodeBase58(const std::vector<unsigned char>& vch)
|
|||||||
return EncodeBase58(&vch[0], &vch[0] + vch.size());
|
return EncodeBase58(&vch[0], &vch[0] + vch.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool DecodeBase58(const char* psz, std::vector<unsigned char>& vchRet)
|
inline bool DecodeBase58(const char* psz, std::vector<unsigned char>& vchRet, const char* pAlphabet=0)
|
||||||
{
|
{
|
||||||
|
const char* pAlpha = pAlphabet ? pAlphabet : ALPHABET;
|
||||||
|
|
||||||
CAutoBN_CTX pctx;
|
CAutoBN_CTX pctx;
|
||||||
vchRet.clear();
|
vchRet.clear();
|
||||||
CBigNum bn58 = 58;
|
CBigNum bn58 = 58;
|
||||||
@@ -82,7 +84,7 @@ inline bool DecodeBase58(const char* psz, std::vector<unsigned char>& vchRet)
|
|||||||
// Convert big endian string to bignum
|
// Convert big endian string to bignum
|
||||||
for (const char* p = psz; *p; p++)
|
for (const char* p = psz; *p; p++)
|
||||||
{
|
{
|
||||||
const char* p1 = strchr(ALPHABET, *p);
|
const char* p1 = strchr(pAlpha, *p);
|
||||||
if (p1 == NULL)
|
if (p1 == NULL)
|
||||||
{
|
{
|
||||||
while (isspace(*p))
|
while (isspace(*p))
|
||||||
@@ -91,7 +93,7 @@ inline bool DecodeBase58(const char* psz, std::vector<unsigned char>& vchRet)
|
|||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
bnChar.setuint(p1 - ALPHABET);
|
bnChar.setuint(p1 - pAlpha);
|
||||||
if (!BN_mul(&bn, &bn, &bn58, pctx))
|
if (!BN_mul(&bn, &bn, &bn58, pctx))
|
||||||
throw bignum_error("DecodeBase58 : BN_mul failed");
|
throw bignum_error("DecodeBase58 : BN_mul failed");
|
||||||
bn += bnChar;
|
bn += bnChar;
|
||||||
@@ -106,7 +108,7 @@ inline bool DecodeBase58(const char* psz, std::vector<unsigned char>& vchRet)
|
|||||||
|
|
||||||
// Restore leading zeros
|
// Restore leading zeros
|
||||||
int nLeadingZeros = 0;
|
int nLeadingZeros = 0;
|
||||||
for (const char* p = psz; *p == ALPHABET[0]; p++)
|
for (const char* p = psz; *p == pAlpha[0]; p++)
|
||||||
nLeadingZeros++;
|
nLeadingZeros++;
|
||||||
vchRet.assign(nLeadingZeros + vchTmp.size(), 0);
|
vchRet.assign(nLeadingZeros + vchTmp.size(), 0);
|
||||||
|
|
||||||
@@ -133,9 +135,9 @@ inline std::string EncodeBase58Check(const std::vector<unsigned char>& vchIn)
|
|||||||
return EncodeBase58(vch);
|
return EncodeBase58(vch);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool DecodeBase58Check(const char* psz, std::vector<unsigned char>& vchRet)
|
inline bool DecodeBase58Check(const char* psz, std::vector<unsigned char>& vchRet, const char* pAlphabet=0)
|
||||||
{
|
{
|
||||||
if (!DecodeBase58(psz, vchRet))
|
if (!DecodeBase58(psz, vchRet, pAlphabet))
|
||||||
return false;
|
return false;
|
||||||
if (vchRet.size() < 4)
|
if (vchRet.size() < 4)
|
||||||
{
|
{
|
||||||
@@ -152,9 +154,9 @@ inline bool DecodeBase58Check(const char* psz, std::vector<unsigned char>& vchRe
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool DecodeBase58Check(const std::string& str, std::vector<unsigned char>& vchRet)
|
inline bool DecodeBase58Check(const std::string& str, std::vector<unsigned char>& vchRet, const char* pAlphabet)
|
||||||
{
|
{
|
||||||
return DecodeBase58Check(str.c_str(), vchRet);
|
return DecodeBase58Check(str.c_str(), vchRet, pAlphabet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -193,10 +195,10 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool SetString(const char* psz, unsigned char version)
|
bool SetString(const char* psz, unsigned char version, const char* pAlphabet = 0)
|
||||||
{
|
{
|
||||||
std::vector<unsigned char> vchTemp;
|
std::vector<unsigned char> vchTemp;
|
||||||
DecodeBase58Check(psz, vchTemp);
|
DecodeBase58Check(psz, vchTemp, pAlphabet);
|
||||||
if (vchTemp.empty() || vchTemp[0] != version)
|
if (vchTemp.empty() || vchTemp[0] != version)
|
||||||
{
|
{
|
||||||
vchData.clear();
|
vchData.clear();
|
||||||
|
|||||||
Reference in New Issue
Block a user