Class ABI


  • public class ABI
    extends java.lang.Object
    Representing a ABI type encode / decode.
    • Constructor Summary

      Constructors 
      Constructor Description
      ABI()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String buildEventString​(ContractEvent event)
      Build a event name string.
      static java.lang.String buildFunctionString​(ContractMethod method)
      Build a function name string.
      static java.util.List<Type> decodeFunctionCall​(ContractMethod method, java.lang.String encodedString)
      Decodes a function call data that composed of function selector and encoded input argument.
      static java.util.List<Type> decodeFunctionCall​(java.lang.String functionAbi, java.lang.String encodedString)
      Decodes a function call data that composed of function selector and encoded input argument.
      static EventValues decodeLog​(java.util.List<ContractIOType> inputs, java.lang.String data, java.util.List<java.lang.String> topics)
      Decodes an ABI encoded log data and indexed topic data
      static Type decodeParameter​(java.lang.String solidityType, java.lang.String encoded)
      Decodes an ABI encoded parameter.
      static java.util.List<Type> decodeParameters​(ContractMethod method, java.lang.String encoded)
      Decodes an ABI encoded output parameters.
      static java.util.List<Type> decodeParameters​(java.util.List<java.lang.String> solidityTypeList, java.lang.String encoded)
      Decodes an ABI encoded parameters.
      static java.lang.String encodeContractDeploy​(ContractMethod constructor, java.lang.String byteCode, java.util.List<java.lang.Object> constructorParams)
      Encodes a data related contract deployment.
      static java.lang.String encodeEventSignature​(ContractEvent event)
      Encodes a event signature.
      static java.lang.String encodeEventSignature​(java.lang.String eventName)
      Encodes a event signature.
      static java.lang.String encodeFunctionCall​(ContractMethod method, java.util.List<java.lang.Object> params)
      Encodes a function call.
      static java.lang.String encodeFunctionCall​(java.lang.String functionSig, java.util.List<java.lang.String> solTypeList, java.util.List<java.lang.Object> params)
      Encodes a function call.
      static java.lang.String encodeFunctionCallWithSolidityWrapper​(ContractMethod method, java.util.List<Type> params)
      Encodes a function call
      static java.lang.String encodeFunctionSignature​(ContractMethod method)
      Encodes a function signature.
      static java.lang.String encodeFunctionSignature​(java.lang.String functionName)
      Encodes a function signature.
      static java.lang.String encodeParameter​(Type parameter)
      Encodes a parameter based on its type to its ABI representation.
      static java.lang.String encodeParameter​(java.lang.String solidityType, java.lang.Object value)
      Encodes a parameter based on its type to its ABI representation.
      static java.lang.String encodeParameters​(ContractMethod method, java.util.List<java.lang.Object> values)
      Encodes a parameters based on its type to its ABI representation.
      static java.lang.String encodeParameters​(java.util.List<Type> parameters)
      Encodes a parameter based on its type to its ABI representation.
      static java.lang.String encodeParameters​(java.util.List<java.lang.String> solidityTypes, java.util.List<java.lang.Object> values)
      Encodes a parameters based on its type to its ABI representation.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ABI

        public ABI()
    • Method Detail

      • encodeFunctionCall

        public static java.lang.String encodeFunctionCall​(ContractMethod method,
                                                          java.util.List<java.lang.Object> params)
                                                   throws java.lang.ClassNotFoundException,
                                                          java.lang.NoSuchMethodException,
                                                          java.lang.reflect.InvocationTargetException,
                                                          java.lang.InstantiationException,
                                                          java.lang.IllegalAccessException
        Encodes a function call.
        Parameters:
        method - A ContractMethod instance.
        params - A List of method parameter.
        Returns:
        String
        Throws:
        java.lang.ClassNotFoundException
        java.lang.NoSuchMethodException
        java.lang.reflect.InvocationTargetException
        java.lang.InstantiationException
        java.lang.IllegalAccessException
      • encodeFunctionCall

        public static java.lang.String encodeFunctionCall​(java.lang.String functionSig,
                                                          java.util.List<java.lang.String> solTypeList,
                                                          java.util.List<java.lang.Object> params)
                                                   throws java.lang.ClassNotFoundException,
                                                          java.lang.NoSuchMethodException,
                                                          java.lang.reflect.InvocationTargetException,
                                                          java.lang.InstantiationException,
                                                          java.lang.IllegalAccessException
        Encodes a function call.
        Parameters:
        functionSig - A function signature string.
        params - A List of method parameter.
        Returns:
        String
        Throws:
        java.lang.ClassNotFoundException
        java.lang.NoSuchMethodException
        java.lang.reflect.InvocationTargetException
        java.lang.InstantiationException
        java.lang.IllegalAccessException
      • encodeFunctionCallWithSolidityWrapper

        public static java.lang.String encodeFunctionCallWithSolidityWrapper​(ContractMethod method,
                                                                             java.util.List<Type> params)
        Encodes a function call
        Parameters:
        method - A ContractMethod instance.
        params - A List of method parameter wrapped solidity wrapper class.
        Returns:
        String
      • encodeFunctionSignature

        public static java.lang.String encodeFunctionSignature​(ContractMethod method)
        Encodes a function signature.
        Parameters:
        method - A ContractMethod instance.
        Returns:
        String
      • encodeFunctionSignature

        public static java.lang.String encodeFunctionSignature​(java.lang.String functionName)
        Encodes a function signature.
        Parameters:
        functionName - A function name string.
        Returns:
        String
      • encodeContractDeploy

        public static java.lang.String encodeContractDeploy​(ContractMethod constructor,
                                                            java.lang.String byteCode,
                                                            java.util.List<java.lang.Object> constructorParams)
                                                     throws java.lang.ClassNotFoundException,
                                                            java.lang.NoSuchMethodException,
                                                            java.lang.InstantiationException,
                                                            java.lang.IllegalAccessException,
                                                            java.lang.reflect.InvocationTargetException
        Encodes a data related contract deployment.
        Parameters:
        constructor - A ContractMethod instance that contains constructor info.
        byteCode - A smart contract bytecode.
        constructorParams - A list of parameter that need to execute Constructor
        Returns:
        String
        Throws:
        java.lang.ClassNotFoundException
        java.lang.NoSuchMethodException
        java.lang.InstantiationException
        java.lang.IllegalAccessException
        java.lang.reflect.InvocationTargetException
      • buildFunctionString

        public static java.lang.String buildFunctionString​(ContractMethod method)
        Build a function name string.
        Parameters:
        method - A ContractMethod instance.
        Returns:
        String
      • encodeEventSignature

        public static java.lang.String encodeEventSignature​(ContractEvent event)
        Encodes a event signature.
        Parameters:
        event - A ContractEvent instance.
        Returns:
        String
      • encodeEventSignature

        public static java.lang.String encodeEventSignature​(java.lang.String eventName)
        Encodes a event signature.
        Parameters:
        eventName - A event signature.
        Returns:
        String
      • buildEventString

        public static java.lang.String buildEventString​(ContractEvent event)
        Build a event name string.
        Parameters:
        event - A ContractEvent instance
        Returns:
        String
      • encodeParameter

        public static java.lang.String encodeParameter​(java.lang.String solidityType,
                                                       java.lang.Object value)
                                                throws java.lang.ClassNotFoundException,
                                                       java.lang.NoSuchMethodException,
                                                       java.lang.InstantiationException,
                                                       java.lang.IllegalAccessException,
                                                       java.lang.reflect.InvocationTargetException
        Encodes a parameter based on its type to its ABI representation.
        Parameters:
        solidityType - A solidity type to encode.
        value - A value to encode
        Returns:
        String
        Throws:
        java.lang.ClassNotFoundException
        java.lang.NoSuchMethodException
        java.lang.InstantiationException
        java.lang.IllegalAccessException
        java.lang.reflect.InvocationTargetException
      • encodeParameters

        public static java.lang.String encodeParameters​(ContractMethod method,
                                                        java.util.List<java.lang.Object> values)
                                                 throws java.lang.ClassNotFoundException,
                                                        java.lang.NoSuchMethodException,
                                                        java.lang.reflect.InvocationTargetException,
                                                        java.lang.InstantiationException,
                                                        java.lang.IllegalAccessException
        Encodes a parameters based on its type to its ABI representation.
        Parameters:
        method - A ContractMethod instance that contains to solidity type
        values - A List of value to encode
        Returns:
        String
        Throws:
        java.lang.ClassNotFoundException
        java.lang.NoSuchMethodException
        java.lang.reflect.InvocationTargetException
        java.lang.InstantiationException
        java.lang.IllegalAccessException
      • encodeParameters

        public static java.lang.String encodeParameters​(java.util.List<java.lang.String> solidityTypes,
                                                        java.util.List<java.lang.Object> values)
                                                 throws java.lang.ClassNotFoundException,
                                                        java.lang.NoSuchMethodException,
                                                        java.lang.InstantiationException,
                                                        java.lang.IllegalAccessException,
                                                        java.lang.reflect.InvocationTargetException
        Encodes a parameters based on its type to its ABI representation.
        Parameters:
        solidityTypes - A list of solidity type to encode
        values - A List of value to encode
        Returns:
        String
        Throws:
        java.lang.ClassNotFoundException
        java.lang.NoSuchMethodException
        java.lang.InstantiationException
        java.lang.IllegalAccessException
        java.lang.reflect.InvocationTargetException
      • encodeParameter

        public static java.lang.String encodeParameter​(Type parameter)
        Encodes a parameter based on its type to its ABI representation.
        Parameters:
        parameter - A parameter that wrapped solidity type wrapper.
        Returns:
        String
      • encodeParameters

        public static java.lang.String encodeParameters​(java.util.List<Type> parameters)
        Encodes a parameter based on its type to its ABI representation.
        Parameters:
        parameters - A List of parameters that wrappped solidity type wrapper
        Returns:
        String
      • decodeParameter

        public static Type decodeParameter​(java.lang.String solidityType,
                                           java.lang.String encoded)
                                    throws java.lang.ClassNotFoundException
        Decodes an ABI encoded parameter.
        Parameters:
        solidityType - A solidity type string.
        encoded - The ABI byte code to decode
        Returns:
        Type
        Throws:
        java.lang.ClassNotFoundException
      • decodeParameters

        public static java.util.List<Type> decodeParameters​(java.util.List<java.lang.String> solidityTypeList,
                                                            java.lang.String encoded)
                                                     throws java.lang.ClassNotFoundException
        Decodes an ABI encoded parameters.
        Parameters:
        solidityTypeList - A List of solidity type string.
        encoded - The ABI byte code to decode
        Returns:
        List
        Throws:
        java.lang.ClassNotFoundException
      • decodeParameters

        public static java.util.List<Type> decodeParameters​(ContractMethod method,
                                                            java.lang.String encoded)
                                                     throws java.lang.ClassNotFoundException
        Decodes an ABI encoded output parameters.
        Parameters:
        method - A ContractMethod instance.
        encoded - The ABI byte code to decoded
        Returns:
        List
        Throws:
        java.lang.ClassNotFoundException
      • decodeLog

        public static EventValues decodeLog​(java.util.List<ContractIOType> inputs,
                                            java.lang.String data,
                                            java.util.List<java.lang.String> topics)
                                     throws java.lang.ClassNotFoundException
        Decodes an ABI encoded log data and indexed topic data
        Parameters:
        inputs - A list of ContractIOType instance.
        data - An ABI-encoded in the data field of a log
        topics - A list of indexed parameter topics of the log.
        Returns:
        EventValues
        Throws:
        java.lang.ClassNotFoundException
      • decodeFunctionCall

        public static java.util.List<Type> decodeFunctionCall​(java.lang.String functionAbi,
                                                              java.lang.String encodedString)
                                                       throws java.lang.ClassNotFoundException
        Decodes a function call data that composed of function selector and encoded input argument.
        Example :
         
          String encodedData = "0x24ee0.....";
          String abi = "{\n" +
                             "  \"name\":\"myMethod\",\n" +
                             "  \"type\":\"function\",\n" +
                             "  \"inputs\":[\n" +
                             "    {\n" +
                             "      \"type\":\"uint256\",\n" +
                             "      \"name\":\"myNumber\"\n" +
                             "    },\n" +
                             "    {\n" +
                             "      \"type\":\"string\",\n" +
                             "      \"name\":\"mystring\"\n" +
                             "    }\n" +
                             "  ]\n" +
                             "}";
        
         List<Type> params = caver.abi.decodeFunctionCall(abi, encoded);
         
         
        Parameters:
        functionAbi - The abi json string of a function.
        encodedString - The encode function call data string.
        Returns:
        List<Type>
        Throws:
        java.lang.ClassNotFoundException
      • decodeFunctionCall

        public static java.util.List<Type> decodeFunctionCall​(ContractMethod method,
                                                              java.lang.String encodedString)
                                                       throws java.lang.ClassNotFoundException
        Decodes a function call data that composed of function selector and encoded input argument.
        Example :
         
         String contractABI = "...";
         Contract contract = caver.contract.create(contractABI);
         ContractMethod method = contract.getMethod("myFunction");
        
         List<Type> result = caver.abi.decodeFunctionCall(method, "0x{ABI-encoded string}");
         
        Parameters:
        method - The ContractMethod instance to decode ABI-encoded string.
        encodedString - The encode function call data string.
        Returns:
        List<Type>
        Throws:
        java.lang.ClassNotFoundException