mirror of
https://github.com/XRPLF/clio.git
synced 2025-12-06 17:27:58 +00:00
clang-format (#86)
* clang-format * ignore clang-format commit; run clang-format in github actions
This commit is contained in:
8
.git-blame-ignore-revs
Normal file
8
.git-blame-ignore-revs
Normal file
@@ -0,0 +1,8 @@
|
||||
# These might help too
|
||||
# Mark any lines that have had a commit skipped using --ignore-rev with a `?`
|
||||
#git config --global blame.markIgnoredLines true
|
||||
# Mark any lines that were added in a skipped commit and can not be attributed with a `*`
|
||||
#git config --global blame.markUnblamableLines true
|
||||
|
||||
# clang-format
|
||||
e41150248a97e4bdc1cf21b54650c4bb7c63928e
|
||||
60
.github/workflows/clang-format.yml
vendored
Normal file
60
.github/workflows/clang-format.yml
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
name: clang-format
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
check:
|
||||
runs-on: ubuntu-18.04
|
||||
env:
|
||||
CLANG_VERSION: 10
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Install clang-format
|
||||
run: |
|
||||
sudo tee /etc/apt/sources.list.d/llvm.list >/dev/null <<EOF
|
||||
deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-${CLANG_VERSION} main
|
||||
deb-src http://apt.llvm.org/bionic/ llvm-toolchain-bionic-${CLANG_VERSION} main
|
||||
EOF
|
||||
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add
|
||||
sudo apt-get update
|
||||
sudo apt-get install clang-format-${CLANG_VERSION}
|
||||
- name: Format src
|
||||
run: find src -type f \( -name '*.cpp' -o -name '*.h' -o -name '*.ipp' \) -print0 | xargs -0 clang-format-${CLANG_VERSION} -i
|
||||
- name: Format unittests
|
||||
run: find unittests -type f \( -name '*.cpp' -o -name '*.h' -o -name '*.ipp' \) -print0 | xargs -0 clang-format-${CLANG_VERSION} -i
|
||||
- name: Check for differences
|
||||
id: assert
|
||||
run: |
|
||||
set -o pipefail
|
||||
git diff --exit-code | tee "clang-format.patch"
|
||||
- name: Upload patch
|
||||
if: failure() && steps.assert.outcome == 'failure'
|
||||
uses: actions/upload-artifact@v2
|
||||
continue-on-error: true
|
||||
with:
|
||||
name: clang-format.patch
|
||||
if-no-files-found: ignore
|
||||
path: clang-format.patch
|
||||
- name: What happened?
|
||||
if: failure() && steps.assert.outcome == 'failure'
|
||||
env:
|
||||
PREAMBLE: |
|
||||
If you are reading this, you are looking at a failed Github Actions
|
||||
job. That means you pushed one or more files that did not conform
|
||||
to the formatting specified in .clang-format. That may be because
|
||||
you neglected to run 'git clang-format' or 'clang-format' before
|
||||
committing, or that your version of clang-format has an
|
||||
incompatibility with the one on this
|
||||
machine, which is:
|
||||
SUGGESTION: |
|
||||
|
||||
To fix it, you can do one of two things:
|
||||
1. Download and apply the patch generated as an artifact of this
|
||||
job to your repo, commit, and push.
|
||||
2. Run 'git-clang-format --extensions c,cpp,h,cxx,ipp develop'
|
||||
in your repo, commit, and push.
|
||||
run: |
|
||||
echo "${PREAMBLE}"
|
||||
clang-format-${CLANG_VERSION} --version
|
||||
echo "${SUGGESTION}"
|
||||
exit 1
|
||||
@@ -234,9 +234,8 @@ BackendInterface::fetchLedgerPage(
|
||||
std::vector<ripple::uint256> keys;
|
||||
while (keys.size() < limit)
|
||||
{
|
||||
ripple::uint256 const& curCursor = keys.size() ? keys.back()
|
||||
: cursor ? *cursor
|
||||
: firstKey;
|
||||
ripple::uint256 const& curCursor =
|
||||
keys.size() ? keys.back() : cursor ? *cursor : firstKey;
|
||||
auto succ = fetchSuccessorKey(curCursor, ledgerSequence);
|
||||
if (!succ)
|
||||
break;
|
||||
|
||||
@@ -1517,4 +1517,3 @@ getLedger(
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
@@ -1107,4 +1107,3 @@ ETLLoadBalancer::execute(Func f, uint32_t ledgerSequence)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,9 @@ public:
|
||||
bool cacheOnly = false) = 0;
|
||||
|
||||
virtual std::optional<boost::json::object>
|
||||
forwardToRippled(boost::json::object const& request, std::string const& clientIp) const = 0;
|
||||
forwardToRippled(
|
||||
boost::json::object const& request,
|
||||
std::string const& clientIp) const = 0;
|
||||
|
||||
virtual ~ETLSource()
|
||||
{
|
||||
@@ -323,7 +325,9 @@ public:
|
||||
handleMessage();
|
||||
|
||||
std::optional<boost::json::object>
|
||||
forwardToRippled(boost::json::object const& request, std::string const& clientIp) const override;
|
||||
forwardToRippled(
|
||||
boost::json::object const& request,
|
||||
std::string const& clientIp) const override;
|
||||
};
|
||||
|
||||
class PlainETLSource : public ETLSourceImpl<PlainETLSource>
|
||||
@@ -556,7 +560,9 @@ public:
|
||||
/// @param request JSON-RPC request
|
||||
/// @return response received from rippled node
|
||||
std::optional<boost::json::object>
|
||||
forwardToRippled(boost::json::object const& request, std::string const& clientIp) const;
|
||||
forwardToRippled(
|
||||
boost::json::object const& request,
|
||||
std::string const& clientIp) const;
|
||||
|
||||
private:
|
||||
/// f is a function that takes an ETLSource as an argument and returns a
|
||||
|
||||
@@ -935,4 +935,3 @@ ReportingETL::ReportingETL(
|
||||
if (config.contains("txn_threshold"))
|
||||
txnThreshold_ = config.at("txn_threshold").as_int64();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
#include <rpc/Counters.h>
|
||||
|
||||
namespace RPC
|
||||
{
|
||||
namespace RPC {
|
||||
|
||||
void
|
||||
Counters::initializeCounter(std::string const& method)
|
||||
{
|
||||
std::shared_lock lk(mutex_);
|
||||
if(methodInfo_.count(method) == 0)
|
||||
{
|
||||
if (methodInfo_.count(method) == 0)
|
||||
{
|
||||
lk.unlock();
|
||||
std::unique_lock ulk(mutex_);
|
||||
|
||||
@@ -57,7 +56,7 @@ Counters::report()
|
||||
{
|
||||
std::shared_lock lk(mutex_);
|
||||
boost::json::object obj = {};
|
||||
|
||||
|
||||
for (auto const& [method, info] : methodInfo_)
|
||||
{
|
||||
boost::json::object counters = {};
|
||||
@@ -73,4 +72,4 @@ Counters::report()
|
||||
return obj;
|
||||
}
|
||||
|
||||
} // namespace RPC
|
||||
} // namespace RPC
|
||||
@@ -1,14 +1,13 @@
|
||||
#ifndef RPC_COUNTERS_H
|
||||
#define RPC_COUNTERS_H
|
||||
|
||||
#include <boost/json.hpp>
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <shared_mutex>
|
||||
#include <boost/json.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace RPC
|
||||
{
|
||||
namespace RPC {
|
||||
|
||||
class Counters
|
||||
{
|
||||
@@ -23,14 +22,14 @@ private:
|
||||
std::atomic_uint forwarded{0};
|
||||
std::atomic_uint duration{0};
|
||||
};
|
||||
|
||||
|
||||
void
|
||||
initializeCounter(std::string const& method);
|
||||
|
||||
std::shared_mutex mutex_;
|
||||
std::unordered_map<std::string, MethodInfo> methodInfo_;
|
||||
|
||||
public:
|
||||
public:
|
||||
Counters() = default;
|
||||
|
||||
void
|
||||
@@ -48,6 +47,6 @@ public:
|
||||
report();
|
||||
};
|
||||
|
||||
} // namespace RPCs
|
||||
} // namespace RPC
|
||||
|
||||
#endif // RPC_COUNTERS_H
|
||||
#endif // RPC_COUNTERS_H
|
||||
@@ -181,7 +181,7 @@ buildResponse(Context const& ctx)
|
||||
|
||||
return *res;
|
||||
}
|
||||
|
||||
|
||||
if (ctx.method == "ping")
|
||||
return boost::json::object{};
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
#include <ripple/protocol/ErrorCodes.h>
|
||||
#include <boost/json.hpp>
|
||||
#include <backend/BackendInterface.h>
|
||||
#include <rpc/Counters.h>
|
||||
#include <optional>
|
||||
#include <rpc/Counters.h>
|
||||
#include <string>
|
||||
#include <variant>
|
||||
/*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <ripple/app/paths/RippleState.h>
|
||||
#include <ripple/app/ledger/Ledger.h>
|
||||
#include <ripple/app/paths/RippleState.h>
|
||||
#include <ripple/basics/StringUtilities.h>
|
||||
#include <ripple/protocol/ErrorCodes.h>
|
||||
#include <ripple/protocol/Indexes.h>
|
||||
@@ -8,13 +8,11 @@
|
||||
#include <boost/json.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <rpc/RPCHelpers.h>
|
||||
#include <backend/BackendInterface.h>
|
||||
#include <backend/DBHelpers.h>
|
||||
#include <rpc/RPCHelpers.h>
|
||||
|
||||
|
||||
namespace RPC
|
||||
{
|
||||
namespace RPC {
|
||||
|
||||
void
|
||||
addLine(
|
||||
@@ -47,13 +45,19 @@ addLine(
|
||||
if (!viewLowest)
|
||||
balance.negate();
|
||||
|
||||
bool lineAuth = flags & (viewLowest ? ripple::lsfLowAuth : ripple::lsfHighAuth);
|
||||
bool lineAuthPeer = flags & (!viewLowest ? ripple::lsfLowAuth : ripple::lsfHighAuth);
|
||||
bool lineNoRipple = flags & (viewLowest ? ripple::lsfLowNoRipple : ripple::lsfHighNoRipple);
|
||||
bool lineAuth =
|
||||
flags & (viewLowest ? ripple::lsfLowAuth : ripple::lsfHighAuth);
|
||||
bool lineAuthPeer =
|
||||
flags & (!viewLowest ? ripple::lsfLowAuth : ripple::lsfHighAuth);
|
||||
bool lineNoRipple =
|
||||
flags & (viewLowest ? ripple::lsfLowNoRipple : ripple::lsfHighNoRipple);
|
||||
bool lineDefaultRipple = flags & ripple::lsfDefaultRipple;
|
||||
bool lineNoRipplePeer = flags & (!viewLowest ? ripple::lsfLowNoRipple : ripple::lsfHighNoRipple);
|
||||
bool lineFreeze = flags & (viewLowest ? ripple::lsfLowFreeze : ripple::lsfHighFreeze);
|
||||
bool lineFreezePeer = flags & (!viewLowest ? ripple::lsfLowFreeze : ripple::lsfHighFreeze);
|
||||
bool lineNoRipplePeer = flags &
|
||||
(!viewLowest ? ripple::lsfLowNoRipple : ripple::lsfHighNoRipple);
|
||||
bool lineFreeze =
|
||||
flags & (viewLowest ? ripple::lsfLowFreeze : ripple::lsfHighFreeze);
|
||||
bool lineFreezePeer =
|
||||
flags & (!viewLowest ? ripple::lsfLowFreeze : ripple::lsfHighFreeze);
|
||||
|
||||
ripple::STAmount const& saBalance(balance);
|
||||
ripple::STAmount const& saLimit(lineLimit);
|
||||
@@ -83,7 +87,7 @@ addLine(
|
||||
jsonLines.push_back(jPeer);
|
||||
}
|
||||
|
||||
Result
|
||||
Result
|
||||
doAccountLines(Context const& context)
|
||||
{
|
||||
auto request = context.params;
|
||||
@@ -95,13 +99,13 @@ doAccountLines(Context const& context)
|
||||
|
||||
auto lgrInfo = std::get<ripple::LedgerInfo>(v);
|
||||
|
||||
if(!request.contains("account"))
|
||||
if (!request.contains("account"))
|
||||
return Status{Error::rpcINVALID_PARAMS, "missingAccount"};
|
||||
|
||||
if(!request.at("account").is_string())
|
||||
if (!request.at("account").is_string())
|
||||
return Status{Error::rpcINVALID_PARAMS, "accountNotString"};
|
||||
|
||||
auto accountID =
|
||||
|
||||
auto accountID =
|
||||
accountFromStringStrict(request.at("account").as_string().c_str());
|
||||
|
||||
if (!accountID)
|
||||
@@ -113,8 +117,8 @@ doAccountLines(Context const& context)
|
||||
if (!request.at("peer").is_string())
|
||||
return Status{Error::rpcINVALID_PARAMS, "peerNotString"};
|
||||
|
||||
peerAccount = accountFromStringStrict(
|
||||
request.at("peer").as_string().c_str());
|
||||
peerAccount =
|
||||
accountFromStringStrict(request.at("peer").as_string().c_str());
|
||||
|
||||
if (!peerAccount)
|
||||
return Status{Error::rpcINVALID_PARAMS, "peerMalformed"};
|
||||
@@ -123,7 +127,7 @@ doAccountLines(Context const& context)
|
||||
std::uint32_t limit = 200;
|
||||
if (request.contains("limit"))
|
||||
{
|
||||
if(!request.at("limit").is_int64())
|
||||
if (!request.at("limit").is_int64())
|
||||
return Status{Error::rpcINVALID_PARAMS, "limitNotInt"};
|
||||
|
||||
limit = request.at("limit").as_int64();
|
||||
@@ -134,7 +138,7 @@ doAccountLines(Context const& context)
|
||||
ripple::uint256 cursor;
|
||||
if (request.contains("cursor"))
|
||||
{
|
||||
if(!request.at("cursor").is_string())
|
||||
if (!request.at("cursor").is_string())
|
||||
return Status{Error::rpcINVALID_PARAMS, "cursorNotString"};
|
||||
|
||||
if (!cursor.parseHex(request.at("cursor").as_string().c_str()))
|
||||
@@ -154,20 +158,15 @@ doAccountLines(Context const& context)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
addLine(jsonLines, sle, *accountID, peerAccount);
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
auto nextCursor =
|
||||
traverseOwnedNodes(
|
||||
*context.backend,
|
||||
*accountID,
|
||||
lgrInfo.seq,
|
||||
cursor,
|
||||
addToResponse);
|
||||
auto nextCursor = traverseOwnedNodes(
|
||||
*context.backend, *accountID, lgrInfo.seq, cursor, addToResponse);
|
||||
|
||||
if (nextCursor)
|
||||
response["marker"] = ripple::strHex(*nextCursor);
|
||||
@@ -175,4 +174,4 @@ doAccountLines(Context const& context)
|
||||
return response;
|
||||
}
|
||||
|
||||
} // namespace RPC
|
||||
} // namespace RPC
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <ripple/app/paths/RippleState.h>
|
||||
#include <ripple/app/ledger/Ledger.h>
|
||||
#include <ripple/app/paths/RippleState.h>
|
||||
#include <ripple/basics/StringUtilities.h>
|
||||
#include <ripple/protocol/ErrorCodes.h>
|
||||
#include <ripple/protocol/Indexes.h>
|
||||
@@ -12,9 +12,7 @@
|
||||
#include <backend/BackendInterface.h>
|
||||
#include <backend/DBHelpers.h>
|
||||
|
||||
|
||||
namespace RPC
|
||||
{
|
||||
namespace RPC {
|
||||
|
||||
void
|
||||
addOffer(boost::json::array& offersJson, ripple::SLE const& offer)
|
||||
@@ -24,7 +22,7 @@ addOffer(boost::json::array& offersJson, ripple::SLE const& offer)
|
||||
|
||||
ripple::STAmount takerPays = offer.getFieldAmount(ripple::sfTakerPays);
|
||||
ripple::STAmount takerGets = offer.getFieldAmount(ripple::sfTakerGets);
|
||||
|
||||
|
||||
boost::json::object obj;
|
||||
|
||||
if (!takerPays.native())
|
||||
@@ -60,7 +58,7 @@ addOffer(boost::json::array& offersJson, ripple::SLE const& offer)
|
||||
obj["quality"] = rate.getText();
|
||||
if (offer.isFieldPresent(ripple::sfExpiration))
|
||||
obj["expiration"] = offer.getFieldU32(ripple::sfExpiration);
|
||||
|
||||
|
||||
offersJson.push_back(obj);
|
||||
};
|
||||
|
||||
@@ -76,23 +74,22 @@ doAccountOffers(Context const& context)
|
||||
|
||||
auto lgrInfo = std::get<ripple::LedgerInfo>(v);
|
||||
|
||||
if(!request.contains("account"))
|
||||
if (!request.contains("account"))
|
||||
return Status{Error::rpcINVALID_PARAMS, "missingAccount"};
|
||||
|
||||
if(!request.at("account").is_string())
|
||||
if (!request.at("account").is_string())
|
||||
return Status{Error::rpcINVALID_PARAMS, "accountNotString"};
|
||||
|
||||
auto accountID =
|
||||
|
||||
auto accountID =
|
||||
accountFromStringStrict(request.at("account").as_string().c_str());
|
||||
|
||||
if (!accountID)
|
||||
return Status{Error::rpcINVALID_PARAMS, "malformedAccount"};
|
||||
|
||||
|
||||
std::uint32_t limit = 200;
|
||||
if (request.contains("limit"))
|
||||
{
|
||||
if(!request.at("limit").is_int64())
|
||||
if (!request.at("limit").is_int64())
|
||||
return Status{Error::rpcINVALID_PARAMS, "limitNotInt"};
|
||||
|
||||
limit = request.at("limit").as_int64();
|
||||
@@ -103,13 +100,13 @@ doAccountOffers(Context const& context)
|
||||
ripple::uint256 cursor;
|
||||
if (request.contains("cursor"))
|
||||
{
|
||||
if(!request.at("cursor").is_string())
|
||||
if (!request.at("cursor").is_string())
|
||||
return Status{Error::rpcINVALID_PARAMS, "cursorNotString"};
|
||||
|
||||
if (!cursor.parseHex(request.at("cursor").as_string().c_str()))
|
||||
return Status{Error::rpcINVALID_PARAMS, "malformedCursor"};
|
||||
}
|
||||
|
||||
|
||||
response["account"] = ripple::to_string(*accountID);
|
||||
response["ledger_hash"] = ripple::strHex(lgrInfo.hash);
|
||||
response["ledger_index"] = lgrInfo.seq;
|
||||
@@ -123,20 +120,15 @@ doAccountOffers(Context const& context)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
addOffer(jsonLines, sle);
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
auto nextCursor =
|
||||
traverseOwnedNodes(
|
||||
*context.backend,
|
||||
*accountID,
|
||||
lgrInfo.seq,
|
||||
cursor,
|
||||
addToResponse);
|
||||
|
||||
auto nextCursor = traverseOwnedNodes(
|
||||
*context.backend, *accountID, lgrInfo.seq, cursor, addToResponse);
|
||||
|
||||
if (nextCursor)
|
||||
response["marker"] = ripple::strHex(*nextCursor);
|
||||
@@ -144,4 +136,4 @@ doAccountOffers(Context const& context)
|
||||
return response;
|
||||
}
|
||||
|
||||
} // namespace RPC
|
||||
} // namespace RPC
|
||||
@@ -84,7 +84,8 @@ doAccountTx(Context const& context)
|
||||
{
|
||||
if (context.range.maxSequence < min.as_int64() ||
|
||||
context.range.minSequence > min.as_int64())
|
||||
return Status{Error::rpcINVALID_PARAMS, "ledgerSeqMaxOutOfRange"};
|
||||
return Status{
|
||||
Error::rpcINVALID_PARAMS, "ledgerSeqMaxOutOfRange"};
|
||||
else
|
||||
minIndex = value_to<std::uint32_t>(min);
|
||||
}
|
||||
@@ -105,7 +106,8 @@ doAccountTx(Context const& context)
|
||||
{
|
||||
if (context.range.maxSequence < max.as_int64() ||
|
||||
context.range.minSequence > max.as_int64())
|
||||
return Status{Error::rpcINVALID_PARAMS, "ledgerSeqMaxOutOfRange"};
|
||||
return Status{
|
||||
Error::rpcINVALID_PARAMS, "ledgerSeqMaxOutOfRange"};
|
||||
else
|
||||
maxIndex = value_to<std::uint32_t>(max);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
namespace RPC {
|
||||
|
||||
|
||||
Result
|
||||
doBookOffers(Context const& context)
|
||||
{
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include <backend/BackendInterface.h>
|
||||
#include <rpc/RPCHelpers.h>
|
||||
|
||||
|
||||
namespace RPC {
|
||||
|
||||
Result
|
||||
@@ -97,7 +96,7 @@ doLedger(Context const& context)
|
||||
entry["tx_blob"] = ripple::strHex(obj.transaction);
|
||||
entry["meta"] = ripple::strHex(obj.metadata);
|
||||
}
|
||||
//entry["ledger_index"] = obj.ledgerSequence;
|
||||
// entry["ledger_index"] = obj.ledgerSequence;
|
||||
return entry;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2,16 +2,15 @@
|
||||
#include <ripple/protocol/STLedgerEntry.h>
|
||||
#include <boost/json.hpp>
|
||||
|
||||
#include <rpc/RPCHelpers.h>
|
||||
#include <backend/BackendInterface.h>
|
||||
#include <rpc/RPCHelpers.h>
|
||||
// {
|
||||
// ledger_hash : <ledger>
|
||||
// ledger_index : <ledger_index>
|
||||
// ...
|
||||
// }
|
||||
|
||||
namespace RPC
|
||||
{
|
||||
namespace RPC {
|
||||
|
||||
using boost::json::value_to;
|
||||
|
||||
@@ -33,7 +32,7 @@ doLedgerEntry(Context const& context)
|
||||
ripple::uint256 key;
|
||||
if (request.contains("index"))
|
||||
{
|
||||
if(!request.at("index").is_string())
|
||||
if (!request.at("index").is_string())
|
||||
return Status{Error::rpcINVALID_PARAMS, "indexNotString"};
|
||||
|
||||
if (!key.parseHex(request.at("index").as_string().c_str()))
|
||||
@@ -41,7 +40,7 @@ doLedgerEntry(Context const& context)
|
||||
}
|
||||
else if (request.contains("account_root"))
|
||||
{
|
||||
if(!request.at("account_root").is_string())
|
||||
if (!request.at("account_root").is_string())
|
||||
return Status{Error::rpcINVALID_PARAMS, "account_rootNotString"};
|
||||
|
||||
auto const account = ripple::parseBase58<ripple::AccountID>(
|
||||
@@ -53,7 +52,7 @@ doLedgerEntry(Context const& context)
|
||||
}
|
||||
else if (request.contains("check"))
|
||||
{
|
||||
if(!request.at("check").is_string())
|
||||
if (!request.at("check").is_string())
|
||||
return Status{Error::rpcINVALID_PARAMS, "checkNotString"};
|
||||
|
||||
if (!key.parseHex(request.at("check").as_string().c_str()))
|
||||
@@ -69,7 +68,8 @@ doLedgerEntry(Context const& context)
|
||||
!key.parseHex(
|
||||
request.at("deposit_preauth").as_string().c_str()))
|
||||
{
|
||||
return Status{Error::rpcINVALID_PARAMS, "deposit_preauthMalformed"};
|
||||
return Status{
|
||||
Error::rpcINVALID_PARAMS, "deposit_preauthMalformed"};
|
||||
}
|
||||
}
|
||||
else if (
|
||||
@@ -78,9 +78,12 @@ doLedgerEntry(Context const& context)
|
||||
{
|
||||
return Status{Error::rpcINVALID_PARAMS, "ownerNotString"};
|
||||
}
|
||||
else if(
|
||||
else if (
|
||||
!request.at("deposit_preauth").as_object().contains("authorized") ||
|
||||
!request.at("deposit_preauth").as_object().at("authorized").is_string())
|
||||
!request.at("deposit_preauth")
|
||||
.as_object()
|
||||
.at("authorized")
|
||||
.is_string())
|
||||
{
|
||||
return Status{Error::rpcINVALID_PARAMS, "authorizedNotString"};
|
||||
}
|
||||
@@ -107,7 +110,7 @@ doLedgerEntry(Context const& context)
|
||||
{
|
||||
if (!request.at("directory").is_object())
|
||||
{
|
||||
if(!request.at("directory").is_string())
|
||||
if (!request.at("directory").is_string())
|
||||
return Status{Error::rpcINVALID_PARAMS, "directoryNotString"};
|
||||
|
||||
if (!key.parseHex(request.at("directory").as_string().c_str()))
|
||||
@@ -135,10 +138,12 @@ doLedgerEntry(Context const& context)
|
||||
if (directory.contains("owner"))
|
||||
{
|
||||
// May not specify both dir_root and owner.
|
||||
return Status{Error::rpcINVALID_PARAMS, "mayNotSpecifyBothDirRootAndOwner"};
|
||||
return Status{
|
||||
Error::rpcINVALID_PARAMS,
|
||||
"mayNotSpecifyBothDirRootAndOwner"};
|
||||
}
|
||||
else if (!uDirRoot.parseHex(
|
||||
directory.at("dir_root").as_string().c_str()))
|
||||
directory.at("dir_root").as_string().c_str()))
|
||||
{
|
||||
return Status{Error::rpcINVALID_PARAMS, "malformedDirRoot"};
|
||||
}
|
||||
@@ -158,14 +163,15 @@ doLedgerEntry(Context const& context)
|
||||
}
|
||||
else
|
||||
{
|
||||
key =
|
||||
ripple::keylet::page(
|
||||
ripple::keylet::ownerDir(*ownerID), subIndex).key;
|
||||
key = ripple::keylet::page(
|
||||
ripple::keylet::ownerDir(*ownerID), subIndex)
|
||||
.key;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return Status{Error::rpcINVALID_PARAMS, "missingOwnerOrDirRoot"};
|
||||
return Status{
|
||||
Error::rpcINVALID_PARAMS, "missingOwnerOrDirRoot"};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -176,13 +182,13 @@ doLedgerEntry(Context const& context)
|
||||
if (!key.parseHex(request.at("escrow").as_string().c_str()))
|
||||
return Status{Error::rpcINVALID_PARAMS, "malformedEscrow"};
|
||||
}
|
||||
else if (
|
||||
else if (
|
||||
!request.at("escrow").as_object().contains("owner") ||
|
||||
!request.at("escrow").as_object().at("owner").is_string())
|
||||
{
|
||||
return Status{Error::rpcINVALID_PARAMS, "malformedOwner"};
|
||||
}
|
||||
else if(
|
||||
else if (
|
||||
!request.at("escrow").as_object().contains("seq") ||
|
||||
!request.at("escrow").as_object().at("seq").is_int64())
|
||||
{
|
||||
@@ -190,14 +196,18 @@ doLedgerEntry(Context const& context)
|
||||
}
|
||||
else
|
||||
{
|
||||
auto const id = ripple::parseBase58<ripple::AccountID>(
|
||||
request.at("escrow").as_object().at("owner").as_string().c_str());
|
||||
auto const id =
|
||||
ripple::parseBase58<ripple::AccountID>(request.at("escrow")
|
||||
.as_object()
|
||||
.at("owner")
|
||||
.as_string()
|
||||
.c_str());
|
||||
|
||||
if (!id)
|
||||
return Status{Error::rpcINVALID_PARAMS, "malformedOwner"};
|
||||
else
|
||||
{
|
||||
std::uint32_t seq =
|
||||
std::uint32_t seq =
|
||||
request.at("escrow").as_object().at("seq").as_int64();
|
||||
key = ripple::keylet::escrow(*id, seq).key;
|
||||
}
|
||||
@@ -251,18 +261,15 @@ doLedgerEntry(Context const& context)
|
||||
return Status{Error::rpcINVALID_PARAMS, "rippleStateNotObject"};
|
||||
|
||||
ripple::Currency currency;
|
||||
boost::json::object const& state = request.at("ripple_state").as_object();
|
||||
boost::json::object const& state =
|
||||
request.at("ripple_state").as_object();
|
||||
|
||||
if (
|
||||
!state.contains("currency") ||
|
||||
!state.at("currency").is_string())
|
||||
if (!state.contains("currency") || !state.at("currency").is_string())
|
||||
{
|
||||
return Status{Error::rpcINVALID_PARAMS, "malformedCurrency"};
|
||||
}
|
||||
|
||||
if (
|
||||
!state.contains("accounts") ||
|
||||
!state.at("accounts").is_array() ||
|
||||
if (!state.contains("accounts") || !state.at("accounts").is_array() ||
|
||||
2 != state.at("accounts").as_array().size() ||
|
||||
!state.at("accounts").as_array().at(0).is_string() ||
|
||||
!state.at("accounts").as_array().at(1).is_string() ||
|
||||
@@ -281,11 +288,10 @@ doLedgerEntry(Context const& context)
|
||||
return Status{Error::rpcINVALID_PARAMS, "malformedAccounts"};
|
||||
|
||||
else if (!ripple::to_currency(
|
||||
currency, state.at("currency").as_string().c_str()))
|
||||
currency, state.at("currency").as_string().c_str()))
|
||||
return Status{Error::rpcINVALID_PARAMS, "malformedCurrency"};
|
||||
|
||||
key = ripple::keylet::line(*id1, *id2, currency).key;
|
||||
|
||||
}
|
||||
else if (request.contains("ticket"))
|
||||
{
|
||||
@@ -296,7 +302,6 @@ doLedgerEntry(Context const& context)
|
||||
|
||||
if (!key.parseHex(request.at("ticket").as_string().c_str()))
|
||||
return Status{Error::rpcINVALID_PARAMS, "malformedTicket"};
|
||||
|
||||
}
|
||||
else if (
|
||||
!request.at("ticket").as_object().contains("account") ||
|
||||
@@ -312,14 +317,19 @@ doLedgerEntry(Context const& context)
|
||||
}
|
||||
else
|
||||
{
|
||||
auto const id = ripple::parseBase58<ripple::AccountID>(
|
||||
request.at("ticket").as_object().at("account").as_string().c_str());
|
||||
auto const id =
|
||||
ripple::parseBase58<ripple::AccountID>(request.at("ticket")
|
||||
.as_object()
|
||||
.at("account")
|
||||
.as_string()
|
||||
.c_str());
|
||||
|
||||
if (!id)
|
||||
return Status{Error::rpcINVALID_PARAMS, "malformedTicketAccount"};
|
||||
return Status{
|
||||
Error::rpcINVALID_PARAMS, "malformedTicketAccount"};
|
||||
else
|
||||
{
|
||||
std::uint32_t seq =
|
||||
std::uint32_t seq =
|
||||
request.at("offer").as_object().at("ticket_seq").as_int64();
|
||||
|
||||
key = ripple::getTicketIndex(*id, seq);
|
||||
@@ -340,7 +350,7 @@ doLedgerEntry(Context const& context)
|
||||
|
||||
if (!dbResponse or dbResponse->size() == 0)
|
||||
return Status{Error::rpcLGR_NOT_FOUND};
|
||||
|
||||
|
||||
response["index"] = ripple::strHex(key);
|
||||
response["ledger_hash"] = ripple::strHex(lgrInfo.hash);
|
||||
response["ledger_index"] = lgrInfo.seq;
|
||||
@@ -359,4 +369,4 @@ doLedgerEntry(Context const& context)
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace RPC
|
||||
@@ -1,10 +1,9 @@
|
||||
|
||||
#include <rpc/RPCHelpers.h>
|
||||
#include <backend/BackendInterface.h>
|
||||
#include <rpc/RPCHelpers.h>
|
||||
|
||||
namespace RPC {
|
||||
|
||||
namespace RPC
|
||||
{
|
||||
|
||||
Result
|
||||
doLedgerRange(Context const& context)
|
||||
{
|
||||
@@ -24,4 +23,4 @@ doLedgerRange(Context const& context)
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace RPC
|
||||
@@ -23,15 +23,15 @@ doServerInfo(Context const& context)
|
||||
response["info"] = boost::json::object{};
|
||||
boost::json::object& info = response["info"].as_object();
|
||||
|
||||
info["complete_ledgers"] =
|
||||
std::to_string(range->minSequence) + "-" +
|
||||
info["complete_ledgers"] = std::to_string(range->minSequence) + "-" +
|
||||
std::to_string(range->maxSequence);
|
||||
|
||||
info["counters"] = boost::json::object{};
|
||||
info["counters"].as_object()["rpc"] = context.counters.report();
|
||||
}
|
||||
|
||||
auto serverInfoRippled = context.balancer->forwardToRippled(context.params, context.clientIp);
|
||||
auto serverInfoRippled =
|
||||
context.balancer->forwardToRippled(context.params, context.clientIp);
|
||||
if (serverInfoRippled && !serverInfoRippled->contains("error"))
|
||||
response["info"].as_object()["load_factor"] = 1;
|
||||
|
||||
|
||||
@@ -4,9 +4,12 @@
|
||||
|
||||
template <class T>
|
||||
inline void
|
||||
sendToSubscribers(std::string const& message, T& subscribers, boost::asio::io_context::strand& strand)
|
||||
sendToSubscribers(
|
||||
std::string const& message,
|
||||
T& subscribers,
|
||||
boost::asio::io_context::strand& strand)
|
||||
{
|
||||
boost::asio::post(strand, [&subscribers, message](){
|
||||
boost::asio::post(strand, [&subscribers, message]() {
|
||||
for (auto it = subscribers.begin(); it != subscribers.end();)
|
||||
{
|
||||
auto& session = *it;
|
||||
@@ -25,18 +28,24 @@ sendToSubscribers(std::string const& message, T& subscribers, boost::asio::io_co
|
||||
|
||||
template <class T>
|
||||
inline void
|
||||
addSession(std::shared_ptr<WsBase> session, T& subscribers, boost::asio::io_context::strand& strand)
|
||||
addSession(
|
||||
std::shared_ptr<WsBase> session,
|
||||
T& subscribers,
|
||||
boost::asio::io_context::strand& strand)
|
||||
{
|
||||
boost::asio::post(strand, [&subscribers, s = std::move(session)](){
|
||||
boost::asio::post(strand, [&subscribers, s = std::move(session)]() {
|
||||
subscribers.emplace(s);
|
||||
});
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void
|
||||
removeSession(std::shared_ptr<WsBase> session, T& subscribers, boost::asio::io_context::strand& strand)
|
||||
removeSession(
|
||||
std::shared_ptr<WsBase> session,
|
||||
T& subscribers,
|
||||
boost::asio::io_context::strand& strand)
|
||||
{
|
||||
boost::asio::post(strand, [&subscribers, s = std::move(session)](){
|
||||
boost::asio::post(strand, [&subscribers, s = std::move(session)]() {
|
||||
subscribers.erase(s);
|
||||
});
|
||||
}
|
||||
@@ -79,9 +88,7 @@ SubscriptionMap<Key>::unsubscribe(
|
||||
|
||||
template <class Key>
|
||||
void
|
||||
SubscriptionMap<Key>::publish(
|
||||
std::string const& message,
|
||||
Key const& account)
|
||||
SubscriptionMap<Key>::publish(std::string const& message, Key const& account)
|
||||
{
|
||||
sendToSubscribers(message, subscribers_[account], strand_);
|
||||
}
|
||||
@@ -114,7 +121,7 @@ boost::json::object
|
||||
SubscriptionManager::subLedger(std::shared_ptr<WsBase>& session)
|
||||
{
|
||||
ledgerSubscribers_.subscribe(session);
|
||||
|
||||
|
||||
auto ledgerRange = backend_->fetchLedgerRange();
|
||||
assert(ledgerRange);
|
||||
auto lgrInfo = backend_->fetchLedgerBySequence(ledgerRange->maxSequence);
|
||||
@@ -294,17 +301,17 @@ SubscriptionManager::forwardProposedTransaction(
|
||||
auto accounts = RPC::getAccountsFromTransaction(transaction);
|
||||
|
||||
for (ripple::AccountID const& account : accounts)
|
||||
accountProposedSubscribers_.publish(pubMsg, account);
|
||||
accountProposedSubscribers_.publish(pubMsg, account);
|
||||
}
|
||||
|
||||
void
|
||||
void
|
||||
SubscriptionManager::forwardManifest(boost::json::object const& response)
|
||||
{
|
||||
std::string pubMsg{boost::json::serialize(response)};
|
||||
manifestSubscribers_.publish(pubMsg);
|
||||
}
|
||||
|
||||
void
|
||||
void
|
||||
SubscriptionManager::forwardValidation(boost::json::object const& response)
|
||||
{
|
||||
std::string pubMsg{boost::json::serialize(response)};
|
||||
@@ -362,4 +369,3 @@ SubscriptionManager::unsubProposedTransactions(std::shared_ptr<WsBase>& session)
|
||||
{
|
||||
txProposedSubscribers_.unsubscribe(session);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
#include <rpc/Counters.h>
|
||||
#include <rpc/RPC.h>
|
||||
#include <vector>
|
||||
#include <webserver/DOSGuard.h>
|
||||
#include <rpc/Counters.h>
|
||||
|
||||
namespace http = boost::beast::http;
|
||||
namespace net = boost::asio;
|
||||
@@ -113,9 +113,9 @@ handle_request(
|
||||
try
|
||||
{
|
||||
request = boost::json::parse(req.body()).as_object();
|
||||
|
||||
|
||||
if (!request.contains("params"))
|
||||
request["params"] = boost::json::array({ boost::json::object {} });
|
||||
request["params"] = boost::json::array({boost::json::object{}});
|
||||
}
|
||||
catch (std::runtime_error const& e)
|
||||
{
|
||||
@@ -134,8 +134,8 @@ handle_request(
|
||||
boost::json::serialize(
|
||||
RPC::make_error(RPC::Error::rpcNOT_READY))));
|
||||
|
||||
std::optional<RPC::Context> context =
|
||||
RPC::make_HttpContext(request, backend, nullptr, balancer, *range, counters, ip);
|
||||
std::optional<RPC::Context> context = RPC::make_HttpContext(
|
||||
request, backend, nullptr, balancer, *range, counters, ip);
|
||||
|
||||
if (!context)
|
||||
return send(httpResponse(
|
||||
@@ -146,12 +146,12 @@ handle_request(
|
||||
|
||||
boost::json::object response{{"result", boost::json::object{}}};
|
||||
boost::json::object& result = response["result"].as_object();
|
||||
|
||||
|
||||
auto start = std::chrono::system_clock::now();
|
||||
auto v = RPC::buildResponse(*context);
|
||||
auto end = std::chrono::system_clock::now();
|
||||
auto us = std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
end - start);
|
||||
auto us =
|
||||
std::chrono::duration_cast<std::chrono::microseconds>(end - start);
|
||||
|
||||
if (auto status = std::get_if<RPC::Status>(&v))
|
||||
{
|
||||
@@ -322,7 +322,7 @@ public:
|
||||
std::move(req_),
|
||||
lambda_,
|
||||
backend_,
|
||||
balancer_,
|
||||
balancer_,
|
||||
dosGuard_,
|
||||
counters_,
|
||||
ip);
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
#include <boost/asio/dispatch.hpp>
|
||||
#include <boost/beast/core.hpp>
|
||||
#include <boost/beast/websocket.hpp>
|
||||
#include <subscriptions/SubscriptionManager.h>
|
||||
#include <webserver/HttpSession.h>
|
||||
#include <webserver/PlainWsSession.h>
|
||||
#include <webserver/SslHttpSession.h>
|
||||
#include <webserver/SslWsSession.h>
|
||||
#include <subscriptions/SubscriptionManager.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
@@ -63,4 +63,4 @@ parse_certs(const char* certFilename, const char* keyFilename)
|
||||
return ctx;
|
||||
}
|
||||
|
||||
# endif // REPORTING_SSL_H
|
||||
#endif // REPORTING_SSL_H
|
||||
@@ -36,12 +36,12 @@ public:
|
||||
RPC::Counters& counters,
|
||||
boost::beast::flat_buffer&& b)
|
||||
: WsSession(
|
||||
backend,
|
||||
subscriptions,
|
||||
balancer,
|
||||
dosGuard,
|
||||
counters,
|
||||
std::move(b))
|
||||
backend,
|
||||
subscriptions,
|
||||
balancer,
|
||||
dosGuard,
|
||||
counters,
|
||||
std::move(b))
|
||||
, ws_(std::move(stream))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -9,10 +9,10 @@
|
||||
|
||||
#include <backend/BackendInterface.h>
|
||||
#include <etl/ETLSource.h>
|
||||
#include <rpc/RPC.h>
|
||||
#include <webserver/DOSGuard.h>
|
||||
#include <rpc/Counters.h>
|
||||
#include <rpc/RPC.h>
|
||||
#include <subscriptions/SubscriptionManager.h>
|
||||
#include <webserver/DOSGuard.h>
|
||||
|
||||
namespace http = boost::beast::http;
|
||||
namespace net = boost::asio;
|
||||
@@ -259,7 +259,7 @@ public:
|
||||
auto start = std::chrono::system_clock::now();
|
||||
auto v = RPC::buildResponse(*context);
|
||||
auto end = std::chrono::system_clock::now();
|
||||
auto us =
|
||||
auto us =
|
||||
std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
end - start);
|
||||
|
||||
|
||||
@@ -2078,4 +2078,3 @@ TEST(Backend, CacheIntegration)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user