forked from FISCO-BCOS/FISCO-BCOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
1926 lines (1732 loc) · 60.9 KB
/
main.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
This file is part of cpp-ethereum.
cpp-ethereum 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.
cpp-ethereum 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 cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file main.cpp
* @author Gav Wood <i@gavwood.com>
* @author Tasha Carl <tasha@carl.pro> - I here by place all my contributions in this file under MIT licence, as specified by http://opensource.org/licenses/MIT.
* @date 2014
* Ethereum client.
*/
#include <thread>
#include <chrono>
#include <fstream>
#include <iostream>
#include <clocale>
#include <signal.h>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/trim_all.hpp>
#include <boost/filesystem.hpp>
#include <libdevcore/FileSystem.h>
#include <libdevcore/easylog.h>
//#include <libethashseal/EthashAux.h>
#include <libevm/VM.h>
#include <libevm/VMFactory.h>
#include <libethcore/KeyManager.h>
#include <libethcore/ICAP.h>
#include <libethereum/All.h>
#include <libethereum/BlockChainSync.h>
#include <libethereum/NodeConnParamsManagerApi.h>
//#include <libethashseal/EthashClient.h>
#include <libpbftseal/PBFT.h>
#include <libsinglepoint/SinglePointClient.h>
#include <libsinglepoint/SinglePoint.h>
#include <libraftseal/Raft.h>
//#include <libethashseal/GenesisInfo.h>
#include <libwebthree/WebThree.h>
#include <libweb3jsonrpc/AccountHolder.h>
#include <libweb3jsonrpc/Eth.h>
#include <libweb3jsonrpc/SafeHttpServer.h>
#include <jsonrpccpp/client/connectors/httpclient.h>
#include <libweb3jsonrpc/ModularServer.h>
#include <libweb3jsonrpc/IpcServer.h>
#include <libweb3jsonrpc/LevelDB.h>
#include <libweb3jsonrpc/Whisper.h>
#include <libweb3jsonrpc/Net.h>
#include <libweb3jsonrpc/Web3.h>
#include <libweb3jsonrpc/SessionManager.h>
#include <libweb3jsonrpc/AdminNet.h>
#include <libweb3jsonrpc/AdminEth.h>
#include <libweb3jsonrpc/AdminUtils.h>
#include <libweb3jsonrpc/Personal.h>
#include <libweb3jsonrpc/Debug.h>
#include <libweb3jsonrpc/Test.h>
#include "Farm.h"
//#include <ethminer/MinerAux.h>
#include "AccountManager.h"
#include <libdevcore/easylog.h>
#include <libdiskencryption/CryptoParam.h>//读取加密方式配置文件
#include <libdiskencryption/GenKey.h>//生成nodekey及datakey文件
#include <libweb3jsonrpc/ChannelRPCServer.h>
#include <libweb3jsonrpc/RPCallback.h>
INITIALIZE_EASYLOGGINGPP
using namespace std;
using namespace dev;
using namespace dev::p2p;
using namespace dev::eth;
using namespace boost::algorithm;
static std::atomic<bool> g_silence = {false};
#include "genesisInfoForWe.h"
#include "GenesisInfo.h"
void help()
{
cout
<< "Usage eth [OPTIONS]" << "\n"
<< "Options:" << "\n" << "\n"
<< "Wallet usage:" << "\n";
AccountManager::streamAccountHelp(cout);
AccountManager::streamWalletHelp(cout);
cout
<< "\n";
cout
<< "Client mode (default):" << "\n"
<< " --mainnet Use the main network protocol." << "\n"
<< " --ropsten Use the Ropsten testnet." << "\n"
<< " --private <name> Use a private chain." << "\n"
<< " --test Testing mode: Disable PoW and provide test rpc interface." << "\n"
<< " --config <file> Configure specialised blockchain using given JSON information." << "\n"
<< " --oppose-dao-fork Ignore DAO hard fork (default is to participate)." << "\n"
<< "\n"
<< " -o,--mode <full/peer> Start a full node or a peer node (default: full)." << "\n"
<< "\n"
<< " -j,--json-rpc Enable JSON-RPC server (default: off)." << "\n"
<< " --ipc Enable IPC server (default: on)." << "\n"
<< " --ipcpath Set .ipc socket path (default: data directory)" << "\n"
<< " --admin-via-http Expose admin interface via http - UNSAFE! (default: off)." << "\n"
<< " --no-ipc Disable IPC server." << "\n"
<< " --json-rpc-port <n> Specify JSON-RPC server port (implies '-j', default: " << SensibleHttpPort << ")." << "\n"
<< " --rpccorsdomain <domain> Domain on which to send Access-Control-Allow-Origin header." << "\n"
<< " --admin <password> Specify admin session key for JSON-RPC (default: auto-generated and printed at start-up)." << "\n"
<< " -K,--kill Kill the blockchain first." << "\n"
<< " -R,--rebuild Rebuild the blockchain from the existing database." << "\n"
<< " --rescue Attempt to rescue a corrupt database." << "\n"
<< "\n"
<< " --import-presale <file> Import a pre-sale key; you'll need to specify the password to this key." << "\n"
<< " -s,--import-secret <secret> Import a secret key into the key store." << "\n"
<< " --master <password> Give the master password for the key store. Use --master \"\" to show a prompt." << "\n"
<< " --password <password> Give a password for a private key." << "\n"
<< "\n"
<< "Client transacting:" << "\n"
/*<< " -B,--block-fees <n> Set the block fee profit in the reference unit, e.g. ¢ (default: 15)." << "\n"
<< " -e,--ether-price <n> Set the ether price in the reference unit, e.g. ¢ (default: 30.679)." << "\n"
<< " -P,--priority <0 - 100> Set the default priority percentage (%) of a transaction (default: 50)." << "\n"*/
<< " --ask <wei> Set the minimum ask gas price under which no transaction will be mined (default " << toString(DefaultGasPrice) << " )." << "\n"
<< " --bid <wei> Set the bid gas price to pay for transactions (default " << toString(DefaultGasPrice) << " )." << "\n"
<< " --unsafe-transactions Allow all transactions to proceed without verification. EXTREMELY UNSAFE."
<< "\n"
<< "Client mining:" << "\n"
<< " -a,--address <addr> Set the author (mining payout) address to given address (default: auto)." << "\n"
<< " -m,--mining <on/off/number> Enable mining, optionally for a specified number of blocks (default: off)." << "\n"
<< " -f,--force-mining Mine even when there are no transactions to mine (default: off)." << "\n"
<< " -C,--cpu When mining, use the CPU." << "\n"
<< " -t, --mining-threads <n> Limit number of CPU/GPU miners to n (default: use everything available on selected platform)." << "\n"
<< "\n"
<< "Client networking:" << "\n"
<< " --client-name <name> Add a name to your client's version string (default: blank)." << "\n"
<< " --bootstrap Connect to the default Ethereum peer servers (default unless --no-discovery used)." << "\n"
<< " --no-bootstrap Do not connect to the default Ethereum peer servers (default only when --no-discovery is used)." << "\n"
<< " -x,--peers <number> Attempt to connect to a given number of peers (default: 11)." << "\n"
<< " --peer-stretch <number> Give the accepted connection multiplier (default: 7)." << "\n"
<< " --public-ip <ip> Force advertised public IP to the given IP (default: auto)." << "\n"
<< " --listen-ip <ip>(:<port>) Listen on the given IP for incoming connections (default: 0.0.0.0)." << "\n"
<< " --listen <port> Listen on the given port for incoming connections (default: 30303)." << "\n"
<< " -r,--remote <host>(:<port>) Connect to the given remote host (default: none)." << "\n"
<< " --port <port> Connect to the given remote port (default: 30303)." << "\n"
<< " --network-id <n> Only connect to other hosts with this network id." << "\n"
<< " --upnp <on/off> Use UPnP for NAT (default: on)." << "\n"
<< " --peerset <list> Space delimited list of peers; element format: type:publickey@ipAddress[:port]." << "\n"
<< " Types:" << "\n"
<< " default Attempt connection when no other peers are available and pinning is disabled." << "\n"
<< " required Keep connected at all times." << "\n"
// TODO:
// << " --trust-peers <filename> Space delimited list of publickeys." << "\n"
<< " --no-discovery Disable node discovery, implies --no-bootstrap." << "\n"
<< " --pin Only accept or connect to trusted peers." << "\n"
<< " --hermit Equivalent to --no-discovery --pin." << "\n"
<< " --sociable Force discovery and no pinning." << "\n"
<< "\n";
//MinerCLI::streamHelp(cout);
cout
<< "Import/export modes:" << "\n"
<< " --from <n> Export only from block n; n may be a decimal, a '0x' prefixed hash, or 'latest'." << "\n"
<< " --to <n> Export only to block n (inclusive); n may be a decimal, a '0x' prefixed hash, or 'latest'." << "\n"
<< " --only <n> Equivalent to --export-from n --export-to n." << "\n"
<< " --dont-check Prevent checking some block aspects. Faster importing, but to apply only when the data is known to be valid." << "\n"
<< "\n"
<< "General Options:" << "\n"
<< " -d,--db-path,--datadir <path> Load database from path (default: " << getDataDir() << ")." << "\n"
#if ETH_EVMJIT
<< " --vm <vm-kind> Select VM; options are: interpreter, jit or smart (default: interpreter)." << "\n"
#endif // ETH_EVMJIT
<< " -v,--verbosity <0 - 9> Set the log verbosity from 0 to 9 (default: 8)." << "\n"
<< " -V,--version Show the version and exit." << "\n"
<< " -h,--help Show this help message and exit." << "\n"
<< "\n"
<< "Experimental / Proof of Concept:" << "\n"
<< " --shh Enable Whisper." << "\n"
<< " --singlepoint Enable singlepoint." << "\n"
<< "\n"
;
exit(0);
}
string ethCredits(bool _interactive = false)
{
std::ostringstream cout;
cout
<< "FISCO-BCOS " << dev::Version << "\n"
<< dev::Copyright << "\n"
<< " See the README for contributors and credits."
<< "\n";
if (_interactive)
cout << "Type 'exit' to quit"
<< "\n"
<< "\n";
return cout.str();
}
void version()
{
cout << "eth version " << dev::Version << "\n";
cout << "eth network protocol version: " << dev::eth::c_protocolVersion << "\n";
cout << "Client database version: " << dev::eth::c_databaseVersion << "\n";
cout << "Build: " << DEV_QUOTED(ETH_BUILD_PLATFORM) << "/" << DEV_QUOTED(ETH_BUILD_TYPE) << "\n";
exit(0);
}
void generateNetworkRlp(string sFilePath)
{
KeyPair kp = KeyPair::create();
RLPStream netData(3);
netData << dev::p2p::c_protocolVersion << kp.secret().ref();
int count = 0;
netData.appendList(count);
writeFile(sFilePath, netData.out());
writeFile(sFilePath + ".pub", kp.pub().hex());
cout << "eth generate network.rlp. " << "\n";
cout << "eth public id is :[" << kp.pub().hex() << "]" << "\n";
cout << "write into file [" << sFilePath << "]" << "\n";
exit(0);
}
/*
The equivalent of setlocale(LC_ALL, “C”) is called before any user code is run.
If the user has an invalid environment setting then it is possible for the call
to set locale to fail, so there are only two possible actions, the first is to
throw a runtime exception and cause the program to quit (default behaviour),
or the second is to modify the environment to something sensible (least
surprising behaviour).
The follow code produces the least surprising behaviour. It will use the user
specified default locale if it is valid, and if not then it will modify the
environment the process is running in to use a sensible default. This also means
that users do not need to install language packs for their OS.
*/
void setDefaultOrCLocale()
{
#if __unix__
if (!std::setlocale(LC_ALL, ""))
{
setenv("LC_ALL", "C", 1);
}
#endif
}
void importPresale(KeyManager& _km, string const& _file, function<string()> _pass)
{
KeyPair k = _km.presaleSecret(contentsString(_file), [&](bool) { return _pass(); });
_km.import(k.secret(), "Presale wallet" + _file + " (insecure)");
}
Address c_config = Address("ccdeac59d35627b7de09332e819d5159e7bb7250");
string pretty(h160 _a, dev::eth::State const& _st)
{
string ns;
h256 n;
if (h160 nameReg = (u160)_st.storage(c_config, 0))
n = _st.storage(nameReg, (u160)(_a));
if (n)
{
std::string s((char const*)n.data(), 32);
if (s.find_first_of('\0') != string::npos)
s.resize(s.find_first_of('\0'));
ns = " " + s;
}
return ns;
}
inline bool isPrime(unsigned _number)
{
if (((!(_number & 1)) && _number != 2 ) || (_number < 2) || (_number % 3 == 0 && _number != 3))
return false;
for (unsigned k = 1; 36 * k * k - 12 * k < _number; ++k)
if ((_number % (6 * k + 1) == 0) || (_number % (6 * k - 1) == 0))
return false;
return true;
}
enum class NodeMode
{
PeerServer,
Full
};
enum class OperationMode
{
Node,
Import,
Export,
ExportGenesis
};
enum class Format
{
Binary,
Hex,
Human
};
void stopSealingAfterXBlocks(eth::Client* _c, unsigned _start, unsigned& io_mining)
{
try
{
if (io_mining != ~(unsigned)0 && io_mining && _c->isMining() && _c->blockChain().details().number - _start == io_mining)
{
_c->stopSealing();
io_mining = ~(unsigned)0;
}
}
catch (InvalidSealEngine&)
{
}
this_thread::sleep_for(chrono::milliseconds(100));
}
class ExitHandler: public SystemManager
{
public:
void exit() { exitHandler(0); }
static void exitHandler(int) { s_shouldExit = true; }
bool shouldExit() const { return s_shouldExit; }
private:
static bool s_shouldExit;
};
bool ExitHandler::s_shouldExit = false;
static map<string, unsigned int> s_mlogIndex;
void rolloutHandler(const char* filename, std::size_t )
{
std::stringstream stream;
map<string, unsigned int>::iterator iter = s_mlogIndex.find(filename);
if (iter != s_mlogIndex.end())
{
stream << filename << "." << iter->second++;
s_mlogIndex[filename] = iter->second++;
}
else
{
stream << filename << "." << 0;
s_mlogIndex[filename] = 0;
}
boost::filesystem::rename(filename, stream.str().c_str());
}
void logRotateByTime()
{
const std::chrono::seconds wakeUpDelta = std::chrono::seconds(20);
static auto nextWakeUp = std::chrono::system_clock::now();
if(std::chrono::system_clock::now() > nextWakeUp)
{
nextWakeUp = std::chrono::system_clock::now() + wakeUpDelta;
}
else
{
return;
}
auto L = el::Loggers::getLogger("default");
if(L == nullptr)
{
LOG(ERROR)<<"Oops, it is not called default!";
}
else
{
L->reconfigure();
}
L = el::Loggers::getLogger("fileLogger");
if(L == nullptr)
{
LOG(ERROR)<<"Oops, it is not called fileLogger!";
}
else
{
L->reconfigure();
}
L = el::Loggers::getLogger("statLogger");
if(L == nullptr)
{
LOG(ERROR)<<"Oops, it is not called fileLogger!";
}
else
{
L->reconfigure();
}
}
//日志配置文件放到log目录
void initEasylogging(const ChainParams& chainParams)
{
string logconf = chainParams.logFileConf;
el::Loggers::addFlag(el::LoggingFlag::MultiLoggerSupport); // Enables support for multiple loggers
el::Loggers::addFlag(el::LoggingFlag::StrictLogFileSizeCheck);
el::Loggers::setVerboseLevel(chainParams.logVerbosity);
if (el::base::utils::File::pathExists(logconf.c_str(), true))
{
el::Logger* fileLogger = el::Loggers::getLogger("fileLogger"); // Register new logger
el::Configurations conf(logconf.c_str());
el::Configurations allConf;
allConf.set(conf.get(el::Level::Global, el::ConfigurationType::Enabled));
allConf.set(conf.get(el::Level::Global, el::ConfigurationType::ToFile));
allConf.set(conf.get(el::Level::Global, el::ConfigurationType::ToStandardOutput));
allConf.set(conf.get(el::Level::Global, el::ConfigurationType::Format));
allConf.set(conf.get(el::Level::Global, el::ConfigurationType::Filename));
allConf.set(conf.get(el::Level::Global, el::ConfigurationType::SubsecondPrecision));
allConf.set(conf.get(el::Level::Global, el::ConfigurationType::MillisecondsWidth));
allConf.set(conf.get(el::Level::Global, el::ConfigurationType::PerformanceTracking));
allConf.set(conf.get(el::Level::Global, el::ConfigurationType::MaxLogFileSize));
allConf.set(conf.get(el::Level::Global, el::ConfigurationType::LogFlushThreshold));
allConf.set(conf.get(el::Level::Trace, el::ConfigurationType::Enabled));
allConf.set(conf.get(el::Level::Debug, el::ConfigurationType::Enabled));
allConf.set(conf.get(el::Level::Fatal, el::ConfigurationType::Enabled));
allConf.set(conf.get(el::Level::Error, el::ConfigurationType::Enabled));
allConf.set(conf.get(el::Level::Warning, el::ConfigurationType::Enabled));
allConf.set(conf.get(el::Level::Verbose, el::ConfigurationType::Enabled));
allConf.set(conf.get(el::Level::Info, el::ConfigurationType::Enabled));
el::Loggers::reconfigureLogger("default", allConf);
el::Loggers::reconfigureLogger(fileLogger, conf);
// stat log,依托于 default 的配置
el::Logger* statLogger = el::Loggers::getLogger("statLogger");
el::Configurations statConf = allConf;
el::Configuration* fileConf = conf.get(el::Level::Global, el::ConfigurationType::Filename);
string stat_prefix = "stat_";
string stat_path = fileConf->value();
if (!stat_path.empty())
{
size_t pos = stat_path.find_last_of("/"); // not support for windows
if ((int)pos == -1) // log file just has name not path
stat_path = stat_prefix + stat_path;
else
stat_path.insert(pos + 1, stat_prefix);
}
else
{
stat_path = stat_prefix + "log_%datetime{%Y%M%d%H}.log";
}
statConf.set(el::Level::Global, el::ConfigurationType::Filename, stat_path);
if (!chainParams.statLog)
{
statConf.set(el::Level::Global, el::ConfigurationType::Enabled, "false");
statConf.set(el::Level::Global, el::ConfigurationType::ToFile, "false");
statConf.set(el::Level::Global, el::ConfigurationType::ToStandardOutput, "false");
}
el::Loggers::reconfigureLogger("statLogger", statConf);
}
el::Helpers::installPreRollOutCallback(rolloutHandler);
}
bool isTrue(std::string const& _m)
{
return _m == "on" || _m == "yes" || _m == "true" || _m == "1";
}
bool isFalse(std::string const& _m)
{
return _m == "off" || _m == "no" || _m == "false" || _m == "0";
}
int main(int argc, char** argv)
{
setDefaultOrCLocale();
// Init defaults
Defaults::get();
//Ethash::init();
NoProof::init();
PBFT::init();
Raft::init();
SinglePoint::init();
/// Operating mode.
OperationMode mode = OperationMode::Node;
// unsigned prime = 0;
// bool yesIReallyKnowWhatImDoing = false;
strings scripts;
/// File name for import/export.
string filename;
bool safeImport = false;
/// Hashes/numbers for export range.
string exportFrom = "1";
string exportTo = "latest";
Format exportFormat = Format::Binary;
/// General params for Node operation
NodeMode nodeMode = NodeMode::Full;
/// bool interactive = false;
int jsonRPCURL = -1;
int jsonRPCSSLURL = -1;
bool adminViaHttp = true;
bool ipc = true;
std::string rpcCorsDomain = "";
string jsonAdmin;
ChainParams chainParams(genesisInfo(eth::Network::MainNetwork), genesisStateRoot(eth::Network::MainNetwork));
u256 gasFloor = Invalid256;
string privateChain;
bool upnp = true;
WithExisting withExisting = WithExisting::Trust;
/// Networking params.
string clientName;
string listenIP;
unsigned short listenPort = 16789;
string publicIP;
string remoteHost;
unsigned short remotePort = 16789;
unsigned peers = 11;
unsigned peerStretch = 7;
std::map<NodeID, pair<NodeIPEndpoint, bool>> preferredNodes;
bool bootstrap = true;
bool disableDiscovery = true;
bool pinning = false;
bool enableDiscovery = false;
bool noPinning = false;
static const unsigned NoNetworkID = (unsigned) - 1;
unsigned networkID = NoNetworkID;
/// Mining params
unsigned mining = ~(unsigned)0;
Address author;
LOG(TRACE) << " Main:: author: " << author;
strings presaleImports;
bytes extraData;
u256 askPrice = DefaultGasPrice;
u256 bidPrice = DefaultGasPrice;
bool alwaysConfirm = true;
/// Wallet password stuff
string masterPassword;
bool masterSet = false;
/// Whisper
bool useWhisper = false;
bool testingMode = false;
bool singlepoint = false;
strings passwordsToNote;
Secrets toImport;
if (argc > 1 && (string(argv[1]) == "wallet" || string(argv[1]) == "account"))
{
if ( (string(argv[1]) == "account") && ( string(argv[2]) == "new") && (4 < argc) ) //eth account new dir pass
{
SecretStore::defaultpath = string(argv[3]);
AccountManager accountm;
return !accountm.execute(argc, argv);
}
else
{
string ret;
cout << "请输入keystore 保存路径:";
getline(cin, ret);
SecretStore::defaultpath = ret;
cout << "keystoredir:" << SecretStore::defaultPath() << "\n";
AccountManager accountm;
return !accountm.execute(argc, argv);
}
}
bool listenSet = false;
string configJSON;
string genesisJSON;
string godminerJSON;
int blockNumber = 0;
std::string contracts;
//dfs related parameters
string strNodeId;
string strGroupId;
string strStoragePath;
Address fileContractAddr;
Address fileServerContractAddr;
for (int i = 1; i < argc; ++i)
{
string arg = argv[i];
/*if (m.interpretOption(i, argc, argv))
{
}
else */if (arg == "--listen-ip" && i + 1 < argc)
{
listenIP = argv[++i];
listenSet = true;
}
else if ((arg == "--listen" || arg == "--listen-port") && i + 1 < argc)
{
listenPort = (short)atoi(argv[++i]);
listenSet = true;
}
else if ((arg == "--public-ip" || arg == "--public") && i + 1 < argc)
{
publicIP = argv[++i];
}
else if ((arg == "-r" || arg == "--remote") && i + 1 < argc)
{
string host = argv[++i];
string::size_type found = host.find_first_of(':');
if (found != std::string::npos)
{
remoteHost = host.substr(0, found);
remotePort = (short)atoi(host.substr(found + 1, host.length()).c_str());
}
else
remoteHost = host;
}
else if (arg == "--port" && i + 1 < argc)
{
remotePort = (short)atoi(argv[++i]);
}
else if (arg == "--password" && i + 1 < argc)
passwordsToNote.push_back(argv[++i]);
else if (arg == "--master" && i + 1 < argc)
{
masterPassword = argv[++i];
masterSet = true;
}
//创世块合约列表
else if ((arg == "--contracts") && i + 1 < argc) {
contracts = argv[++i];
}
//创世块blocknumber
else if ((arg == "--blocknumber") && i + 1 < argc) {
blockNumber = atoi(argv[++i]);
}
//创世块路径
else if ((arg == "--export-genesis") && i + 1 < argc) {
mode = OperationMode::ExportGenesis;
filename = argv[++i];
}
else if ((arg == "-I" || arg == "--import" || arg == "import") && i + 1 < argc)
{
mode = OperationMode::Import;
filename = argv[++i];
}
else if (arg == "--dont-check")
safeImport = true;
else if ((arg == "-E" || arg == "--export" || arg == "export") && i + 1 < argc)
{
mode = OperationMode::Export;
filename = argv[++i];
}
else if (arg == "--script" && i + 1 < argc)
scripts.push_back(argv[++i]);
else if (arg == "--format" && i + 1 < argc)
{
string m = argv[++i];
if (m == "binary")
exportFormat = Format::Binary;
else if (m == "hex")
exportFormat = Format::Hex;
else if (m == "human")
exportFormat = Format::Human;
else
{
LOG(ERROR) << "Bad " << arg << " option: " << m << "\n";
return -1;
}
}
else if (arg == "--to" && i + 1 < argc)
exportTo = argv[++i];
else if (arg == "--from" && i + 1 < argc)
exportFrom = argv[++i];
else if (arg == "--only" && i + 1 < argc)
exportTo = exportFrom = argv[++i];
else if (arg == "--upnp" && i + 1 < argc)
{
string m = argv[++i];
if (isTrue(m))
upnp = true;
else if (isFalse(m))
upnp = false;
else
{
LOG(ERROR) << "Bad " << arg << " option: " << m << "\n";
return -1;
}
}
else if (arg == "--network-id" && i + 1 < argc)
try {
networkID = stol(argv[++i]);
}
catch (...)
{
LOG(ERROR) << "Bad " << arg << " option: " << argv[i] << "\n";
return -1;
}
else if (arg == "--private" && i + 1 < argc)
try {
privateChain = argv[++i];
}
catch (...)
{
LOG(ERROR) << "Bad " << arg << " option: " << argv[i] << "\n";
return -1;
}
else if (arg == "--independent" && i + 1 < argc)
try {
privateChain = argv[++i];
noPinning = enableDiscovery = true;
}
catch (...)
{
LOG(ERROR) << "Bad " << arg << " option: " << argv[i] << "\n";
return -1;
}
else if (arg == "-K" || arg == "--kill-blockchain" || arg == "--kill")
withExisting = WithExisting::Kill;
else if (arg == "-R" || arg == "--rebuild")
withExisting = WithExisting::Verify;
else if (arg == "-R" || arg == "--rescue")
withExisting = WithExisting::Rescue;
else if (arg == "--client-name" && i + 1 < argc)
clientName = argv[++i];
else if ((arg == "-a" || arg == "--address" || arg == "--author") && i + 1 < argc)
try {
author = h160(fromHex(argv[++i], WhenError::Throw));
}
catch (BadHexCharacter&)
{
LOG(ERROR) << "Bad hex in " << arg << " option: " << argv[i] << "\n";
return -1;
}
catch (...)
{
LOG(ERROR) << "Bad " << arg << " option: " << argv[i] << "\n";
return -1;
}
else if ((arg == "-s" || arg == "--import-secret") && i + 1 < argc)
{
Secret s(fromHex(argv[++i]));
toImport.emplace_back(s);
}
else if ((arg == "-S" || arg == "--import-session-secret") && i + 1 < argc)
{
Secret s(fromHex(argv[++i]));
toImport.emplace_back(s);
}
else if ((arg == "-d" || arg == "--path" || arg == "--db-path" || arg == "--datadir") && i + 1 < argc)
setDataDir(argv[++i]);
else if (arg == "--ipcpath" && i + 1 < argc )
setIpcPath(argv[++i]);
else if ((arg == "--genesis-json" || arg == "--genesis") && i + 1 < argc)
{
try
{
genesisJSON = contentsString(argv[++i]);
}
catch (...)
{
LOG(ERROR) << "Bad " << arg << " option: " << argv[i] << "\n";
return -1;
}
}
else if (arg == "--config" && i + 1 < argc)
{
try
{
setConfigPath(argv[++i]);
configJSON = contentsString(getConfigPath());
}
catch (...)
{
LOG(ERROR) << "Bad " << arg << " option: " << argv[i] << "\n";
return -1;
}
}
else if (arg == "--extra-data" && i + 1 < argc)
{
try
{
extraData = fromHex(argv[++i]);
}
catch (...)
{
LOG(ERROR) << "Bad " << arg << " option: " << argv[i] << "\n";
return -1;
}
}
else if (arg == "--gas-floor" && i + 1 < argc)
gasFloor = u256(argv[++i]);
else if (arg == "--mainnet")
chainParams = ChainParams(genesisInfo(eth::Network::MainNetwork), genesisStateRoot(eth::Network::MainNetwork));
else if (arg == "--ropsten" || arg == "--testnet")
chainParams = ChainParams(genesisInfo(eth::Network::Ropsten), genesisStateRoot(eth::Network::Ropsten));
else if (arg == "--oppose-dao-fork")
{
chainParams = ChainParams(genesisInfo(eth::Network::MainNetwork), genesisStateRoot(eth::Network::MainNetwork));
chainParams.otherParams["daoHardforkBlock"] = toHex(u256(-1) - 10, HexPrefix::Add);
}
else if (arg == "--bob")
{
cout << "Asking Bob for blocks (this should work in theoreum)..." << "\n";
while (true)
{
u256 x(h256::random());
u256 c;
for (; x != 1; ++c)
{
x = (x & 1) == 0 ? x / 2 : 3 * x + 1;
cout << toHex(x) << "\n";
this_thread::sleep_for(chrono::seconds(1));
}
cout << "Block number: " << hex << c << "\n";
exit(0);
}
}
else if (arg == "--ask" && i + 1 < argc)
{
try
{
askPrice = u256(argv[++i]);
}
catch (...)
{
LOG(ERROR) << "Bad " << arg << " option: " << argv[i] << "\n";
return -1;
}
}
else if (arg == "--bid" && i + 1 < argc)
{
try
{
bidPrice = u256(argv[++i]);
}
catch (...)
{
LOG(ERROR) << "Bad " << arg << " option: " << argv[i] << "\n";
return -1;
}
}
else if ((arg == "-m" || arg == "--mining") && i + 1 < argc)
{
string m = argv[++i];
if (isTrue(m))
mining = ~(unsigned)0;
else if (isFalse(m))
mining = 0;
else
try {
mining = stoi(m);
}
catch (...) {
LOG(ERROR) << "Unknown " << arg << " option: " << m << "\n";
return -1;
}
}
else if (arg == "-b" || arg == "--bootstrap")
bootstrap = true;
else if (arg == "--no-bootstrap")
bootstrap = false;
else if (arg == "--no-discovery")
{
disableDiscovery = true;
bootstrap = false;
}
else if (arg == "--pin")
pinning = true;
else if (arg == "--hermit")
pinning = disableDiscovery = true;
else if (arg == "--sociable")
noPinning = enableDiscovery = true;
else if (arg == "--unsafe-transactions")
alwaysConfirm = false;
else if (arg == "--import-presale" && i + 1 < argc)
presaleImports.push_back(argv[++i]);
/*else if (arg == "--old-interactive")
interactive = true;*/
else if ((arg == "-j" || arg == "--json-rpc"))
jsonRPCURL = jsonRPCURL == -1 ? SensibleHttpPort : jsonRPCURL;
else if (arg == "--admin-via-http")
adminViaHttp = true;
else if (arg == "--json-rpc-port" && i + 1 < argc)
jsonRPCURL = atoi(argv[++i]);
else if (arg == "--rpccorsdomain" && i + 1 < argc)
rpcCorsDomain = argv[++i];
else if (arg == "--json-admin" && i + 1 < argc)
jsonAdmin = argv[++i];
else if (arg == "--ipc")
ipc = true;
else if (arg == "--no-ipc")
ipc = false;
else if ((arg == "-x" || arg == "--peers") && i + 1 < argc)
peers = atoi(argv[++i]);
else if (arg == "--peer-stretch" && i + 1 < argc)
peerStretch = atoi(argv[++i]);
else if (arg == "--peerset" && i + 1 < argc)
{
string peerset = argv[++i];
if (peerset.empty())
{
LOG(ERROR) << "--peerset argument must not be empty";
return -1;
}
vector<string> each;
boost::split(each, peerset, boost::is_any_of("\t "));
for (auto const& p : each)
{
string type;
string pubk;
string hostIP;
unsigned short port = c_defaultListenPort;
// type:key@ip[:port]
vector<string> typeAndKeyAtHostAndPort;
boost::split(typeAndKeyAtHostAndPort, p, boost::is_any_of(":"));
if (typeAndKeyAtHostAndPort.size() < 2 || typeAndKeyAtHostAndPort.size() > 3)
continue;
type = typeAndKeyAtHostAndPort[0];
if (typeAndKeyAtHostAndPort.size() == 3)
port = (uint16_t)atoi(typeAndKeyAtHostAndPort[2].c_str());
vector<string> keyAndHost;
boost::split(keyAndHost, typeAndKeyAtHostAndPort[1], boost::is_any_of("@"));
if (keyAndHost.size() != 2)
continue;
pubk = keyAndHost[0];
if (pubk.size() != 128)
continue;
hostIP = keyAndHost[1];
// todo: use Network::resolveHost()
if (hostIP.size() < 4 /* g.it */)
continue;
bool required = type == "required";
if (!required && type != "default")
continue;
Public publicKey(fromHex(pubk));
try
{
preferredNodes[publicKey] = make_pair(NodeIPEndpoint(bi::address::from_string(hostIP), port, port), required);
}
catch (...)
{
LOG(ERROR) << "Unrecognized peerset: " << peerset << "\n";
return -1;
}
}
}
else if ((arg == "-o" || arg == "--mode") && i + 1 < argc)
{
string m = argv[++i];
if (m == "full")
nodeMode = NodeMode::Full;
else if (m == "peer")
nodeMode = NodeMode::PeerServer;
else
{
LOG(ERROR) << "Unknown mode: " << m << "\n";
return -1;
}
}
#if ETH_EVMJIT