mirror of
https://github.com/XRPLF/clio.git
synced 2026-04-29 15:37:53 +00:00
add random and ping
This commit is contained in:
@@ -103,7 +103,9 @@ target_sources(clio PRIVATE
|
||||
# Subscribe
|
||||
src/rpc/handlers/Subscribe.cpp
|
||||
# Server
|
||||
src/rpc/handlers/ServerInfo.cpp)
|
||||
src/rpc/handlers/ServerInfo.cpp
|
||||
# Utility
|
||||
src/rpc/handlers/Random.cpp)
|
||||
|
||||
|
||||
message(${Boost_LIBRARIES})
|
||||
|
||||
@@ -79,5 +79,8 @@ doUnsubscribe(Context const& context);
|
||||
Result
|
||||
doServerInfo(Context const& context);
|
||||
|
||||
// Utility methods
|
||||
Result
|
||||
doRandom(Context const& context);
|
||||
} // namespace RPC
|
||||
#endif
|
||||
|
||||
@@ -110,7 +110,8 @@ static std::unordered_map<std::string, std::function<Result(Context const&)>>
|
||||
{"server_info", &doServerInfo},
|
||||
{"unsubscribe", &doUnsubscribe},
|
||||
{"tx", &doTx},
|
||||
{"transaction_entry", &doTransactionEntry}};
|
||||
{"transaction_entry", &doTransactionEntry},
|
||||
{"random", &doRandom}};
|
||||
|
||||
static std::unordered_set<std::string> forwardCommands{
|
||||
"submit",
|
||||
@@ -155,6 +156,8 @@ buildResponse(Context const& ctx)
|
||||
return Status{Error::rpcFAILED_TO_FORWARD};
|
||||
return res;
|
||||
}
|
||||
if (ctx.method == "ping")
|
||||
return boost::json::object{};
|
||||
|
||||
if (handlerTable.find(ctx.method) == handlerTable.end())
|
||||
return Status{Error::rpcUNKNOWN_COMMAND};
|
||||
|
||||
16
src/rpc/handlers/Random.cpp
Normal file
16
src/rpc/handlers/Random.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include <ripple/beast/utility/rngfill.h>
|
||||
#include <ripple/crypto/csprng.h>
|
||||
#include <rpc/RPCHelpers.h>
|
||||
namespace RPC {
|
||||
|
||||
Result
|
||||
doRandom(Context const& context)
|
||||
{
|
||||
ripple::uint256 rand;
|
||||
|
||||
beast::rngfill(rand.begin(), rand.size(), ripple::crypto_prng());
|
||||
boost::json::object result;
|
||||
result["random"] = ripple::strHex(rand);
|
||||
return result;
|
||||
}
|
||||
} // namespace RPC
|
||||
17
test.py
17
test.py
@@ -24,6 +24,17 @@ def isSubset(sub, sup):
|
||||
return True
|
||||
|
||||
|
||||
async def call(ip,port,msg):
|
||||
address = 'ws://' + str(ip) + ':' + str(port)
|
||||
try:
|
||||
async with websockets.connect(address) as ws:
|
||||
await ws.send(msg)
|
||||
res = json.loads(await ws.recv())
|
||||
print(json.dumps(res,indent=4,sort_keys=True))
|
||||
except websockets.exceptions.ConnectionClosedError as e:
|
||||
print(e)
|
||||
|
||||
|
||||
def compareAccountInfo(aldous, p2p):
|
||||
p2p = p2p["result"]["account_data"]
|
||||
aldous = aldous["object"]
|
||||
@@ -970,7 +981,7 @@ async def verifySubscribe(ip,clioPort,ripdPort):
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser(description='test script for xrpl-reporting')
|
||||
parser.add_argument('action', choices=["account_info", "tx", "txs","account_tx", "account_tx_full","ledger_data", "ledger_data_full", "book_offers","ledger","ledger_range","ledger_entry", "ledgers", "ledger_entries","account_txs","account_infos","account_txs_full","book_offerses","ledger_diff","perf","fee","server_info", "gaps","subscribe","verify_subscribe"])
|
||||
parser.add_argument('action', choices=["account_info", "tx", "txs","account_tx", "account_tx_full","ledger_data", "ledger_data_full", "book_offers","ledger","ledger_range","ledger_entry", "ledgers", "ledger_entries","account_txs","account_infos","account_txs_full","book_offerses","ledger_diff","perf","fee","server_info", "gaps","subscribe","verify_subscribe","call"])
|
||||
|
||||
parser.add_argument('--ip', default='127.0.0.1')
|
||||
parser.add_argument('--port', default='8080')
|
||||
@@ -1004,6 +1015,7 @@ parser.add_argument('--numRunners',default=1)
|
||||
parser.add_argument('--count',default=-1)
|
||||
parser.add_argument('--streams',default=None)
|
||||
parser.add_argument('--accounts',default=None)
|
||||
parser.add_argument('--request',default=None)
|
||||
|
||||
|
||||
|
||||
@@ -1026,6 +1038,9 @@ def run(args):
|
||||
elif args.action == "perf":
|
||||
asyncio.get_event_loop().run_until_complete(
|
||||
perf(args.ip,args.port))
|
||||
elif args.action == "call":
|
||||
asyncio.get_event_loop().run_until_complete(
|
||||
call(args.ip,args.port,args.request))
|
||||
elif args.action == "gaps":
|
||||
missing = []
|
||||
for x in range(rng[0],rng[1]):
|
||||
|
||||
Reference in New Issue
Block a user