Java Code Examples for org.fisco.bcos.web3j.abi.datatypes.DynamicArray

The following examples show how to use org.fisco.bcos.web3j.abi.datatypes.DynamicArray. 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: Evidence.java    License: Apache License 2.0 6 votes vote down vote up
public RemoteCall<Tuple7<String, String, String, List<BigInteger>, List<byte[]>, List<byte[]>, List<String>>> getEvidence() {
    final Function function = new Function(FUNC_GETEVIDENCE, 
            Arrays.<Type>asList(), 
            Arrays.<TypeReference<?>>asList(new TypeReference<Utf8String>() {}, new TypeReference<Utf8String>() {}, new TypeReference<Utf8String>() {}, new TypeReference<DynamicArray<Uint8>>() {}, new TypeReference<DynamicArray<Bytes32>>() {}, new TypeReference<DynamicArray<Bytes32>>() {}, new TypeReference<DynamicArray<Address>>() {}));
    return new RemoteCall<Tuple7<String, String, String, List<BigInteger>, List<byte[]>, List<byte[]>, List<String>>>(
            new Callable<Tuple7<String, String, String, List<BigInteger>, List<byte[]>, List<byte[]>, List<String>>>() {
                @Override
                public Tuple7<String, String, String, List<BigInteger>, List<byte[]>, List<byte[]>, List<String>> call() throws Exception {
                    List<Type> results = executeCallMultipleValueReturn(function);
                    return new Tuple7<String, String, String, List<BigInteger>, List<byte[]>, List<byte[]>, List<String>>(
                            (String) results.get(0).getValue(), 
                            (String) results.get(1).getValue(), 
                            (String) results.get(2).getValue(), 
                            convertToNative((List<Uint8>) results.get(3).getValue()), 
                            convertToNative((List<Bytes32>) results.get(4).getValue()), 
                            convertToNative((List<Bytes32>) results.get(5).getValue()), 
                            convertToNative((List<Address>) results.get(6).getValue()));
                }
            });
}
 
Example 2
Source Project: WeEvent   Source File: TopicController.java    License: Apache License 2.0 6 votes vote down vote up
public RemoteCall<Tuple3<BigInteger, BigInteger, List<String>>> listTopicName(BigInteger pageIndex, BigInteger pageSize) {
    final Function function = new Function(FUNC_LISTTOPICNAME, 
            Arrays.<Type>asList(new org.fisco.bcos.web3j.abi.datatypes.generated.Uint256(pageIndex), 
            new org.fisco.bcos.web3j.abi.datatypes.generated.Uint256(pageSize)), 
            Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}, new TypeReference<Uint256>() {}, new TypeReference<DynamicArray<Utf8String>>() {}));
    return new RemoteCall<Tuple3<BigInteger, BigInteger, List<String>>>(
            new Callable<Tuple3<BigInteger, BigInteger, List<String>>>() {
                @Override
                public Tuple3<BigInteger, BigInteger, List<String>> call() throws Exception {
                    List<Type> results = executeCallMultipleValueReturn(function);
                    return new Tuple3<BigInteger, BigInteger, List<String>>(
                            (BigInteger) results.get(0).getValue(), 
                            (BigInteger) results.get(1).getValue(), 
                            convertToNative((List<Utf8String>) results.get(2).getValue()));
                }
            });
}
 
Example 3
Source Project: WeEvent   Source File: Topic.java    License: Apache License 2.0 6 votes vote down vote up
public RemoteCall<TransactionReceipt> flushSnapshot(List<String> topicName, List<BigInteger> lastSequence,
                                                    List<BigInteger> lastBlock, List<BigInteger> lastTimestamp,
                                                    List<String> lastSender) {
    final Function function = new Function(
            FUNC_FLUSHSNAPSHOT, 
            Arrays.<Type>asList(topicName.isEmpty()?org.fisco.bcos.web3j.abi.datatypes.DynamicArray.empty("string[]"):
                    new org.fisco.bcos.web3j.abi.datatypes.DynamicArray<org.fisco.bcos.web3j.abi.datatypes.Utf8String>(
                    org.fisco.bcos.web3j.abi.Utils.typeMap(topicName, org.fisco.bcos.web3j.abi.datatypes.Utf8String.class)), 
            lastSequence.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(lastSequence, org.fisco.bcos.web3j.abi.datatypes.generated.Uint256.class)), 
            lastBlock.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(lastBlock, org.fisco.bcos.web3j.abi.datatypes.generated.Uint256.class)), 
            lastTimestamp.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(lastTimestamp, org.fisco.bcos.web3j.abi.datatypes.generated.Uint256.class)), 
            lastSender.isEmpty()?org.fisco.bcos.web3j.abi.datatypes.DynamicArray.empty("address[]"):
                new org.fisco.bcos.web3j.abi.datatypes.DynamicArray<org.fisco.bcos.web3j.abi.datatypes.Address>(
                    org.fisco.bcos.web3j.abi.Utils.typeMap(lastSender, org.fisco.bcos.web3j.abi.datatypes.Address.class))), 
            Collections.<TypeReference<?>>emptyList());
    return executeRemoteCallTransaction(function);
}
 
Example 4
Source Project: WeEvent   Source File: Topic.java    License: Apache License 2.0 6 votes vote down vote up
public void flushSnapshot(List<String> topicName, List<BigInteger> lastSequence, List<BigInteger> lastBlock,
                          List<BigInteger> lastTimestamp, List<String> lastSender, TransactionSucCallback callback) {
    final Function function = new Function(
            FUNC_FLUSHSNAPSHOT, 
            Arrays.<Type>asList(topicName.isEmpty()?org.fisco.bcos.web3j.abi.datatypes.DynamicArray.empty("string[]"):
                    new org.fisco.bcos.web3j.abi.datatypes.DynamicArray<org.fisco.bcos.web3j.abi.datatypes.Utf8String>(
                    org.fisco.bcos.web3j.abi.Utils.typeMap(topicName, org.fisco.bcos.web3j.abi.datatypes.Utf8String.class)), 
            lastSequence.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(lastSequence, org.fisco.bcos.web3j.abi.datatypes.generated.Uint256.class)), 
            lastBlock.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(lastBlock, org.fisco.bcos.web3j.abi.datatypes.generated.Uint256.class)), 
            lastTimestamp.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(lastTimestamp, org.fisco.bcos.web3j.abi.datatypes.generated.Uint256.class)), 
            lastSender.isEmpty()?org.fisco.bcos.web3j.abi.datatypes.DynamicArray.empty("address[]"):
                new org.fisco.bcos.web3j.abi.datatypes.DynamicArray<org.fisco.bcos.web3j.abi.datatypes.Address>(
                    org.fisco.bcos.web3j.abi.Utils.typeMap(lastSender, org.fisco.bcos.web3j.abi.datatypes.Address.class))), 
            Collections.<TypeReference<?>>emptyList());
    asyncExecuteTransaction(function, callback);
}
 
Example 5
Source Project: WeEvent   Source File: Topic.java    License: Apache License 2.0 6 votes vote down vote up
public String flushSnapshotSeq(List<String> topicName, List<BigInteger> lastSequence, List<BigInteger> lastBlock, List<BigInteger> lastTimestamp, List<String> lastSender) {
    final Function function = new Function(
            FUNC_FLUSHSNAPSHOT, 
            Arrays.<Type>asList(topicName.isEmpty()?org.fisco.bcos.web3j.abi.datatypes.DynamicArray.empty("string[]"):
                    new org.fisco.bcos.web3j.abi.datatypes.DynamicArray<org.fisco.bcos.web3j.abi.datatypes.Utf8String>(
                    org.fisco.bcos.web3j.abi.Utils.typeMap(topicName, org.fisco.bcos.web3j.abi.datatypes.Utf8String.class)), 
            lastSequence.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(lastSequence, org.fisco.bcos.web3j.abi.datatypes.generated.Uint256.class)), 
            lastBlock.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(lastBlock, org.fisco.bcos.web3j.abi.datatypes.generated.Uint256.class)), 
            lastTimestamp.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(lastTimestamp, org.fisco.bcos.web3j.abi.datatypes.generated.Uint256.class)), 
            lastSender.isEmpty()?org.fisco.bcos.web3j.abi.datatypes.DynamicArray.empty("address[]"):
                new org.fisco.bcos.web3j.abi.datatypes.DynamicArray<org.fisco.bcos.web3j.abi.datatypes.Address>(
                    org.fisco.bcos.web3j.abi.Utils.typeMap(lastSender, org.fisco.bcos.web3j.abi.datatypes.Address.class))), 
            Collections.<TypeReference<?>>emptyList());
    return createTransactionSeq(function);
}
 
Example 6
Source Project: WeEvent   Source File: Topic.java    License: Apache License 2.0 6 votes vote down vote up
public Tuple5<List<String>, List<BigInteger>, List<BigInteger>, List<BigInteger>, List<String>> getFlushSnapshotInput(TransactionReceipt transactionReceipt) {
    String data = transactionReceipt.getInput().substring(10);
    final Function function = new Function(FUNC_FLUSHSNAPSHOT, 
            Arrays.<Type>asList(), 
            Arrays.<TypeReference<?>>asList(
                new TypeReference<DynamicArray<Utf8String>>() {},
                new TypeReference<DynamicArray<Uint256>>() {},
                new TypeReference<DynamicArray<Uint256>>() {},
                new TypeReference<DynamicArray<Uint256>>() {},
                new TypeReference<DynamicArray<Address>>() {}));
    List<Type> results = FunctionReturnDecoder.decode(data, function.getOutputParameters());;
    return new Tuple5<List<String>, List<BigInteger>, List<BigInteger>, List<BigInteger>, List<String>>(

            convertToNative((List<Utf8String>) results.get(0).getValue()), 
            convertToNative((List<Uint256>) results.get(1).getValue()), 
            convertToNative((List<Uint256>) results.get(2).getValue()), 
            convertToNative((List<Uint256>) results.get(3).getValue()), 
            convertToNative((List<Address>) results.get(4).getValue())
            );
}
 
Example 7
Source Project: web3sdk   Source File: ContractLifeCyclePrecompiled.java    License: Apache License 2.0 6 votes vote down vote up
public RemoteCall<Tuple2<BigInteger, List<String>>> listManager(String addr) {
    final Function function =
            new Function(
                    FUNC_LISTMANAGER,
                    Arrays.<Type>asList(new org.fisco.bcos.web3j.abi.datatypes.Address(addr)),
                    Arrays.<TypeReference<?>>asList(
                            new TypeReference<Int256>() {},
                            new TypeReference<DynamicArray<Address>>() {}));
    return new RemoteCall<Tuple2<BigInteger, List<String>>>(
            new Callable<Tuple2<BigInteger, List<String>>>() {
                @Override
                public Tuple2<BigInteger, List<String>> call() throws Exception {
                    List<Type> results = executeCallMultipleValueReturn(function);
                    return new Tuple2<BigInteger, List<String>>(
                            (BigInteger) results.get(0).getValue(),
                            convertToNative((List<Address>) results.get(1).getValue()));
                }
            });
}
 
Example 8
Source Project: web3sdk   Source File: TypeDecoder.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public static <T extends Type> T decodeDynamicArray(
        String input, int offset, java.lang.reflect.Type type) {

    int length = decodeUintAsInt(input, offset);

    BiFunction<List<T>, String, T> function =
            (elements, typeName) -> {
                if (elements.isEmpty()) {
                    return (T) DynamicArray.empty(typeName);
                } else {
                    return (T) new DynamicArray<>(elements);
                }
            };

    int valueOffset = offset + MAX_BYTE_LENGTH_FOR_HEX_STRING;

    return decodeArrayElements(input, valueOffset, type, length, function);
}
 
Example 9
Source Project: web3sdk   Source File: Utils.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
public static <T extends Type> boolean dynamicType(java.lang.reflect.Type type)
        throws ClassNotFoundException {

    Class<T> cls = Utils.getClassType(type);
    // dynamic type
    if (Utf8String.class.isAssignableFrom(cls)
            || DynamicBytes.class.isAssignableFrom(cls)
            || DynamicArray.class.isAssignableFrom(cls)) {
        return true;
    }

    // not static type
    if (!StaticArray.class.isAssignableFrom(cls)) {
        return false;
    }

    // unpack static array for checking if dynamic type
    java.lang.reflect.Type[] types = ((ParameterizedType) type).getActualTypeArguments();
    return dynamicType(types[0]);
}
 
Example 10
Source Project: web3sdk   Source File: MixContract.java    License: Apache License 2.0 6 votes vote down vote up
public RemoteCall<Tuple3<List<byte[]>, List<BigInteger>, List<byte[]>>> read(String name) {
    final Function function =
            new Function(
                    FUNC_READ,
                    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 11
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 12
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 13
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 14
Source Project: web3sdk   Source File: EventEncoderTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testEventbuildMethodSignature0() {
    Event event =
            new Event(
                    "g",
                    Arrays.<TypeReference<?>>asList(
                            new TypeReference<DynamicArray<DynamicArray<Uint256>>>() {},
                            new TypeReference<DynamicArray<Utf8String>>() {}));

    assertThat(
            EventEncoder.buildMethodSignature(event.getName(), event.getParameters()),
            is("g(uint256[][],string[])"));

    assertThat(
            EventEncoder.encode(event),
            is("0x2289b18cd8c6e198648b35d3bcf2ff8668984543f01927711c161bcf7b5e1bba"));

    assertThat(
            EventEncoder.buildEventSignature("g(uint256[][],string[])"),
            is("0x2289b18cd8c6e198648b35d3bcf2ff8668984543f01927711c161bcf7b5e1bba"));
}
 
Example 15
Source Project: web3sdk   Source File: EventEncoderTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testEventbuildMethodSignature1() {
    Event event =
            new Event(
                    "f",
                    Arrays.<TypeReference<?>>asList(
                            new TypeReference<Uint>() {},
                            new TypeReference<DynamicArray<Uint32>>() {},
                            new TypeReference<Bytes10>() {},
                            new TypeReference<DynamicBytes>() {}));

    assertThat(
            EventEncoder.buildMethodSignature(event.getName(), event.getParameters()),
            is("f(uint256,uint32[],bytes10,bytes)"));

    assertThat(
            EventEncoder.encode(event),
            is("0x8be652465888a0c5d65fc9d0a7e898b9ca98de97185c53a54ec408fd2fd5d45d"));

    assertThat(
            EventEncoder.buildEventSignature("f(uint256,uint32[],bytes10,bytes)"),
            is("0x8be652465888a0c5d65fc9d0a7e898b9ca98de97185c53a54ec408fd2fd5d45d"));
}
 
Example 16
Source Project: web3sdk   Source File: EventEncoderTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testEventbuildMethodSignature2() {
    Event event =
            new Event(
                    "f",
                    Arrays.<TypeReference<?>>asList(
                            new TypeReference<DynamicBytes>() {},
                            new TypeReference<Bool>() {},
                            new TypeReference<DynamicArray<Uint256>>() {}));

    assertThat(
            EventEncoder.buildMethodSignature(event.getName(), event.getParameters()),
            is("f(bytes,bool,uint256[])"));

    assertThat(
            EventEncoder.encode(event),
            is("0xa83b3f0112fa8ecc02937d734929bbaa30731fe27b20195418852fb64ac2837d"));

    assertThat(
            EventEncoder.buildEventSignature("f(bytes,bool,uint256[])"),
            is("0xa83b3f0112fa8ecc02937d734929bbaa30731fe27b20195418852fb64ac2837d"));
}
 
Example 17
Source Project: web3sdk   Source File: EventEncoderTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testEventbuildMethodSignature5() {
    Event event =
            new Event(
                    "test5",
                    Arrays.<TypeReference<?>>asList(
                            new TypeReference<
                                    DynamicArray<
                                            DynamicArray<
                                                    DynamicArray<
                                                            DynamicArray<Utf8String>>>>>() {}));

    assertThat(
            EventEncoder.buildMethodSignature(event.getName(), event.getParameters()),
            is("test5(string[][][][])"));

    assertThat(
            EventEncoder.encode(event),
            is("0x69f175db6ba77ff81ba5e31ca58ddfeb6b2ea420d1233fba18371dc63a12e9c1"));

    assertThat(
            EventEncoder.buildEventSignature("test5(string[][][][])"),
            is("0x69f175db6ba77ff81ba5e31ca58ddfeb6b2ea420d1233fba18371dc63a12e9c1"));
}
 
Example 18
Source Project: web3sdk   Source File: EventEncoderTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testEventbuildMethodSignature6() {
    Event event =
            new Event(
                    "test6",
                    Arrays.<TypeReference<?>>asList(
                            new TypeReference<Uint256>() {},
                            new TypeReference<Int256>() {},
                            new TypeReference<Utf8String>() {},
                            new TypeReference<DynamicArray<Utf8String>>() {},
                            new TypeReference<StaticArray3<Utf8String>>() {}));

    assertThat(
            EventEncoder.buildMethodSignature(event.getName(), event.getParameters()),
            is("test6(uint256,int256,string,string[],string[3])"));

    assertThat(
            EventEncoder.encode(event),
            is("0x5199068657caa55d23ad866ba738a7f21e567e6f50aa8173ac108efdd5d3bb79"));

    assertThat(
            EventEncoder.buildEventSignature("test6(uint256,int256,string,string[],string[3])"),
            is("0x5199068657caa55d23ad866ba738a7f21e567e6f50aa8173ac108efdd5d3bb79"));
}
 
Example 19
Source Project: web3sdk   Source File: EventEncoderTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testEventbuildMethodSignature9() {
    Event event =
            new Event(
                    "test9",
                    Arrays.<TypeReference<?>>asList(
                            new TypeReference<Utf8String>() {},
                            new TypeReference<Uint256>() {},
                            new TypeReference<StaticArray6<Uint256>>() {},
                            new TypeReference<DynamicArray<Uint256>>() {},
                            new TypeReference<Bool>() {},
                            new TypeReference<Address>() {}));

    assertThat(
            EventEncoder.buildMethodSignature(event.getName(), event.getParameters()),
            is("test9(string,uint256,uint256[6],uint256[],bool,address)"));

    assertThat(
            EventEncoder.encode(event),
            is("0xa37d8a63087cf5837e0b9ff13d07d756479f8afdfe4b05ea3dfdc98154ef58ed"));

    assertThat(
            EventEncoder.buildEventSignature(
                    "test9(string,uint256,uint256[6],uint256[],bool,address)"),
            is("0xa37d8a63087cf5837e0b9ff13d07d756479f8afdfe4b05ea3dfdc98154ef58ed"));
}
 
Example 20
Source Project: web3sdk   Source File: EventEncoderTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testEventbuildMethodSignature10() {
    Event event =
            new Event(
                    "test10",
                    Arrays.<TypeReference<?>>asList(
                            new TypeReference<DynamicArray<Utf8String>>() {}));

    assertThat(
            EventEncoder.buildMethodSignature(event.getName(), event.getParameters()),
            is("test10(string[])"));

    assertThat(
            EventEncoder.encode(event),
            is("0xfb9fe4911c195fb1112aaa9c3ac5a54a0c521f8cb0f4ee9290a9bff28542d051"));

    assertThat(
            EventEncoder.buildEventSignature("test10(string[])"),
            is("0xfb9fe4911c195fb1112aaa9c3ac5a54a0c521f8cb0f4ee9290a9bff28542d051"));
}
 
Example 21
Source Project: evidenceSample   Source File: Evidence.java    License: Apache License 2.0 6 votes vote down vote up
public RemoteCall<Tuple7<String, String, String, List<BigInteger>, List<byte[]>, List<byte[]>, List<String>>> getEvidence() {
    final Function function = new Function(FUNC_GETEVIDENCE, 
            Arrays.<Type>asList(), 
            Arrays.<TypeReference<?>>asList(new TypeReference<Utf8String>() {}, new TypeReference<Utf8String>() {}, new TypeReference<Utf8String>() {}, new TypeReference<DynamicArray<Uint8>>() {}, new TypeReference<DynamicArray<Bytes32>>() {}, new TypeReference<DynamicArray<Bytes32>>() {}, new TypeReference<DynamicArray<Address>>() {}));
    return new RemoteCall<Tuple7<String, String, String, List<BigInteger>, List<byte[]>, List<byte[]>, List<String>>>(
            new Callable<Tuple7<String, String, String, List<BigInteger>, List<byte[]>, List<byte[]>, List<String>>>() {
                @Override
                public Tuple7<String, String, String, List<BigInteger>, List<byte[]>, List<byte[]>, List<String>> call() throws Exception {
                    List<Type> results = executeCallMultipleValueReturn(function);
                    return new Tuple7<String, String, String, List<BigInteger>, List<byte[]>, List<byte[]>, List<String>>(
                            (String) results.get(0).getValue(), 
                            (String) results.get(1).getValue(), 
                            (String) results.get(2).getValue(), 
                            convertToNative((List<Uint8>) results.get(3).getValue()), 
                            convertToNative((List<Bytes32>) results.get(4).getValue()), 
                            convertToNative((List<Bytes32>) results.get(5).getValue()), 
                            convertToNative((List<Address>) results.get(6).getValue()));
                }
            });
}
 
Example 22
Source Project: WeBASE-Front   Source File: AbiUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * input parameter format.
 * 
 * @param funcInputTypes list
 * @param params list
 * @return
 */
public static List<Type> inputFormat(List<String> funcInputTypes, List<Object> params)
        throws FrontException {
    List<Type> finalInputs = new ArrayList<>();
    for (int i = 0; i < funcInputTypes.size(); i++) {
        Class<? extends Type> inputType = null;
        Object input = null;
        if (funcInputTypes.get(i).contains("[")
                && funcInputTypes.get(i).contains("]")) {
            List<Object> arrList;
            try {
                arrList = (List<Object>) params.get(i);
            } catch (ClassCastException e) {
                log.error("params of index {} parse List error: {}", i, params.get(i));
                throw new FrontException(ConstantCode.PARAM_ERROR);
            }
            List<Type> arrParams = new ArrayList<>();
            for (int j = 0; j < arrList.size(); j++) {
                inputType = AbiTypes.getType(
                        funcInputTypes.get(i).substring(0, funcInputTypes.get(i).indexOf("[")));
                input = ContractTypeUtil.parseByType(
                        funcInputTypes.get(i).substring(0, funcInputTypes.get(i).indexOf("[")),
                        arrList.get(j).toString());
                arrParams.add(ContractTypeUtil.generateClassFromInput(input.toString(), inputType));
            }
            finalInputs.add(new DynamicArray<>(arrParams));
        } else {
            inputType = AbiTypes.getType(funcInputTypes.get(i));
            input = ContractTypeUtil.parseByType(funcInputTypes.get(i),
                    params.get(i).toString());
            finalInputs.add(ContractTypeUtil.generateClassFromInput(input.toString(), inputType));
        }
    }
    return finalInputs;
}
 
Example 23
Source Project: WeBASE-Front   Source File: EvidenceSignersData.java    License: Apache License 2.0 5 votes vote down vote up
public RemoteCall<List> getSigners() {
    final Function function = new Function(FUNC_GETSIGNERS, 
            Arrays.<Type>asList(), 
            Arrays.<TypeReference<?>>asList(new TypeReference<DynamicArray<Address>>() {}));
    return new RemoteCall<List>(
            new Callable<List>() {
                @Override
                @SuppressWarnings("unchecked")
                public List call() throws Exception {
                    List<Type> result = (List<Type>) executeCallSingleValueReturn(function, List.class);
                    return convertToNative(result);
                }
            });
}
 
Example 24
Source Project: WeBASE-Front   Source File: Evidence.java    License: Apache License 2.0 5 votes vote down vote up
public RemoteCall<List> getSigners() {
    final Function function = new Function(FUNC_GETSIGNERS, 
            Arrays.<Type>asList(), 
            Arrays.<TypeReference<?>>asList(new TypeReference<DynamicArray<Address>>() {}));
    return new RemoteCall<List>(
            new Callable<List>() {
                @Override
                @SuppressWarnings("unchecked")
                public List call() throws Exception {
                    List<Type> result = (List<Type>) executeCallSingleValueReturn(function, List.class);
                    return convertToNative(result);
                }
            });
}
 
Example 25
Source Project: WeBASE-Front   Source File: HelloWorld.java    License: Apache License 2.0 5 votes vote down vote up
public RemoteCall<List> get() {
    final Function function = new Function(FUNC_GET, 
            Arrays.<Type>asList(), 
            Arrays.<TypeReference<?>>asList(new TypeReference<DynamicArray<Uint256>>() {}));
    return new RemoteCall<List>(
            new Callable<List>() {
                @Override
                @SuppressWarnings("unchecked")
                public List call() throws Exception {
                    List<Type> result = (List<Type>) executeCallSingleValueReturn(function, List.class);
                    return convertToNative(result);
                }
            });
}
 
Example 26
Source Project: WeBASE-Front   Source File: HelloWorld.java    License: Apache License 2.0 5 votes vote down vote up
public RemoteCall<TransactionReceipt> set(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 executeRemoteCallTransaction(function);
}
 
Example 27
Source Project: WeBASE-Front   Source File: HelloWorld.java    License: Apache License 2.0 5 votes vote down vote up
public void set(List<BigInteger> _ua, TransactionSucCallback callback) {
    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());
    asyncExecuteTransaction(function, callback);
}
 
Example 28
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);
}
 
Example 29
Source Project: WeBASE-Front   Source File: HelloWorld.java    License: Apache License 2.0 5 votes vote down vote up
public Tuple1<List<BigInteger>> getSetInput(TransactionReceipt transactionReceipt) {
    String data = transactionReceipt.getInput().substring(10);
    final Function function = new Function(FUNC_SET, 
            Arrays.<Type>asList(), 
            Arrays.<TypeReference<?>>asList(new TypeReference<DynamicArray<Uint256>>() {}));
    List<Type> results = FunctionReturnDecoder.decode(data, function.getOutputParameters());;
    return new Tuple1<List<BigInteger>>(

            convertToNative((List<Uint256>) results.get(0).getValue())
            );
}
 
Example 30
Source Project: WeBASE-Transaction   Source File: ContractAbiUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * input parameter format.
 * 
 * @param funcInputTypes list
 * @param params list
 * @return
 */
public static List<Type> inputFormat(List<String> funcInputTypes, List<Object> params)
        throws BaseException {
    List<Type> finalInputs = new ArrayList<>();
    for (int i = 0; i < funcInputTypes.size(); i++) {
        Class<? extends Type> inputType = null;
        Object input = null;
        if (funcInputTypes.get(i).contains("[")
                && funcInputTypes.get(i).contains("]")) {
            List<Object> arrList =
                    new ArrayList<>(Arrays.asList(params.get(i).toString().split(",")));
            inputType = ContractTypeUtil.getType(
                    funcInputTypes.get(i).substring(0, funcInputTypes.get(i).indexOf("[")));
            List<Type> arrParams = new ArrayList<>();
            for (int j = 0; j < arrList.size(); j++) {
                input = ContractTypeUtil.parseByType(
                        funcInputTypes.get(i).substring(0, funcInputTypes.get(i).indexOf("[")),
                        arrList.get(j).toString());
                arrParams.add(ContractTypeUtil.encodeString(input.toString(), inputType));
            }
            finalInputs.add(new DynamicArray<>(arrParams));
        } else {
            inputType = ContractTypeUtil.getType(funcInputTypes.get(i));
            input = ContractTypeUtil.parseByType(funcInputTypes.get(i),
                    params.get(i).toString());
            finalInputs.add(ContractTypeUtil.encodeString(input.toString(), inputType));
        }
    }
    return finalInputs;
}