-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteos.cpp
169 lines (146 loc) · 4.42 KB
/
teos.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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <boost/algorithm/string.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/program_options.hpp>
#include <teoslib/command/get_commands.hpp>
#include <teoslib/command/wallet_commands.hpp>
#include <teoslib/command/create_commands.hpp>
#include <teoslib/command/set_commands.hpp>
#include <teoslib/command/push_commands.hpp>
#include <teoslib/command/other_commands.hpp>
#include <teoslib/command/subcommands.hpp>
#include <teoslib/control/build_contract.hpp>
#include <teoslib/control/daemon_controls.hpp>
#include <teoslib/control/config.hpp>
#include <teos/teos.hpp>
#define IF_ELSE(commandName_, classPrefix) \
if (commandName == #commandName_) \
{ \
classPrefix##Options(argc, argv).go(); \
} \
else
#define HELP \
std::cout << usage << endl; \
std::cout << desc << endl; \
std::cout << commands << endl;
const char* usage = R"(
Command Line Interface to Eos Daemon
Usage: ./teos [HOST:PORT] [OPTIONS] [COMMAND] [SUBCOMMAND] [OPTIONS]
for example:
192.168.229.140:8888 get block 255
)";
const char* commands = R"(
Commands:
create Create various items, on and off the blockchain
get Retrieve various items and information from the blockchain
set Set or update blockchain state
transfer Transfer EOS from account to account
wallet Interact with local wallet
benchmark Configure and execute benchmarks
push Push arbitrary transactions to the blockchain
node Test EOS chain node procedures
)";
std::map<const std::string, const std::string> subcommandMap = {
{ "create", createSubcommands },
{ "get", getSubcommands },
{ "set", setSubcommands },
{ "wallet", walletSubcommands },
{ "benchmark", benchmarkSubcommands },
{ "push", pushSubcommands }
};
int main(int argc, const char *argv[]) {
using namespace std;
using namespace teos;
using namespace teos::command;
using namespace teos::control;
using namespace boost::program_options;
options_description desc("Options");
string command;
string subcommand;
TeosCommand::httpAddress = LOCALHOST_HTTP_ADDRESS;
TeosCommand::httpWalletAddress = TeosCommand::httpAddress;
TeosControl::executable = argv[0];
if (argc > 1)
{
string httpAddress(argv[1]);
size_t colon = httpAddress.find(":");
if (colon != std::string::npos)
{
TeosCommand::httpAddress = httpAddress;
TeosCommand::httpWalletAddress = TeosCommand::httpAddress;
argv++;
argc--;
}
if (strcmp(argv[1], USE_CONFIG_JSON) == 0)
{
TeosCommand::httpAddress = "";
TeosCommand::httpWalletAddress = TeosCommand::httpAddress;
argv++;
argc--;
}
if (strcmp(argv[1], LOCALHOST_ADDRESS) == 0)
{
argv++;
argc--;
}
if (strcmp(argv[1], TEST_ADDRESS) == 0)
{
TeosCommand::httpAddress = TEST_HTTP_ADDRESS;
TeosCommand::httpWalletAddress = TeosCommand::httpAddress;
argv++;
argc--;
}
}
if (argc > 1){
command = argv[1];
argv++;
argc--;
} else {
HELP
return 0;
}
if (argc > 1){
subcommand = argv[1];
argv++;
argc--;
string commandName = command + "_" + subcommand;
IF_ELSE(version_client, VersionClient)
IF_ELSE(get_info, GetInfo)
IF_ELSE(get_block, GetBlock)
IF_ELSE(get_account, GetAccount)
IF_ELSE(get_accounts, GetAccounts)
IF_ELSE(get_code, GetCode)
IF_ELSE(get_table, GetTable)
IF_ELSE(wallet_create, WalletCreate)
IF_ELSE(wallet_list, WalletList)
IF_ELSE(wallet_keys, WalletKeys)
IF_ELSE(wallet_import, WalletImport)
IF_ELSE(wallet_open, WalletOpen)
IF_ELSE(wallet_lock, WalletLock)
IF_ELSE(wallet_lock_all, WalletLockAll)
IF_ELSE(wallet_unlock, WalletUnlock)
IF_ELSE(create_key, CreateKey)
IF_ELSE(create_account, CreateAccount)
IF_ELSE(set_contract, SetContract)
IF_ELSE(push_action, PushAction)
IF_ELSE(daemon_start, DaemonStart)
IF_ELSE(daemon_stop, DaemonStop)
IF_ELSE(build_contract, BuildContract)
IF_ELSE(generate_abi, GenerateAbi)
IF_ELSE(bootstrap_contract, BootstrapContract)
IF_ELSE(delete_contract, DeleteContract)
IF_ELSE(get_config, GetConfig)
{
cout << "unknown command!" << endl;
}
} else {
HELP
return 0;
}
return 0;
}