| 746 | } |
| 747 | |
| 748 | Value listcontracts(const Array& params, bool fHelp) { |
| 749 | if (fHelp || params.size() != 1) { |
| 750 | throw runtime_error( |
| 751 | "listcontracts \"show detail\"\n" |
| 752 | "\nget the list of all contracts\n" |
| 753 | "\nArguments:\n" |
| 754 | "1. show detail (boolean, required) show contract in detail if true.\n" |
| 755 | "\nReturn an object contains all contracts\n" |
| 756 | "\nResult:\n" |
| 757 | "\nExamples:\n" + |
| 758 | HelpExampleCli("listcontracts", "true") + "\nAs json rpc call\n" + HelpExampleRpc("listcontracts", "true")); |
| 759 | } |
| 760 | |
| 761 | bool showDetail = params[0].get_bool(); |
| 762 | |
| 763 | auto dbIt = MakeDbIterator(pCdMan->pContractCache->contractCache); |
| 764 | Object obj; |
| 765 | Array contractArray; |
| 766 | for (dbIt->First(); dbIt->IsValid(); dbIt->Next()) { |
| 767 | Object contractObject; |
| 768 | const auto ®idKey = dbIt->GetKey(); |
| 769 | const CUniversalContractStore &contract = dbIt->GetValue(); |
| 770 | contractObject.push_back(Pair("contract_regid", regidKey.ToString())); |
| 771 | contractObject.push_back(Pair("memo", contract.memo)); |
| 772 | |
| 773 | if (showDetail) { |
| 774 | contractObject.push_back(Pair("vm_type", contract.vm_type)); |
| 775 | contractObject.push_back(Pair("upgradable", contract.upgradable)); |
| 776 | contractObject.push_back(Pair("code", HexStr(contract.code))); |
| 777 | contractObject.push_back(Pair("abi", contract.abi)); |
| 778 | } |
| 779 | |
| 780 | contractArray.push_back(contractObject); |
| 781 | } |
| 782 | |
| 783 | obj.push_back(Pair("count", contractArray.size())); |
| 784 | obj.push_back(Pair("contracts", contractArray)); |
| 785 | |
| 786 | return obj; |
| 787 | } |
| 788 | |
| 789 | Value getcontractinfo(const Array& params, bool fHelp) { |
| 790 | if (fHelp || params.size() != 1) |
nothing calls this directly
no test coverage detected