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

The following examples show how to use org.fisco.bcos.web3j.abi.TypeReference. These examples are extracted from open source projects. 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 Project: WeBASE-Front   Source File: AbiUtil.java    License: 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 2
Source Project: web3sdk   Source File: CRUD.java    License: 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 3
Source Project: web3sdk   Source File: TableTest.java    License: 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 Project: web3sdk   Source File: TableTest.java    License: 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
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 6
Source Project: WeBASE-Codegen-Monkey   Source File: TypeReferenceUtils.java    License: 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 7
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 8
Source Project: web3sdk   Source File: MixContract.java    License: Apache License 2.0 5 votes vote down vote up
public RemoteCall<TransactionReceipt> remove(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 executeRemoteCallTransaction(function);
}
 
Example 9
Source Project: web3sdk   Source File: Permission.java    License: Apache License 2.0 5 votes vote down vote up
public String removeSeq(String table_name, String addr) {
    final Function function =
            new Function(
                    FUNC_REMOVE,
                    Arrays.<Type>asList(
                            new org.fisco.bcos.web3j.abi.datatypes.Utf8String(table_name),
                            new org.fisco.bcos.web3j.abi.datatypes.Utf8String(addr)),
                    Collections.<TypeReference<?>>emptyList());
    return createTransactionSeq(function);
}
 
Example 10
public RemoteCall<String> get_ring_sig() {
    final Function function =
            new Function(
                    FUNC_GET_RING_SIG,
                    Arrays.<Type>asList(),
                    Arrays.<TypeReference<?>>asList(new TypeReference<Utf8String>() {}));
    return executeRemoteCallSingleValueReturn(function, String.class);
}
 
Example 11
Source Project: web3sdk   Source File: ParallelOk.java    License: Apache License 2.0 5 votes vote down vote up
public String registerParallelFunctionSeq(String functionName, BigInteger criticalSize) {
    final Function function =
            new Function(
                    FUNC_REGISTERPARALLELFUNCTION,
                    Arrays.<Type>asList(
                            new org.fisco.bcos.web3j.abi.datatypes.Utf8String(functionName),
                            new org.fisco.bcos.web3j.abi.datatypes.generated.Uint256(
                                    criticalSize)),
                    Collections.<TypeReference<?>>emptyList());
    return createTransactionSeq(function);
}
 
Example 12
Source Project: web3sdk   Source File: CRUD.java    License: Apache License 2.0 5 votes vote down vote up
public RemoteCall<TransactionReceipt> remove(
        String tableName, String key, String condition, String optional) {
    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());
    return executeRemoteCallTransaction(function);
}
 
Example 13
Source Project: web3sdk   Source File: ChainGovernance.java    License: Apache License 2.0 5 votes vote down vote up
public void unfreezeAccount(String account, TransactionSucCallback callback) {
    final Function function =
            new Function(
                    FUNC_UNFREEZEACCOUNT,
                    Arrays.<Type>asList(
                            new org.fisco.bcos.web3j.abi.datatypes.Address(account)),
                    Collections.<TypeReference<?>>emptyList());
    asyncExecuteTransaction(function, callback);
}
 
Example 14
public RemoteCall<Boolean> get_group_verify_result() {
    final Function function =
            new Function(
                    FUNC_GET_GROUP_VERIFY_RESULT,
                    Arrays.<Type>asList(),
                    Arrays.<TypeReference<?>>asList(new TypeReference<Bool>() {}));
    return executeRemoteCallSingleValueReturn(function, Boolean.class);
}
 
Example 15
Source Project: evidenceSample   Source File: Evidence.java    License: Apache License 2.0 5 votes vote down vote up
public RemoteCall<TransactionReceipt> addSignatures(BigInteger v, byte[] r, byte[] s) {
    final Function function = new Function(
            FUNC_ADDSIGNATURES, 
            Arrays.<Type>asList(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)), 
            Collections.<TypeReference<?>>emptyList());
    return executeRemoteCallTransaction(function);
}
 
Example 16
Source Project: WeBASE-Front   Source File: Ok.java    License: Apache License 2.0 5 votes vote down vote up
public RemoteCall<TransactionReceipt> trans(BigInteger num) {
    final Function function = new Function(
            FUNC_TRANS, 
            Arrays.<Type>asList(new org.fisco.bcos.web3j.abi.datatypes.generated.Uint256(num)), 
            Collections.<TypeReference<?>>emptyList());
    return executeRemoteCallTransaction(function);
}
 
Example 17
Source Project: web3sdk   Source File: ContractLifeCyclePrecompiled.java    License: Apache License 2.0 5 votes vote down vote up
public Tuple1<String> getFreezeInput(TransactionReceipt transactionReceipt) {
    String data = transactionReceipt.getInput().substring(10);
    final Function function =
            new Function(
                    FUNC_FREEZE,
                    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 18
Source Project: web3sdk   Source File: ParallelOk.java    License: Apache License 2.0 5 votes vote down vote up
public RemoteCall<BigInteger> balanceOf(String name) {
    final Function function =
            new Function(
                    FUNC_BALANCEOF,
                    Arrays.<Type>asList(
                            new org.fisco.bcos.web3j.abi.datatypes.Utf8String(name)),
                    Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}));
    return executeRemoteCallSingleValueReturn(function, BigInteger.class);
}
 
Example 19
Source Project: web3sdk   Source File: DagTransfer.java    License: Apache License 2.0 5 votes vote down vote up
public void userDraw(String user, BigInteger balance, TransactionSucCallback callback) {
    final Function function =
            new Function(
                    FUNC_USERDRAW,
                    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 20
Source Project: web3sdk   Source File: TableFactory.java    License: Apache License 2.0 5 votes vote down vote up
public void createTable(
        String tableName, String key, String valueField, TransactionSucCallback callback) {
    final Function function =
            new Function(
                    FUNC_CREATETABLE,
                    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(valueField)),
                    Collections.<TypeReference<?>>emptyList());
    asyncExecuteTransaction(function, callback);
}
 
Example 21
Source Project: web3sdk   Source File: EvidenceVerify.java    License: Apache License 2.0 5 votes vote down vote up
public Tuple8<String, String, String, String, byte[], BigInteger, byte[], byte[]>
        getInsertEvidenceInput(TransactionReceipt transactionReceipt) {
    String data = transactionReceipt.getInput().substring(10);
    final Function function =
            new Function(
                    FUNC_INSERTEVIDENCE,
                    Arrays.<Type>asList(),
                    Arrays.<TypeReference<?>>asList(
                            new TypeReference<Utf8String>() {},
                            new TypeReference<Utf8String>() {},
                            new TypeReference<Utf8String>() {},
                            new TypeReference<Address>() {},
                            new TypeReference<Bytes32>() {},
                            new TypeReference<Uint8>() {},
                            new TypeReference<Bytes32>() {},
                            new TypeReference<Bytes32>() {}));
    List<Type> results = FunctionReturnDecoder.decode(data, function.getOutputParameters());
    ;
    return new Tuple8<String, String, String, String, byte[], BigInteger, byte[], byte[]>(
            (String) results.get(0).getValue(),
            (String) results.get(1).getValue(),
            (String) results.get(2).getValue(),
            (String) results.get(3).getValue(),
            (byte[]) results.get(4).getValue(),
            (BigInteger) results.get(5).getValue(),
            (byte[]) results.get(6).getValue(),
            (byte[]) results.get(7).getValue());
}
 
Example 22
public RemoteCall<TransactionReceipt> update_group_sig_data(
        String new_sig, String new_message, String new_gpk_info, String new_pbc_param_info) {
    final Function function =
            new Function(
                    FUNC_UPDATE_GROUP_SIG_DATA,
                    Arrays.<Type>asList(
                            new Utf8String(new_sig),
                            new Utf8String(new_message),
                            new Utf8String(new_gpk_info),
                            new Utf8String(new_pbc_param_info)),
                    Collections.<TypeReference<?>>emptyList());
    return executeRemoteCallTransaction(function);
}
 
Example 23
Source Project: WeBASE-Front   Source File: Evidence.java    License: Apache License 2.0 5 votes vote down vote up
public String addSignaturesSeq(BigInteger v, byte[] r, byte[] s) {
    final Function function = new Function(
            FUNC_ADDSIGNATURES, 
            Arrays.<Type>asList(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)), 
            Collections.<TypeReference<?>>emptyList());
    return createTransactionSeq(function);
}
 
Example 24
public RemoteCall<String> get_group_gpk_info() {
    final Function function =
            new Function(
                    FUNC_GET_GROUP_GPK_INFO,
                    Arrays.<Type>asList(),
                    Arrays.<TypeReference<?>>asList(new TypeReference<Utf8String>() {}));
    return executeRemoteCallSingleValueReturn(function, String.class);
}
 
Example 25
Source Project: web3sdk   Source File: MixContract.java    License: Apache License 2.0 5 votes vote down vote up
public RemoteCall<BigInteger> totalKeys() {
    final Function function =
            new Function(
                    FUNC_TOTALKEYS,
                    Arrays.<Type>asList(),
                    Arrays.<TypeReference<?>>asList(new TypeReference<Int256>() {}));
    return executeRemoteCallSingleValueReturn(function, BigInteger.class);
}
 
Example 26
Source Project: WeEvent   Source File: FiscoBcos2.java    License: Apache License 2.0 5 votes vote down vote up
public CompletableFuture<SendResult> sendRawTransaction(String topicName, String transactionHex) {
    return web3j.sendRawTransaction(transactionHex).sendAsync().thenApplyAsync(ethSendTransaction -> {
        SendResult sendResult = new SendResult();
        sendResult.setTopic(topicName);

        Optional<TransactionReceipt> receiptOptional = getTransactionReceiptRequest(ethSendTransaction.getTransactionHash());
        if (receiptOptional.isPresent()) {
            List<TypeReference<?>> referencesList = Collections.singletonList(new TypeReference<Uint256>() {
            });
            List<Type> returnList = FunctionReturnDecoder.decode(
                    String.valueOf(receiptOptional.get().getOutput()),
                    Utils.convert(referencesList));

            int sequence = ((BigInteger) returnList.get(0).getValue()).intValue();
            if (sequence == 0) {
                log.error("this FISCO-BCOS account has no permission to publish event");
                sendResult.setStatus(SendResult.SendResultStatus.NO_PERMISSION);
            } else {
                sendResult.setStatus(SendResult.SendResultStatus.SUCCESS);
                sendResult.setEventId(DataTypeUtils.encodeEventId(topicName,
                        receiptOptional.get().getBlockNumber().intValue(),
                        sequence));
            }
        } else {
            sendResult.setStatus(SendResult.SendResultStatus.ERROR);
        }

        return sendResult;
    });
}
 
Example 27
Source Project: web3sdk   Source File: TransactionDecoder.java    License: 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 28
Source Project: web3sdk   Source File: TableTest.java    License: Apache License 2.0 5 votes vote down vote up
public String insertSeq(String name, BigInteger item_id, String item_name) {
    final Function function =
            new Function(
                    FUNC_INSERT,
                    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 createTransactionSeq(function);
}
 
Example 29
Source Project: web3sdk   Source File: Permission.java    License: Apache License 2.0 5 votes vote down vote up
public Tuple2<String, String> getRemoveInput(TransactionReceipt transactionReceipt) {
    String data = transactionReceipt.getInput().substring(10);
    final Function function =
            new Function(
                    FUNC_REMOVE,
                    Arrays.<Type>asList(),
                    Arrays.<TypeReference<?>>asList(
                            new TypeReference<Utf8String>() {},
                            new TypeReference<Utf8String>() {}));
    List<Type> results = FunctionReturnDecoder.decode(data, function.getOutputParameters());
    ;
    return new Tuple2<String, String>(
            (String) results.get(0).getValue(), (String) results.get(1).getValue());
}
 
Example 30
Source Project: WeBASE-Front   Source File: HelloWorld.java    License: Apache License 2.0 5 votes vote down vote up
public String setSeq(List<BigInteger> _ua) {
    final Function function = new Function(
            FUNC_SET, 
            Arrays.<Type>asList(_ua.isEmpty()?org.fisco.bcos.web3j.abi.datatypes.DynamicArray.empty("uint256[]"):new org.fisco.bcos.web3j.abi.datatypes.DynamicArray<org.fisco.bcos.web3j.abi.datatypes.generated.Uint256>(
                    org.fisco.bcos.web3j.abi.Utils.typeMap(_ua, org.fisco.bcos.web3j.abi.datatypes.generated.Uint256.class))), 
            Collections.<TypeReference<?>>emptyList());
    return createTransactionSeq(function);
}