| 621 | }; |
| 622 | |
| 623 | UniValue searchlogs(const UniValue& params, bool fHelp) |
| 624 | { |
| 625 | if (fHelp || params.size() < 2) |
| 626 | throw std::runtime_error( |
| 627 | "searchlogs <fromBlock> <toBlock> (address) (topics)\n" |
| 628 | "requires -logevents to be enabled" |
| 629 | "\nArgument:\n" |
| 630 | "1. \"fromBlock\" (numeric, required) The number of the earliest block (latest may be given to mean the most recent block).\n" |
| 631 | "2. \"toBlock\" (string, required) The number of the latest block (-1 may be given to mean the most recent block).\n" |
| 632 | "3. \"address\" (string, optional) An address or a list of addresses to only get logs from particular account(s).\n" |
| 633 | "4. \"topics\" (string, optional) An array of values from which at least one must appear in the log entries. The order is important, if you want to leave topics out use null, e.g. [\"null\", \"0x00...\"]. \n" |
| 634 | "5. \"minconf\" (uint, optional, default=0) Minimal number of confirmations before a log is returned\n" |
| 635 | "\nExamples:\n" |
| 636 | + HelpExampleCli("searchlogs", "0 472000 '{\"addresses\": [\"04159f89d938b5d2de4b67bdbf482f788a97946a\"]}' '{\"topics\": [\"null\",\"ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef\"]}'") |
| 637 | + HelpExampleRpc("searchlogs", "0 472000 {\"addresses\": [\"04159f89d938b5d2de4b67bdbf482f788a97946a\"]} {\"topics\": [\"null\",\"ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef\"]}") |
| 638 | ); |
| 639 | |
| 640 | if(!fLogEvents) |
| 641 | throw JSONRPCError(RPC_INTERNAL_ERROR, "Events indexing disabled"); |
| 642 | |
| 643 | int curheight = 0; |
| 644 | |
| 645 | LOCK(cs_main); |
| 646 | |
| 647 | SearchLogsParams logsParams(params); |
| 648 | |
| 649 | std::vector<std::vector<uint256>> hashesToBlock; |
| 650 | |
| 651 | curheight = pblocktree->ReadHeightIndex(logsParams.fromBlock, logsParams.toBlock, logsParams.minconf, hashesToBlock, logsParams.addresses); |
| 652 | |
| 653 | if (curheight == -1) { |
| 654 | throw JSONRPCError(RPC_INVALID_PARAMETER, "Incorrect params"); |
| 655 | } |
| 656 | |
| 657 | UniValue result(UniValue::VARR); |
| 658 | |
| 659 | auto topics = logsParams.topics; |
| 660 | |
| 661 | for(const auto& hashesTx : hashesToBlock) |
| 662 | { |
| 663 | for(const auto& e : hashesTx) |
| 664 | { |
| 665 | std::vector<TransactionReceiptInfo> receipts = pstorageresult->getResult(uintToh256(e)); |
| 666 | |
| 667 | for(const auto& receipt : receipts) { |
| 668 | if(receipt.logs.empty()) { |
| 669 | continue; |
| 670 | } |
| 671 | |
| 672 | if (!topics.empty()) { |
| 673 | for (size_t i = 0; i < topics.size(); i++) { |
| 674 | const auto& tc = topics[i]; |
| 675 | |
| 676 | if (!tc) { |
| 677 | continue; |
| 678 | } |
| 679 | |
| 680 | for (const auto& log: receipt.logs) { |
nothing calls this directly
no test coverage detected