Split RPCHandler into a large number of small parts:

* Handler methods of RPCHandler are extracted into individual files.
* Helper methods of RPCHandler are converted into free functions, and
  extracted into individual files.
* Much code leaves ripple_app/rpc/RPCHandler.cpp and enters ripple_rpc/.
This commit is contained in:
Tom Swirly
2014-04-17 12:55:51 -04:00
committed by Vinnie Falco
parent f26d95d0bb
commit 7fed69fc13
81 changed files with 6788 additions and 4183 deletions

View File

@@ -0,0 +1,93 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012-2014 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#include "AccountFromString.h"
namespace ripple {
namespace RPC {
// --> strIdent: public key, account ID, or regular seed.
// --> bStrict: Only allow account id or public key.
// <-- bIndex: true if iIndex > 0 and used the index.
Json::Value accountFromString (Ledger::ref lrLedger, RippleAddress& naAccount,
bool& bIndex, const std::string& strIdent,
const int iIndex, const bool bStrict, NetworkOPs& netOps)
{
RippleAddress naSeed;
if (naAccount.setAccountPublic (strIdent) || naAccount.setAccountID (strIdent))
{
// Got the account.
bIndex = false;
}
else if (bStrict)
{
return naAccount.setAccountID (strIdent, Base58::getBitcoinAlphabet ())
? rpcError (rpcACT_BITCOIN)
: rpcError (rpcACT_MALFORMED);
}
// Must be a seed.
else if (!naSeed.setSeedGeneric (strIdent))
{
return rpcError (rpcBAD_SEED);
}
else
{
// We allow the use of the seeds to access #0.
// This is poor practice and merely for debuging convenience.
RippleAddress naRegular0Public;
RippleAddress naRegular0Private;
RippleAddress naGenerator = RippleAddress::createGeneratorPublic (naSeed);
naRegular0Public.setAccountPublic (naGenerator, 0);
naRegular0Private.setAccountPrivate (naGenerator, naSeed, 0);
// uint160 uGeneratorID = naRegular0Public.getAccountID();
SLE::pointer sleGen = netOps.getGenerator (lrLedger, naRegular0Public.getAccountID ());
if (!sleGen)
{
// Didn't find a generator map, assume it is a master generator.
nothing ();
}
else
{
// Found master public key.
Blob vucCipher = sleGen->getFieldVL (sfGenerator);
Blob vucMasterGenerator = naRegular0Private.accountPrivateDecrypt (naRegular0Public, vucCipher);
if (vucMasterGenerator.empty ())
{
rpcError (rpcNO_GEN_DECRYPT);
}
naGenerator.setGenerator (vucMasterGenerator);
}
bIndex = !iIndex;
naAccount.setAccountPublic (naGenerator, iIndex);
}
return Json::Value (Json::objectValue);
}
} // RPC
} // ripple

View File

@@ -0,0 +1,38 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012=2014 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef RIPPLE_RPC_ACCOUNTFROMSTRING_H_INCLUDED
#define RIPPLE_RPC_ACCOUNTFROMSTRING_H_INCLUDED
namespace ripple {
namespace RPC {
Json::Value accountFromString (
Ledger::ref lrLedger,
RippleAddress& naAccount,
bool& bIndex,
const std::string& strIdent,
const int iIndex,
const bool bStrict,
NetworkOPs& netOps);
} // RPC
} // ripple
#endif

View File

@@ -0,0 +1,63 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012-2014 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#include "Accounts.h"
namespace ripple {
namespace RPC {
Json::Value accounts (
Ledger::ref lrLedger,
const RippleAddress& naMasterGenerator,
NetworkOPs& netOps)
{
Json::Value jsonAccounts (Json::arrayValue);
// YYY Don't want to leak to thin server that these accounts are related.
// YYY Would be best to alternate requests to servers and to cache results.
unsigned int uIndex = 0;
do
{
RippleAddress naAccount;
naAccount.setAccountPublic (naMasterGenerator, uIndex++);
AccountState::pointer as = netOps.getAccountState (lrLedger, naAccount);
if (as)
{
Json::Value jsonAccount (Json::objectValue);
as->addJson (jsonAccount);
jsonAccounts.append (jsonAccount);
}
else
{
uIndex = 0;
}
}
while (uIndex);
return jsonAccounts;
}
} // RPC
} // ripple

View File

@@ -0,0 +1,34 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2014 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef RIPPLE_RPC_ACCOUNTS_H_INCLUDED
#define RIPPLE_RPC_ACCOUNTS_H_INCLUDED
namespace ripple {
namespace RPC {
Json::Value accounts (
Ledger::ref lrLedger,
const RippleAddress& naMasterGenerator,
NetworkOPs& netOps);
} // RPC
} // ripple
#endif

View File

@@ -0,0 +1,125 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012-2014 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#include "Authorize.h"
namespace ripple {
namespace RPC {
// Given a seed and a source account get the regular public and private key for authorizing transactions.
// - Make sure the source account can pay.
// --> naRegularSeed : To find the generator
// --> naSrcAccountID : Account we want the public and private regular keys to.
// <-- naAccountPublic : Regular public key for naSrcAccountID
// <-- naAccountPrivate : Regular private key for naSrcAccountID
// <-- saSrcBalance: Balance minus fee.
// --> naVerifyGenerator : If provided, the found master public generator must match.
// XXX Be more lenient, allow use of master generator on claimed accounts.
Json::Value authorize (Ledger::ref lrLedger,
const RippleAddress& naRegularSeed, const RippleAddress& naSrcAccountID,
RippleAddress& naAccountPublic, RippleAddress& naAccountPrivate,
STAmount& saSrcBalance, const STAmount& saFee, AccountState::pointer& asSrc,
const RippleAddress& naVerifyGenerator, NetworkOPs& netOps)
{
// Source/paying account must exist.
asSrc = netOps.getAccountState (lrLedger, naSrcAccountID);
if (!asSrc)
{
return rpcError (rpcSRC_ACT_NOT_FOUND);
}
RippleAddress naMasterGenerator;
if (asSrc->haveAuthorizedKey ())
{
Json::Value obj = getMasterGenerator (lrLedger, naRegularSeed, naMasterGenerator, netOps);
if (!obj.empty ())
return obj;
}
else
{
// Try the seed as a master seed.
naMasterGenerator = RippleAddress::createGeneratorPublic (naRegularSeed);
}
// If naVerifyGenerator is provided, make sure it is the master generator.
if (naVerifyGenerator.isValid () && naMasterGenerator != naVerifyGenerator)
{
return rpcError (rpcWRONG_SEED);
}
// Find the index of the account from the master generator, so we can generate the public and private keys.
RippleAddress naMasterAccountPublic;
unsigned int iIndex = 0;
bool bFound = false;
// Don't look at ledger entries to determine if the account exists. Don't want to leak to thin server that these accounts are
// related.
while (!bFound && iIndex != getConfig ().ACCOUNT_PROBE_MAX)
{
naMasterAccountPublic.setAccountPublic (naMasterGenerator, iIndex);
WriteLog (lsDEBUG, RPCHandler) << "authorize: " << iIndex << " : " << naMasterAccountPublic.humanAccountID () << " : " << naSrcAccountID.humanAccountID ();
bFound = naSrcAccountID.getAccountID () == naMasterAccountPublic.getAccountID ();
if (!bFound)
++iIndex;
}
if (!bFound)
{
return rpcError (rpcACT_NOT_FOUND);
}
// Use the regular generator to determine the associated public and private keys.
RippleAddress naGenerator = RippleAddress::createGeneratorPublic (naRegularSeed);
naAccountPublic.setAccountPublic (naGenerator, iIndex);
naAccountPrivate.setAccountPrivate (naGenerator, naRegularSeed, iIndex);
if (asSrc->haveAuthorizedKey () && (asSrc->getAuthorizedKey ().getAccountID () != naAccountPublic.getAccountID ()))
{
// Log::out() << "iIndex: " << iIndex;
// Log::out() << "sfAuthorizedKey: " << strHex(asSrc->getAuthorizedKey().getAccountID());
// Log::out() << "naAccountPublic: " << strHex(naAccountPublic.getAccountID());
return rpcError (rpcPASSWD_CHANGED);
}
saSrcBalance = asSrc->getBalance ();
if (saSrcBalance < saFee)
{
WriteLog (lsINFO, RPCHandler) << "authorize: Insufficient funds for fees: fee=" << saFee.getText () << " balance=" << saSrcBalance.getText ();
return rpcError (rpcINSUF_FUNDS);
}
else
{
saSrcBalance -= saFee;
}
return Json::Value ();
}
} // RPC
} // ripple

View File

@@ -0,0 +1,41 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012-2014 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef RIPPLE_RPC_AUTHORIZE_H_INCLUDED
#define RIPPLE_RPC_AUTHORIZE_H_INCLUDED
namespace ripple {
namespace RPC {
Json::Value authorize (
Ledger::ref lrLedger,
const RippleAddress& naRegularSeed,
const RippleAddress& naSrcAccountID,
RippleAddress& naAccountPublic,
RippleAddress& naAccountPrivate,
STAmount& saSrcBalance,
const STAmount& saFee,
AccountState::pointer& asSrc,
const RippleAddress& naVerifyGenerator,
NetworkOPs& netOps);
} // RPC
} // ripple
#endif

View File

@@ -17,6 +17,9 @@
*/
//==============================================================================
#ifndef RIPPLE_RPC_PRINT_H_INCLUDED
#define RIPPLE_RPC_PRINT_H_INCLUDED
namespace ripple {
namespace RPC {
@@ -44,3 +47,5 @@ public:
}
}
#endif

View File

@@ -0,0 +1,61 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012-2014 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#include "GetMasterGenerator.h"
namespace ripple {
namespace RPC {
// Look up the master public generator for a regular seed so we may index source accounts ids.
// --> naRegularSeed
// <-- naMasterGenerator
Json::Value getMasterGenerator (
Ledger::ref lrLedger, const RippleAddress& naRegularSeed,
RippleAddress& naMasterGenerator, NetworkOPs& netOps)
{
RippleAddress na0Public; // To find the generator's index.
RippleAddress na0Private; // To decrypt the master generator's cipher.
RippleAddress naGenerator = RippleAddress::createGeneratorPublic (naRegularSeed);
na0Public.setAccountPublic (naGenerator, 0);
na0Private.setAccountPrivate (naGenerator, naRegularSeed, 0);
SLE::pointer sleGen = netOps.getGenerator (lrLedger, na0Public.getAccountID ());
if (!sleGen)
{
// No account has been claimed or has had it password set for seed.
return rpcError (rpcNO_ACCOUNT);
}
Blob vucCipher = sleGen->getFieldVL (sfGenerator);
Blob vucMasterGenerator = na0Private.accountPrivateDecrypt (na0Public, vucCipher);
if (vucMasterGenerator.empty ())
{
return rpcError (rpcFAIL_GEN_DECRYPT);
}
naMasterGenerator.setGenerator (vucMasterGenerator);
return Json::Value (Json::objectValue);
}
} // RPC
} // ripple

View File

@@ -0,0 +1,35 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012-2014 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef RIPPLE_RPC_GETMASTERGENERATOR_H_INCLUDED
#define RIPPLE_RPC_GETMASTERGENERATOR_H_INCLUDED
namespace ripple {
namespace RPC {
Json::Value getMasterGenerator (
Ledger::ref lrLedger,
const RippleAddress& naRegularSeed,
RippleAddress& naMasterGenerator,
NetworkOPs& netOps);
} // RPC
} // ripple
#endif

View File

@@ -0,0 +1,91 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012-2014 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#include "../handlers/AccountCurrencies.cpp"
#include "../handlers/AccountInfo.cpp"
#include "../handlers/AccountLines.cpp"
#include "../handlers/AccountOffers.cpp"
#include "../handlers/AccountTx.cpp"
#include "../handlers/AccountTxOld.cpp"
#include "../handlers/AccountTxSwitch.cpp"
#include "../handlers/BlackList.cpp"
#include "../handlers/BookOffers.cpp"
#include "../handlers/Connect.cpp"
#include "../handlers/ConsensusInfo.cpp"
#include "../handlers/Feature.cpp"
#include "../handlers/FetchInfo.cpp"
#include "../handlers/GetCounts.cpp"
#include "../handlers/Ledger.cpp"
#include "../handlers/LedgerAccept.cpp"
#include "../handlers/LedgerCleaner.cpp"
#include "../handlers/LedgerClosed.cpp"
#include "../handlers/LedgerCurrent.cpp"
#include "../handlers/LedgerData.cpp"
#include "../handlers/LedgerEntry.cpp"
#include "../handlers/LedgerHeader.cpp"
#include "../handlers/LogLevel.cpp"
#include "../handlers/LogRotate.cpp"
#include "../handlers/NicknameInfo.cpp"
#include "../handlers/OwnerInfo.cpp"
#include "../handlers/PathFind.cpp"
#include "../handlers/Peers.cpp"
#include "../handlers/Ping.cpp"
#include "../handlers/Print.cpp"
#include "../handlers/Profile.cpp"
#include "../handlers/ProofCreate.cpp"
#include "../handlers/ProofSolve.cpp"
#include "../handlers/ProofVerify.cpp"
#include "../handlers/Random.cpp"
#include "../handlers/RipplePathFind.cpp"
#include "../handlers/SMS.cpp"
#include "../handlers/ServerInfo.cpp"
#include "../handlers/ServerState.cpp"
#include "../handlers/Sign.cpp"
#include "../handlers/Stop.cpp"
#include "../handlers/Submit.cpp"
#include "../handlers/Subscribe.cpp"
#include "../handlers/TransactionEntry.cpp"
#include "../handlers/Tx.cpp"
#include "../handlers/TxHistory.cpp"
#include "../handlers/UnlAdd.cpp"
#include "../handlers/UnlDelete.cpp"
#include "../handlers/UnlList.cpp"
#include "../handlers/UnlLoad.cpp"
#include "../handlers/UnlNetwork.cpp"
#include "../handlers/UnlReset.cpp"
#include "../handlers/UnlScore.cpp"
#include "../handlers/Unsubscribe.cpp"
#include "../handlers/ValidationCreate.cpp"
#include "../handlers/ValidationSeed.cpp"
#include "../handlers/WalletAccounts.cpp"
#include "../handlers/WalletPropose.cpp"
#include "../handlers/WalletSeed.cpp"
#include "AccountFromString.cpp"
#include "Accounts.cpp"
#include "Authorize.cpp"
#include "GetMasterGenerator.cpp"
#include "LegacyPathFind.cpp"
#include "LookupLedger.cpp"
#include "ParseAccountIds.cpp"
#include "TransactionSign.cpp"
#include "../../ripple_overlay/api/Overlay.h"
#include <tuple>

View File

@@ -0,0 +1,61 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012-2014 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#include "LegacyPathFind.h"
namespace ripple {
namespace RPC {
LegacyPathFind::LegacyPathFind (bool isAdmin) : m_isOkay (false)
{
if (isAdmin)
++inProgress;
else
{
if ((getApp().getJobQueue ().getJobCountGE (jtCLIENT) > 50) ||
getApp().getFeeTrack().isLoadedLocal ())
return;
do
{
int prevVal = inProgress.load();
if (prevVal >= maxInProgress)
return;
if (inProgress.compare_exchange_strong (prevVal, prevVal + 1,
std::memory_order_release, std::memory_order_relaxed))
break;
}
while (1);
}
m_isOkay = true;
}
LegacyPathFind::~LegacyPathFind ()
{
if (m_isOkay)
--inProgress;
}
std::atomic <int> LegacyPathFind::inProgress (0);
int LegacyPathFind::maxInProgress (2);
} // RPC
} // ripple

View File

@@ -0,0 +1,47 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012-2014 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef RIPPLE_RPC_LEGACYPATHFIND_H_INCLUDED
#define RIPPLE_RPC_LEGACYPATHFIND_H_INCLUDED
namespace ripple {
namespace RPC {
class LegacyPathFind
{
public:
LegacyPathFind (bool isAdmin);
~LegacyPathFind ();
bool isOkay () const
{
return m_isOkay;
}
private:
static std::atomic <int> inProgress;
static int maxInProgress;
bool m_isOkay;
};
} // RPC
} // ripple
#endif

View File

@@ -0,0 +1,182 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012-2014 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#include "LookupLedger.h"
namespace ripple {
namespace RPC {
static const int LEDGER_CURRENT = -1;
static const int LEDGER_CLOSED = -2;
static const int LEDGER_VALIDATED = -3;
// The previous version of the lookupLedger command would accept the
// "ledger_index" argument as a string and silently treat it as a request to
// return the current ledger which, while not strictly wrong, could cause a
// lot of confusion.
//
// The code now robustly validates the input and ensures that the only possible
// values for the "ledger_index" parameter are the index of a ledger passed as
// an integer or one of the strings "current", "closed" or "validated".
// Additionally, the code ensures that the value passed in "ledger_hash" is a
// string and a valid hash. Invalid values will return an appropriate error
// code.
//
// In the absence of the "ledger_hash" or "ledger_index" parameters, the code
// assumes that "ledger_index" has the value "current".
Json::Value lookupLedger (
Json::Value const& params,
Ledger::pointer& lpLedger,
NetworkOPs& netOps)
{
Json::Value jvResult;
Json::Value ledger_hash = params.get ("ledger_hash", Json::Value ("0"));
Json::Value ledger_index = params.get ("ledger_index", Json::Value ("current"));
// Support for DEPRECATED "ledger" - attempt to deduce our input
if (params.isMember ("ledger"))
{
if (params["ledger"].asString ().size () > 12)
{
ledger_hash = params["ledger"];
ledger_index = Json::Value ("");
}
else if (params["ledger"].isNumeric ())
{
ledger_index = params["ledger"];
ledger_hash = Json::Value ("0");
}
else
{
ledger_index = params["ledger"];
ledger_hash = Json::Value ("0");
}
}
uint256 uLedger (0);
if (!ledger_hash.isString() || !uLedger.SetHex (ledger_hash.asString ()))
{
jvResult["error"] = "ledgerHashMalformed";
return jvResult;
}
std::int32_t iLedgerIndex = LEDGER_CURRENT;
// We only try to parse a ledger index if we have not already
// determined that we have a ledger hash.
if (!uLedger)
{
if (ledger_index.isNumeric ())
iLedgerIndex = ledger_index.asInt ();
else
{
std::string strLedger = ledger_index.asString ();
if (strLedger == "current")
{
iLedgerIndex = LEDGER_CURRENT;
}
else if (strLedger == "closed")
{
iLedgerIndex = LEDGER_CLOSED;
}
else if (strLedger == "validated")
{
iLedgerIndex = LEDGER_VALIDATED;
}
else
{
jvResult["error"] = "ledgerIndexMalformed";
return jvResult;
}
}
}
// The ledger was directly specified by hash.
if (!!uLedger)
{
lpLedger = netOps.getLedgerByHash (uLedger);
if (!lpLedger)
{
jvResult["error"] = "ledgerNotFound";
return jvResult;
}
iLedgerIndex = lpLedger->getLedgerSeq ();
}
switch (iLedgerIndex)
{
case LEDGER_CURRENT:
lpLedger = netOps.getCurrentLedger ();
iLedgerIndex = lpLedger->getLedgerSeq ();
assert (lpLedger->isImmutable () && !lpLedger->isClosed ());
break;
case LEDGER_CLOSED:
lpLedger = getApp().getLedgerMaster ().getClosedLedger ();
iLedgerIndex = lpLedger->getLedgerSeq ();
assert (lpLedger->isImmutable () && lpLedger->isClosed ());
break;
case LEDGER_VALIDATED:
lpLedger = netOps.getValidatedLedger ();
iLedgerIndex = lpLedger->getLedgerSeq ();
assert (lpLedger->isImmutable () && lpLedger->isClosed ());
break;
}
if (iLedgerIndex <= 0)
{
jvResult["error"] = "ledgerIndexMalformed";
return jvResult;
}
if (!lpLedger)
{
lpLedger = netOps.getLedgerBySeq (iLedgerIndex);
if (!lpLedger)
{
jvResult["error"] = "ledgerNotFound"; // ledger_index from future?
return jvResult;
}
}
if (lpLedger->isClosed ())
{
if (!!uLedger)
jvResult["ledger_hash"] = uLedger.ToString ();
jvResult["ledger_index"] = iLedgerIndex;
}
else
{
// CHECKME - What is this supposed to signify?
jvResult["ledger_current_index"] = iLedgerIndex;
}
return jvResult;
}
} // RPC
} // ripple

View File

@@ -0,0 +1,34 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012-2014 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef RIPPLE_RPC_LOOKUPLEDGER_H_INCLUDED
#define RIPPLE_RPC_LOOKUPLEDGER_H_INCLUDED
namespace ripple {
namespace RPC {
Json::Value lookupLedger (
Json::Value const& jvRequest,
Ledger::pointer& lpLedger,
NetworkOPs& netOps);
} // RPC
} // ripple
#endif

View File

@@ -0,0 +1,48 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012-2014 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#include "ParseAccountIds.h"
namespace ripple {
namespace RPC {
boost::unordered_set<RippleAddress> parseAccountIds (const Json::Value& jvArray)
{
boost::unordered_set<RippleAddress> usnaResult;
for (Json::Value::const_iterator it = jvArray.begin (); it != jvArray.end (); it++)
{
RippleAddress naString;
if (! (*it).isString () || !naString.setAccountID ((*it).asString ()))
{
usnaResult.clear ();
break;
}
else
{
(void) usnaResult.insert (naString);
}
}
return usnaResult;
}
} // RPC
} // ripple

View File

@@ -0,0 +1,31 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012-2014 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef RIPPLE_RPC_PARSEACCOUNTIDS_H_INCLUDED
#define RIPPLE_RPC_PARSEACCOUNTIDS_H_INCLUDED
namespace ripple {
namespace RPC {
boost::unordered_set <RippleAddress> parseAccountIds (const Json::Value& jvArray);
} // RPC
} // ripple
#endif

View File

@@ -0,0 +1,547 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012-2014 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#include "TransactionSign.h"
namespace ripple {
class LegacyPathFind
{
public:
LegacyPathFind (bool isAdmin) : m_isOkay (false)
{
if (isAdmin)
++inProgress;
else
{
if ((getApp().getJobQueue ().getJobCountGE (jtCLIENT) > 50) ||
getApp().getFeeTrack().isLoadedLocal ())
return;
do
{
int prevVal = inProgress.load();
if (prevVal >= maxInProgress)
return;
if (inProgress.compare_exchange_strong (prevVal, prevVal + 1,
std::memory_order_release, std::memory_order_relaxed))
break;
}
while (1);
}
m_isOkay = true;
}
~LegacyPathFind ()
{
if (m_isOkay)
--inProgress;
}
bool isOkay ()
{
return m_isOkay;
}
private:
static std::atomic <int> inProgress;
static int maxInProgress;
bool m_isOkay;
};
std::atomic <int> LegacyPathFind::inProgress (0);
int LegacyPathFind::maxInProgress (2);
//------------------------------------------------------------------------------
// VFALCO TODO Move this to a Tuning.h or Defaults.h
enum
{
defaultAutoFillFeeMultiplier = 10
};
namespace RPC {
/** Fill in the fee on behalf of the client.
This is called when the client does not explicitly specify the fee.
The client may also put a ceiling on the amount of the fee. This ceiling
is expressed as a multiplier based on the current ledger's fee schedule.
JSON fields
"Fee" The fee paid by the transaction. Omitted when the client
wants the fee filled in.
"fee_mult_max" A multiplier applied to the current ledger's transaction
fee that caps the maximum the fee server should auto fill.
If this optional field is not specified, then a default
multiplier is used.
@param tx The JSON corresponding to the transaction to fill in
@param ledger A ledger for retrieving the current fee schedule
@param result A JSON object for injecting error results, if any
@param admin `true` if this is called by an administrative endpoint.
*/
static void autofill_fee (Json::Value& request,
Ledger::pointer ledger, Json::Value& result, bool admin)
{
Json::Value& tx (request["tx_json"]);
if (tx.isMember ("Fee"))
return;
int mult (defaultAutoFillFeeMultiplier);
if (request.isMember ("fee_mult_max"))
{
if (request["fee_mult_max"].isNumeric ())
{
mult = request["fee_mult_max"].asInt();
}
else
{
RPC::inject_error (rpcHIGH_FEE, RPC::expected_field_message (
"fee_mult_max", "a number"), result);
return;
}
}
// Administrative endpoints are exempt from local fees
std::uint64_t fee = ledger->scaleFeeLoad (
getConfig().FEE_DEFAULT, admin);
std::uint64_t const limit (mult * getConfig().FEE_DEFAULT);
if (fee > limit)
{
std::stringstream ss;
ss <<
"Fee of " << fee <<
" exceeds the requested tx limit of " << limit;
RPC::inject_error (rpcHIGH_FEE, ss.str(), result);
return;
}
tx ["Fee"] = (int) fee;
}
//------------------------------------------------------------------------------
// VFALCO TODO This function should take a reference to the params, modify it
// as needed, and then there should be a separate function to
// submit the tranaction
//
Json::Value transactionSign (
Json::Value params, bool bSubmit, bool bFailHard,
Application::ScopedLockType& mlh, NetworkOPs& netOps, int role)
{
Json::Value jvResult;
WriteLog (lsDEBUG, RPCHandler) << boost::str (boost::format ("transactionSign: %s") % params);
if (! params.isMember ("secret"))
return RPC::missing_field_error ("secret");
if (! params.isMember ("tx_json"))
return RPC::missing_field_error ("tx_json");
RippleAddress naSeed;
if (! naSeed.setSeedGeneric (params["secret"].asString ()))
return RPC::make_error (rpcBAD_SEED,
RPC::invalid_field_message ("secret"));
Json::Value& tx_json (params ["tx_json"]);
if (! tx_json.isObject ())
return RPC::object_field_error ("tx_json");
if (! tx_json.isMember ("TransactionType"))
return RPC::missing_field_error ("tx_json.TransactionType");
std::string const sType = tx_json ["TransactionType"].asString ();
if (! tx_json.isMember ("Account"))
return RPC::make_error (rpcSRC_ACT_MISSING,
RPC::missing_field_message ("tx_json.Account"));
RippleAddress raSrcAddressID;
if (! raSrcAddressID.setAccountID (tx_json["Account"].asString ()))
return RPC::make_error (rpcSRC_ACT_MALFORMED,
RPC::invalid_field_message ("tx_json.Account"));
bool const bOffline (
params.isMember ("offline") && params["offline"].asBool ());
if (! tx_json.isMember ("Sequence") && bOffline)
return RPC::missing_field_error ("tx_json.Sequence");
// Check for current ledger
if (!bOffline && !getConfig ().RUN_STANDALONE &&
(getApp().getLedgerMaster().getValidatedLedgerAge() > 120))
return rpcError (rpcNO_CURRENT);
// Check for load
if (getApp().getFeeTrack().isLoadedCluster() && (role != Config::ADMIN))
return rpcError(rpcTOO_BUSY);
Ledger::pointer lSnapshot = netOps.getCurrentLedger ();
AccountState::pointer asSrc = bOffline
? AccountState::pointer () // Don't look up address if offline.
: netOps.getAccountState (lSnapshot, raSrcAddressID);
if (!bOffline && !asSrc)
{
// If not offline and did not find account, error.
WriteLog (lsDEBUG, RPCHandler) << boost::str (boost::format ("transactionSign: Failed to find source account in current ledger: %s")
% raSrcAddressID.humanAccountID ());
return rpcError (rpcSRC_ACT_NOT_FOUND);
}
autofill_fee (params, lSnapshot, jvResult, role == Config::ADMIN);
if (RPC::contains_error (jvResult))
return jvResult;
if ("Payment" == sType)
{
RippleAddress dstAccountID;
if (! tx_json.isMember ("Amount"))
return RPC::missing_field_error ("tx_json.Amount");
STAmount amount;
if (! amount.bSetJson (tx_json ["Amount"]))
return RPC::invalid_field_error ("tx_json.Amount");
if (!tx_json.isMember ("Destination"))
return RPC::missing_field_error ("tx_json.Destination");
if (!dstAccountID.setAccountID (tx_json["Destination"].asString ()))
return RPC::invalid_field_error ("tx_json.Destination");
if (tx_json.isMember ("Paths") && params.isMember ("build_path"))
return RPC::make_error (rpcINVALID_PARAMS,
"Cannot specify both 'tx_json.Paths' and 'tx_json.build_path'");
if (!tx_json.isMember ("Paths") && tx_json.isMember ("Amount") && params.isMember ("build_path"))
{
// Need a ripple path.
STPathSet spsPaths;
uint160 uSrcCurrencyID;
uint160 uSrcIssuerID;
STAmount saSendMax;
if (tx_json.isMember ("SendMax"))
{
if (!saSendMax.bSetJson (tx_json ["SendMax"]))
return RPC::invalid_field_error ("tx_json.SendMax");
}
else
{
// If no SendMax, default to Amount with sender as issuer.
saSendMax = amount;
saSendMax.setIssuer (raSrcAddressID.getAccountID ());
}
if (saSendMax.isNative () && amount.isNative ())
return RPC::make_error (rpcINVALID_PARAMS,
"Cannot build XRP to XRP paths.");
{
LegacyPathFind lpf (role == Config::ADMIN);
if (!lpf.isOkay ())
return rpcError (rpcTOO_BUSY);
bool bValid;
RippleLineCache::pointer cache = boost::make_shared<RippleLineCache> (lSnapshot);
Pathfinder pf (cache, raSrcAddressID, dstAccountID,
saSendMax.getCurrency (), saSendMax.getIssuer (), amount, bValid);
STPath extraPath;
if (!bValid || !pf.findPaths (getConfig ().PATH_SEARCH_OLD, 4, spsPaths, extraPath))
{
WriteLog (lsDEBUG, RPCHandler) << "transactionSign: build_path: No paths found.";
return rpcError (rpcNO_PATH);
}
else
{
WriteLog (lsDEBUG, RPCHandler) << "transactionSign: build_path: " << spsPaths.getJson (0);
}
if (!spsPaths.isEmpty ())
{
tx_json["Paths"] = spsPaths.getJson (0);
}
}
}
}
if (!tx_json.isMember ("Fee")
&& (
"AccountSet" == tx_json["TransactionType"].asString ()
|| "OfferCreate" == tx_json["TransactionType"].asString ()
|| "OfferCancel" == tx_json["TransactionType"].asString ()
|| "TrustSet" == tx_json["TransactionType"].asString ()))
{
tx_json["Fee"] = (int) getConfig ().FEE_DEFAULT;
}
if (!tx_json.isMember ("Sequence"))
{
if (bOffline)
{
// If offline, Sequence is mandatory.
return rpcError (rpcINVALID_PARAMS);
}
else
{
tx_json["Sequence"] = asSrc->getSeq ();
}
}
if (!tx_json.isMember ("Flags")) tx_json["Flags"] = tfFullyCanonicalSig;
if (!bOffline)
{
SLE::pointer sleAccountRoot = netOps.getSLEi (lSnapshot,
Ledger::getAccountRootIndex (raSrcAddressID.getAccountID ()));
if (!sleAccountRoot)
{
// XXX Ignore transactions for accounts not created.
return rpcError (rpcSRC_ACT_NOT_FOUND);
}
}
bool bHaveAuthKey = false;
RippleAddress naAuthorizedPublic;
RippleAddress naSecret = RippleAddress::createSeedGeneric (
params["secret"].asString ());
RippleAddress naMasterGenerator = RippleAddress::createGeneratorPublic (
naSecret);
// Find the index of Account from the master generator, so we can generate
// the public and private keys.
RippleAddress naMasterAccountPublic;
unsigned int iIndex = 0;
bool bFound = false;
// Don't look at ledger entries to determine if the account exists.
// Don't want to leak to thin server that these accounts are related.
while (!bFound && iIndex != getConfig ().ACCOUNT_PROBE_MAX)
{
naMasterAccountPublic.setAccountPublic (naMasterGenerator, iIndex);
WriteLog (lsWARNING, RPCHandler) <<
"authorize: " << iIndex <<
" : " << naMasterAccountPublic.humanAccountID () <<
" : " << raSrcAddressID.humanAccountID ();
bFound = raSrcAddressID.getAccountID () == naMasterAccountPublic.getAccountID ();
if (!bFound)
++iIndex;
}
if (!bFound)
{
return rpcError (rpcBAD_SECRET);
}
// Use the generator to determine the associated public and private keys.
RippleAddress naGenerator = RippleAddress::createGeneratorPublic (
naSecret);
RippleAddress naAccountPublic = RippleAddress::createAccountPublic (
naGenerator, iIndex);
RippleAddress naAccountPrivate = RippleAddress::createAccountPrivate (
naGenerator, naSecret, iIndex);
if (bHaveAuthKey
// The generated pair must match authorized...
&& naAuthorizedPublic.getAccountID () != naAccountPublic.getAccountID ()
// ... or the master key must have been used.
&& raSrcAddressID.getAccountID () != naAccountPublic.getAccountID ())
{
// Log::out() << "iIndex: " << iIndex;
// Log::out() << "sfAuthorizedKey: " << strHex(asSrc->getAuthorizedKey().getAccountID());
// Log::out() << "naAccountPublic: " << strHex(naAccountPublic.getAccountID());
return rpcError (rpcSRC_ACT_NOT_FOUND);
}
std::unique_ptr<STObject> sopTrans;
{
STParsedJSON parsed ("tx_json", tx_json);
if (parsed.object.get() != nullptr)
{
// VFALCO NOTE No idea why this doesn't compile.
//sopTrans = parsed.object;
sopTrans.reset (parsed.object.release());
}
else
{
jvResult ["error"] = parsed.error ["error"];
jvResult ["error_code"] = parsed.error ["error_code"];
jvResult ["error_message"] = parsed.error ["error_message"];
return jvResult;
}
}
sopTrans->setFieldVL (sfSigningPubKey, naAccountPublic.getAccountPublic ());
SerializedTransaction::pointer stpTrans;
try
{
stpTrans = boost::make_shared<SerializedTransaction> (*sopTrans);
}
catch (std::exception&)
{
return RPC::make_error (rpcINTERNAL,
"Exception occurred during transaction");
}
std::string reason;
if (!passesLocalChecks (*stpTrans, reason))
{
return RPC::make_error (rpcINVALID_PARAMS,
reason);
}
if (params.isMember ("debug_signing"))
{
jvResult["tx_unsigned"] = strHex (
stpTrans->getSerializer ().peekData ());
jvResult["tx_signing_hash"] = stpTrans->getSigningHash ().ToString ();
}
// FIXME: For performance, transactions should not be signed in this code path.
stpTrans->sign (naAccountPrivate);
Transaction::pointer tpTrans;
try
{
tpTrans = boost::make_shared<Transaction> (stpTrans, false);
}
catch (std::exception&)
{
return RPC::make_error (rpcINTERNAL,
"Exception occurred during transaction");
}
try
{
// FIXME: For performance, should use asynch interface
tpTrans = netOps.submitTransactionSync (tpTrans,
role == Config::ADMIN, true, bFailHard, bSubmit);
if (!tpTrans)
{
return RPC::make_error (rpcINTERNAL,
"Unable to sterilize transaction.");
}
}
catch (std::exception&)
{
return RPC::make_error (rpcINTERNAL,
"Exception occurred during transaction submission.");
}
try
{
jvResult["tx_json"] = tpTrans->getJson (0);
jvResult["tx_blob"] = strHex (
tpTrans->getSTransaction ()->getSerializer ().peekData ());
if (temUNCERTAIN != tpTrans->getResult ())
{
std::string sToken;
std::string sHuman;
transResultInfo (tpTrans->getResult (), sToken, sHuman);
jvResult["engine_result"] = sToken;
jvResult["engine_result_code"] = tpTrans->getResult ();
jvResult["engine_result_message"] = sHuman;
}
return jvResult;
}
catch (std::exception&)
{
return RPC::make_error (rpcINTERNAL,
"Exception occurred during JSON handling.");
}
}
class JSONRPC_test : public beast::unit_test::suite
{
public:
void testAutoFillFees ()
{
RippleAddress rootSeedMaster = RippleAddress::createSeedGeneric ("masterpassphrase");
RippleAddress rootGeneratorMaster = RippleAddress::createGeneratorPublic (rootSeedMaster);
RippleAddress rootAddress = RippleAddress::createAccountPublic (rootGeneratorMaster, 0);
std::uint64_t startAmount (100000);
Ledger::pointer ledger (boost::make_shared <Ledger> (
rootAddress, startAmount));
{
Json::Value req;
Json::Value result;
Json::Reader ().parse (
"{ \"fee_mult_max\" : 1, \"tx_json\" : { } } "
, req);
autofill_fee (req, ledger, result, true);
expect (! contains_error (result));
}
{
Json::Value req;
Json::Value result;
Json::Reader ().parse (
"{ \"fee_mult_max\" : 0, \"tx_json\" : { } } "
, req);
autofill_fee (req, ledger, result, true);
expect (contains_error (result));
}
}
void run ()
{
testAutoFillFees ();
}
};
BEAST_DEFINE_TESTSUITE(JSONRPC,ripple_app,ripple);
} // RPC
} // ripple

View File

@@ -0,0 +1,37 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012-2014 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef RIPPLE_RPC_TRANSACTIONSIGN_H_INCLUDED
#define RIPPLE_RPC_TRANSACTIONSIGN_H_INCLUDED
namespace ripple {
namespace RPC {
Json::Value transactionSign (
Json::Value jvRequest,
bool bSubmit,
bool bFailHard,
Application::ScopedLockType& mlh,
NetworkOPs& netOps,
int role);
} // RPC
} // ripple
#endif