Search in sources :

Example 1 with LogResult

use of org.fisco.bcos.web3j.tx.txdecode.LogResult in project web3sdk by FISCO-BCOS.

the class Service method onReceiveEventLogPush.

public void onReceiveEventLogPush(ChannelHandlerContext ctx, BcosMessage message) {
    String content = new String(message.getData());
    try {
        EventLogFilterPushResponse resp = ObjectMapperFactory.getObjectMapper().readValue(content, EventLogFilterPushResponse.class);
        if (resp == null || Strings.isEmpty(resp.getFilterID())) {
            logger.error(" event log response invalid format, content: {}", content);
            return;
        }
        EventLogPushCallback callback = (EventLogPushCallback) eventLogFilterManager.getFilterCallback(resp.getFilterID());
        if (callback == null) {
            logger.debug(" event log push message cannot find callback, filterID: {}, content: {}", resp.getFilterID(), content);
            return;
        }
        if (resp.getResult() == EventLogFilterPushStatus.SUCCESS.getStatus()) {
            if (!resp.getLogs().isEmpty()) {
                List<LogResult> logResults = new ArrayList<LogResult>();
                for (Log log : resp.getLogs()) {
                    LogResult logResult = callback.transferLogToLogResult(log);
                    if (logResult == null) {
                        logger.warn(" event log push message decode failed, filterID: {}, log: {}", resp.getFilterID(), log);
                    } else {
                        logResults.add(logResult);
                    }
                }
                callback.onPushEventLog(EventLogFilterPushStatus.SUCCESS.getStatus(), logResults);
                // update status
                callback.getFilter().updateByLogResult(logResults);
                logger.info(" log size: {}, blocknumber: {}", logResults.size(), logResults.get(0).getLog().getBlockNumber());
            }
        } else if (resp.getResult() == EventLogFilterPushStatus.PUSH_COMPLETED.getStatus()) {
            // event log push end
            callback.onPushEventLog(EventLogFilterPushStatus.PUSH_COMPLETED.getStatus(), null);
            eventLogFilterManager.removeFilterAndCallback(callback.getFilter().getRegisterID(), resp.getFilterID());
            logger.info("event log push message push end, filterID: {}, registerID: {}, content: {}", resp.getFilterID(), callback.getFilter().getRegisterID(), content);
        } else {
            callback.onPushEventLog(resp.getResult(), null);
            // should remove callback function
            eventLogFilterManager.removeFilterAndCallback(callback.getFilter().getRegisterID(), resp.getFilterID());
            logger.warn("event log push message, filterID: {}, registerID: {}, code: {}, content: {}", resp.getFilterID(), callback.getFilter().getRegisterID(), resp.getResult(), content);
        }
    } catch (Exception e) {
        logger.error("event log push message exception, error message: {}, content: {}", e.getMessage(), content);
    }
}
Also used : EventLogPushCallback(org.fisco.bcos.channel.event.filter.EventLogPushCallback) Log(org.fisco.bcos.web3j.protocol.core.methods.response.Log) LogResult(org.fisco.bcos.web3j.tx.txdecode.LogResult) ArrayList(java.util.ArrayList) EventLogFilterPushResponse(org.fisco.bcos.channel.event.filter.EventLogFilterPushResponse) KeyStoreException(java.security.KeyStoreException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) TransactionException(org.fisco.bcos.web3j.protocol.exceptions.TransactionException) NoSuchProviderException(java.security.NoSuchProviderException)

Example 2 with LogResult

use of org.fisco.bcos.web3j.tx.txdecode.LogResult in project web3sdk by FISCO-BCOS.

the class ServiceEventLogPushCallback method transferLogToLogResult.

@Override
public LogResult transferLogToLogResult(Log log) {
    LogResult logResult = new LogResult();
    logResult.setLog(log);
    return logResult;
}
Also used : LogResult(org.fisco.bcos.web3j.tx.txdecode.LogResult)

Aggregations

LogResult (org.fisco.bcos.web3j.tx.txdecode.LogResult)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 NoSuchProviderException (java.security.NoSuchProviderException)1 CertificateException (java.security.cert.CertificateException)1 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)1 ArrayList (java.util.ArrayList)1 EventLogFilterPushResponse (org.fisco.bcos.channel.event.filter.EventLogFilterPushResponse)1 EventLogPushCallback (org.fisco.bcos.channel.event.filter.EventLogPushCallback)1 Log (org.fisco.bcos.web3j.protocol.core.methods.response.Log)1 TransactionException (org.fisco.bcos.web3j.protocol.exceptions.TransactionException)1