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

The following examples show how to use org.fisco.bcos.web3j.abi.datatypes.generated.Bytes10. 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: EventEncoderTest.java    From web3sdk with 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 #2
Source File: FunctionReturnDecoderTest.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
@Test
public void testMixTypeDecode1() {
    // function function() constant
    // returns(uint256,uint256[],uint256,bytes10,string)
    Function function =
            new Function(
                    "function",
                    Collections.<Type>emptyList(),
                    Arrays.asList(
                            new TypeReference<Uint256>() {},
                            new TypeReference<DynamicArray<Uint256>>() {},
                            new TypeReference<Bytes10>() {},
                            new TypeReference<Utf8String>() {}));

    assertThat(
            FunctionReturnDecoder.decode(
                    "0000000000000000000000000000000000000000000000000000000000000123"
                            + "0000000000000000000000000000000000000000000000000000000000000080"
                            + "3132333435363738393000000000000000000000000000000000000000000000"
                            + "00000000000000000000000000000000000000000000000000000000000000e0"
                            + "0000000000000000000000000000000000000000000000000000000000000002"
                            + "0000000000000000000000000000000000000000000000000000000000000456"
                            + "0000000000000000000000000000000000000000000000000000000000000789"
                            + "000000000000000000000000000000000000000000000000000000000000000d"
                            + "48656c6c6f2c20776f726c642100000000000000000000000000000000000000",
                    function.getOutputParameters()),
            equalTo(
                    Arrays.asList(
                            new Uint256(291),
                            new DynamicArray<Uint256>(new Uint256(1110), new Uint256(1929)),
                            new Bytes10("1234567890".getBytes()),
                            new Utf8String("Hello, world!"))));
}
 
Example #3
Source File: FunctionEncoderTest.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
@Test
public void testFunctionMDynamicArrayEncode2() {
    Function function =
            new Function(
                    "f",
                    Arrays.asList(
                            new Uint(BigInteger.valueOf(0x123)),
                            new DynamicArray<>(
                                    new Uint32(BigInteger.valueOf(0x456)),
                                    new Uint32(BigInteger.valueOf(0x789))),
                            new Bytes10("1234567890".getBytes()),
                            new DynamicBytes("Hello, world!".getBytes())),
                    Collections.<TypeReference<?>>emptyList());

    assertThat(
            FunctionEncoder.encode(function),
            is(
                    "0x8be65246"
                            + "0000000000000000000000000000000000000000000000000000000000000123"
                            + "0000000000000000000000000000000000000000000000000000000000000080"
                            + "3132333435363738393000000000000000000000000000000000000000000000"
                            + "00000000000000000000000000000000000000000000000000000000000000e0"
                            + "0000000000000000000000000000000000000000000000000000000000000002"
                            + "0000000000000000000000000000000000000000000000000000000000000456"
                            + "0000000000000000000000000000000000000000000000000000000000000789"
                            + "000000000000000000000000000000000000000000000000000000000000000d"
                            + "48656c6c6f2c20776f726c642100000000000000000000000000000000000000"));
}
 
Example #4
Source File: FunctionEncoderTest.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
@Test
public void testMixTypeEncode1() {
    // function  set0(uint256,uint256[],uint256,bytes10,string)
    Function function =
            new Function(
                    "set0",
                    Arrays.asList(
                            new Uint256(291),
                            new DynamicArray<Uint256>(new Uint256(1110), new Uint256(1929)),
                            new Bytes10("1234567890".getBytes()),
                            new Utf8String("Hello, world!")),
                    Collections.singletonList(
                            new TypeReference<DynamicArray<Utf8String>>() {}));

    assertThat(
            FunctionEncoder.encodeParameters(
                    function.getInputParameters(), new StringBuilder()),
            is(
                    "0000000000000000000000000000000000000000000000000000000000000123"
                            + "0000000000000000000000000000000000000000000000000000000000000080"
                            + "3132333435363738393000000000000000000000000000000000000000000000"
                            + "00000000000000000000000000000000000000000000000000000000000000e0"
                            + "0000000000000000000000000000000000000000000000000000000000000002"
                            + "0000000000000000000000000000000000000000000000000000000000000456"
                            + "0000000000000000000000000000000000000000000000000000000000000789"
                            + "000000000000000000000000000000000000000000000000000000000000000d"
                            + "48656c6c6f2c20776f726c642100000000000000000000000000000000000000"));
}
 
Example #5
Source File: DynamicArrayReference.java    From web3sdk with Apache License 2.0 4 votes vote down vote up
public static TypeReference<?> create(String type, boolean indexed) throws BaseException {

        if (ContractTypeUtil.invalidInt(type)) {
            return new TypeReference<DynamicArray<Int256>>(indexed) {};
        } else if (ContractTypeUtil.invalidUint(type)) {
            return new TypeReference<DynamicArray<Uint256>>(indexed) {};
        }

        switch (type) {
            case "address":
                return new TypeReference<DynamicArray<Address>>(indexed) {};
            case "bool":
                return new TypeReference<DynamicArray<Bool>>(indexed) {};
            case "string":
                return new TypeReference<DynamicArray<Utf8String>>(indexed) {};
            case "bytes":
                return new TypeReference<DynamicArray<DynamicBytes>>(indexed) {};
            case "bytes1":
                return new TypeReference<DynamicArray<Bytes1>>(indexed) {};
            case "bytes2":
                return new TypeReference<DynamicArray<Bytes2>>(indexed) {};
            case "bytes3":
                return new TypeReference<DynamicArray<Bytes3>>(indexed) {};
            case "bytes4":
                return new TypeReference<DynamicArray<Bytes4>>(indexed) {};
            case "bytes5":
                return new TypeReference<DynamicArray<Bytes5>>(indexed) {};
            case "bytes6":
                return new TypeReference<DynamicArray<Bytes6>>(indexed) {};
            case "bytes7":
                return new TypeReference<DynamicArray<Bytes7>>(indexed) {};
            case "bytes8":
                return new TypeReference<DynamicArray<Bytes8>>(indexed) {};
            case "bytes9":
                return new TypeReference<DynamicArray<Bytes9>>(indexed) {};
            case "bytes10":
                return new TypeReference<DynamicArray<Bytes10>>(indexed) {};
            case "bytes11":
                return new TypeReference<DynamicArray<Bytes11>>(indexed) {};
            case "bytes12":
                return new TypeReference<DynamicArray<Bytes12>>(indexed) {};
            case "bytes13":
                return new TypeReference<DynamicArray<Bytes13>>(indexed) {};
            case "bytes14":
                return new TypeReference<DynamicArray<Bytes14>>(indexed) {};
            case "bytes15":
                return new TypeReference<DynamicArray<Bytes15>>(indexed) {};
            case "bytes16":
                return new TypeReference<DynamicArray<Bytes16>>(indexed) {};
            case "bytes17":
                return new TypeReference<DynamicArray<Bytes17>>(indexed) {};
            case "bytes18":
                return new TypeReference<DynamicArray<Bytes18>>(indexed) {};
            case "bytes19":
                return new TypeReference<DynamicArray<Bytes19>>(indexed) {};
            case "bytes20":
                return new TypeReference<DynamicArray<Bytes20>>(indexed) {};
            case "bytes21":
                return new TypeReference<DynamicArray<Bytes21>>(indexed) {};
            case "bytes22":
                return new TypeReference<DynamicArray<Bytes22>>(indexed) {};
            case "bytes23":
                return new TypeReference<DynamicArray<Bytes23>>(indexed) {};
            case "bytes24":
                return new TypeReference<DynamicArray<Bytes24>>(indexed) {};
            case "bytes25":
                return new TypeReference<DynamicArray<Bytes25>>(indexed) {};
            case "bytes26":
                return new TypeReference<DynamicArray<Bytes26>>(indexed) {};
            case "bytes27":
                return new TypeReference<DynamicArray<Bytes27>>(indexed) {};
            case "bytes28":
                return new TypeReference<DynamicArray<Bytes28>>(indexed) {};
            case "bytes29":
                return new TypeReference<DynamicArray<Bytes29>>(indexed) {};
            case "bytes30":
                return new TypeReference<DynamicArray<Bytes30>>(indexed) {};
            case "bytes31":
                return new TypeReference<DynamicArray<Bytes31>>(indexed) {};
            case "bytes32":
                return new TypeReference<DynamicArray<Bytes32>>(indexed) {};
            default:
                throw new BaseException(
                        201201,
                        String.format(" %s[] unsupported encoding dynamic array type ", type));
        }
    }