<?php
$_HTML['title'] = 'Eth Event Log';
$_HTML['meta']['keywords'] = "Eth Event Loge,Eth Event Log in PHP,PHP";
include_once "../common.php";
include_once("html_header.php");

?>
<h2 class="mt-3">Ethereum Event Log</h2>
<hr/>
	<p>
		The log mechanism is one of the most important features of a virtual machine, which is used to output specific binary data and record it in transaction-receipt while the virtual machine is running a contract. Based on the Log mechanism, the Event feature is implemented to help developers confirm, check, and quickly retrieve specific states of a smart contract. This article introduces the basics of the Event mechanism and how to decode the Event Log.
	</p>
<hr/>
<ul>
	<li>Events in Solidity are defined by the <span class='grey_info'>event</span> keyword.</li>
	<li>Logging an event is implemented by <span class='grey_info'>emit</span> keyword.</li>
	<li>An event function can contain several indexed or unindexed parameters.<br/>
		More about <span class='grey_info'>indexed</span> keyword: 
		<ul>
			<li>Ease of searching, generated logs will be added to bloom filter.</li>
			<li>In codings, it is only relevant to event function.</li>
			<li>Maximum up to three indexed arguments in event function.</li>
		</ul>
	</li>
	</li>
	<li>Gas cost by event emit <span class='grey_info'>375 + 375 * numberOfIndexedParameters + numberOfUnindexedBits</span>. For example
		<pre>
// 375 + 375 * 0 + 160 (address always 160 bits) = 535
event NewEvent(address addr)

// 375 + 375 * 1 + 0 = 750
event NewEvent(address indexed addr) 
		</pre>
	</li>
</ul>
<hr/>
<h3 class="mt-3" id='hashtag2'>Event Log Decoder</h3>

<p>
Maximum records return  from <B>eth_getLogs</B> is up to 10,000 otherwise error is return. 
</p>


<ul class="nav nav-tabs">
	<li class="nav-item">
		<a data-toggle="tab" class="nav-link active" href="#form1_tabitem1">Visual</a>
	</li>
	<li class="nav-item">
		<a data-toggle="tab" class="nav-link" href="#form1_tabitem2">Coding</a>
	</li>
</ul>
<div class="tab-content">
	<div id="form1_tabitem1" class="tab-pane fade show active">
		<iframe src="eth_event_log_decode.php" width="100%" scrolling="no" frameborder="no"></iframe>
	</div>
	<div id="form1_tabitem2" class="tab-pane fade">
<pre style='border-radius:none;'><?php echo htmlentities(file_get_contents("eth_event_log_decode.php"));?></pre> 		
	</div>
</div>

<h3 class="mt-3" id='hashtag2'>"OR" Logical Operator</h3>
<p>
In <span class='grey_info'>Event Log Decoder</span> section, we have demonstrate usage of both "NULL" and "AND". This section we will show more examples include usage of "OR" for better understanding.
</p>

<div class="table-responsive">
	<table class="table table-sm table-bordered">
		<tr><th style='width:30%;'>Topics Array</th><th>Description</th></tr>
		<tr><td>[]</td><td>Anything</td></tr>
		<tr><td>[ A ]</td><td rowspan=2>topic[0] = A</td></tr>
		<tr><td>[ A, null ]</td></tr>
		<tr><td>[ null, B ]</td><td rowspan=3>topic[1] = B</td></tr>
		<tr><td>[ null, [ B ] ]</td></tr>
		<tr><td>[ null, [ B ], null ]</td></tr>
		<tr><td>[ A, B ]</td><td rowspan=3>(topic[0] = A) AND (topic[1] = B)</td></tr>
		<tr><td>[ A, [ B ] ]</td></tr>
		<tr><td>[ A, [ B ], null ]</td></tr>
		
		<tr><td>[ [ A, B ] ]</td><td rowspan=2>(topic[0] = A) OR (topic[0] = B)</td></tr>
		<tr><td>[ [ A, B ], null ]</td></tr>
		
		<tr><td>[ [ A, B ], [ C, D ] ]</td><td>[ (topic[0] = A) OR (topic[0] = B) ] AND [ (topic[1] = C) OR (topic[1] = D) ]</td></tr>
	</table>
</div>

<h3 class="mt-3" id='hashtag2'>Other Filter Log Methods</h3>
<p>
	Methods listed in table below are useful to get data with polling methods such as Websocket, Long Polling, Short Polling, HTTP2, Server-Sent Events(sse) and etc.
</p>

<div class="table-responsive">
	<table class="table table-sm table-bordered">
		<tr><th style='width:30%;'>Method</th><th>Description</th></tr>
		<tr><td>eth_newFilter</td><td>Take same parameter as  <span class='grey_info'>eth_getLogs</span>, but return a filter ID.</td></tr>
		<tr><td>eth_newBlockFilter</td><td>Return filter ID, and filter effects on new block.</td></tr>
		<tr><td>eth_getFilterLogs</td><td>Pass in filter ID that generated by eth_newFilter and as the result this return an array of logs.</td></tr>
		<tr><td>eth_getFilterChanges</td><td>Polling method. Its Return subject to type of filter ID, either an array of logs or new block which occurred since last poll. Filter ID can be implicitly remove if time out occur due to inactivity.</td></tr>
		<tr><td>eth_uninstallFilter</td><td>Explicitly remove pre-existing filter ID.</td></tr>
		

	</table>
</div>

<h3 class="mt-3" id='hashtag2'>Bloom Filter</h3>
<p>
	This section is alias of <a href="eth_bloom_filter.php">Bloom Filter</a> page.
</p>

<?php
include_once("html_footer.php");