forked from mit-dci/CryptoCurrency
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcryptoserver.h
70 lines (57 loc) · 3.16 KB
/
cryptoserver.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
63
64
65
66
67
68
69
70
/* 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_CRYPTOSERVER_H_
#define JSONRPC_CPP_STUB_CRYPTOSERVER_H_
#include <jsonrpccpp/server.h>
#include "wallet.h"
class CryptoRPCServer : public jsonrpc::AbstractServer<CryptoRPCServer>
{
public:
CryptoRPCServer(jsonrpc::AbstractServerConnector &conn, jsonrpc::serverVersion_t type = jsonrpc::JSONRPC_SERVER_V2) : jsonrpc::AbstractServer<CryptoRPCServer>(conn, type)
{
this->bindAndAddMethod(jsonrpc::Procedure("getinfo", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, NULL), &CryptoRPCServer::getinfoI);
this->bindAndAddMethod(jsonrpc::Procedure("account", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "account",jsonrpc::JSON_STRING, NULL), &CryptoRPCServer::accountI);
this->bindAndAddMethod(jsonrpc::Procedure("sendtoaddress", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_BOOLEAN, "address",jsonrpc::JSON_STRING,"amount",jsonrpc::JSON_REAL,"fee",jsonrpc::JSON_REAL, NULL), &CryptoRPCServer::sendtoaddressI);
}
inline virtual void getinfoI(const Json::Value &request, Json::Value &response)
{
(void)request;
response = this->getinfo();
}
inline virtual void accountI(const Json::Value &request, Json::Value &response)
{
response = this->account(request["account"].asString());
}
inline virtual void sendtoaddressI(const Json::Value &request, Json::Value &response)
{
response = this->sendtoaddress(request["address"].asString(), request["amount"].asDouble(), request["fee"].asDouble());
}
virtual Json::Value getinfo() = 0;
virtual Json::Value account(const std::string& account) = 0;
virtual bool sendtoaddress(const std::string& address, double amount, double fee) = 0;
};
class CryptoServer : public CryptoRPCServer
{
public:
CryptoServer(jsonrpc::AbstractServerConnector &connector);
virtual Json::Value getinfo();
virtual Json::Value account(const std::string& account);
virtual bool sendtoaddress(const std::string& address, double amount, double fee);
void setWallet(CryptoCurrency::Wallet* Wallet, CryptoCurrency::Protocol* Protocol, CryptoKernel::Blockchain* Blockchain);
private:
CryptoCurrency::Wallet* wallet;
CryptoCurrency::Protocol* protocol;
CryptoKernel::Blockchain* blockchain;
};
#endif //JSONRPC_CPP_STUB_CRYPTOSERVER_H_