forked from mit-dci/CryptoCurrency
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcryptoclient.h
62 lines (54 loc) · 2.49 KB
/
cryptoclient.h
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
/* CryptoCurrency - An example crypto-currency using the CryptoKernel library as a base
Copyright (C) 2016 James Lovejoy
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef JSONRPC_CPP_STUB_CRYPTOCLIENT_H_
#define JSONRPC_CPP_STUB_CRYPTOCLIENT_H_
#include <jsonrpccpp/client.h>
class CryptoClient : public jsonrpc::Client
{
public:
CryptoClient(jsonrpc::IClientConnector &conn, jsonrpc::clientVersion_t type = jsonrpc::JSONRPC_CLIENT_V2) : jsonrpc::Client(conn, type) {}
Json::Value getinfo() throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p = Json::nullValue;
Json::Value result = this->CallMethod("getinfo",p);
if (result.isObject())
return result;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value account(const std::string& account) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["account"] = account;
Json::Value result = this->CallMethod("account",p);
if (result.isObject())
return result;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
bool sendtoaddress(const std::string& address, double amount, double fee) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["address"] = address;
p["amount"] = amount;
p["fee"] = fee;
Json::Value result = this->CallMethod("sendtoaddress",p);
if (result.isBool())
return result.asBool();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
};
#endif //JSONRPC_CPP_STUB_CRYPTOCLIENT_H_