org.fisco.bcos.web3j.abi.EventEncoder Maven / Gradle / Ivy
package org.fisco.bcos.web3j.abi;
import java.util.List;
import java.util.stream.Collectors;
import org.fisco.bcos.web3j.abi.datatypes.Event;
import org.fisco.bcos.web3j.abi.datatypes.Type;
import org.fisco.bcos.web3j.crypto.Hash;
import org.fisco.bcos.web3j.utils.Numeric;
/**
* Ethereum filter encoding. Further limited details are available here.
*/
public class EventEncoder {
private EventEncoder() {}
public static String encode(Event event) {
String methodSignature = buildMethodSignature(event.getName(), event.getParameters());
return buildEventSignature(methodSignature);
}
static String buildMethodSignature(
String methodName, List> parameters) {
StringBuilder result = new StringBuilder();
result.append(methodName);
result.append("(");
String params =
parameters.stream().map(p -> Utils.getTypeName(p)).collect(Collectors.joining(","));
result.append(params);
result.append(")");
return result.toString();
}
public static String buildEventSignature(String methodSignature) {
byte[] input = methodSignature.getBytes();
byte[] hash = Hash.sha3(input);
return Numeric.toHexString(hash);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy