Java源码示例:org.fisco.bcos.web3j.abi.TypeReference
示例1
/**
* 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;
}
示例2
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);
}
示例3
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()));
}
});
}
示例4
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()));
}
});
}
示例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());
}
示例6
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;
}
示例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);
}
示例8
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);
}
示例9
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);
}
示例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);
}
示例11
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);
}
示例12
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);
}
示例13
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);
}
示例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);
}
示例15
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);
}
示例16
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);
}
示例17
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());
}
示例18
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);
}
示例19
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);
}
示例20
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);
}
示例21
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());
}
示例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);
}
示例23
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);
}
示例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);
}
示例25
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);
}
示例26
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;
});
}
示例27
/**
* @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);
}
示例28
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);
}
示例29
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());
}
示例30
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);
}