From abbf4b82b06d3eae32fa169cfe445829f69d526e Mon Sep 17 00:00:00 2001 From: Miguel Portilla Date: Tue, 24 May 2016 13:21:32 -0400 Subject: [PATCH] Consolidate RPC utility functions (RIPD-947) --- Builds/VisualStudio2015/RippleD.vcxproj | 42 +- .../VisualStudio2015/RippleD.vcxproj.filters | 44 +- src/ripple/protocol/JsonFields.h | 10 +- src/ripple/rpc/KeypairForSignature.h | 42 -- src/ripple/rpc/RPCVersion.h | 46 -- .../rpc/handlers/AccountCurrenciesHandler.cpp | 3 +- src/ripple/rpc/handlers/AccountInfo.cpp | 4 +- src/ripple/rpc/handlers/AccountLines.cpp | 4 +- src/ripple/rpc/handlers/AccountObjects.cpp | 5 +- src/ripple/rpc/handlers/AccountOffers.cpp | 5 +- src/ripple/rpc/handlers/AccountTx.cpp | 3 +- src/ripple/rpc/handlers/AccountTxOld.cpp | 3 +- src/ripple/rpc/handlers/BookOffers.cpp | 3 +- src/ripple/rpc/handlers/GatewayBalances.cpp | 3 +- src/ripple/rpc/handlers/LedgerData.cpp | 2 +- src/ripple/rpc/handlers/LedgerEntry.cpp | 2 +- src/ripple/rpc/handlers/LedgerHandler.cpp | 2 +- src/ripple/rpc/handlers/LedgerHeader.cpp | 2 +- src/ripple/rpc/handlers/NoRippleCheck.cpp | 4 +- src/ripple/rpc/handlers/OwnerInfo.cpp | 2 +- src/ripple/rpc/handlers/RipplePathFind.cpp | 2 +- src/ripple/rpc/handlers/Subscribe.cpp | 2 +- src/ripple/rpc/handlers/TransactionEntry.cpp | 3 +- src/ripple/rpc/handlers/Tx.cpp | 2 +- src/ripple/rpc/handlers/Unsubscribe.cpp | 2 +- src/ripple/rpc/handlers/Version.h | 2 +- src/ripple/rpc/handlers/WalletPropose.cpp | 2 +- src/ripple/rpc/impl/AccountFromString.cpp | 80 --- src/ripple/rpc/impl/AccountFromString.h | 44 -- src/ripple/rpc/impl/Command.h | 35 - src/ripple/rpc/impl/DoPrint.h | 55 -- src/ripple/rpc/impl/GetAccountObjects.cpp | 109 --- src/ripple/rpc/impl/GetAccountObjects.h | 45 -- src/ripple/rpc/impl/KeypairForSignature.cpp | 199 ------ src/ripple/rpc/impl/LookupLedger.cpp | 249 ------- src/ripple/rpc/impl/LookupLedger.h | 56 -- src/ripple/rpc/impl/ParseAccountIds.cpp | 44 -- src/ripple/rpc/impl/ParseAccountIds.h | 35 - src/ripple/rpc/impl/RPCHelpers.cpp | 672 ++++++++++++++++++ src/ripple/rpc/impl/RPCHelpers.h | 135 ++++ src/ripple/rpc/impl/RPCVersion.cpp | 30 - src/ripple/rpc/impl/TransactionSign.cpp | 2 +- src/ripple/rpc/impl/Utilities.cpp | 146 ---- src/ripple/rpc/impl/Utilities.h | 69 -- src/ripple/rpc/tests/KeyGeneration.test.cpp | 2 +- src/ripple/unity/rpcx.cpp | 8 +- 46 files changed, 846 insertions(+), 1415 deletions(-) delete mode 100644 src/ripple/rpc/KeypairForSignature.h delete mode 100644 src/ripple/rpc/RPCVersion.h delete mode 100644 src/ripple/rpc/impl/AccountFromString.cpp delete mode 100644 src/ripple/rpc/impl/AccountFromString.h delete mode 100644 src/ripple/rpc/impl/Command.h delete mode 100644 src/ripple/rpc/impl/DoPrint.h delete mode 100644 src/ripple/rpc/impl/GetAccountObjects.cpp delete mode 100644 src/ripple/rpc/impl/GetAccountObjects.h delete mode 100644 src/ripple/rpc/impl/KeypairForSignature.cpp delete mode 100644 src/ripple/rpc/impl/LookupLedger.cpp delete mode 100644 src/ripple/rpc/impl/LookupLedger.h delete mode 100644 src/ripple/rpc/impl/ParseAccountIds.cpp delete mode 100644 src/ripple/rpc/impl/ParseAccountIds.h create mode 100644 src/ripple/rpc/impl/RPCHelpers.cpp create mode 100644 src/ripple/rpc/impl/RPCHelpers.h delete mode 100644 src/ripple/rpc/impl/RPCVersion.cpp delete mode 100644 src/ripple/rpc/impl/Utilities.cpp delete mode 100644 src/ripple/rpc/impl/Utilities.h diff --git a/Builds/VisualStudio2015/RippleD.vcxproj b/Builds/VisualStudio2015/RippleD.vcxproj index 5e78e760cf..f4b8096a05 100644 --- a/Builds/VisualStudio2015/RippleD.vcxproj +++ b/Builds/VisualStudio2015/RippleD.vcxproj @@ -3284,54 +3284,28 @@ True True - - True - True - - - - - True - True - - - True True - - True - True - True True - - True - True - - - - - True - True - - - True True - + True True + + True True @@ -3344,22 +3318,12 @@ - - True - True - - - - - - - diff --git a/Builds/VisualStudio2015/RippleD.vcxproj.filters b/Builds/VisualStudio2015/RippleD.vcxproj.filters index 36d25db9fd..fb28e80080 100644 --- a/Builds/VisualStudio2015/RippleD.vcxproj.filters +++ b/Builds/VisualStudio2015/RippleD.vcxproj.filters @@ -3741,51 +3741,27 @@ ripple\rpc\handlers - - ripple\rpc\impl - - - ripple\rpc\impl - - - ripple\rpc\impl - - - ripple\rpc\impl - ripple\rpc\impl ripple\rpc\impl - - ripple\rpc\impl - ripple\rpc\impl ripple\rpc\impl - - ripple\rpc\impl - - - ripple\rpc\impl - - - ripple\rpc\impl - - - ripple\rpc\impl - ripple\rpc\impl - + ripple\rpc\impl + + ripple\rpc\impl + ripple\rpc\impl @@ -3798,27 +3774,15 @@ ripple\rpc\impl - - ripple\rpc\impl - - - ripple\rpc\impl - ripple\rpc - - ripple\rpc - ripple\rpc ripple\rpc - - ripple\rpc - ripple\rpc diff --git a/src/ripple/protocol/JsonFields.h b/src/ripple/protocol/JsonFields.h index 50d16fc19d..01e2896672 100644 --- a/src/ripple/protocol/JsonFields.h +++ b/src/ripple/protocol/JsonFields.h @@ -206,15 +206,15 @@ JSS ( latency ); // out: PeerImp JSS ( last ); // out: RPCVersion JSS ( last_close ); // out: NetworkOPs JSS ( ledger ); // in: NetworkOPs, LedgerCleaner, - // LookupLedger + // RPCHelpers // out: NetworkOPs, PeerImp -JSS ( ledger_current_index ); // out: NetworkOPs, LookupLedger, +JSS ( ledger_current_index ); // out: NetworkOPs, RPCHelpers, // LedgerCurrent, LedgerAccept JSS ( ledger_data ); // out: LedgerHeader -JSS ( ledger_hash ); // in: LookupLedger, LedgerRequest, +JSS ( ledger_hash ); // in: RPCHelpers, LedgerRequest, // RipplePathFind, TransactionEntry, // handlers/Ledger - // out: NetworkOPs, LookupLedger, + // out: NetworkOPs, RPCHelpers, // LedgerClosed, LedgerData JSS ( ledger_hit_rate ); // out: GetCounts JSS ( ledger_index ); // in/out: many @@ -412,7 +412,7 @@ JSS ( url_password ); // in: Subscribe JSS ( url_username ); // in: Subscribe JSS ( urlgravatar ); // JSS ( username ); // in: Subscribe -JSS ( validated ); // out: NetworkOPs, LookupLedger, AccountTx* +JSS ( validated ); // out: NetworkOPs, RPCHelpers, AccountTx* // Tx JSS ( validated_ledger ); // out: NetworkOPs JSS ( validated_ledgers ); // out: NetworkOPs diff --git a/src/ripple/rpc/KeypairForSignature.h b/src/ripple/rpc/KeypairForSignature.h deleted file mode 100644 index c1398cc6da..0000000000 --- a/src/ripple/rpc/KeypairForSignature.h +++ /dev/null @@ -1,42 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of rippled: https://github.com/ripple/rippled - Copyright (c) 2015 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_SIGNATUREKEYPAIR_H_INCLUDED -#define RIPPLE_RPC_SIGNATUREKEYPAIR_H_INCLUDED - -#include -#include -#include -#include -#include -#include - -namespace ripple { -namespace RPC { - -boost::optional -getSeedFromRPC (Json::Value const& params, Json::Value& error); - -std::pair -keypairForSignature (Json::Value const& params, Json::Value& error); - -} // RPC -} // ripple - -#endif diff --git a/src/ripple/rpc/RPCVersion.h b/src/ripple/rpc/RPCVersion.h deleted file mode 100644 index 24c9497fbc..0000000000 --- a/src/ripple/rpc/RPCVersion.h +++ /dev/null @@ -1,46 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of rippled: https://github.com/ripple/rippled - Copyright (c) 2012, 2013 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 RIPPLED_RIPPLE_RPC_VERSIONS_H -#define RIPPLED_RIPPLE_RPC_VERSIONS_H - -#include -#include -#include - -namespace ripple { -namespace RPC { - -extern beast::SemanticVersion const firstVersion; -extern beast::SemanticVersion const goodVersion; -extern beast::SemanticVersion const lastVersion; - -template -void setVersion(Object& parent) -{ - auto&& object = addObject (parent, jss::version); - object[jss::first] = firstVersion.print(); - object[jss::good] = goodVersion.print(); - object[jss::last] = lastVersion.print(); -} - -} // RPC -} // ripple - -#endif diff --git a/src/ripple/rpc/handlers/AccountCurrenciesHandler.cpp b/src/ripple/rpc/handlers/AccountCurrenciesHandler.cpp index 9964be1d8a..2cce120afc 100644 --- a/src/ripple/rpc/handlers/AccountCurrenciesHandler.cpp +++ b/src/ripple/rpc/handlers/AccountCurrenciesHandler.cpp @@ -23,8 +23,7 @@ #include #include #include -#include -#include +#include namespace ripple { diff --git a/src/ripple/rpc/handlers/AccountInfo.cpp b/src/ripple/rpc/handlers/AccountInfo.cpp index 726fbfc21d..157eebe095 100644 --- a/src/ripple/rpc/handlers/AccountInfo.cpp +++ b/src/ripple/rpc/handlers/AccountInfo.cpp @@ -26,10 +26,8 @@ #include #include #include -#include #include -#include -#include +#include namespace ripple { diff --git a/src/ripple/rpc/handlers/AccountLines.cpp b/src/ripple/rpc/handlers/AccountLines.cpp index cc50862db8..58213faf6c 100644 --- a/src/ripple/rpc/handlers/AccountLines.cpp +++ b/src/ripple/rpc/handlers/AccountLines.cpp @@ -26,10 +26,8 @@ #include #include #include -#include -#include +#include #include -#include namespace ripple { diff --git a/src/ripple/rpc/handlers/AccountObjects.cpp b/src/ripple/rpc/handlers/AccountObjects.cpp index 5ca75a12a5..52ef5c291f 100644 --- a/src/ripple/rpc/handlers/AccountObjects.cpp +++ b/src/ripple/rpc/handlers/AccountObjects.cpp @@ -27,11 +27,8 @@ #include #include #include -#include -#include -#include +#include #include -#include #include #include diff --git a/src/ripple/rpc/handlers/AccountOffers.cpp b/src/ripple/rpc/handlers/AccountOffers.cpp index ab7340dfca..b022cb1377 100644 --- a/src/ripple/rpc/handlers/AccountOffers.cpp +++ b/src/ripple/rpc/handlers/AccountOffers.cpp @@ -21,15 +21,14 @@ #include #include #include +#include #include #include #include #include #include -#include -#include +#include #include -#include namespace ripple { diff --git a/src/ripple/rpc/handlers/AccountTx.cpp b/src/ripple/rpc/handlers/AccountTx.cpp index 59244159b6..1f55da1b5c 100644 --- a/src/ripple/rpc/handlers/AccountTx.cpp +++ b/src/ripple/rpc/handlers/AccountTx.cpp @@ -30,8 +30,7 @@ #include #include #include -#include -#include +#include #include namespace ripple { diff --git a/src/ripple/rpc/handlers/AccountTxOld.cpp b/src/ripple/rpc/handlers/AccountTxOld.cpp index dcca79e614..fb894197cd 100644 --- a/src/ripple/rpc/handlers/AccountTxOld.cpp +++ b/src/ripple/rpc/handlers/AccountTxOld.cpp @@ -28,8 +28,7 @@ #include #include #include -#include -#include +#include #include namespace ripple { diff --git a/src/ripple/rpc/handlers/BookOffers.cpp b/src/ripple/rpc/handlers/BookOffers.cpp index 0e6b67c963..a777c2bf32 100644 --- a/src/ripple/rpc/handlers/BookOffers.cpp +++ b/src/ripple/rpc/handlers/BookOffers.cpp @@ -28,8 +28,7 @@ #include #include #include -#include -#include +#include namespace ripple { diff --git a/src/ripple/rpc/handlers/GatewayBalances.cpp b/src/ripple/rpc/handlers/GatewayBalances.cpp index a6ef5a4eb9..01088d28ac 100644 --- a/src/ripple/rpc/handlers/GatewayBalances.cpp +++ b/src/ripple/rpc/handlers/GatewayBalances.cpp @@ -27,8 +27,7 @@ #include #include #include -#include -#include +#include namespace ripple { diff --git a/src/ripple/rpc/handlers/LedgerData.cpp b/src/ripple/rpc/handlers/LedgerData.cpp index 4c8ec73c2a..90ec8b20d3 100644 --- a/src/ripple/rpc/handlers/LedgerData.cpp +++ b/src/ripple/rpc/handlers/LedgerData.cpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/ripple/rpc/handlers/LedgerEntry.cpp b/src/ripple/rpc/handlers/LedgerEntry.cpp index 6d2bd50766..d9d9b31cf2 100644 --- a/src/ripple/rpc/handlers/LedgerEntry.cpp +++ b/src/ripple/rpc/handlers/LedgerEntry.cpp @@ -27,7 +27,7 @@ #include #include #include -#include +#include namespace ripple { diff --git a/src/ripple/rpc/handlers/LedgerHandler.cpp b/src/ripple/rpc/handlers/LedgerHandler.cpp index e23267eca4..3f6bb8078e 100644 --- a/src/ripple/rpc/handlers/LedgerHandler.cpp +++ b/src/ripple/rpc/handlers/LedgerHandler.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include namespace ripple { diff --git a/src/ripple/rpc/handlers/LedgerHeader.cpp b/src/ripple/rpc/handlers/LedgerHeader.cpp index 8be13dce72..7ca4326101 100644 --- a/src/ripple/rpc/handlers/LedgerHeader.cpp +++ b/src/ripple/rpc/handlers/LedgerHeader.cpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include namespace ripple { diff --git a/src/ripple/rpc/handlers/NoRippleCheck.cpp b/src/ripple/rpc/handlers/NoRippleCheck.cpp index 578335f361..a97093dcf1 100644 --- a/src/ripple/rpc/handlers/NoRippleCheck.cpp +++ b/src/ripple/rpc/handlers/NoRippleCheck.cpp @@ -27,10 +27,8 @@ #include #include #include -#include -#include +#include #include -#include namespace ripple { diff --git a/src/ripple/rpc/handlers/OwnerInfo.cpp b/src/ripple/rpc/handlers/OwnerInfo.cpp index dc3eb83e9f..88e96d90f7 100644 --- a/src/ripple/rpc/handlers/OwnerInfo.cpp +++ b/src/ripple/rpc/handlers/OwnerInfo.cpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include namespace ripple { diff --git a/src/ripple/rpc/handlers/RipplePathFind.cpp b/src/ripple/rpc/handlers/RipplePathFind.cpp index 5d2a90789b..914fd9298e 100644 --- a/src/ripple/rpc/handlers/RipplePathFind.cpp +++ b/src/ripple/rpc/handlers/RipplePathFind.cpp @@ -41,7 +41,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/ripple/rpc/handlers/Subscribe.cpp b/src/ripple/rpc/handlers/Subscribe.cpp index 1f97ba5069..acc64cfe41 100644 --- a/src/ripple/rpc/handlers/Subscribe.cpp +++ b/src/ripple/rpc/handlers/Subscribe.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/ripple/rpc/handlers/TransactionEntry.cpp b/src/ripple/rpc/handlers/TransactionEntry.cpp index 3c0ee4c030..13ea07e204 100644 --- a/src/ripple/rpc/handlers/TransactionEntry.cpp +++ b/src/ripple/rpc/handlers/TransactionEntry.cpp @@ -19,9 +19,10 @@ #include #include +#include #include #include -#include +#include namespace ripple { diff --git a/src/ripple/rpc/handlers/Tx.cpp b/src/ripple/rpc/handlers/Tx.cpp index e4d7b9afcb..09012b6ca4 100644 --- a/src/ripple/rpc/handlers/Tx.cpp +++ b/src/ripple/rpc/handlers/Tx.cpp @@ -27,7 +27,7 @@ #include #include #include -#include +#include namespace ripple { diff --git a/src/ripple/rpc/handlers/Unsubscribe.cpp b/src/ripple/rpc/handlers/Unsubscribe.cpp index 879b93be72..09402f66cc 100644 --- a/src/ripple/rpc/handlers/Unsubscribe.cpp +++ b/src/ripple/rpc/handlers/Unsubscribe.cpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include namespace ripple { diff --git a/src/ripple/rpc/handlers/Version.h b/src/ripple/rpc/handlers/Version.h index 1c5c99d3d7..f45b91cb4f 100644 --- a/src/ripple/rpc/handlers/Version.h +++ b/src/ripple/rpc/handlers/Version.h @@ -20,7 +20,7 @@ #ifndef RIPPLED_RIPPLE_RPC_HANDLERS_VERSION_H #define RIPPLED_RIPPLE_RPC_HANDLERS_VERSION_H -#include +#include namespace ripple { namespace RPC { diff --git a/src/ripple/rpc/handlers/WalletPropose.cpp b/src/ripple/rpc/handlers/WalletPropose.cpp index dad3e9d0cc..51a90e3aef 100644 --- a/src/ripple/rpc/handlers/WalletPropose.cpp +++ b/src/ripple/rpc/handlers/WalletPropose.cpp @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/ripple/rpc/impl/AccountFromString.cpp b/src/ripple/rpc/impl/AccountFromString.cpp deleted file mode 100644 index 025c38b872..0000000000 --- a/src/ripple/rpc/impl/AccountFromString.cpp +++ /dev/null @@ -1,80 +0,0 @@ -//------------------------------------------------------------------------------ -/* - 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 -#include -#include -#include -#include -#include -#include -#include -#include - -namespace ripple { -namespace RPC { - -boost::optional accountFromStringStrict (std::string const& account) -{ - boost::optional result; - - auto const publicKey = parseBase58 ( - TokenType::TOKEN_ACCOUNT_PUBLIC, - account); - - if (publicKey) - result = calcAccountID (*publicKey); - else - result = parseBase58 (account); - - return result; -} - -Json::Value accountFromString ( - AccountID& result, std::string const& strIdent, bool bStrict) -{ - if (auto accountID = accountFromStringStrict (strIdent)) - { - result = *accountID; - return Json::objectValue; - } - - if (bStrict) - { - auto id = deprecatedParseBitcoinAccountID (strIdent); - return rpcError (id ? rpcACT_BITCOIN : rpcACT_MALFORMED); - } - - // We allow the use of the seeds which is poor practice - // and merely for debugging convenience. - auto const seed = parseGenericSeed (strIdent); - - if (!seed) - return rpcError (rpcBAD_SEED); - - auto const keypair = generateKeyPair ( - KeyType::secp256k1, - *seed); - - result = calcAccountID (keypair.first); - return Json::objectValue; -} - -} // RPC -} // ripple diff --git a/src/ripple/rpc/impl/AccountFromString.h b/src/ripple/rpc/impl/AccountFromString.h deleted file mode 100644 index 527f611f32..0000000000 --- a/src/ripple/rpc/impl/AccountFromString.h +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -/* - 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 - -#include -#include - -namespace ripple { -namespace RPC { - -/** Get an AccountID from an account ID or public key. */ -boost::optional accountFromStringStrict (std::string const&); - -// --> strIdent: public key, account ID, or regular seed. -// --> bStrict: Only allow account id or public key. -// -// Returns a Json::objectValue, containing error information if there was one. -Json::Value accountFromString ( - AccountID& result, - std::string const& strIdent, - bool bStrict = false); - -} // RPC -} // ripple - -#endif diff --git a/src/ripple/rpc/impl/Command.h b/src/ripple/rpc/impl/Command.h deleted file mode 100644 index b136f31e7b..0000000000 --- a/src/ripple/rpc/impl/Command.h +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of rippled: https://github.com/ripple/rippled - Copyright (c) 2012, 2013 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_COMMAND_H_INCLUDED -#define RIPPLE_RPC_COMMAND_H_INCLUDED - -namespace ripple { -namespace RPC { - -/** Base class common to all RPC commands. */ -class Command -{ -public: -}; - -} -} - -#endif diff --git a/src/ripple/rpc/impl/DoPrint.h b/src/ripple/rpc/impl/DoPrint.h deleted file mode 100644 index 7d33ec6d95..0000000000 --- a/src/ripple/rpc/impl/DoPrint.h +++ /dev/null @@ -1,55 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of rippled: https://github.com/ripple/rippled - Copyright (c) 2012, 2013 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_DOPRINT_H_INCLUDED -#define RIPPLE_RPC_DOPRINT_H_INCLUDED - -#include -#include -#include - -namespace ripple { -namespace RPC { - -class DoPrint -{ -public: - void operator() (Request& req) - { - JsonPropertyStream stream; - - if (req.params.isObject() && - req.params[jss::params].isArray() && - req.params[jss::params][0u].isString ()) - { - req.app.write (stream, req.params[jss::params][0u].asString()); - } - else - { - req.app.write (stream); - } - - req.result = stream.top(); - } -}; - -} -} - -#endif diff --git a/src/ripple/rpc/impl/GetAccountObjects.cpp b/src/ripple/rpc/impl/GetAccountObjects.cpp deleted file mode 100644 index a8a798e6bf..0000000000 --- a/src/ripple/rpc/impl/GetAccountObjects.cpp +++ /dev/null @@ -1,109 +0,0 @@ -//------------------------------------------------------------------------------ -/* - 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 -#include -#include -#include - -namespace ripple { -namespace RPC { - -bool -getAccountObjects (ReadView const& ledger, AccountID const& account, - LedgerEntryType const type, uint256 dirIndex, uint256 const& entryIndex, - std::uint32_t const limit, Json::Value& jvResult) -{ - auto const rootDirIndex = getOwnerDirIndex (account); - auto found = false; - - if (dirIndex.isZero ()) - { - dirIndex = rootDirIndex; - found = true; - } - - auto dir = ledger.read({ltDIR_NODE, dirIndex}); - if (! dir) - return false; - - std::uint32_t i = 0; - auto& jvObjects = jvResult[jss::account_objects]; - for (;;) - { - auto const& entries = dir->getFieldV256 (sfIndexes); - auto iter = entries.begin (); - - if (! found) - { - iter = std::find (iter, entries.end (), entryIndex); - if (iter == entries.end ()) - return false; - - found = true; - } - - for (; iter != entries.end (); ++iter) - { - auto const sleNode = ledger.read(keylet::child(*iter)); - if (type == ltINVALID || sleNode->getType () == type) - { - jvObjects.append (sleNode->getJson (0)); - - if (++i == limit) - { - if (++iter != entries.end ()) - { - jvResult[jss::limit] = limit; - jvResult[jss::marker] = to_string (dirIndex) + ',' + - to_string (*iter); - return true; - } - - break; - } - } - } - - auto const nodeIndex = dir->getFieldU64 (sfIndexNext); - if (nodeIndex == 0) - return true; - - dirIndex = getDirNodeIndex (rootDirIndex, nodeIndex); - dir = ledger.read({ltDIR_NODE, dirIndex}); - if (! dir) - return true; - - if (i == limit) - { - auto const& e = dir->getFieldV256 (sfIndexes); - if (! e.empty ()) - { - jvResult[jss::limit] = limit; - jvResult[jss::marker] = to_string (dirIndex) + ',' + - to_string (*e.begin ()); - } - - return true; - } - } -} - -} // RPC -} // ripple diff --git a/src/ripple/rpc/impl/GetAccountObjects.h b/src/ripple/rpc/impl/GetAccountObjects.h deleted file mode 100644 index 354b880672..0000000000 --- a/src/ripple/rpc/impl/GetAccountObjects.h +++ /dev/null @@ -1,45 +0,0 @@ -//------------------------------------------------------------------------------ -/* - 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_ACCOUNT_OBJECTS_H_INCLUDED -#define RIPPLE_RPC_ACCOUNT_OBJECTS_H_INCLUDED - -#include - -namespace ripple { -namespace RPC { - -/** Gathers all objects for an account in a ledger. - @param ledger Ledger to search account objects. - @param account AccountID to find objects for. - @param type Gathers objects of this type. ltINVALID gathers all types. - @param dirIndex Begin gathering account objects from this directory. - @param entryIndex Begin gathering objects from this directory node. - @param limit Maximum number of objects to find. - @param jvResult A JSON result that holds the request objects. -*/ -bool -getAccountObjects (ReadView const& ledger, AccountID const& account, - LedgerEntryType const type, uint256 dirIndex, uint256 const& entryIndex, - std::uint32_t const limit, Json::Value& jvResult); - -} // RPC -} // ripple - -#endif diff --git a/src/ripple/rpc/impl/KeypairForSignature.cpp b/src/ripple/rpc/impl/KeypairForSignature.cpp deleted file mode 100644 index 1d53010967..0000000000 --- a/src/ripple/rpc/impl/KeypairForSignature.cpp +++ /dev/null @@ -1,199 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of rippled: https://github.com/ripple/rippled - Copyright (c) 2012-2015 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 -#include -#include -#include -#include -#include - -namespace ripple { -namespace RPC { - -boost::optional -getSeedFromRPC (Json::Value const& params, Json::Value& error) -{ - // The array should be constexpr, but that makes Visual Studio unhappy. - static char const* const seedTypes[] - { - jss::passphrase.c_str(), - jss::seed.c_str(), - jss::seed_hex.c_str() - }; - - // Identify which seed type is in use. - char const* seedType = nullptr; - int count = 0; - for (auto t : seedTypes) - { - if (params.isMember (t)) - { - ++count; - seedType = t; - } - } - - if (count != 1) - { - error = RPC::make_param_error ( - "Exactly one of the following must be specified: " + - std::string(jss::passphrase) + ", " + - std::string(jss::seed) + " or " + - std::string(jss::seed_hex)); - return boost::none; - } - - // Make sure a string is present - if (! params[seedType].isString()) - { - error = RPC::expected_field_error (seedType, "string"); - return boost::none; - } - - auto const fieldContents = params[seedType].asString(); - - // Convert string to seed. - boost::optional seed; - - if (seedType == jss::seed.c_str()) - seed = parseBase58 (fieldContents); - else if (seedType == jss::passphrase.c_str()) - seed = parseGenericSeed (fieldContents); - else if (seedType == jss::seed_hex.c_str()) - { - uint128 s; - - if (s.SetHexExact (fieldContents)) - seed.emplace (Slice(s.data(), s.size())); - } - - if (!seed) - error = rpcError (rpcBAD_SEED); - - return seed; -} - -std::pair -keypairForSignature (Json::Value const& params, Json::Value& error) -{ - bool const has_key_type = params.isMember (jss::key_type); - - // All of the secret types we allow, but only one at a time. - // The array should be constexpr, but that makes Visual Studio unhappy. - static char const* const secretTypes[] - { - jss::passphrase.c_str(), - jss::secret.c_str(), - jss::seed.c_str(), - jss::seed_hex.c_str() - }; - - // Identify which secret type is in use. - char const* secretType = nullptr; - int count = 0; - for (auto t : secretTypes) - { - if (params.isMember (t)) - { - ++count; - secretType = t; - } - } - - if (count == 0 || secretType == nullptr) - { - error = RPC::missing_field_error (jss::secret); - return { }; - } - - if (count > 1) - { - error = RPC::make_param_error ( - "Exactly one of the following must be specified: " + - std::string(jss::passphrase) + ", " + - std::string(jss::secret) + ", " + - std::string(jss::seed) + " or " + - std::string(jss::seed_hex)); - return { }; - } - - KeyType keyType = KeyType::secp256k1; - boost::optional seed; - - if (has_key_type) - { - if (! params[jss::key_type].isString()) - { - error = RPC::expected_field_error ( - jss::key_type, "string"); - return { }; - } - - keyType = keyTypeFromString ( - params[jss::key_type].asString()); - - if (keyType == KeyType::invalid) - { - error = RPC::invalid_field_error(jss::key_type); - return { }; - } - - if (secretType == jss::secret.c_str()) - { - error = RPC::make_param_error ( - "The secret field is not allowed if " + - std::string(jss::key_type) + " is used."); - return { }; - } - - seed = getSeedFromRPC (params, error); - } - else - { - if (! params[jss::secret].isString()) - { - error = RPC::expected_field_error ( - jss::secret, "string"); - return { }; - } - - seed = parseGenericSeed ( - params[jss::secret].asString ()); - } - - if (!seed) - { - if (!contains_error (error)) - { - error = RPC::make_error (rpcBAD_SEED, - RPC::invalid_field_message (secretType)); - } - - return { }; - } - - if (keyType != KeyType::secp256k1 && keyType != KeyType::ed25519) - LogicError ("keypairForSignature: invalid key type"); - - return generateKeyPair (keyType, *seed); -} - -} // RPC -} // ripple diff --git a/src/ripple/rpc/impl/LookupLedger.cpp b/src/ripple/rpc/impl/LookupLedger.cpp deleted file mode 100644 index 5709850c7e..0000000000 --- a/src/ripple/rpc/impl/LookupLedger.cpp +++ /dev/null @@ -1,249 +0,0 @@ -//------------------------------------------------------------------------------ -/* - 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace ripple { -namespace RPC { - -namespace { - -bool isValidatedOld (LedgerMaster& ledgerMaster, bool standalone) -{ - if (standalone) - return false; - - return ledgerMaster.getValidatedLedgerAge () > - Tuning::maxValidatedLedgerAge; -} - -template -Status ledgerFromRequest (T& ledger, Context& context) -{ - static auto const minSequenceGap = 10; - - ledger.reset(); - - auto& params = context.params; - auto& ledgerMaster = context.ledgerMaster; - - auto indexValue = params[jss::ledger_index]; - auto hashValue = params[jss::ledger_hash]; - - // We need to support the legacy "ledger" field. - auto& legacyLedger = params[jss::ledger]; - if (legacyLedger) - { - if (legacyLedger.asString().size () > 12) - hashValue = legacyLedger; - else - indexValue = legacyLedger; - } - - if (hashValue) - { - if (! hashValue.isString ()) - return {rpcINVALID_PARAMS, "ledgerHashNotString"}; - - uint256 ledgerHash; - if (! ledgerHash.SetHex (hashValue.asString ())) - return {rpcINVALID_PARAMS, "ledgerHashMalformed"}; - - ledger = ledgerMaster.getLedgerByHash (ledgerHash); - if (ledger == nullptr) - return {rpcLGR_NOT_FOUND, "ledgerNotFound"}; - } - else if (indexValue.isNumeric()) - { - ledger = ledgerMaster.getLedgerBySeq (indexValue.asInt ()); - - if (ledger == nullptr) - { - auto cur = ledgerMaster.getCurrentLedger(); - if (cur->info().seq == indexValue.asInt()) - ledger = cur; - } - - if (ledger == nullptr) - return {rpcLGR_NOT_FOUND, "ledgerNotFound"}; - - if (ledger->info().seq > ledgerMaster.getValidLedgerIndex() && - isValidatedOld(ledgerMaster, context.app.config().standalone())) - { - ledger.reset(); - return {rpcNO_NETWORK, "InsufficientNetworkMode"}; - } - } - else - { - if (isValidatedOld (ledgerMaster, context.app.config().standalone())) - return {rpcNO_NETWORK, "InsufficientNetworkMode"}; - - auto const index = indexValue.asString (); - if (index == "validated") - { - ledger = ledgerMaster.getValidatedLedger (); - if (ledger == nullptr) - return {rpcNO_NETWORK, "InsufficientNetworkMode"}; - - assert (! ledger->open()); - } - else - { - if (index.empty () || index == "current") - { - ledger = ledgerMaster.getCurrentLedger (); - assert (ledger->open()); - } - else if (index == "closed") - { - ledger = ledgerMaster.getClosedLedger (); - assert (! ledger->open()); - } - else - { - return {rpcINVALID_PARAMS, "ledgerIndexMalformed"}; - } - - if (ledger == nullptr) - return {rpcNO_NETWORK, "InsufficientNetworkMode"}; - - if (ledger->info().seq + minSequenceGap < - ledgerMaster.getValidLedgerIndex ()) - { - ledger.reset (); - return {rpcNO_NETWORK, "InsufficientNetworkMode"}; - } - } - } - - return Status::OK; -} - -bool isValidated (LedgerMaster& ledgerMaster, ReadView const& ledger, - Application& app) -{ - if (ledger.open()) - return false; - - if (ledger.info().validated) - return true; - - auto seq = ledger.info().seq; - try - { - // Use the skip list in the last validated ledger to see if ledger - // comes before the last validated ledger (and thus has been - // validated). - auto hash = ledgerMaster.walkHashBySeq (seq); - - if (!hash || ledger.info().hash != *hash) - { - // This ledger's hash is not the hash of the validated ledger - if (hash) - { - assert(hash->isNonZero()); - uint256 valHash = getHashByIndex (seq, app); - if (valHash == ledger.info().hash) - { - // SQL database doesn't match ledger chain - ledgerMaster.clearLedger (seq); - } - } - return false; - } - } - catch (SHAMapMissingNode const&) - { - auto stream = app.journal ("RPCHandler").warn(); - JLOG (stream) - << "Missing SHANode " << std::to_string (seq); - return false; - } - - // Mark ledger as validated to save time if we see it again. - ledger.info().validated = true; - return true; -} - -} // namespace - -// 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". -// -// Returns a Json::objectValue. If there was an error, it will be in that -// return value. Otherwise, the object contains the field "validated" and -// optionally the fields "ledger_hash", "ledger_index" and -// "ledger_current_index", if they are defined. -Status lookupLedger ( - std::shared_ptr& ledger, Context& context, - Json::Value& result) -{ - if (auto status = ledgerFromRequest (ledger, context)) - return status; - - auto& info = ledger->info(); - - if (!ledger->open()) - { - result[jss::ledger_hash] = to_string (info.hash); - result[jss::ledger_index] = info.seq; - } - else - { - result[jss::ledger_current_index] = info.seq; - } - - result[jss::validated] = isValidated (context.ledgerMaster, *ledger, context.app); - return Status::OK; -} - -Json::Value lookupLedger ( - std::shared_ptr& ledger, Context& context) -{ - Json::Value result; - if (auto status = lookupLedger (ledger, context, result)) - status.inject (result); - - return result; -} - -} // RPC -} // ripple diff --git a/src/ripple/rpc/impl/LookupLedger.h b/src/ripple/rpc/impl/LookupLedger.h deleted file mode 100644 index eab8469a39..0000000000 --- a/src/ripple/rpc/impl/LookupLedger.h +++ /dev/null @@ -1,56 +0,0 @@ -//------------------------------------------------------------------------------ -/* - 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 - -#include -#include - -namespace Json { -class Value; -} - -namespace ripple { - -class ReadView; - -namespace RPC { - -struct Context; - -/** Look up a ledger from a request and fill a Json::Result with either - an error, or data representing a ledger. - - If there is no error in the return value, then the ledger pointer will have - been filled. -*/ -Json::Value lookupLedger (std::shared_ptr&, Context&); - -/** Look up a ledger from a request and fill a Json::Result with the data - representing a ledger. - - If the returned Status is OK, the ledger pointer will have been filled. */ -Status lookupLedger ( - std::shared_ptr&, Context&, Json::Value& result); - -} // RPC -} // ripple - -#endif diff --git a/src/ripple/rpc/impl/ParseAccountIds.cpp b/src/ripple/rpc/impl/ParseAccountIds.cpp deleted file mode 100644 index 91cfcec84e..0000000000 --- a/src/ripple/rpc/impl/ParseAccountIds.cpp +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -/* - 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 -#include - -namespace ripple { -namespace RPC { - -hash_set -parseAccountIds (Json::Value const& jvArray) -{ - hash_set result; - for (auto const& jv: jvArray) - { - if (! jv.isString()) - return hash_set(); - auto const id = - parseBase58(jv.asString()); - if (! id) - return hash_set(); - result.insert(*id); - } - return result; -} - -} // RPC -} // ripple diff --git a/src/ripple/rpc/impl/ParseAccountIds.h b/src/ripple/rpc/impl/ParseAccountIds.h deleted file mode 100644 index db80da12fa..0000000000 --- a/src/ripple/rpc/impl/ParseAccountIds.h +++ /dev/null @@ -1,35 +0,0 @@ -//------------------------------------------------------------------------------ -/* - 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 - -#include -#include - -namespace ripple { -namespace RPC { - -hash_set -parseAccountIds (Json::Value const& jvArray); - -} // RPC -} // ripple - -#endif diff --git a/src/ripple/rpc/impl/RPCHelpers.cpp b/src/ripple/rpc/impl/RPCHelpers.cpp new file mode 100644 index 0000000000..05af0aa72b --- /dev/null +++ b/src/ripple/rpc/impl/RPCHelpers.cpp @@ -0,0 +1,672 @@ +//------------------------------------------------------------------------------ +/* + 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 +#include +#include +#include +#include +#include +#include +#include +#include + +namespace ripple { +namespace RPC { + +boost::optional +accountFromStringStrict(std::string const& account) +{ + boost::optional result; + + auto const publicKey = parseBase58 ( + TokenType::TOKEN_ACCOUNT_PUBLIC, + account); + + if (publicKey) + result = calcAccountID (*publicKey); + else + result = parseBase58 (account); + + return result; +} + +Json::Value +accountFromString( + AccountID& result, std::string const& strIdent, bool bStrict) +{ + if (auto accountID = accountFromStringStrict (strIdent)) + { + result = *accountID; + return Json::objectValue; + } + + if (bStrict) + { + auto id = deprecatedParseBitcoinAccountID (strIdent); + return rpcError (id ? rpcACT_BITCOIN : rpcACT_MALFORMED); + } + + // We allow the use of the seeds which is poor practice + // and merely for debugging convenience. + auto const seed = parseGenericSeed (strIdent); + + if (!seed) + return rpcError (rpcBAD_SEED); + + auto const keypair = generateKeyPair ( + KeyType::secp256k1, + *seed); + + result = calcAccountID (keypair.first); + return Json::objectValue; +} + +bool +getAccountObjects(ReadView const& ledger, AccountID const& account, + LedgerEntryType const type, uint256 dirIndex, uint256 const& entryIndex, + std::uint32_t const limit, Json::Value& jvResult) +{ + auto const rootDirIndex = getOwnerDirIndex (account); + auto found = false; + + if (dirIndex.isZero ()) + { + dirIndex = rootDirIndex; + found = true; + } + + auto dir = ledger.read({ltDIR_NODE, dirIndex}); + if (! dir) + return false; + + std::uint32_t i = 0; + auto& jvObjects = jvResult[jss::account_objects]; + for (;;) + { + auto const& entries = dir->getFieldV256 (sfIndexes); + auto iter = entries.begin (); + + if (! found) + { + iter = std::find (iter, entries.end (), entryIndex); + if (iter == entries.end ()) + return false; + + found = true; + } + + for (; iter != entries.end (); ++iter) + { + auto const sleNode = ledger.read(keylet::child(*iter)); + if (type == ltINVALID || sleNode->getType () == type) + { + jvObjects.append (sleNode->getJson (0)); + + if (++i == limit) + { + if (++iter != entries.end ()) + { + jvResult[jss::limit] = limit; + jvResult[jss::marker] = to_string (dirIndex) + ',' + + to_string (*iter); + return true; + } + + break; + } + } + } + + auto const nodeIndex = dir->getFieldU64 (sfIndexNext); + if (nodeIndex == 0) + return true; + + dirIndex = getDirNodeIndex (rootDirIndex, nodeIndex); + dir = ledger.read({ltDIR_NODE, dirIndex}); + if (! dir) + return true; + + if (i == limit) + { + auto const& e = dir->getFieldV256 (sfIndexes); + if (! e.empty ()) + { + jvResult[jss::limit] = limit; + jvResult[jss::marker] = to_string (dirIndex) + ',' + + to_string (*e.begin ()); + } + + return true; + } + } +} + +namespace { + +bool +isValidatedOld(LedgerMaster& ledgerMaster, bool standalone) +{ + if (standalone) + return false; + + return ledgerMaster.getValidatedLedgerAge () > + Tuning::maxValidatedLedgerAge; +} + +template +Status +ledgerFromRequest(T& ledger, Context& context) +{ + static auto const minSequenceGap = 10; + + ledger.reset(); + + auto& params = context.params; + auto& ledgerMaster = context.ledgerMaster; + + auto indexValue = params[jss::ledger_index]; + auto hashValue = params[jss::ledger_hash]; + + // We need to support the legacy "ledger" field. + auto& legacyLedger = params[jss::ledger]; + if (legacyLedger) + { + if (legacyLedger.asString().size () > 12) + hashValue = legacyLedger; + else + indexValue = legacyLedger; + } + + if (hashValue) + { + if (! hashValue.isString ()) + return {rpcINVALID_PARAMS, "ledgerHashNotString"}; + + uint256 ledgerHash; + if (! ledgerHash.SetHex (hashValue.asString ())) + return {rpcINVALID_PARAMS, "ledgerHashMalformed"}; + + ledger = ledgerMaster.getLedgerByHash (ledgerHash); + if (ledger == nullptr) + return {rpcLGR_NOT_FOUND, "ledgerNotFound"}; + } + else if (indexValue.isNumeric()) + { + ledger = ledgerMaster.getLedgerBySeq (indexValue.asInt ()); + + if (ledger == nullptr) + { + auto cur = ledgerMaster.getCurrentLedger(); + if (cur->info().seq == indexValue.asInt()) + ledger = cur; + } + + if (ledger == nullptr) + return {rpcLGR_NOT_FOUND, "ledgerNotFound"}; + + if (ledger->info().seq > ledgerMaster.getValidLedgerIndex() && + isValidatedOld(ledgerMaster, context.app.config().standalone())) + { + ledger.reset(); + return {rpcNO_NETWORK, "InsufficientNetworkMode"}; + } + } + else + { + if (isValidatedOld (ledgerMaster, context.app.config().standalone())) + return {rpcNO_NETWORK, "InsufficientNetworkMode"}; + + auto const index = indexValue.asString (); + if (index == "validated") + { + ledger = ledgerMaster.getValidatedLedger (); + if (ledger == nullptr) + return {rpcNO_NETWORK, "InsufficientNetworkMode"}; + + assert (! ledger->open()); + } + else + { + if (index.empty () || index == "current") + { + ledger = ledgerMaster.getCurrentLedger (); + assert (ledger->open()); + } + else if (index == "closed") + { + ledger = ledgerMaster.getClosedLedger (); + assert (! ledger->open()); + } + else + { + return {rpcINVALID_PARAMS, "ledgerIndexMalformed"}; + } + + if (ledger == nullptr) + return {rpcNO_NETWORK, "InsufficientNetworkMode"}; + + if (ledger->info().seq + minSequenceGap < + ledgerMaster.getValidLedgerIndex ()) + { + ledger.reset (); + return {rpcNO_NETWORK, "InsufficientNetworkMode"}; + } + } + } + + return Status::OK; +} + +bool +isValidated(LedgerMaster& ledgerMaster, ReadView const& ledger, + Application& app) +{ + if (ledger.open()) + return false; + + if (ledger.info().validated) + return true; + + auto seq = ledger.info().seq; + try + { + // Use the skip list in the last validated ledger to see if ledger + // comes before the last validated ledger (and thus has been + // validated). + auto hash = ledgerMaster.walkHashBySeq (seq); + + if (!hash || ledger.info().hash != *hash) + { + // This ledger's hash is not the hash of the validated ledger + if (hash) + { + assert(hash->isNonZero()); + uint256 valHash = getHashByIndex (seq, app); + if (valHash == ledger.info().hash) + { + // SQL database doesn't match ledger chain + ledgerMaster.clearLedger (seq); + } + } + return false; + } + } + catch (SHAMapMissingNode const&) + { + auto stream = app.journal ("RPCHandler").warn(); + JLOG (stream) + << "Missing SHANode " << std::to_string (seq); + return false; + } + + // Mark ledger as validated to save time if we see it again. + ledger.info().validated = true; + return true; +} + +} // namespace + +// 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". +// +// Returns a Json::objectValue. If there was an error, it will be in that +// return value. Otherwise, the object contains the field "validated" and +// optionally the fields "ledger_hash", "ledger_index" and +// "ledger_current_index", if they are defined. +Status +lookupLedger(std::shared_ptr& ledger, Context& context, + Json::Value& result) +{ + if (auto status = ledgerFromRequest (ledger, context)) + return status; + + auto& info = ledger->info(); + + if (!ledger->open()) + { + result[jss::ledger_hash] = to_string (info.hash); + result[jss::ledger_index] = info.seq; + } + else + { + result[jss::ledger_current_index] = info.seq; + } + + result[jss::validated] = isValidated (context.ledgerMaster, *ledger, context.app); + return Status::OK; +} + +Json::Value +lookupLedger(std::shared_ptr& ledger, Context& context) +{ + Json::Value result; + if (auto status = lookupLedger (ledger, context, result)) + status.inject (result); + + return result; +} + +hash_set +parseAccountIds(Json::Value const& jvArray) +{ + hash_set result; + for (auto const& jv: jvArray) + { + if (! jv.isString()) + return hash_set(); + auto const id = + parseBase58(jv.asString()); + if (! id) + return hash_set(); + result.insert(*id); + } + return result; +} + +void +addPaymentDeliveredAmount(Json::Value& meta, RPC::Context& context, + std::shared_ptr transaction, TxMeta::pointer transactionMeta) +{ + // We only want to add a "delivered_amount" field if the transaction + // succeeded - otherwise nothing could have been delivered. + if (! transaction) + return; + + auto serializedTx = transaction->getSTransaction (); + if (! serializedTx || serializedTx->getTxnType () != ttPAYMENT) + return; + + if (transactionMeta) + { + if (transactionMeta->getResultTER() != tesSUCCESS) + return; + + // If the transaction explicitly specifies a DeliveredAmount in the + // metadata then we use it. + if (transactionMeta->hasDeliveredAmount ()) + { + meta[jss::delivered_amount] = + transactionMeta->getDeliveredAmount ().getJson (1); + return; + } + } + else if (transaction->getResult() != tesSUCCESS) + { + return; + } + + // Ledger 4594095 is the first ledger in which the DeliveredAmount field + // was present when a partial payment was made and its absence indicates + // that the amount delivered is listed in the Amount field. + if (transaction->getLedger () >= 4594095) + { + meta[jss::delivered_amount] = + serializedTx->getFieldAmount (sfAmount).getJson (1); + return; + } + + // If the ledger closed long after the DeliveredAmount code was deployed + // then its absence indicates that the amount delivered is listed in the + // Amount field. DeliveredAmount went live January 24, 2014. + using namespace std::chrono_literals; + auto ct = + context.ledgerMaster.getCloseTimeBySeq (transaction->getLedger ()); + if (ct && (*ct > NetClock::time_point{446000000s})) + { + // 446000000 is in Feb 2014, well after DeliveredAmount went live + meta[jss::delivered_amount] = + serializedTx->getFieldAmount (sfAmount).getJson (1); + return; + } + + // Otherwise we report "unavailable" which cannot be parsed into a + // sensible amount. + meta[jss::delivered_amount] = Json::Value ("unavailable"); +} + +void +injectSLE(Json::Value& jv, SLE const& sle) +{ + jv = sle.getJson(0); + if (sle.getType() == ltACCOUNT_ROOT) + { + if (sle.isFieldPresent(sfEmailHash)) + { + auto const& hash = + sle.getFieldH128(sfEmailHash); + Blob const b (hash.begin(), hash.end()); + std::string md5 = strHex(makeSlice(b)); + boost::to_lower(md5); + // VFALCO TODO Give a name and move this constant + // to a more visible location. Also + // shouldn't this be https? + jv[jss::urlgravatar] = str(boost::format( + "http://www.gravatar.com/avatar/%s") % md5); + } + } + else + { + jv[jss::Invalid] = true; + } +} + +boost::optional +readLimitField(unsigned int& limit, Tuning::LimitRange const& range, + Context const& context) +{ + limit = range.rdefault; + if (auto const& jvLimit = context.params[jss::limit]) + { + if (! (jvLimit.isUInt() || (jvLimit.isInt() && jvLimit.asInt() >= 0))) + return RPC::expected_field_error (jss::limit, "unsigned integer"); + + limit = jvLimit.asUInt(); + if (! isUnlimited (context.role)) + limit = std::max(range.rmin, std::min(range.rmax, limit)); + } + return boost::none; +} + +boost::optional +getSeedFromRPC(Json::Value const& params, Json::Value& error) +{ + // The array should be constexpr, but that makes Visual Studio unhappy. + static char const* const seedTypes[] + { + jss::passphrase.c_str(), + jss::seed.c_str(), + jss::seed_hex.c_str() + }; + + // Identify which seed type is in use. + char const* seedType = nullptr; + int count = 0; + for (auto t : seedTypes) + { + if (params.isMember (t)) + { + ++count; + seedType = t; + } + } + + if (count != 1) + { + error = RPC::make_param_error ( + "Exactly one of the following must be specified: " + + std::string(jss::passphrase) + ", " + + std::string(jss::seed) + " or " + + std::string(jss::seed_hex)); + return boost::none; + } + + // Make sure a string is present + if (! params[seedType].isString()) + { + error = RPC::expected_field_error (seedType, "string"); + return boost::none; + } + + auto const fieldContents = params[seedType].asString(); + + // Convert string to seed. + boost::optional seed; + + if (seedType == jss::seed.c_str()) + seed = parseBase58 (fieldContents); + else if (seedType == jss::passphrase.c_str()) + seed = parseGenericSeed (fieldContents); + else if (seedType == jss::seed_hex.c_str()) + { + uint128 s; + + if (s.SetHexExact (fieldContents)) + seed.emplace (Slice(s.data(), s.size())); + } + + if (!seed) + error = rpcError (rpcBAD_SEED); + + return seed; +} + +std::pair +keypairForSignature(Json::Value const& params, Json::Value& error) +{ + bool const has_key_type = params.isMember (jss::key_type); + + // All of the secret types we allow, but only one at a time. + // The array should be constexpr, but that makes Visual Studio unhappy. + static char const* const secretTypes[] + { + jss::passphrase.c_str(), + jss::secret.c_str(), + jss::seed.c_str(), + jss::seed_hex.c_str() + }; + + // Identify which secret type is in use. + char const* secretType = nullptr; + int count = 0; + for (auto t : secretTypes) + { + if (params.isMember (t)) + { + ++count; + secretType = t; + } + } + + if (count == 0 || secretType == nullptr) + { + error = RPC::missing_field_error (jss::secret); + return { }; + } + + if (count > 1) + { + error = RPC::make_param_error ( + "Exactly one of the following must be specified: " + + std::string(jss::passphrase) + ", " + + std::string(jss::secret) + ", " + + std::string(jss::seed) + " or " + + std::string(jss::seed_hex)); + return { }; + } + + KeyType keyType = KeyType::secp256k1; + boost::optional seed; + + if (has_key_type) + { + if (! params[jss::key_type].isString()) + { + error = RPC::expected_field_error ( + jss::key_type, "string"); + return { }; + } + + keyType = keyTypeFromString ( + params[jss::key_type].asString()); + + if (keyType == KeyType::invalid) + { + error = RPC::invalid_field_error(jss::key_type); + return { }; + } + + if (secretType == jss::secret.c_str()) + { + error = RPC::make_param_error ( + "The secret field is not allowed if " + + std::string(jss::key_type) + " is used."); + return { }; + } + + seed = getSeedFromRPC (params, error); + } + else + { + if (! params[jss::secret].isString()) + { + error = RPC::expected_field_error ( + jss::secret, "string"); + return { }; + } + + seed = parseGenericSeed ( + params[jss::secret].asString ()); + } + + if (!seed) + { + if (!contains_error (error)) + { + error = RPC::make_error (rpcBAD_SEED, + RPC::invalid_field_message (secretType)); + } + + return { }; + } + + if (keyType != KeyType::secp256k1 && keyType != KeyType::ed25519) + LogicError ("keypairForSignature: invalid key type"); + + return generateKeyPair (keyType, *seed); +} + +beast::SemanticVersion const firstVersion ("1.0.0"); +beast::SemanticVersion const goodVersion ("1.0.0"); +beast::SemanticVersion const lastVersion ("1.0.0"); + +} // RPC +} // ripple diff --git a/src/ripple/rpc/impl/RPCHelpers.h b/src/ripple/rpc/impl/RPCHelpers.h new file mode 100644 index 0000000000..8382d14817 --- /dev/null +++ b/src/ripple/rpc/impl/RPCHelpers.h @@ -0,0 +1,135 @@ +//------------------------------------------------------------------------------ +/* + 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_RPCHELPERS_H_INCLUDED +#define RIPPLE_RPC_RPCHELPERS_H_INCLUDED + +#include +#include +#include +#include +#include +#include + +namespace Json { +class Value; +} + +namespace ripple { + +class ReadView; +class Transaction; + +namespace RPC { + +struct Context; + +/** Get an AccountID from an account ID or public key. */ +boost::optional +accountFromStringStrict (std::string const&); + +// --> strIdent: public key, account ID, or regular seed. +// --> bStrict: Only allow account id or public key. +// +// Returns a Json::objectValue, containing error information if there was one. +Json::Value +accountFromString (AccountID& result, std::string const& strIdent, + bool bStrict = false); + +/** Gathers all objects for an account in a ledger. + @param ledger Ledger to search account objects. + @param account AccountID to find objects for. + @param type Gathers objects of this type. ltINVALID gathers all types. + @param dirIndex Begin gathering account objects from this directory. + @param entryIndex Begin gathering objects from this directory node. + @param limit Maximum number of objects to find. + @param jvResult A JSON result that holds the request objects. +*/ +bool +getAccountObjects (ReadView const& ledger, AccountID const& account, + LedgerEntryType const type, uint256 dirIndex, uint256 const& entryIndex, + std::uint32_t const limit, Json::Value& jvResult); + +/** Look up a ledger from a request and fill a Json::Result with either + an error, or data representing a ledger. + + If there is no error in the return value, then the ledger pointer will have + been filled. +*/ +Json::Value +lookupLedger (std::shared_ptr&, Context&); + +/** Look up a ledger from a request and fill a Json::Result with the data + representing a ledger. + + If the returned Status is OK, the ledger pointer will have been filled. +*/ +Status +lookupLedger (std::shared_ptr&, Context&, Json::Value& result); + +hash_set +parseAccountIds(Json::Value const& jvArray); + +void +addPaymentDeliveredAmount(Json::Value&, Context&, + std::shared_ptr, TxMeta::pointer); + +/** Inject JSON describing ledger entry + + Effects: + Adds the JSON description of `sle` to `jv`. + + If `sle` holds an account root, also adds the + urlgravatar field JSON if sfEmailHash is present. +*/ +void +injectSLE(Json::Value& jv, SLE const& sle); + +/** Retrieve the limit value from a Context, or set a default - + then restrict the limit by max and min if not an ADMIN request. + + If there is an error, return it as JSON. +*/ +boost::optional +readLimitField(unsigned int& limit, Tuning::LimitRange const&, Context const&); + +boost::optional +getSeedFromRPC(Json::Value const& params, Json::Value& error); + +std::pair +keypairForSignature(Json::Value const& params, Json::Value& error); + +extern beast::SemanticVersion const firstVersion; +extern beast::SemanticVersion const goodVersion; +extern beast::SemanticVersion const lastVersion; + +template +void +setVersion(Object& parent) +{ + auto&& object = addObject (parent, jss::version); + object[jss::first] = firstVersion.print(); + object[jss::good] = goodVersion.print(); + object[jss::last] = lastVersion.print(); +} + +} // RPC +} // ripple + +#endif diff --git a/src/ripple/rpc/impl/RPCVersion.cpp b/src/ripple/rpc/impl/RPCVersion.cpp deleted file mode 100644 index 8317c27184..0000000000 --- a/src/ripple/rpc/impl/RPCVersion.cpp +++ /dev/null @@ -1,30 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of rippled: https://github.com/ripple/rippled - Copyright (c) 2012, 2013 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 - -namespace ripple { -namespace RPC { - -beast::SemanticVersion const firstVersion ("1.0.0"); -beast::SemanticVersion const goodVersion ("1.0.0"); -beast::SemanticVersion const lastVersion ("1.0.0"); - -} // RPC -} // ripple diff --git a/src/ripple/rpc/impl/TransactionSign.cpp b/src/ripple/rpc/impl/TransactionSign.cpp index 35e36e22e6..7e0a258a49 100644 --- a/src/ripple/rpc/impl/TransactionSign.cpp +++ b/src/ripple/rpc/impl/TransactionSign.cpp @@ -34,8 +34,8 @@ #include #include #include -#include #include +#include #include #include #include diff --git a/src/ripple/rpc/impl/Utilities.cpp b/src/ripple/rpc/impl/Utilities.cpp deleted file mode 100644 index 0591fc11cc..0000000000 --- a/src/ripple/rpc/impl/Utilities.cpp +++ /dev/null @@ -1,146 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of rippled: https://github.com/ripple/rippled - Copyright (c) 2012, 2013 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace ripple { -namespace RPC { - -void -addPaymentDeliveredAmount ( - Json::Value& meta, - RPC::Context& context, - std::shared_ptr transaction, - TxMeta::pointer transactionMeta) -{ - // We only want to add a "delivered_amount" field if the transaction - // succeeded - otherwise nothing could have been delivered. - if (! transaction) - return; - - auto serializedTx = transaction->getSTransaction (); - if (! serializedTx || serializedTx->getTxnType () != ttPAYMENT) - return; - - if (transactionMeta) - { - if (transactionMeta->getResultTER() != tesSUCCESS) - return; - - // If the transaction explicitly specifies a DeliveredAmount in the - // metadata then we use it. - if (transactionMeta->hasDeliveredAmount ()) - { - meta[jss::delivered_amount] = - transactionMeta->getDeliveredAmount ().getJson (1); - return; - } - } - else if (transaction->getResult() != tesSUCCESS) - { - return; - } - - // Ledger 4594095 is the first ledger in which the DeliveredAmount field - // was present when a partial payment was made and its absence indicates - // that the amount delivered is listed in the Amount field. - if (transaction->getLedger () >= 4594095) - { - meta[jss::delivered_amount] = - serializedTx->getFieldAmount (sfAmount).getJson (1); - return; - } - - // If the ledger closed long after the DeliveredAmount code was deployed - // then its absence indicates that the amount delivered is listed in the - // Amount field. DeliveredAmount went live January 24, 2014. - using namespace std::chrono_literals; - auto ct = - context.ledgerMaster.getCloseTimeBySeq (transaction->getLedger ()); - if (ct && (*ct > NetClock::time_point{446000000s})) - { - // 446000000 is in Feb 2014, well after DeliveredAmount went live - meta[jss::delivered_amount] = - serializedTx->getFieldAmount (sfAmount).getJson (1); - return; - } - - // Otherwise we report "unavailable" which cannot be parsed into a - // sensible amount. - meta[jss::delivered_amount] = Json::Value ("unavailable"); -} - -void -injectSLE (Json::Value& jv, - SLE const& sle) -{ - jv = sle.getJson(0); - if (sle.getType() == ltACCOUNT_ROOT) - { - if (sle.isFieldPresent(sfEmailHash)) - { - auto const& hash = - sle.getFieldH128(sfEmailHash); - Blob const b (hash.begin(), hash.end()); - std::string md5 = strHex(makeSlice(b)); - boost::to_lower(md5); - // VFALCO TODO Give a name and move this constant - // to a more visible location. Also - // shouldn't this be https? - jv[jss::urlgravatar] = str(boost::format( - "http://www.gravatar.com/avatar/%s") % md5); - } - } - else - { - jv[jss::Invalid] = true; - } -} - -boost::optional readLimitField( - unsigned int& limit, - Tuning::LimitRange const& range, - Context const& context) -{ - limit = range.rdefault; - if (auto const& jvLimit = context.params[jss::limit]) - { - if (! (jvLimit.isUInt() || (jvLimit.isInt() && jvLimit.asInt() >= 0))) - return RPC::expected_field_error (jss::limit, "unsigned integer"); - - limit = jvLimit.asUInt(); - if (! isUnlimited (context.role)) - limit = std::max(range.rmin, std::min(range.rmax, limit)); - } - return boost::none; -} - -} // ripple -} // RPC diff --git a/src/ripple/rpc/impl/Utilities.h b/src/ripple/rpc/impl/Utilities.h deleted file mode 100644 index d2123126a2..0000000000 --- a/src/ripple/rpc/impl/Utilities.h +++ /dev/null @@ -1,69 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of rippled: https://github.com/ripple/rippled - Copyright (c) 2012, 2013 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_IMPL_UTILITIES_H_INCLUDED -#define RIPPLE_RPC_IMPL_UTILITIES_H_INCLUDED - -#include -#include -#include -#include - -namespace Json { -class Value; -} - -namespace ripple { - -class Transaction; - -namespace RPC { - -struct Context; - -void -addPaymentDeliveredAmount ( - Json::Value&, - Context&, - std::shared_ptr, - TxMeta::pointer); - -/** Inject JSON describing ledger entry - - Effects: - Adds the JSON description of `sle` to `jv`. - - If `sle` holds an account root, also adds the - urlgravatar field JSON if sfEmailHash is present. -*/ -void -injectSLE (Json::Value& jv, - SLE const& sle); - -/** Retrieve the limit value from a Context, or set a default - - then restrict the limit by max and min if not an ADMIN request. - - If there is an error, return it as JSON. */ -boost::optional readLimitField( - unsigned int& limit, Tuning::LimitRange const&, Context const&); - -} // RPC -} // ripple - -#endif diff --git a/src/ripple/rpc/tests/KeyGeneration.test.cpp b/src/ripple/rpc/tests/KeyGeneration.test.cpp index b5edd2b16a..f97c242da5 100644 --- a/src/ripple/rpc/tests/KeyGeneration.test.cpp +++ b/src/ripple/rpc/tests/KeyGeneration.test.cpp @@ -25,7 +25,7 @@ #include #include #include -#include +#include namespace ripple { diff --git a/src/ripple/unity/rpcx.cpp b/src/ripple/unity/rpcx.cpp index 8d6ef5e909..4dbf34dfc8 100644 --- a/src/ripple/unity/rpcx.cpp +++ b/src/ripple/unity/rpcx.cpp @@ -28,7 +28,6 @@ #include #include -#include #include #include @@ -89,15 +88,10 @@ #include #include -#include -#include #include -#include #include -#include -#include #include -#include +#include #include #include