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

The following examples show how to use org.fisco.bcos.web3j.abi.TypeReference. 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: TypeReferenceUtils.java    From WeBASE-Codegen-Monkey with Apache License 2.0 6 votes vote down vote up
public static TypeReference<?> getTypeRef(String solType) throws BaseException {
    AbiDefinition.NamedType.Type type = new AbiDefinition.NamedType.Type(solType);
    // nested array , not support now.
    if (type.getDepth() > 1) {
        throw new BaseException(201202, String.format("type:%s unsupported array decoding", type.getName()));
    }

    TypeReference<?> typeReference = null;
    if (type.dynamicArray()) {
        typeReference = DynamicArrayReference.create(type.getBaseName(), false);
    } else if (type.staticArray()) {
        typeReference = StaticArrayReference.create(type.getBaseName(), type.getDimensions(), false);
    } else {
        typeReference = TypeReference.create(ContractTypeUtil.getType(solType), false);
    }
    return typeReference;
}
 
Example #2
Source File: TestGroupSig.java    From group-signature-client with GNU General Public License v3.0 6 votes vote down vote up
public Tuple4<String, String, String, String> getUpdate_group_sig_dataInput(
        TransactionReceipt transactionReceipt) {
    String data = transactionReceipt.getInput().substring(10);
    final Function function =
            new Function(
                    FUNC_UPDATE_GROUP_SIG_DATA,
                    Arrays.<Type>asList(),
                    Arrays.<TypeReference<?>>asList(
                            new TypeReference<Utf8String>() {},
                            new TypeReference<Utf8String>() {},
                            new TypeReference<Utf8String>() {},
                            new TypeReference<Utf8String>() {}));
    List<Type> results = FunctionReturnDecoder.decode(data, function.getOutputParameters());
    ;
    return new Tuple4<String, String, String, String>(
            (String) results.get(0).getValue(),
            (String) results.get(1).getValue(),
            (String) results.get(2).getValue(),
            (String) results.get(3).getValue());
}
 
Example #3
Source File: TableTest.java    From web3sdk with Apache License 2.0 6 votes vote down vote up
public RemoteCall<Tuple3<List<byte[]>, List<BigInteger>, List<byte[]>>> select(String name) {
    final Function function =
            new Function(
                    FUNC_SELECT,
                    Arrays.<Type>asList(
                            new org.fisco.bcos.web3j.abi.datatypes.Utf8String(name)),
                    Arrays.<TypeReference<?>>asList(
                            new TypeReference<DynamicArray<Bytes32>>() {},
                            new TypeReference<DynamicArray<Int256>>() {},
                            new TypeReference<DynamicArray<Bytes32>>() {}));
    return new RemoteCall<Tuple3<List<byte[]>, List<BigInteger>, List<byte[]>>>(
            new Callable<Tuple3<List<byte[]>, List<BigInteger>, List<byte[]>>>() {
                @Override
                public Tuple3<List<byte[]>, List<BigInteger>, List<byte[]>> call()
                        throws Exception {
                    List<Type> results = executeCallMultipleValueReturn(function);
                    return new Tuple3<List<byte[]>, List<BigInteger>, List<byte[]>>(
                            convertToNative((List<Bytes32>) results.get(0).getValue()),
                            convertToNative((List<Int256>) results.get(1).getValue()),
                            convertToNative((List<Bytes32>) results.get(2).getValue()));
                }
            });
}
 
Example #4
Source File: TableTest.java    From web3sdk with Apache License 2.0 6 votes vote down vote up
public RemoteCall<Tuple3<List<String>, List<BigInteger>, List<String>>> select(String name) {
    final Function function =
            new Function(
                    FUNC_SELECT,
                    Arrays.<Type>asList(
                            new org.fisco.bcos.web3j.abi.datatypes.Utf8String(name)),
                    Arrays.<TypeReference<?>>asList(
                            new TypeReference<DynamicArray<Utf8String>>() {},
                            new TypeReference<DynamicArray<Int256>>() {},
                            new TypeReference<DynamicArray<Utf8String>>() {}));
    return new RemoteCall<Tuple3<List<String>, List<BigInteger>, List<String>>>(
            new Callable<Tuple3<List<String>, List<BigInteger>, List<String>>>() {
                @Override
                public Tuple3<List<String>, List<BigInteger>, List<String>> call()
                        throws Exception {
                    List<Type> results = executeCallMultipleValueReturn(function);
                    return new Tuple3<List<String>, List<BigInteger>, List<String>>(
                            convertToNative((List<Utf8String>) results.get(0).getValue()),
                            convertToNative((List<Int256>) results.get(1).getValue()),
                            convertToNative((List<Utf8String>) results.get(2).getValue()));
                }
            });
}
 
Example #5
Source File: CRUD.java    From web3sdk with Apache License 2.0 6 votes vote down vote up
public void remove(
        String tableName,
        String key,
        String condition,
        String optional,
        TransactionSucCallback callback) {
    final Function function =
            new Function(
                    FUNC_REMOVE,
                    Arrays.<Type>asList(
                            new org.fisco.bcos.web3j.abi.datatypes.Utf8String(tableName),
                            new org.fisco.bcos.web3j.abi.datatypes.Utf8String(key),
                            new org.fisco.bcos.web3j.abi.datatypes.Utf8String(condition),
                            new org.fisco.bcos.web3j.abi.datatypes.Utf8String(optional)),
                    Collections.<TypeReference<?>>emptyList());
    asyncExecuteTransaction(function, callback);
}
 
Example #6
Source File: AbiUtil.java    From WeBASE-Front with Apache License 2.0 6 votes vote down vote up
/**
 * output parameter format.
 * 
 * @param funOutputTypes list
 * @return
 */
public static List<TypeReference<?>> outputFormat(List<String> funOutputTypes)
        throws FrontException {
    List<TypeReference<?>> finalOutputs = new ArrayList<>();
    for (int i = 0; i < funOutputTypes.size(); i++) {
        Class<? extends Type> outputType = null;
        TypeReference<?> typeReference = null;
        if (funOutputTypes.get(i).contains("[")
                && funOutputTypes.get(i).contains("]")) {
            typeReference = ContractTypeUtil.getArrayType(
                    funOutputTypes.get(i).substring(0, funOutputTypes.get(i).indexOf("[")));
        } else {
            outputType = AbiTypes.getType(funOutputTypes.get(i));
            typeReference = TypeReference.create(outputType);
        }
        finalOutputs.add(typeReference);
    }
    return finalOutputs;
}
 
Example #7
Source File: TestRingSig.java    From group-signature-client with GNU General Public License v3.0 5 votes vote down vote up
public void verify_ring_sig(TransactionSucCallback callback) {
    final Function function =
            new Function(
                    FUNC_VERIFY_RING_SIG,
                    Arrays.<Type>asList(),
                    Collections.<TypeReference<?>>emptyList());
    asyncExecuteTransaction(function, callback);
}
 
Example #8
Source File: TableTest.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
public RemoteCall<TransactionReceipt> update(
        String name, BigInteger item_id, String item_name) {
    final Function function =
            new Function(
                    FUNC_UPDATE,
                    Arrays.<Type>asList(
                            new org.fisco.bcos.web3j.abi.datatypes.Utf8String(name),
                            new org.fisco.bcos.web3j.abi.datatypes.generated.Int256(item_id),
                            new org.fisco.bcos.web3j.abi.datatypes.Utf8String(item_name)),
                    Collections.<TypeReference<?>>emptyList());
    return executeRemoteCallTransaction(function);
}
 
Example #9
Source File: HelloWorld.java    From WeBASE-Codegen-Monkey with Apache License 2.0 5 votes vote down vote up
public RemoteCall<TransactionReceipt> set(String n) {
    final Function function = new Function(
            FUNC_SET, 
            Arrays.<Type>asList(new org.fisco.bcos.web3j.abi.datatypes.Utf8String(n)), 
            Collections.<TypeReference<?>>emptyList());
    return executeRemoteCallTransaction(function);
}
 
Example #10
Source File: ChainGovernance.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
public RemoteCall<TransactionReceipt> revokeOperator(String user) {
    final Function function =
            new Function(
                    FUNC_REVOKEOPERATOR,
                    Arrays.<Type>asList(new org.fisco.bcos.web3j.abi.datatypes.Address(user)),
                    Collections.<TypeReference<?>>emptyList());
    return executeRemoteCallTransaction(function);
}
 
Example #11
Source File: CNS.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
public RemoteCall<TransactionReceipt> insert(
        String name, String version, String addr, String abi) {
    final Function function =
            new Function(
                    FUNC_INSERT,
                    Arrays.<Type>asList(
                            new Utf8String(name),
                            new Utf8String(version),
                            new Utf8String(addr),
                            new Utf8String(abi)),
                    Collections.<TypeReference<?>>emptyList());
    return executeRemoteCallTransaction(function);
}
 
Example #12
Source File: Topic.java    From WeEvent with Apache License 2.0 5 votes vote down vote up
public String addOperatorSeq(String topicName, String operatorAddress) {
    final Function function = new Function(
            FUNC_ADDOPERATOR, 
            Arrays.<Type>asList(new org.fisco.bcos.web3j.abi.datatypes.Utf8String(topicName), 
            new org.fisco.bcos.web3j.abi.datatypes.Address(operatorAddress)), 
            Collections.<TypeReference<?>>emptyList());
    return createTransactionSeq(function);
}
 
Example #13
Source File: ChainGovernance.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
public Tuple1<String> getRevokeCommitteeMemberInput(TransactionReceipt transactionReceipt) {
    String data = transactionReceipt.getInput().substring(10);
    final Function function =
            new Function(
                    FUNC_REVOKECOMMITTEEMEMBER,
                    Arrays.<Type>asList(),
                    Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}));
    List<Type> results = FunctionReturnDecoder.decode(data, function.getOutputParameters());
    ;
    return new Tuple1<String>((String) results.get(0).getValue());
}
 
Example #14
Source File: ChainGovernance.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
public String updateCommitteeMemberWeightSeq(String user, BigInteger weight) {
    final Function function =
            new Function(
                    FUNC_UPDATECOMMITTEEMEMBERWEIGHT,
                    Arrays.<Type>asList(
                            new org.fisco.bcos.web3j.abi.datatypes.Address(user),
                            new org.fisco.bcos.web3j.abi.datatypes.generated.Int256(weight)),
                    Collections.<TypeReference<?>>emptyList());
    return createTransactionSeq(function);
}
 
Example #15
Source File: Topic.java    From WeEvent with Apache License 2.0 5 votes vote down vote up
public RemoteCall<TransactionReceipt> publishWeEvent(String topicName, String eventContent, String extensions) {
    final Function function = new Function(
            FUNC_PUBLISHWEEVENT, 
            Arrays.<Type>asList(new org.fisco.bcos.web3j.abi.datatypes.Utf8String(topicName), 
            new org.fisco.bcos.web3j.abi.datatypes.Utf8String(eventContent), 
            new org.fisco.bcos.web3j.abi.datatypes.Utf8String(extensions)), 
            Collections.<TypeReference<?>>emptyList());
    return executeRemoteCallTransaction(function);
}
 
Example #16
Source File: ChainGovernance.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
public Tuple1<BigInteger> getGrantOperatorOutput(TransactionReceipt transactionReceipt) {
    String data = transactionReceipt.getOutput();
    final Function function =
            new Function(
                    FUNC_GRANTOPERATOR,
                    Arrays.<Type>asList(),
                    Arrays.<TypeReference<?>>asList(new TypeReference<Int256>() {}));
    List<Type> results = FunctionReturnDecoder.decode(data, function.getOutputParameters());
    ;
    return new Tuple1<BigInteger>((BigInteger) results.get(0).getValue());
}
 
Example #17
Source File: ContractLifeCyclePrecompiled.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
public RemoteCall<TransactionReceipt> freeze(String addr) {
    final Function function =
            new Function(
                    FUNC_FREEZE,
                    Arrays.<Type>asList(new org.fisco.bcos.web3j.abi.datatypes.Address(addr)),
                    Collections.<TypeReference<?>>emptyList());
    return executeRemoteCallTransaction(function);
}
 
Example #18
Source File: ChainGovernance.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
public String unfreezeAccountSeq(String account) {
    final Function function =
            new Function(
                    FUNC_UNFREEZEACCOUNT,
                    Arrays.<Type>asList(
                            new org.fisco.bcos.web3j.abi.datatypes.Address(account)),
                    Collections.<TypeReference<?>>emptyList());
    return createTransactionSeq(function);
}
 
Example #19
Source File: TableTest.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
public String removeSeq(String name, BigInteger item_id) {
    final Function function =
            new Function(
                    FUNC_REMOVE,
                    Arrays.<Type>asList(
                            new org.fisco.bcos.web3j.abi.datatypes.Utf8String(name),
                            new org.fisco.bcos.web3j.abi.datatypes.generated.Int256(item_id)),
                    Collections.<TypeReference<?>>emptyList());
    return createTransactionSeq(function);
}
 
Example #20
Source File: TestRingSig.java    From group-signature-client with GNU General Public License v3.0 5 votes vote down vote up
public RemoteCall<String> get_ring_message() {
    final Function function =
            new Function(
                    FUNC_GET_RING_MESSAGE,
                    Arrays.<Type>asList(),
                    Arrays.<TypeReference<?>>asList(new TypeReference<Utf8String>() {}));
    return executeRemoteCallSingleValueReturn(function, String.class);
}
 
Example #21
Source File: Consensus.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
public RemoteCall<TransactionReceipt> remove(String nodeID) {
    final Function function =
            new Function(
                    FUNC_REMOVE,
                    Arrays.<Type>asList(
                            new org.fisco.bcos.web3j.abi.datatypes.Utf8String(nodeID)),
                    Collections.<TypeReference<?>>emptyList());
    return executeRemoteCallTransaction(function);
}
 
Example #22
Source File: DagTransfer.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
public void userSave(String user, BigInteger balance, TransactionSucCallback callback) {
    final Function function =
            new Function(
                    FUNC_USERSAVE,
                    Arrays.<Type>asList(
                            new org.fisco.bcos.web3j.abi.datatypes.Utf8String(user),
                            new org.fisco.bcos.web3j.abi.datatypes.generated.Uint256(balance)),
                    Collections.<TypeReference<?>>emptyList());
    asyncExecuteTransaction(function, callback);
}
 
Example #23
Source File: ContractAbiUtil.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
/**
 * @param paramTypes
 * @return
 * @throws BaseException
 */
public static List<TypeReference<?>> paramFormat(List<NamedType> paramTypes)
        throws BaseException {
    List<TypeReference<?>> finalOutputs = new ArrayList<>();

    for (int i = 0; i < paramTypes.size(); i++) {

        AbiDefinition.NamedType.Type type =
                new AbiDefinition.NamedType.Type(paramTypes.get(i).getType());
        // nested array , not support now.
        if (type.getDepth() > 1) {
            throw new BaseException(
                    201202,
                    String.format("type:%s unsupported array decoding", type.getName()));
        }

        TypeReference<?> typeReference = null;
        if (type.dynamicArray()) {
            typeReference =
                    DynamicArrayReference.create(
                            type.getBaseName(), paramTypes.get(i).isIndexed());
        } else if (type.staticArray()) {
            typeReference =
                    StaticArrayReference.create(
                            type.getBaseName(),
                            type.getDimensions(),
                            paramTypes.get(i).isIndexed());
        } else {
            typeReference =
                    TypeReference.create(
                            ContractTypeUtil.getType(paramTypes.get(i).getType()),
                            paramTypes.get(i).isIndexed());
        }

        finalOutputs.add(typeReference);
    }
    return finalOutputs;
}
 
Example #24
Source File: FunctionInputDecode.java    From WeBASE-Collect-Bee with Apache License 2.0 5 votes vote down vote up
/**
 * decode function input, return List<Type>.
 * 
 * @param rawInput
 * @param inputParameters
 * @return
 * @return List<Type>
 */
public static List<Type> decode(String rawInput, List<TypeReference<Type>> inputParameters) {
    String input = Numeric.cleanHexPrefix(rawInput);
    log.info("input without Prefix : {}", input);

    if (input == null || input.length() == 0) {
        return Collections.emptyList();
    } else {
        return build(input, inputParameters);
    }
}
 
Example #25
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 #26
Source File: ContractLifeCyclePrecompiled.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
public void unfreeze(String addr, TransactionSucCallback callback) {
    final Function function =
            new Function(
                    FUNC_UNFREEZE,
                    Arrays.<Type>asList(new org.fisco.bcos.web3j.abi.datatypes.Address(addr)),
                    Collections.<TypeReference<?>>emptyList());
    asyncExecuteTransaction(function, callback);
}
 
Example #27
Source File: ContractLifeCyclePrecompiled.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
public Tuple1<BigInteger> getGrantManagerOutput(TransactionReceipt transactionReceipt) {
    String data = transactionReceipt.getOutput();
    final Function function =
            new Function(
                    FUNC_GRANTMANAGER,
                    Arrays.<Type>asList(),
                    Arrays.<TypeReference<?>>asList(new TypeReference<Int256>() {}));
    List<Type> results = FunctionReturnDecoder.decode(data, function.getOutputParameters());
    ;
    return new Tuple1<BigInteger>((BigInteger) results.get(0).getValue());
}
 
Example #28
Source File: MixContract.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
public RemoteCall<TransactionReceipt> create() {
    final Function function =
            new Function(
                    FUNC_CREATE,
                    Arrays.<Type>asList(),
                    Collections.<TypeReference<?>>emptyList());
    return executeRemoteCallTransaction(function);
}
 
Example #29
Source File: ContractAbiUtilTest.java    From WeBASE-Front with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetFunctionFromAbi() throws Exception {
    String contractName = "hello";
    String version = "1.0";
    List<AbiDefinition> abiList = ContractAbiUtil.loadContractDefinition(new File("src/test/resources/solidity/Ok.abi"));
    ContractAbiUtil.setContractWithAbi(contractName, version, abiList, false);
    List<ContractAbiUtil.VersionEvent> versionEvents = contractEventMap.get("hello");
    String funcName = "trans";
    List<String> funcInputTypes = versionEvents.get(0).getFuncInputs().get(funcName);
    ArrayList a = new ArrayList();
    a.add("123");
    List<Object> params = a;
    List<Type> finalInputs = AbiUtil.inputFormat(funcInputTypes, params);
    List<String> funOutputTypes = ContractAbiUtil.getFuncOutputType(contractName, "trans", version);
    List<TypeReference<?>> finalOutputs = outputFormat(funOutputTypes);
    Function function = new Function(funcName, finalInputs, finalOutputs);

    Ok okDemo = Ok.deploy(web3j, credentials, gasPrice, gasLimit).send();
    ContractGasProvider contractGasProvider = new StaticGasProvider(Constants.GAS_PRICE, Constants.GAS_LIMIT);
    CommonContract commonContract = CommonContract.load(okDemo.getContractAddress(), web3j, credentials, contractGasProvider);

    TransactionReceipt t  = TransService.execTransaction(function, commonContract);
    System.out.println("***********************");
    System.out.println(t);

    //invoke get function
    String funcName1 = "get";
    List<String> funcInputTypes1 = versionEvents.get(0).getFuncInputs().get(funcName1);
    ArrayList a1 = new ArrayList();
    List<Object> params1 = a1;
    List<Type> finalInputs1 = AbiUtil.inputFormat(funcInputTypes1, params1);

    List<String> funOutputTypes1 = ContractAbiUtil.getFuncOutputType(contractName, funcName1, version);
    List<TypeReference<?>> finalOutputs1 = outputFormat(funOutputTypes1);
    Function function1 = new Function(funcName1, finalInputs1, finalOutputs1);
    Object o  = TransService.execCall(funOutputTypes1, function1, commonContract);
}
 
Example #30
Source File: Permission.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
public Tuple1<BigInteger> getGrantWriteOutput(TransactionReceipt transactionReceipt) {
    String data = transactionReceipt.getOutput();
    final Function function =
            new Function(
                    FUNC_GRANTWRITE,
                    Arrays.<Type>asList(),
                    Arrays.<TypeReference<?>>asList(new TypeReference<Int256>() {}));
    List<Type> results = FunctionReturnDecoder.decode(data, function.getOutputParameters());
    ;
    return new Tuple1<BigInteger>((BigInteger) results.get(0).getValue());
}