MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / setgenerate

Function setgenerate

src/rpc/rpcmining.cpp:37–96  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35static bool GetMiningInfo() { return fMining; }
36
37Value setgenerate(const Array& params, bool fHelp) {
38 if (fHelp || (params.size() != 1 && params.size() != 2))
39 throw runtime_error(
40 "setgenerate generate ( genblocklimit )\n"
41 "\nSet 'generate' true or false to turn generation on or off.\n"
42 "Generation is limited to 'genblocklimit' processors, -1 is unlimited.\n"
43 "See the getgenerate call for the current setting.\n"
44 "\nArguments:\n"
45 "1. generate (boolean, required) Set to true to turn on generation, off to turn off.\n"
46 "2. genblocklimit (numeric, optional) Set the processor limit for when generation is on. Can be -1 for "
47 "unlimited.\n"
48 " Note: in -regtest mode, genblocklimit controls how many blocks are generated "
49 "immediately.\n"
50 "\nExamples:\n"
51 "\nSet the generation on with a limit of one processor\n" +
52 HelpExampleCli("setgenerate", "true 1") + "\nAs json rpc call\n" +
53 HelpExampleRpc("setgenerate", "true, 1") + "\nTurn off generation\n" +
54 HelpExampleCli("setgenerate", "false") + "\nAs json rpc call\n" + HelpExampleRpc("setgenerate", "false"));
55
56 static bool fGenerate = false;
57
58 set<CKeyID> setKeyId;
59 setKeyId.clear();
60 pWalletMain->GetKeys(setKeyId, true);
61
62 bool bSetEmpty(true);
63 for (auto & keyId : setKeyId) {
64 CUserID userId(keyId);
65 CAccount acctInfo;
66 if (pCdMan->pAccountCache->GetAccount(userId, acctInfo)) {
67 bSetEmpty = false;
68 break;
69 }
70 }
71
72 if (bSetEmpty)
73 throw JSONRPCError(RPC_INVALID_PARAMETER, "No key for mining");
74
75 if (params.size() > 0)
76 fGenerate = params[0].get_bool();
77
78 int genBlockLimit = 1;
79 if (params.size() == 2) {
80 genBlockLimit = params[1].get_int();
81 if(genBlockLimit <= 0) {
82 throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid genblocklimit");
83 }
84 }
85 Object obj;
86 if (fGenerate == false){
87 GenerateProduceBlockThread(false, pWalletMain, 1);
88
89 obj.push_back(Pair("msg", "stoping mining"));
90 return obj;
91 }
92
93 GenerateProduceBlockThread(true, pWalletMain, genBlockLimit);
94 obj.push_back(Pair("msg", "in mining"));

Callers

nothing calls this directly

Calls 12

HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
JSONRPCErrorFunction · 0.85
PairClass · 0.85
get_boolMethod · 0.80
get_intMethod · 0.80
push_backMethod · 0.80
sizeMethod · 0.45
clearMethod · 0.45
GetKeysMethod · 0.45
GetAccountMethod · 0.45

Tested by

no test coverage detected