This repository has been archived by the owner on Feb 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
myapi_1.cc
84 lines (67 loc) · 1.79 KB
/
myapi_1.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* Copyright 2019 Bloq Inc.
* Distributed under the MIT/X11 software license, see the accompanying
* file COPYING or http://www.opensource.org/licenses/mit-license.php.
*/
#include <string>
#include <map>
#include <univalue.h>
#include "myapi_1.h"
#include "server.h"
using namespace std;
map<string,RpcCallInfo> myapi_1_list = {
{ "ping", { "ping", } },
{ "echo", { "echo", } },
};
// =======================================================================
// RPC implementation section
// =======================================================================
//
//
// RPC "ping"
//
static UniValue myapi_1_ping(const UniValue& jreq, const UniValue& params)
{
UniValue result("pong");
return jrpcOk(jreq, result);
}
//
// RPC "echo"
//
static UniValue myapi_1_echo(const UniValue& jreq, const UniValue& params)
{
return jrpcOk(jreq, params);
}
// =======================================================================
// RPC service dispatch and metadata/reflection
// =======================================================================
//
//
// reflection: describe all RPC methods supported by myapi v1
//
UniValue MyApiInfo::list_methods()
{
return list_method_helper(myapi_1_list);
}
const RpcCallInfo& MyApiInfo::call_info(const std::string& method)
{
return myapi_1_list[method];
}
//
// dispatch JSON-RPC request to myapi v1 RPCs
//
UniValue MyApiInfo::execute(const UniValue& jreq)
{
const string& method = jreq["method"].getValStr();
const UniValue& params = jreq["params"];
UniValue uret = rpc_call_check(jreq, method, params);
if (!uret.isNull())
return uret;
if (method == "ping")
return myapi_1_ping(jreq, params);
else if (method == "echo")
return myapi_1_echo(jreq, params);
else {
assert(0 && "invalid source code rpc list");
return NullUniValue; // not reached
}
}