Skip to content

Commit

Permalink
Merge pull request #27 from keyko-io/issue/add_bool_type
Browse files Browse the repository at this point in the history
support for web3 boolean types
  • Loading branch information
josepablofm78 authored Apr 3, 2020
2 parents b2ed76c + 95a4625 commit 23a45ad
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.keyko.monitoring</groupId>
<artifactId>web3-event-streamer</artifactId>
<version>0.2.4</version>
<version>0.2.5</version>
<name>Web3 Monitoring Event Streamer</name>
<url>https://github.com/keyko-io/web3-event-streamer</url>
<inceptionYear>2019</inceptionYear>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.keyko.monitoring.exceptions;

public class TypeConversionException extends EventStreamerException {

public TypeConversionException(String message, Throwable e) {
super(message, e);
}

public TypeConversionException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.keyko.monitoring.preprocessing;

import io.keyko.monitoring.exceptions.EventFromLogException;
import io.keyko.monitoring.exceptions.TypeConversionException;
import io.keyko.monitoring.schemas.*;
import io.keyko.monitoring.serde.Web3MonitoringSerdes;
import io.keyko.monitoring.services.EventLogService;
Expand Down Expand Up @@ -191,7 +192,7 @@ public static KStream<String, EventRecord> transformLogToEvent (KStream<String,
eventFromLog = EventLogService.getEventFromLog(logRecord, getContractAbiUrl, apiKey);
log.debug("Get eventRecord from LogRecord OK!");
return Arrays.asList(eventFromLog);
} catch (EventFromLogException e) {
} catch (EventFromLogException| TypeConversionException e) {
log.debug("Error getting eventRecord from logRecord: " + e.getMessage());
if (sendErrorsToTopic){
log.debug("Sending logRecord to error topic in Kakfa");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.keyko.monitoring.exceptions.AbiNotFoundException;
import io.keyko.monitoring.exceptions.EtherscanException;
import io.keyko.monitoring.exceptions.EventFromLogException;
import io.keyko.monitoring.exceptions.TypeConversionException;
import io.keyko.monitoring.model.ContractData;
import io.keyko.monitoring.schemas.*;
import org.apache.log4j.Logger;
Expand All @@ -22,7 +23,7 @@ public class EventLogService {

private static Logger log = Logger.getLogger(EventLogService.class);

public static EventRecord getEventFromLog(LogRecord log, String getContractAbiUrl, String apiKey) throws EventFromLogException {
public static EventRecord getEventFromLog(LogRecord log, String getContractAbiUrl, String apiKey) throws EventFromLogException, TypeConversionException {

String contractAddress = log.getAddress();
ContractData contractData = null;
Expand Down Expand Up @@ -141,7 +142,7 @@ else if (o instanceof StringParameter) {

}

private static List<Object> web3ToMonitoringType(List<Type> parameters, AbiDefinition eventAbi, Boolean indexed) {
private static List<Object> web3ToMonitoringType(List<Type> parameters, AbiDefinition eventAbi, Boolean indexed) throws TypeConversionException {

List<Object> monitoringParameters = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.keyko.monitoring.services;

import io.keyko.monitoring.exceptions.TypeConversionException;
import io.keyko.monitoring.schemas.NumberParameter;
import io.keyko.monitoring.schemas.StringParameter;
import org.web3j.abi.datatypes.Type;
Expand All @@ -11,7 +12,7 @@
public class Web3ParameterConverter {


public static Object convertWeb3Type(Type parameter, String name) {
public static Object convertWeb3Type(Type parameter, String name) throws TypeConversionException {

String parameterType = parameter.getTypeAsString();

Expand All @@ -26,10 +27,15 @@ public static Object convertWeb3Type(Type parameter, String name) {
return new NumberParameter(name, parameterType, value.toString(), truncateToLong(value));
}

if (parameterType.equals("bool")) {
BigInteger value = (Boolean) parameter.getValue() ? BigInteger.ONE : BigInteger.ZERO;
return new NumberParameter(name, parameterType, value.toString(), truncateToLong(value));
}

if (parameterType.startsWith("bytes"))
return new StringParameter(name, parameterType, trim(Numeric.toHexString((byte[]) parameter.getValue())));

return null;
throw new TypeConversionException("Unsupported type: " + parameterType);

}

Expand Down

0 comments on commit 23a45ad

Please sign in to comment.