MCPcopy Create free account
hub / github.com/LUX-Core/lux / waitforlogs

Function waitforlogs

src/rpcblockchain.cpp:742–871  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

740};
741
742UniValue waitforlogs(const UniValue& params, bool fHelp) {
743 if (fHelp) {
744 throw std::runtime_error(
745 "waitforlogs (fromBlock) (toBlock) (filter) (minconf)\n"
746 "requires -logevents to be enabled\n"
747 "\nWaits for a new logs and return matching log entries. When the call returns, it also specifies the next block number to start waiting for new logs.\n"
748 "By calling waitforlogs repeatedly using the returned nextBlock number, a client can receive a stream of the current log entires.\n"
749 "\nThis call is different from the similarly named waitforlogs. This call returns individual matching log entries, `searchlogs` returns a transaction receipt if one of the log entries of that transaction matches the filter conditions.\n"
750 "\nArguments:\n"
751 "1. fromBlock (int | \"latest\", optional, default=null) The block number to start looking for logs. ()\n"
752 "2. toBlock (int | \"latest\", optional, default=null) The block number to stop looking for logs. If null, will wait indefinitely into the future.\n"
753 "3. filter ({ addresses?: Hex160String[], topics?: Hex256String[] }, optional default={}) Filter conditions for logs. Addresses and topics are specified as array of hexadecimal strings\n"
754 "4. minconf (uint, optional, default=6) Minimal number of confirmations before a log is returned\n"
755 "\nResult:\n"
756 "An object with the following properties:\n"
757 "1. logs (LogEntry[]) Array of matchiing log entries. This may be empty if `filter` removed all entries."
758 "2. count (int) How many log entries are returned."
759 "3. nextBlock (int) To wait for new log entries haven't seen before, use this number as `fromBlock`"
760 "\nUsage:\n"
761 "`waitforlogs` waits for new logs, starting from the tip of the chain.\n"
762 "`waitforlogs 600` waits for new logs, but starting from block 600. If there are logs available, this call will return immediately.\n"
763 "`waitforlogs 600 700` waits for new logs, but only up to 700th block\n"
764 "`waitforlogs null null` this is equivalent to `waitforlogs`, using default parameter values\n"
765 "`waitforlogs null null` { \"addresses\": [ \"ff0011...\" ], \"topics\": [ \"c0fefe\"] }` waits for logs in the future matching the specified conditions\n"
766 "\nSample Output:\n"
767 "{\n\"entries\": [\n {\n\"blockHash\": \"000000000013ca244452d2af443a3de40d9084fa1b12755e421178faaa329bdf\",\n\"blockNumber\": 352754,\n\"transactionHash\": \"23dbfa9bcb0ce1b0247e04563de558edbbd6cdf3b08f13a5643994476f3d9d3a\",\n"
768 );
769 }
770
771 if (!fLogEvents)
772 throw JSONRPCError(RPC_INTERNAL_ERROR, "Events indexing disabled");
773
774 WaitForLogsParams logsParams(params);
775
776 std::vector<std::vector<uint256>> hashesToBlock;
777
778 int curheight = 0;
779
780 auto& addresses = logsParams.addresses;
781 auto& filterTopics = logsParams.topics;
782
783 while (curheight == 0) {
784 {
785 LOCK(cs_main);
786 curheight = pblocktree->ReadHeightIndex(logsParams.fromBlock, logsParams.toBlock, logsParams.minconf,
787 hashesToBlock, addresses);
788 }
789
790 if (curheight > 0) {
791 break;
792 }
793
794 if (curheight == -1) {
795 throw JSONRPCError(RPC_INVALID_PARAMETER, "Incorrect params");
796 }
797
798 // wait for a new block to arrive
799 {

Callers

nothing calls this directly

Calls 12

JSONRPCErrorFunction · 0.85
IsRPCRunningFunction · 0.85
uintToh256Function · 0.85
assignJSONFunction · 0.85
PairFunction · 0.85
ReadHeightIndexMethod · 0.80
getResultMethod · 0.80
wait_forMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45
getMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected