| 140 | } |
| 141 | |
| 142 | static RPCMethod getnetworkhashps() |
| 143 | { |
| 144 | return RPCMethod{ |
| 145 | "getnetworkhashps", |
| 146 | "Returns the estimated network hashes per second based on the last n blocks.\n" |
| 147 | "Pass in [blocks] to override # of blocks, -1 specifies since last difficulty change.\n" |
| 148 | "Pass in [height] to estimate the network speed at the time when a certain block was found.\n", |
| 149 | { |
| 150 | {"nblocks", RPCArg::Type::NUM, RPCArg::Default{120}, "The number of previous blocks to calculate estimate from, or -1 for blocks since last difficulty change."}, |
| 151 | {"height", RPCArg::Type::NUM, RPCArg::Default{-1}, "To estimate at the time of the given height."}, |
| 152 | }, |
| 153 | RPCResult{ |
| 154 | RPCResult::Type::NUM, "", "Hashes per second estimated"}, |
| 155 | RPCExamples{ |
| 156 | HelpExampleCli("getnetworkhashps", "") |
| 157 | + HelpExampleRpc("getnetworkhashps", "") |
| 158 | }, |
| 159 | [](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue |
| 160 | { |
| 161 | ChainstateManager& chainman = EnsureAnyChainman(request.context); |
| 162 | LOCK(cs_main); |
| 163 | return GetNetworkHashPS(self.Arg<int>("nblocks"), self.Arg<int>("height"), chainman.ActiveChain()); |
| 164 | }, |
| 165 | }; |
| 166 | } |
| 167 | |
| 168 | static bool GenerateBlock(ChainstateManager& chainman, CBlock&& block, uint64_t& max_tries, std::shared_ptr<const CBlock>& block_out, bool process_new_block) |
| 169 | { |
no test coverage detected