从javascript访问事件日志是简单而直接的,但是我试图从Java客户机访问日志。任何示例代码都会有所帮助。
发布于 2016-07-13 20:28:35
您可以使用JsonRpc类对块的日志执行筛选。您可以从EthereumImpl的实例中获得它,如下所示:
JsonRpc jsonrpc = ethereum.getApplicationContext().getBean(JsonRpc.class);
然后,可以传递给它一个FilterRequest对象,告诉它要搜索什么:
FilterRequest fr = new FilterRequest();
fr.fromBlock = "latest";
fr.toBlock = "latest";
fr.address = ""; //String or String[] - addresses to match
fr.topics = ...//String or String[] of topics to match
//Hash of event signature is first, then indexed parameters
//I believe you can give it a String[][] also, so for each param in the event you can filter for multiple options
Object[] logs = jsonrpc.eth_getLogs(fr);
for(Object logObject : logs) {
LogFilterElement log = (LogFilterElement)logObject;
//do stuff with the log of the event
}
LogFilterElement有来自事件的地址、主题和数据,但是它仍然是十六进制格式,所以您必须对其进行解码。事件的索引值仅在主题中找到,而索引的可变长度数据(如字符串或字节)仅作为散列存储在主题中。
我编写了一个EthereumEventManager类来自己处理这些东西。你可以看看它,这里。您可以为筛选器请求添加侦听器,然后侦听新块,并在找到这些筛选器请求时通知它们。随意使用它,修改它,或从它中学习你认为合适的。这不是很好的文件,但如果你有任何问题,我很乐意回答它们。
发布于 2016-06-20 13:50:36
您可以从onTransactionExecuted接口监听EthereumListner (),并使用TransactionExecutionSummary对象检索日志信息,参见事件跟踪和从ethereumj解码。
有关更多细节,请参见所提供的答案。
https://ethereum.stackexchange.com/questions/6315
复制相似问题