Search in sources :

Example 51 with Function

use of org.fisco.bcos.web3j.abi.datatypes.Function in project web3sdk by FISCO-BCOS.

the class RevertResolverTest method isOutputStartWithRevertMethodTest.

@Test
public void isOutputStartWithRevertMethodTest() {
    String revertMessage = "isOutputStartWithRevertMethodTest";
    Function revertFunction = newFunction("Error", revertMessage);
    String revertABI = FunctionEncoder.encode(revertFunction);
    Function testFunction = newFunction("testFunc", revertMessage);
    String testABI = FunctionEncoder.encode(testFunction);
    assertTrue(RevertResolver.isOutputStartWithRevertMethod(revertABI));
    assertFalse(RevertResolver.isOutputStartWithRevertMethod(testABI));
    assertTrue(RevertResolver.isOutputStartWithRevertMethod(revertABI));
    assertFalse(RevertResolver.isOutputStartWithRevertMethod(testABI));
}
Also used : Function(org.fisco.bcos.web3j.abi.datatypes.Function) Utf8String(org.fisco.bcos.web3j.abi.datatypes.Utf8String) Test(org.junit.Test)

Example 52 with Function

use of org.fisco.bcos.web3j.abi.datatypes.Function in project web3sdk by FISCO-BCOS.

the class RevertResolverTest method tryResolveRevertMessageTest0.

@Test
public void tryResolveRevertMessageTest0() throws IOException {
    String revertMessage = "";
    Function revertFunction = newFunction("Error", revertMessage);
    String revertABI = FunctionEncoder.encode(revertFunction);
    Function testFunction = newFunction("testFunc", revertMessage);
    String testABI = FunctionEncoder.encode(testFunction);
    Tuple2<Boolean, String> booleanStringTuple2 = RevertResolver.tryResolveRevertMessage("", "");
    assertFalse(booleanStringTuple2.getValue1());
    Tuple2<Boolean, String> booleanStringTuple20 = RevertResolver.tryResolveRevertMessage("0x0", revertABI);
    assertFalse(booleanStringTuple20.getValue1());
    Tuple2<Boolean, String> booleanStringTuple21 = RevertResolver.tryResolveRevertMessage("0x0", testABI);
    assertFalse(booleanStringTuple21.getValue1());
    Tuple2<Boolean, String> booleanStringTuple22 = RevertResolver.tryResolveRevertMessage("0x1", testABI);
    assertFalse(booleanStringTuple22.getValue1());
    Tuple2<Boolean, String> booleanStringTuple23 = RevertResolver.tryResolveRevertMessage("0x1", revertABI);
    assertTrue(booleanStringTuple23.getValue1());
    assertEquals(booleanStringTuple23.getValue2(), revertMessage);
}
Also used : Function(org.fisco.bcos.web3j.abi.datatypes.Function) Utf8String(org.fisco.bcos.web3j.abi.datatypes.Utf8String) Test(org.junit.Test)

Example 53 with Function

use of org.fisco.bcos.web3j.abi.datatypes.Function in project web3sdk by FISCO-BCOS.

the class RevertResolverTest method tryResolveRevertMessageSMTest0.

@Test
public void tryResolveRevertMessageSMTest0() throws IOException {
    EncryptType.setEncryptType(EncryptType.SM2_TYPE);
    String revertMessage = "";
    Function revertFunction = newFunction("Error", revertMessage);
    String revertABI = FunctionEncoder.encode(revertFunction);
    Function testFunction = newFunction("testFunc", revertMessage);
    String testABI = FunctionEncoder.encode(testFunction);
    Tuple2<Boolean, String> booleanStringTuple2 = RevertResolver.tryResolveRevertMessage("", "");
    assertFalse(booleanStringTuple2.getValue1());
    Tuple2<Boolean, String> booleanStringTuple20 = RevertResolver.tryResolveRevertMessage("0x0", revertABI);
    assertFalse(booleanStringTuple20.getValue1());
    Tuple2<Boolean, String> booleanStringTuple21 = RevertResolver.tryResolveRevertMessage("0x0", testABI);
    assertFalse(booleanStringTuple21.getValue1());
    Tuple2<Boolean, String> booleanStringTuple22 = RevertResolver.tryResolveRevertMessage("0x1", testABI);
    assertFalse(booleanStringTuple22.getValue1());
    Tuple2<Boolean, String> booleanStringTuple23 = RevertResolver.tryResolveRevertMessage("0x1", revertABI);
    assertTrue(booleanStringTuple23.getValue1());
    assertEquals(booleanStringTuple23.getValue2(), revertMessage);
    EncryptType.setEncryptType(EncryptType.ECDSA_TYPE);
}
Also used : Function(org.fisco.bcos.web3j.abi.datatypes.Function) Utf8String(org.fisco.bcos.web3j.abi.datatypes.Utf8String) Test(org.junit.Test)

Example 54 with Function

use of org.fisco.bcos.web3j.abi.datatypes.Function in project web3sdk by FISCO-BCOS.

the class TransactionDecoder method decodeOutputReturnObject.

/**
 * @param input
 * @param output
 * @return
 * @throws BaseException
 */
public InputAndOutputResult decodeOutputReturnObject(String input, String output) throws BaseException {
    String updatedInput = addHexPrefixToString(input);
    String updatedOutput = addHexPrefixToString(output);
    // select abi
    AbiDefinition abiDefinition = selectAbiDefinition(updatedInput);
    // decode output
    List<NamedType> outputTypes = abiDefinition.getOutputs();
    List<TypeReference<?>> outputTypeReference = ContractAbiUtil.paramFormat(outputTypes);
    Function function = new Function(abiDefinition.getName(), null, outputTypeReference);
    List<Type> resultType = FunctionReturnDecoder.decode(updatedOutput, function.getOutputParameters());
    // set result to java bean
    List<ResultEntity> resultList = new ArrayList<>();
    for (int i = 0; i < outputTypes.size(); i++) {
        resultList.add(new ResultEntity(outputTypes.get(i).getName(), outputTypes.get(i).getType(), resultType.get(i)));
    }
    String methodSign = decodeMethodSign(abiDefinition);
    return new InputAndOutputResult(methodSign, FunctionEncoder.buildMethodId(methodSign), resultList);
}
Also used : NamedType(org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition.NamedType) ArrayList(java.util.ArrayList) Function(org.fisco.bcos.web3j.abi.datatypes.Function) CollectionType(com.fasterxml.jackson.databind.type.CollectionType) Type(org.fisco.bcos.web3j.abi.datatypes.Type) NamedType(org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition.NamedType) AbiDefinition(org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition) TypeReference(org.fisco.bcos.web3j.abi.TypeReference)

Example 55 with Function

use of org.fisco.bcos.web3j.abi.datatypes.Function in project web3sdk by FISCO-BCOS.

the class TransactionDecoder method decodeInputReturnObject.

/**
 * @param input
 * @return
 * @throws BaseException
 */
public InputAndOutputResult decodeInputReturnObject(String input) throws BaseException {
    String updatedInput = addHexPrefixToString(input);
    // select abi
    AbiDefinition abiDefinition = selectAbiDefinition(updatedInput);
    // decode input
    List<NamedType> inputTypes = abiDefinition.getInputs();
    List<TypeReference<?>> inputTypeReferences = ContractAbiUtil.paramFormat(inputTypes);
    Function function = new Function(abiDefinition.getName(), null, inputTypeReferences);
    List<Type> resultType = FunctionReturnDecoder.decode(updatedInput.substring(10), function.getOutputParameters());
    // set result to java bean
    List<ResultEntity> resultList = new ArrayList<ResultEntity>();
    for (int i = 0; i < inputTypes.size(); i++) {
        resultList.add(new ResultEntity(inputTypes.get(i).getName(), inputTypes.get(i).getType(), resultType.get(i)));
    }
    String methodSign = decodeMethodSign(abiDefinition);
    return new InputAndOutputResult(methodSign, FunctionEncoder.buildMethodId(methodSign), resultList);
}
Also used : NamedType(org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition.NamedType) ArrayList(java.util.ArrayList) Function(org.fisco.bcos.web3j.abi.datatypes.Function) CollectionType(com.fasterxml.jackson.databind.type.CollectionType) Type(org.fisco.bcos.web3j.abi.datatypes.Type) NamedType(org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition.NamedType) AbiDefinition(org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition) TypeReference(org.fisco.bcos.web3j.abi.TypeReference)

Aggregations

Function (org.fisco.bcos.web3j.abi.datatypes.Function)108 Utf8String (org.fisco.bcos.web3j.abi.datatypes.Utf8String)59 Type (org.fisco.bcos.web3j.abi.datatypes.Type)41 TypeReference (org.fisco.bcos.web3j.abi.TypeReference)38 Tuple1 (org.fisco.bcos.web3j.tuples.generated.Tuple1)26 Int256 (org.fisco.bcos.web3j.abi.datatypes.generated.Int256)22 Address (org.fisco.bcos.web3j.abi.datatypes.Address)19 Uint256 (org.fisco.bcos.web3j.abi.datatypes.generated.Uint256)16 Test (org.junit.Test)15 EncryptType (org.fisco.bcos.web3j.crypto.EncryptType)11 Bytes32 (org.fisco.bcos.web3j.abi.datatypes.generated.Bytes32)8 NamedType (org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition.NamedType)8 Bool (org.fisco.bcos.web3j.abi.datatypes.Bool)6 DynamicBytes (org.fisco.bcos.web3j.abi.datatypes.DynamicBytes)6 Tuple2 (org.fisco.bcos.web3j.tuples.generated.Tuple2)6 CollectionType (com.fasterxml.jackson.databind.type.CollectionType)2 ArrayList (java.util.ArrayList)2 AbiDefinition (org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition)2 TransactionReceipt (org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt)2 DynamicArray (org.fisco.bcos.web3j.abi.datatypes.DynamicArray)1