-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathxjson_proc.h
More file actions
65 lines (57 loc) · 2.47 KB
/
xjson_proc.h
File metadata and controls
65 lines (57 loc) · 2.47 KB
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
// Copyright (c) 2017-2018 Telos Foundation & contributors
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#pragma once
#include <string>
#include <memory>
#include "json/json.h"
#include "xserver_response_code.h"
#include "xchaincore.h"
#include "xstring.h"
namespace top
{
namespace httpserver
{
#define SET_RESPONSE_CODE(error_code) m_response_code.m_code = error_code;\
m_response_json["result"] = m_response_code.m_code;\
m_response_json["msg"] = m_response_code.to_string();
#define SET_JSON_RESPONSE_OK json_proc.m_response_code.m_code = xhttp_error_code::ok;\
json_proc.m_response_json["result"] = json_proc.m_response_code.m_code;\
json_proc.m_response_json["msg"] = json_proc.m_response_code.to_string();
#define SET_JSON_PROC_RESPONSE(error_code) json_proc.m_response_code.m_code = error_code;\
json_proc.m_response_json["result"] = json_proc.m_response_code.m_code;\
json_proc.m_response_json["msg"] = json_proc.m_response_code.to_string();
#define TIMEOUT_RESPONSE "{\"result\":99, \"msg\":\"request time out\"}"
inline std::string set_response_from_consensus(const chain::xconsensus_reply_t& consensus_reply)
{
xJson::FastWriter writer;
xJson::Value result;
result["result"] = consensus_reply.m_result_code;
result["msg"] = consensus_reply.m_result_msg;
result["hash_id"] = string_utl::base64_encode(consensus_reply.m_tx_hash.data(), consensus_reply.m_tx_hash.size());
return writer.write(result);
}
class xjson_proc
{
public:
bool parse_json(const std::string& str_content);
std::string get_response();
std::string get_request();
public:
xJson::Reader m_reader;
xJson::FastWriter m_writer;
xJson::Value m_request_json;
xJson::Value m_response_json;
xserver_response_code m_response_code;
std::shared_ptr<top::chain::xtransaction_t> m_tx;
};
class xjson_parse
{
public:
bool parse_json(const std::string& str_content);
public:
xJson::Reader m_reader;
xJson::Value m_json;
};
}
}