Refactor AccountID (RIPD-953):

All AccountID functionality is removed from RippleAddress and
replaced with free functions. The AccountID to string conversion
cache is factored out as an explicit type with an instance in
the Application object. New base58 conversion functions are used,
with no dependence on OpenSSL.

All types and free functions related to AccountID are consolidated
into one header file. Routines to operate on "tokens" are also
introduced and consolidated into a single header file.

A token one of the cryptographic primitives used in Ripple:

    Secret Seed
    Server Public Key
    Server Secret Key
    Account ID
    Account Public Key
    Account Private Key

    and these deprecated primitives:

    Account Family Seed
    Account Family Generator
This commit is contained in:
Vinnie Falco
2015-06-18 11:05:18 -07:00
parent 63d438c979
commit 2f485672fa
109 changed files with 1901 additions and 1545 deletions

View File

@@ -143,63 +143,62 @@ void PathRequest::updateComplete ()
bool PathRequest::isValid (RippleLineCache::ref crCache)
{
ScopedLockType sl (mLock);
bValid = raSrcAccount.isSet () && raDstAccount.isSet () &&
bValid = raSrcAccount && raDstAccount &&
saDstAmount > zero;
Ledger::pointer lrLedger = crCache->getLedger ();
if (bValid)
{
auto asSrc = getAccountState(
*crCache->getLedger(), raSrcAccount,
getApp().getSLECache());
if (!asSrc)
if (! crCache->getLedger()->exists(
keylet::account(*raSrcAccount)))
{
// no source account
bValid = false;
jvStatus = rpcError (rpcSRC_ACT_NOT_FOUND);
}
}
if (bValid)
{
auto const sleDest = cachedRead(*crCache->getLedger(),
keylet::account(*raDstAccount).key,
getApp().getSLECache(), ltACCOUNT_ROOT);
Json::Value& jvDestCur =
(jvStatus[jss::destination_currencies] = Json::arrayValue);
if (!sleDest)
{
// no destination account
jvDestCur.append (Json::Value ("XRP"));
if (!saDstAmount.native ())
{
// only XRP can be send to a non-existent account
bValid = false;
jvStatus = rpcError (rpcACT_NOT_FOUND);
}
else if (saDstAmount < STAmount (lrLedger->getReserve (0)))
{
// payment must meet reserve
bValid = false;
jvStatus = rpcError (rpcDST_AMT_MALFORMED);
}
}
else
{
auto asDst = getAccountState(*lrLedger,
raDstAccount, getApp().getSLECache());
bool const disallowXRP (
sleDest->getFlags() & lsfDisallowXRP);
Json::Value& jvDestCur =
(jvStatus[jss::destination_currencies] = Json::arrayValue);
auto usDestCurrID = accountDestCurrencies (
*raDstAccount, crCache, !disallowXRP);
if (!asDst)
{
// no destination account
jvDestCur.append (Json::Value ("XRP"));
for (auto const& currency : usDestCurrID)
jvDestCur.append (to_string (currency));
if (!saDstAmount.native ())
{
// only XRP can be send to a non-existent account
bValid = false;
jvStatus = rpcError (rpcACT_NOT_FOUND);
}
else if (saDstAmount < STAmount (lrLedger->getReserve (0)))
{
// payment must meet reserve
bValid = false;
jvStatus = rpcError (rpcDST_AMT_MALFORMED);
}
}
else
{
bool const disallowXRP (
asDst->sle().getFlags() & lsfDisallowXRP);
auto usDestCurrID = accountDestCurrencies (
raDstAccount, crCache, !disallowXRP);
for (auto const& currency : usDestCurrID)
jvDestCur.append (to_string (currency));
jvStatus["destination_tag"] =
(asDst->sle().getFlags () & lsfRequireDestTag)
!= 0;
}
jvStatus["destination_tag"] =
(sleDest->getFlags () & lsfRequireDestTag)
!= 0;
}
}
@@ -240,7 +239,7 @@ Json::Value PathRequest::doCreate (
if (bValid)
{
m_journal.debug << iIdentifier
<< " valid: " << raSrcAccount.humanAccountID ();
<< " valid: " << toBase58(*raSrcAccount);
m_journal.debug << iIdentifier
<< " Deliver: " << saDstAmount.getFullText ();
}
@@ -260,7 +259,9 @@ int PathRequest::parseJson (Json::Value const& jvParams, bool complete)
if (jvParams.isMember (jss::source_account))
{
if (!raSrcAccount.setAccountID (jvParams[jss::source_account].asString ()))
raSrcAccount = parseBase58<AccountID>(
jvParams[jss::source_account].asString());
if (! raSrcAccount)
{
jvStatus = rpcError (rpcSRC_ACT_MALFORMED);
return PFR_PJ_INVALID;
@@ -274,7 +275,9 @@ int PathRequest::parseJson (Json::Value const& jvParams, bool complete)
if (jvParams.isMember (jss::destination_account))
{
if (!raDstAccount.setAccountID (jvParams[jss::destination_account].asString ()))
raDstAccount = parseBase58<AccountID>(
jvParams[jss::destination_account].asString());
if (! raDstAccount)
{
jvStatus = rpcError (rpcDST_ACT_MALFORMED);
return PFR_PJ_INVALID;
@@ -344,7 +347,7 @@ int PathRequest::parseJson (Json::Value const& jvParams, bool complete)
if (uCur.isNonZero() && uIss.isZero())
{
uIss = raSrcAccount.getAccountID();
uIss = *raSrcAccount;
}
sciSourceCurrencies.insert ({uCur, uIss});
@@ -390,8 +393,8 @@ Json::Value PathRequest::doUpdate (RippleLineCache::ref cache, bool fast)
if (sourceCurrencies.empty ())
{
auto usCurrencies =
accountSourceCurrencies (raSrcAccount, cache, true);
bool sameAccount = raSrcAccount == raDstAccount;
accountSourceCurrencies (*raSrcAccount, cache, true);
bool sameAccount = *raSrcAccount == *raDstAccount;
for (auto const& c: usCurrencies)
{
if (!sameAccount || (c != saDstAmount.getCurrency ()))
@@ -399,13 +402,13 @@ Json::Value PathRequest::doUpdate (RippleLineCache::ref cache, bool fast)
if (c.isZero ())
sourceCurrencies.insert ({c, xrpAccount()});
else
sourceCurrencies.insert ({c, raSrcAccount.getAccountID ()});
sourceCurrencies.insert ({c, *raSrcAccount});
}
}
}
jvStatus[jss::source_account] = raSrcAccount.humanAccountID ();
jvStatus[jss::destination_account] = raDstAccount.humanAccountID ();
jvStatus[jss::source_account] = getApp().accountIDCache().toBase58(*raSrcAccount);
jvStatus[jss::destination_account] = getApp().accountIDCache().toBase58(*raDstAccount);
jvStatus[jss::destination_amount] = saDstAmount.getJson (0);
if (!jvId.isNull ())
@@ -453,8 +456,8 @@ Json::Value PathRequest::doUpdate (RippleLineCache::ref cache, bool fast)
FindPaths fp (
cache,
raSrcAccount.getAccountID (),
raDstAccount.getAccountID (),
*raSrcAccount,
*raDstAccount,
saDstAmount,
iLevel,
4); // iMaxPaths
@@ -486,7 +489,7 @@ Json::Value PathRequest::doUpdate (RippleLineCache::ref cache, bool fast)
? currIssuer.account
: isXRP (currIssuer.currency)
? xrpAccount()
: raSrcAccount.getAccountID ();
: *raSrcAccount;
STAmount saMaxAmount ({currIssuer.currency, sourceAccount}, 1);
saMaxAmount.negate ();
@@ -496,8 +499,8 @@ Json::Value PathRequest::doUpdate (RippleLineCache::ref cache, bool fast)
sandbox,
saMaxAmount,
saDstAmount,
raDstAccount.getAccountID (),
raSrcAccount.getAccountID (),
*raDstAccount,
*raSrcAccount,
spsPaths);
if (!fullLiquidityPath.empty() &&
@@ -511,8 +514,8 @@ Json::Value PathRequest::doUpdate (RippleLineCache::ref cache, bool fast)
sandbox,
saMaxAmount,
saDstAmount,
raDstAccount.getAccountID (),
raSrcAccount.getAccountID (),
*raDstAccount,
*raSrcAccount,
spsPaths);
if (rc.result () != tesSUCCESS)
m_journal.warning