All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bcos.web3j.abi.EventEncoder Maven / Gradle / Ivy

There is a newer version: 2.6.6
Show newest version
package org.bcos.web3j.abi;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import org.bcos.web3j.abi.datatypes.Event;
import org.bcos.web3j.abi.datatypes.Type;
import org.bcos.web3j.crypto.Hash;
import org.bcos.web3j.utils.Numeric;

/**
 * 

Ethereum filter encoding. * Further limited details are available * here. *

*/ public class EventEncoder { private EventEncoder() { } public static String encode(Event function) { List> indexedParameters = function.getIndexedParameters(); List> nonIndexedParameters = function.getNonIndexedParameters(); String methodSignature = buildMethodSignature(function.getName(), indexedParameters, nonIndexedParameters); return buildEventSignature(methodSignature); } static String buildMethodSignature( String methodName, List> indexParameters, List> nonIndexedParameters) { List> parameters = new ArrayList<>(indexParameters); parameters.addAll(nonIndexedParameters); 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(); } 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