org.fisco.bcos.web3j.abi.datatypes.generated.Uint16 Java Examples

The following examples show how to use org.fisco.bcos.web3j.abi.datatypes.generated.Uint16. 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: CallContractTest.java    From web3sdk with Apache License 2.0 4 votes vote down vote up
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);
}