Search in sources :

Example 21 with AbiDefinition

use of org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition in project web3sdk by FISCO-BCOS.

the class ContractAbiUtil method getConstructorAbiDefinition.

/**
 * @param contractAbi
 * @return
 */
public static AbiDefinition getConstructorAbiDefinition(String contractAbi) {
    try {
        ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper();
        AbiDefinition[] abiDefinitions = objectMapper.readValue(contractAbi, AbiDefinition[].class);
        for (AbiDefinition abiDefinition : abiDefinitions) {
            if (TYPE_CONSTRUCTOR.equals(abiDefinition.getType())) {
                return abiDefinition;
            }
        }
    } catch (JsonProcessingException e) {
        logger.warn(" invalid  json, abi: {}, e: {} ", contractAbi, e);
    }
    return null;
}
Also used : AbiDefinition(org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 22 with AbiDefinition

use of org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition in project web3sdk by FISCO-BCOS.

the class ContractAbiUtil method getEventAbiDefinitions.

/**
 * @param contractAbi
 * @return
 */
public static List<AbiDefinition> getEventAbiDefinitions(String contractAbi) {
    List<AbiDefinition> result = new ArrayList<>();
    try {
        ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper();
        AbiDefinition[] abiDefinitions = objectMapper.readValue(contractAbi, AbiDefinition[].class);
        for (AbiDefinition abiDefinition : abiDefinitions) {
            if (TYPE_EVENT.equals(abiDefinition.getType())) {
                result.add(abiDefinition);
            }
        }
    } catch (JsonProcessingException e) {
        logger.warn(" invalid json, abi: {}, e: {} ", contractAbi, e);
    }
    return result;
}
Also used : AbiDefinition(org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition) ArrayList(java.util.ArrayList) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

AbiDefinition (org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition)22 ArrayList (java.util.ArrayList)15 NamedType (org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition.NamedType)10 Type (org.fisco.bcos.web3j.abi.datatypes.Type)9 TypeReference (org.fisco.bcos.web3j.abi.TypeReference)8 Utf8String (org.fisco.bcos.web3j.abi.datatypes.Utf8String)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 List (java.util.List)7 Log (org.fisco.bcos.web3j.protocol.core.methods.response.Log)7 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)5 CollectionType (com.fasterxml.jackson.databind.type.CollectionType)4 Address (org.fisco.bcos.web3j.abi.datatypes.Address)4 Bool (org.fisco.bcos.web3j.abi.datatypes.Bool)4 DynamicBytes (org.fisco.bcos.web3j.abi.datatypes.DynamicBytes)4 Event (org.fisco.bcos.web3j.abi.datatypes.Event)4 Function (org.fisco.bcos.web3j.abi.datatypes.Function)4 Bytes32 (org.fisco.bcos.web3j.abi.datatypes.generated.Bytes32)4 Int256 (org.fisco.bcos.web3j.abi.datatypes.generated.Int256)4 Uint256 (org.fisco.bcos.web3j.abi.datatypes.generated.Uint256)4 MethodSpec (com.squareup.javapoet.MethodSpec)3