-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrpc_test.cpp
53 lines (46 loc) · 1.43 KB
/
rpc_test.cpp
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
#include <iostream>
#include <vector>
#include <initializer_list>
#include <cpprest/json.h>
#include <cpprest/http_client.h>
#include <cpprest/interopstream.h>
#include "include/rpc.h"
using namespace std;
using namespace web;
int main(int argc, char* argv[]) {
json::value params = json::value::object();
random_device rd;
string uri(argv[1]);
string method(argv[2]);
for (int i=3; i<argc; i++) { // kvPair from argv[]
string k,v;
istringstream ss(argv[i]);
if (getline(ss, k, '=') && getline(ss, v))
params[U(k)] = json::value(v);
}
// type convertor
if(params.has_field("offset")) {
int32_t offset = stoul(params[U("offset")].as_string());
params[U("offset")] = json::value(offset);
}
if(params.has_field("limit")) {
int32_t limit = stoul(params[U("limit")].as_string());
params[U("limit")] = json::value(limit);
}
if(params.has_field("meta")) {
if(0 == params["meta"].as_string().compare("true")) {
params["meta"] = json::value(true);
} else {
params["meta"] = json::value(false);
}
}
if(params.has_field("txPool")) {
if(0 == params["txPool"].as_string().compare("true")) {
params["txPool"] = json::value(true);
} else {
params["txPool"] = json::value(false);
}
}
auto js = RPCCall(method, params);
cout << js << endl;
}