use of org.fisco.bcos.web3j.abi.datatypes.StaticArray in project web3sdk by FISCO-BCOS.
the class CallContractTest method testSyncCallContract.
private static void testSyncCallContract(CallContract callContract, String address) {
CallResult contractResult;
contractResult = callContract.call(address, "getStringOld", new Utf8String("hello world"), new Int256(10086), new Bool(true));
List<TypeReference<?>> referencesList = Arrays.<TypeReference<?>>asList(new TypeReference<Utf8String>() {
});
List<Type> returnList1 = FunctionReturnDecoder.decode(contractResult.getOutput(), Utils.convert(referencesList));
System.out.println("call getStringOld: " + (String) returnList1.get(0).getValue());
TransactionReceipt receipt;
receipt = callContract.sendTransaction(gasPrice, gasLimit, address, "setAndget", new Utf8String("hello world"), new Int256(10086));
referencesList = Arrays.<TypeReference<?>>asList(new TypeReference<Utf8String>() {
}, new TypeReference<Int256>() {
});
List<Type> returnList2 = FunctionReturnDecoder.decode(receipt.getOutput(), Utils.convert(referencesList));
System.out.println("call setAndget: " + (String) returnList2.get(0).getValue() + ", " + (BigInteger) returnList2.get(1).getValue());
receipt = callContract.sendTransaction(address, "setAndget", new Utf8String("hello world"), new Int256(10086));
referencesList = Arrays.<TypeReference<?>>asList(new TypeReference<Utf8String>() {
}, new TypeReference<Int256>() {
});
List<Type> returnList3 = FunctionReturnDecoder.decode(receipt.getOutput(), Utils.convert(referencesList));
System.out.println("default call setAndget: " + (String) returnList3.get(0).getValue() + ", " + (BigInteger) returnList3.get(1).getValue());
contractResult = callContract.call(address, "getArray", new StaticArray2(typeMap(Arrays.asList(BigInteger.valueOf(-1), BigInteger.valueOf(2)), Int16.class)), new DynamicArray(typeMap(Arrays.asList(BigInteger.valueOf(2), BigInteger.valueOf(2)), Uint16.class)));
List<Type> returnList4 = callContract.decode(contractResult.getOutput(), new TypeReference<StaticArray2<Int16>>() {
}, new TypeReference<DynamicArray<Int16>>() {
});
System.out.println("call getArray: " + callContract.convertList((List<Type>) returnList4.get(0).getValue()) + ", " + callContract.convertList((List<Type>) returnList4.get(1).getValue()));
List<List<BigInteger>> dyadicArray = new ArrayList<List<BigInteger>>();
dyadicArray.add(Arrays.asList(BigInteger.valueOf(-1), BigInteger.valueOf(2)));
dyadicArray.add(Arrays.asList(BigInteger.valueOf(-1), BigInteger.valueOf(992)));
byte[] bytes = new byte[] { 'a', 'b' };
contractResult = callContract.call(address, "newTest", new StaticArray2(typeMap(dyadicArray, StaticArray2.class, Int256.class)), new DynamicBytes(bytes));
List<Type> returnList5 = callContract.decode(contractResult.getOutput(), new TypeReference<StaticArray2<StaticArray2<Int256>>>() {
}, new TypeReference<DynamicBytes>() {
});
System.out.println("call newTest: " + callContract.convertListList((List<StaticArray<Int256>>) returnList5.get(0).getValue()) + ", " + new String((byte[]) returnList5.get(1).getValue()) + ", " + dyadicArray);
}
Aggregations