| 702 | } |
| 703 | |
| 704 | Value disconnectblock(const Array& params, bool fHelp) { |
| 705 | if (fHelp || params.size() != 1) { |
| 706 | throw runtime_error("disconnectblock \"numbers\"\n" |
| 707 | "\ndisconnect block\n" |
| 708 | "\nArguments:\n" |
| 709 | "1. \"number \" (numeric, required) the number of block(s) to be disconnected\n" |
| 710 | "\nResult:\n" |
| 711 | "\"disconnect result\" (bool) \n" |
| 712 | "\nExamples:\n" |
| 713 | + HelpExampleCli("disconnectblock", "\"1\"") |
| 714 | + "\nAs json rpc call\n" |
| 715 | + HelpExampleRpc("disconnectblock", "\"1\"")); |
| 716 | } |
| 717 | int32_t number = params[0].get_int(); |
| 718 | |
| 719 | |
| 720 | if (number >= chainActive.Height()) |
| 721 | throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid number"); |
| 722 | |
| 723 | if (number > 0) { |
| 724 | CValidationState state; |
| 725 | do { |
| 726 | CBlockIndex * pTipIndex = chainActive.Tip(); |
| 727 | if (!DisconnectTip(state)) |
| 728 | throw JSONRPCError(RPC_MISC_ERROR, "DisconnectTip err"); |
| 729 | |
| 730 | chainMostWork.SetTip(pTipIndex->pprev); |
| 731 | if (!EraseBlockIndexFromSet(pTipIndex)) |
| 732 | throw JSONRPCError(RPC_MISC_ERROR, "EraseBlockIndexFromSet err"); |
| 733 | |
| 734 | if (!pCdMan->pBlockIndexDb->EraseBlockIndex(pTipIndex->GetBlockHash())) |
| 735 | throw JSONRPCError(RPC_MISC_ERROR, "EraseBlockIndex err"); |
| 736 | |
| 737 | mapBlockIndex.erase(pTipIndex->GetBlockHash()); |
| 738 | } while (--number); |
| 739 | } |
| 740 | |
| 741 | Object obj; |
| 742 | obj.push_back( |
| 743 | Pair("tip", strprintf("hash:%s hight:%s", chainActive.Tip()->GetBlockHash().ToString(), chainActive.Height()))); |
| 744 | |
| 745 | return obj; |
| 746 | } |
| 747 | |
| 748 | Value listcontracts(const Array& params, bool fHelp) { |
| 749 | if (fHelp || params.size() != 1) { |
nothing calls this directly
no test coverage detected