org.fisco.bcos.web3j.abi.FunctionEncoder Java Examples

The following examples show how to use org.fisco.bcos.web3j.abi.FunctionEncoder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Contract.java    From web3sdk with Apache License 2.0 6 votes vote down vote up
protected String createTransactionSeq(Function function) {
    try {
        String signedTransaction =
                createSeq(
                        contractAddress,
                        FunctionEncoder.encode(function),
                        BigInteger.ZERO,
                        gasProvider.getGasPrice(function.getName()),
                        gasProvider.getGasLimit(function.getName()));
        return signedTransaction;
    } catch (IOException e) {
        // e.print_Stack_Trace();
        logger.error(" IOException, message:{}", e.getMessage());
        return "";
    }
}
 
Example #2
Source File: TestGroupSig.java    From group-signature-client with GNU General Public License v3.0 6 votes vote down vote up
@Deprecated
public static RemoteCall<TestGroupSig> deploy(
        Web3j web3j,
        TransactionManager transactionManager,
        BigInteger gasPrice,
        BigInteger gasLimit,
        String _sig,
        String _message,
        String _gpk_info,
        String _pbc_param_info) {
    String encodedConstructor =
            FunctionEncoder.encodeConstructor(
                    Arrays.<Type>asList(
                            new Utf8String(_sig),
                            new Utf8String(_message),
                            new Utf8String(_gpk_info),
                            new Utf8String(_pbc_param_info)));
    return deployRemoteCall(
            TestGroupSig.class,
            web3j,
            transactionManager,
            gasPrice,
            gasLimit,
            BINARY,
            encodedConstructor);
}
 
Example #3
Source File: TestGroupSig.java    From group-signature-client with GNU General Public License v3.0 6 votes vote down vote up
@Deprecated
public static RemoteCall<TestGroupSig> deploy(
        Web3j web3j,
        Credentials credentials,
        BigInteger gasPrice,
        BigInteger gasLimit,
        String _sig,
        String _message,
        String _gpk_info,
        String _pbc_param_info) {
    String encodedConstructor =
            FunctionEncoder.encodeConstructor(
                    Arrays.<Type>asList(
                            new Utf8String(_sig),
                            new Utf8String(_message),
                            new Utf8String(_gpk_info),
                            new Utf8String(_pbc_param_info)));
    return deployRemoteCall(
            TestGroupSig.class,
            web3j,
            credentials,
            gasPrice,
            gasLimit,
            BINARY,
            encodedConstructor);
}
 
Example #4
Source File: TestGroupSig.java    From group-signature-client with GNU General Public License v3.0 6 votes vote down vote up
public static RemoteCall<TestGroupSig> deploy(
        Web3j web3j,
        TransactionManager transactionManager,
        ContractGasProvider contractGasProvider,
        String _sig,
        String _message,
        String _gpk_info,
        String _pbc_param_info) {
    String encodedConstructor =
            FunctionEncoder.encodeConstructor(
                    Arrays.<Type>asList(
                            new Utf8String(_sig),
                            new Utf8String(_message),
                            new Utf8String(_gpk_info),
                            new Utf8String(_pbc_param_info)));
    return deployRemoteCall(
            TestGroupSig.class,
            web3j,
            transactionManager,
            contractGasProvider,
            BINARY,
            encodedConstructor);
}
 
Example #5
Source File: TestGroupSig.java    From group-signature-client with GNU General Public License v3.0 6 votes vote down vote up
public static RemoteCall<TestGroupSig> deploy(
        Web3j web3j,
        Credentials credentials,
        ContractGasProvider contractGasProvider,
        String _sig,
        String _message,
        String _gpk_info,
        String _pbc_param_info) {
    String encodedConstructor =
            FunctionEncoder.encodeConstructor(
                    Arrays.<Type>asList(
                            new Utf8String(_sig),
                            new Utf8String(_message),
                            new Utf8String(_gpk_info),
                            new Utf8String(_pbc_param_info)));
    return deployRemoteCall(
            TestGroupSig.class,
            web3j,
            credentials,
            contractGasProvider,
            BINARY,
            encodedConstructor);
}
 
Example #6
Source File: TestRingSig.java    From group-signature-client with GNU General Public License v3.0 6 votes vote down vote up
@Deprecated
public static RemoteCall<TestRingSig> deploy(
        Web3j web3j,
        TransactionManager transactionManager,
        BigInteger gasPrice,
        BigInteger gasLimit,
        String _sig,
        String _message,
        String _param_info) {
    String encodedConstructor =
            FunctionEncoder.encodeConstructor(
                    Arrays.<Type>asList(
                            new Utf8String(_sig),
                            new Utf8String(_message),
                            new Utf8String(_param_info)));
    return deployRemoteCall(
            TestRingSig.class,
            web3j,
            transactionManager,
            gasPrice,
            gasLimit,
            BINARY,
            encodedConstructor);
}
 
Example #7
Source File: TestRingSig.java    From group-signature-client with GNU General Public License v3.0 6 votes vote down vote up
@Deprecated
public static RemoteCall<TestRingSig> deploy(
        Web3j web3j,
        Credentials credentials,
        BigInteger gasPrice,
        BigInteger gasLimit,
        String _sig,
        String _message,
        String _param_info) {
    String encodedConstructor =
            FunctionEncoder.encodeConstructor(
                    Arrays.<Type>asList(
                            new Utf8String(_sig),
                            new Utf8String(_message),
                            new Utf8String(_param_info)));
    return deployRemoteCall(
            TestRingSig.class,
            web3j,
            credentials,
            gasPrice,
            gasLimit,
            BINARY,
            encodedConstructor);
}
 
Example #8
Source File: TestRingSig.java    From group-signature-client with GNU General Public License v3.0 6 votes vote down vote up
public static RemoteCall<TestRingSig> deploy(
        Web3j web3j,
        TransactionManager transactionManager,
        ContractGasProvider contractGasProvider,
        String _sig,
        String _message,
        String _param_info) {
    String encodedConstructor =
            FunctionEncoder.encodeConstructor(
                    Arrays.<Type>asList(
                            new Utf8String(_sig),
                            new Utf8String(_message),
                            new Utf8String(_param_info)));
    return deployRemoteCall(
            TestRingSig.class,
            web3j,
            transactionManager,
            contractGasProvider,
            BINARY,
            encodedConstructor);
}
 
Example #9
Source File: TestRingSig.java    From group-signature-client with GNU General Public License v3.0 6 votes vote down vote up
public static RemoteCall<TestRingSig> deploy(
        Web3j web3j,
        Credentials credentials,
        ContractGasProvider contractGasProvider,
        String _sig,
        String _message,
        String _param_info) {
    String encodedConstructor =
            FunctionEncoder.encodeConstructor(
                    Arrays.<Type>asList(
                            new Utf8String(_sig),
                            new Utf8String(_message),
                            new Utf8String(_param_info)));
    return deployRemoteCall(
            TestRingSig.class,
            web3j,
            credentials,
            contractGasProvider,
            BINARY,
            encodedConstructor);
}
 
Example #10
Source File: RevertResolverTest.java    From web3sdk with Apache License 2.0 6 votes vote down vote up
@Test
public void hasRevertMessageTest() throws IOException {
    String revertMessage = "RevertMessage";
    Function revertFunction = newFunction("Error", revertMessage);
    String revertABI = FunctionEncoder.encode(revertFunction);

    Function testFunction = newFunction("testFunc", revertMessage);
    String testABI = FunctionEncoder.encode(testFunction);

    assertFalse(RevertResolver.hasRevertMessage(null, null));
    assertFalse(RevertResolver.hasRevertMessage("", null));
    assertFalse(RevertResolver.hasRevertMessage(null, ""));
    assertFalse(RevertResolver.hasRevertMessage("", ""));
    assertFalse(RevertResolver.hasRevertMessage("0x0", ""));
    assertFalse(RevertResolver.hasRevertMessage("0x0", ""));
    assertFalse(RevertResolver.hasRevertMessage("0x0", revertABI));
    assertTrue(RevertResolver.hasRevertMessage("0x1", revertABI));
    assertFalse(RevertResolver.hasRevertMessage(null, revertABI));

    assertFalse(RevertResolver.hasRevertMessage("0x0", testABI));
    assertFalse(RevertResolver.hasRevertMessage("0x1", testABI));
    assertFalse(RevertResolver.hasRevertMessage(null, testABI));
}
 
Example #11
Source File: RevertResolverTest.java    From web3sdk with Apache License 2.0 6 votes vote down vote up
@Test
public void hasRevertMessageSMTest() throws IOException {
    EncryptType.setEncryptType(EncryptType.SM2_TYPE);
    String revertMessage = "RevertMessage";
    Function revertFunction = newFunction("Error", revertMessage);
    String revertABI = FunctionEncoder.encode(revertFunction);

    Function testFunction = newFunction("testFunc", revertMessage);
    String testABI = FunctionEncoder.encode(testFunction);

    assertFalse(RevertResolver.hasRevertMessage(null, null));
    assertFalse(RevertResolver.hasRevertMessage("", null));
    assertFalse(RevertResolver.hasRevertMessage(null, ""));
    assertFalse(RevertResolver.hasRevertMessage("", ""));
    assertFalse(RevertResolver.hasRevertMessage("0x0", ""));
    assertFalse(RevertResolver.hasRevertMessage("0x0", ""));
    assertFalse(RevertResolver.hasRevertMessage("0x0", revertABI));
    assertTrue(RevertResolver.hasRevertMessage("0x1", revertABI));
    assertFalse(RevertResolver.hasRevertMessage(null, revertABI));

    assertFalse(RevertResolver.hasRevertMessage("0x0", testABI));
    assertFalse(RevertResolver.hasRevertMessage("0x1", testABI));
    assertFalse(RevertResolver.hasRevertMessage(null, testABI));
    EncryptType.setEncryptType(EncryptType.ECDSA_TYPE);
}
 
Example #12
Source File: RevertResolverTest.java    From web3sdk with Apache License 2.0 6 votes vote down vote up
@Test
public void isOutputStartWithRevertMethodSMTest() {
    EncryptType.setEncryptType(EncryptType.SM2_TYPE);
    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));
    EncryptType.setEncryptType(EncryptType.ECDSA_TYPE);
}
 
Example #13
Source File: ContractService.java    From WeBASE-Front with Apache License 2.0 6 votes vote down vote up
public static String constructorEncodedByContractNameAndVersion(String contractName,
        String version, List<Object> params) throws FrontException {
    // Constructor encoded
    String encodedConstructor = "";
    String functionName = contractName;
    // input handle
    List<String> funcInputTypes =
            ContractAbiUtil.getFuncInputType(contractName, functionName, version);
    if (funcInputTypes != null && funcInputTypes.size() > 0) {
        if (funcInputTypes.size() == params.size()) {
            List<Type> finalInputs = AbiUtil.inputFormat(funcInputTypes, params);
            encodedConstructor = FunctionEncoder.encodeConstructor(finalInputs);
            log.info("deploy encodedConstructor:{}", encodedConstructor);
        } else {
            log.warn("deploy fail. funcInputTypes:{}, params:{}", funcInputTypes, params);
            throw new FrontException(ConstantCode.IN_FUNCPARAM_ERROR);
        }
    }
    return encodedConstructor;
}
 
Example #14
Source File: ContractService.java    From WeBASE-Front with Apache License 2.0 6 votes vote down vote up
/**
 * encode constructor function
 */
private static String constructorEncoded(String contractName,
        ContractAbiUtil.VersionEvent versionEvent, List<Object> params) throws FrontException {
    // Constructor encoded
    String encodedConstructor = "";
    String functionName = contractName;
    // input handle
    List<String> funcInputTypes = versionEvent.getFuncInputs().get(functionName);

    if (funcInputTypes != null && funcInputTypes.size() > 0) {
        if (funcInputTypes.size() == params.size()) {
            List<Type> finalInputs = AbiUtil.inputFormat(funcInputTypes, params);
            encodedConstructor = FunctionEncoder.encodeConstructor(finalInputs);
            log.info("deploy encodedConstructor:{}", encodedConstructor);
        } else {
            log.warn("deploy fail. funcInputTypes:{}, params:{}", funcInputTypes, params);
            throw new FrontException(ConstantCode.IN_FUNCPARAM_ERROR);
        }
    }
    return encodedConstructor;
}
 
Example #15
Source File: Evidence.java    From evidenceSample with Apache License 2.0 5 votes vote down vote up
@Deprecated
public static RemoteCall<Evidence> deploy(Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit, String evi, String info, String id, BigInteger v, byte[] r, byte[] s, String addr, String sender) {
    String encodedConstructor = FunctionEncoder.encodeConstructor(Arrays.<Type>asList(new org.fisco.bcos.web3j.abi.datatypes.Utf8String(evi), 
            new org.fisco.bcos.web3j.abi.datatypes.Utf8String(info), 
            new org.fisco.bcos.web3j.abi.datatypes.Utf8String(id), 
            new org.fisco.bcos.web3j.abi.datatypes.generated.Uint8(v), 
            new org.fisco.bcos.web3j.abi.datatypes.generated.Bytes32(r), 
            new org.fisco.bcos.web3j.abi.datatypes.generated.Bytes32(s), 
            new org.fisco.bcos.web3j.abi.datatypes.Address(addr), 
            new org.fisco.bcos.web3j.abi.datatypes.Address(sender)));
    return deployRemoteCall(Evidence.class, web3j, transactionManager, gasPrice, gasLimit, BINARY, encodedConstructor);
}
 
Example #16
Source File: Contract.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
protected TransactionReceipt executeTransaction(Function function)
        throws IOException, TransactionException {

    Callback callback = new Callback();

    asyncExecuteTransaction(FunctionEncoder.encode(function), function.getName(), callback);
    try {
        callback.semaphore.acquire(1);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }

    return callback.receipt;
}
 
Example #17
Source File: Contract.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
/**
 * Execute constant function call - i.e. a call that does not change state of the contract
 *
 * @param function to call
 * @return {@link List} of values returned by function call
 */
private List<Type> executeCall(Function function) throws IOException {
    String encodedFunction = FunctionEncoder.encode(function);
    Call ethCall =
            web3j.call(
                            Transaction.createEthCallTransaction(
                                    transactionManager.getFromAddress(),
                                    contractAddress,
                                    encodedFunction),
                            defaultBlockParameter)
                    .send();

    String value = ethCall.getValue().getOutput();
    return FunctionReturnDecoder.decode(value, function.getOutputParameters());
}
 
Example #18
Source File: TransactionDecoder.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
/**
 * @param input
 * @param output
 * @return
 * @throws TransactionException
 * @throws BaseException
 */
public InputAndOutputResult decodeOutputReturnObject(String input, String output)
        throws TransactionException, 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);
}
 
Example #19
Source File: TransactionDecoder.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
/**
 * @param input
 * @return
 * @throws BaseException
 * @throws TransactionException
 */
public InputAndOutputResult decodeInputReturnObject(String input)
        throws BaseException, TransactionException {

    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);
}
 
Example #20
Source File: TransactionDecoder.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
public TransactionDecoder(String abi, String bin) {
    this.abi = abi;
    this.bin = bin;
    methodIDMap = new HashMap<String, AbiDefinition>();
    List<AbiDefinition> funcAbiDefinitionList = ContractAbiUtil.getFuncAbiDefinition(abi);
    for (AbiDefinition abiDefinition : funcAbiDefinitionList) {
        String methodSign = decodeMethodSign(abiDefinition);
        String methodID = FunctionEncoder.buildMethodId(methodSign);
        methodIDMap.put(methodID, abiDefinition);
    }
}
 
Example #21
Source File: CallContract.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
public CallResult call(String contractAddress, String funcName, Type... args) {
    final Function function =
            new Function(
                    funcName,
                    Arrays.<Type>asList(args),
                    Collections.<TypeReference<?>>emptyList());
    String data = FunctionEncoder.encode(function);
    Call ethCall;
    try {
        ethCall =
                web3j.call(
                                Transaction.createEthCallTransaction(
                                        credentials.getAddress(), contractAddress, data),
                                DefaultBlockParameterName.LATEST)
                        .send();
    } catch (Exception e) {
        return new CallResult(StatusCode.ExceptionCatched, e.getMessage(), "0x");
    }

    Call.CallOutput callOutput = ethCall.getValue();
    if (callOutput != null) {
        return new CallResult(
                callOutput.getStatus(),
                StatusCode.getStatusMessage(callOutput.getStatus()),
                callOutput.getOutput());
    } else {
        return new CallResult(
                StatusCode.ErrorInRPC,
                StatusCode.getStatusMessage(StatusCode.ErrorInRPC),
                "0x");
    }
}
 
Example #22
Source File: RevertResolverTest.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
@Test
public void tryResolveRevertMessageSMTest() throws IOException {
    EncryptType.setEncryptType(EncryptType.SM2_TYPE);
    String revertMessage = "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);
}
 
Example #23
Source File: RevertResolverTest.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #24
Source File: RevertResolverTest.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #25
Source File: Evidence.java    From evidenceSample with Apache License 2.0 5 votes vote down vote up
public static RemoteCall<Evidence> deploy(Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider, String evi, String info, String id, BigInteger v, byte[] r, byte[] s, String addr, String sender) {
    String encodedConstructor = FunctionEncoder.encodeConstructor(Arrays.<Type>asList(new org.fisco.bcos.web3j.abi.datatypes.Utf8String(evi), 
            new org.fisco.bcos.web3j.abi.datatypes.Utf8String(info), 
            new org.fisco.bcos.web3j.abi.datatypes.Utf8String(id), 
            new org.fisco.bcos.web3j.abi.datatypes.generated.Uint8(v), 
            new org.fisco.bcos.web3j.abi.datatypes.generated.Bytes32(r), 
            new org.fisco.bcos.web3j.abi.datatypes.generated.Bytes32(s), 
            new org.fisco.bcos.web3j.abi.datatypes.Address(addr), 
            new org.fisco.bcos.web3j.abi.datatypes.Address(sender)));
    return deployRemoteCall(Evidence.class, web3j, credentials, contractGasProvider, BINARY, encodedConstructor);
}
 
Example #26
Source File: Evidence.java    From evidenceSample with Apache License 2.0 5 votes vote down vote up
public static RemoteCall<Evidence> deploy(Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider, String evi, String info, String id, BigInteger v, byte[] r, byte[] s, String addr, String sender) {
    String encodedConstructor = FunctionEncoder.encodeConstructor(Arrays.<Type>asList(new org.fisco.bcos.web3j.abi.datatypes.Utf8String(evi), 
            new org.fisco.bcos.web3j.abi.datatypes.Utf8String(info), 
            new org.fisco.bcos.web3j.abi.datatypes.Utf8String(id), 
            new org.fisco.bcos.web3j.abi.datatypes.generated.Uint8(v), 
            new org.fisco.bcos.web3j.abi.datatypes.generated.Bytes32(r), 
            new org.fisco.bcos.web3j.abi.datatypes.generated.Bytes32(s), 
            new org.fisco.bcos.web3j.abi.datatypes.Address(addr), 
            new org.fisco.bcos.web3j.abi.datatypes.Address(sender)));
    return deployRemoteCall(Evidence.class, web3j, transactionManager, contractGasProvider, BINARY, encodedConstructor);
}
 
Example #27
Source File: Evidence.java    From evidenceSample with Apache License 2.0 5 votes vote down vote up
@Deprecated
public static RemoteCall<Evidence> deploy(Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit, String evi, String info, String id, BigInteger v, byte[] r, byte[] s, String addr, String sender) {
    String encodedConstructor = FunctionEncoder.encodeConstructor(Arrays.<Type>asList(new org.fisco.bcos.web3j.abi.datatypes.Utf8String(evi), 
            new org.fisco.bcos.web3j.abi.datatypes.Utf8String(info), 
            new org.fisco.bcos.web3j.abi.datatypes.Utf8String(id), 
            new org.fisco.bcos.web3j.abi.datatypes.generated.Uint8(v), 
            new org.fisco.bcos.web3j.abi.datatypes.generated.Bytes32(r), 
            new org.fisco.bcos.web3j.abi.datatypes.generated.Bytes32(s), 
            new org.fisco.bcos.web3j.abi.datatypes.Address(addr), 
            new org.fisco.bcos.web3j.abi.datatypes.Address(sender)));
    return deployRemoteCall(Evidence.class, web3j, credentials, gasPrice, gasLimit, BINARY, encodedConstructor);
}
 
Example #28
Source File: RevertResolverTest.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
@Test
public void tryResolveRevertMessageTest() throws IOException {
    String revertMessage = "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("", "");
    assertTrue(!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);
}
 
Example #29
Source File: RevertResolverTest.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example #30
Source File: FiscoBcosBroker4ProducerTest.java    From WeEvent with Apache License 2.0 5 votes vote down vote up
private String buildWeEvent(WeEvent event) throws BrokerException {
    final Function function = new Function(
            Topic.FUNC_PUBLISHWEEVENT,
            Arrays.<Type>asList(new org.fisco.bcos.web3j.abi.datatypes.Utf8String(event.getTopic()),
                    new org.fisco.bcos.web3j.abi.datatypes.Utf8String(new String(event.getContent(), StandardCharsets.UTF_8)),
                    new org.fisco.bcos.web3j.abi.datatypes.Utf8String(JsonHelper.object2Json(event.getExtensions()))),
            Collections.<TypeReference<?>>emptyList());
    return FunctionEncoder.encode(function);
}