org.fisco.bcos.web3j.abi.datatypes.DynamicBytes Java Examples

The following examples show how to use org.fisco.bcos.web3j.abi.datatypes.DynamicBytes. 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 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 #2
Source File: TypeDecoder.java    From web3sdk with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
static <T extends Type> T decode(String input, int offset, Class<T> type) {
    if (NumericType.class.isAssignableFrom(type)) {
        return (T) decodeNumeric(input.substring(offset), (Class<NumericType>) type);
    } else if (Address.class.isAssignableFrom(type)) {
        return (T) decodeAddress(input.substring(offset));
    } else if (Bool.class.isAssignableFrom(type)) {
        return (T) decodeBool(input, offset);
    } else if (Bytes.class.isAssignableFrom(type)) {
        return (T) decodeBytes(input, offset, (Class<Bytes>) type);
    } else if (DynamicBytes.class.isAssignableFrom(type)) {
        return (T) decodeDynamicBytes(input, offset);
    } else if (Utf8String.class.isAssignableFrom(type)) {
        return (T) decodeUtf8String(input, offset);
    } else if (Array.class.isAssignableFrom(type)) {
        throw new UnsupportedOperationException(
                "Array types must be wrapped in a TypeReference");
    } else {
        throw new UnsupportedOperationException("Type cannot be encoded: " + type.getClass());
    }
}
 
Example #3
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 #4
Source File: Utils.java    From web3sdk with Apache License 2.0 6 votes vote down vote up
static String getSimpleTypeName(Class<?> type) {
    String simpleName = type.getSimpleName().toLowerCase();

    if (type.equals(Uint.class)
            || type.equals(Int.class)
            || type.equals(Ufixed.class)
            || type.equals(Fixed.class)) {
        return simpleName + "256";
    } else if (type.equals(Utf8String.class)) {
        return "string";
    } else if (type.equals(DynamicBytes.class)) {
        return "bytes";
    } else {
        return simpleName;
    }
}
 
Example #5
Source File: Utils.java    From web3sdk with 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 #6
Source File: AbiTypesMapperGenerator.java    From web3sdk with Apache License 2.0 6 votes vote down vote up
private MethodSpec.Builder addTypes(MethodSpec.Builder builder, String packageName) {
    builder =
            addStatement(
                    builder, packageName, Address.TYPE_NAME, Address.class.getSimpleName());

    builder = addStatement(builder, packageName, Bool.TYPE_NAME, Bool.class.getSimpleName());

    builder =
            addStatement(
                    builder,
                    packageName,
                    Utf8String.TYPE_NAME,
                    Utf8String.class.getSimpleName());

    builder =
            addStatement(
                    builder,
                    packageName,
                    DynamicBytes.TYPE_NAME,
                    DynamicBytes.class.getSimpleName());

    // TODO: Fixed array & dynamic array support
    return builder;
}
 
Example #7
Source File: ResultEntityTest.java    From web3sdk with Apache License 2.0 6 votes vote down vote up
@Test
public void typeToObjectTest0() {

    assertThat(ResultEntity.typeToObject(new Uint256(2)), is(new BigInteger("2")));
    assertThat(ResultEntity.typeToObject(new Int256(-1)), is(new BigInteger("-1")));
    assertThat(ResultEntity.typeToObject(new Utf8String("adsfjkl")), is("adsfjkl"));
    assertThat(ResultEntity.typeToObject(new Bool(true)), is(true));
    assertThat(ResultEntity.typeToObject(new DynamicBytes("0x111".getBytes())), is("0x111"));
    assertThat(
            ResultEntity.typeToObject(new Address("0x111")),
            is("0x0000000000000000000000000000000000000111"));
    assertThat(
            ResultEntity.typeToObject(
                    new Bytes32("01234567890123456789012345678912".getBytes())),
            is("01234567890123456789012345678912"));
}
 
Example #8
Source File: SolidityFunctionWrapper.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
static TypeName getNativeType(TypeName typeName) {

        if (typeName instanceof ParameterizedTypeName) {
            return getNativeType((ParameterizedTypeName) typeName);
        }

        String simpleName = ((ClassName) typeName).simpleName();

        if (simpleName.startsWith(Address.class.getSimpleName())) {
            return TypeName.get(String.class);
        } else if (simpleName.startsWith("Uint")) {
            return TypeName.get(BigInteger.class);
        } else if (simpleName.startsWith("Int")) {
            return TypeName.get(BigInteger.class);
        } else if (simpleName.startsWith(Utf8String.class.getSimpleName())) {
            return TypeName.get(String.class);
        } else if (simpleName.startsWith("Bytes")) {
            return TypeName.get(byte[].class);
        } else if (simpleName.startsWith(DynamicBytes.class.getSimpleName())) {
            return TypeName.get(byte[].class);
        } else if (simpleName.startsWith(Bool.class.getSimpleName())) {
            return TypeName.get(Boolean.class); // boolean cannot be a parameterized type
        } else {
            throw new UnsupportedOperationException(
                    "Unsupported type: " + typeName + ", no native type mapping exists.");
        }
    }
 
Example #9
Source File: TypeDecoder.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
static DynamicBytes decodeDynamicBytes(String input, int offset) {
    int encodedLength = decodeUintAsInt(input, offset);
    int hexStringEncodedLength = encodedLength << 1;

    int valueOffset = offset + MAX_BYTE_LENGTH_FOR_HEX_STRING;

    String data = input.substring(valueOffset, valueOffset + hexStringEncodedLength);
    byte[] bytes = Numeric.hexStringToByteArray(data);

    return new DynamicBytes(bytes);
}
 
Example #10
Source File: ContractTypeUtilTest.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
@Test
public void getTypeTest() throws BaseException {
    assertThat(ContractTypeUtil.getType("bytes").getName(), is(DynamicBytes.class.getName()));
    assertThat(ContractTypeUtil.getType("address").getName(), is(Address.class.getName()));
    assertThat(ContractTypeUtil.getType("string").getName(), is(Utf8String.class.getName()));
    assertThat(ContractTypeUtil.getType("int").getName(), is(Int256.class.getName()));
    assertThat(ContractTypeUtil.getType("uint").getName(), is(Uint256.class.getName()));
    assertThat(ContractTypeUtil.getType("int256").getName(), is(Int256.class.getName()));
    assertThat(ContractTypeUtil.getType("uint256").getName(), is(Uint256.class.getName()));
    assertThat(ContractTypeUtil.getType("int8").getName(), is(Int8.class.getName()));
    assertThat(ContractTypeUtil.getType("uint8").getName(), is(Uint8.class.getName()));
    assertThat(ContractTypeUtil.getType("bool").getName(), is(Bool.class.getName()));
    assertThat(ContractTypeUtil.getType("bytes1").getName(), is(Bytes1.class.getName()));
    assertThat(ContractTypeUtil.getType("bytes32").getName(), is(Bytes32.class.getName()));
}
 
Example #11
Source File: ResultEntity.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
public static Object typeToObject(Type type) {
    Object obj = null;
    if (type instanceof NumericType) { // uint int
        obj = ((NumericType) type).getValue();
    } else if (type instanceof Bool) { // bool
        obj = ((Bool) type).getValue();
    } else if (type instanceof Address) { // address
        obj = type.toString();
    } else if (type instanceof Bytes) { // bytes32
        obj = new String(((Bytes) type).getValue()).trim();
    } else if (type instanceof DynamicBytes) { // bytes
        obj = new String(((DynamicBytes) type).getValue()).trim();
    } else if (type instanceof Utf8String) { // string
        obj = ((Utf8String) type).getValue();
    } else if (type instanceof Array) { // T[] T[k]
        List<Object> r = new ArrayList<Object>();
        List l = ((Array) type).getValue();
        for (int i = 0; i < l.size(); ++i) {
            r.add(typeToObject((Type) l.get(i)));
        }

        obj = (Object) r;
    } else {
        obj = (Object) obj;
    }

    return obj;
}
 
Example #12
Source File: TransactionDecoderTest.java    From web3sdk with Apache License 2.0 4 votes vote down vote up
@Test
public void testStaticParams1()
        throws JsonProcessingException, TransactionException, BaseException {

    /*
    function test(uint256[4] _u,int256[4] _i,bool[4] _b,address[4] _addr,bytes32[4] _bs32,string[4] _s,bytes[4] _bs) public constant returns (uint256[2],int256[2],bool[2],address[2],bytes32[2],string[2],bytes[2]) {

       }
       */

    TransactionDecoder decode =
            TransactionDecoderFactory.buildTransactionDecoder(
                    "[{\"constant\":true,\"inputs\":[{\"name\":\"_u\",\"type\":\"uint256[4]\"},{\"name\":\"_i\",\"type\":\"int256[4]\"},{\"name\":\"_b\",\"type\":\"bool[4]\"},{\"name\":\"_addr\",\"type\":\"address[4]\"},{\"name\":\"_bs32\",\"type\":\"bytes32[4]\"},{\"name\":\"_s\",\"type\":\"string[4]\"},{\"name\":\"_bs\",\"type\":\"bytes[4]\"}],\"name\":\"test\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256[2]\"},{\"name\":\"\",\"type\":\"int256[2]\"},{\"name\":\"\",\"type\":\"bool[2]\"},{\"name\":\"\",\"type\":\"address[2]\"},{\"name\":\"\",\"type\":\"bytes32[2]\"},{\"name\":\"\",\"type\":\"string[2]\"},{\"name\":\"\",\"type\":\"bytes[2]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_u\",\"type\":\"uint256\"},{\"name\":\"_i\",\"type\":\"int256\"},{\"name\":\"_b\",\"type\":\"bool\"},{\"name\":\"_addr\",\"type\":\"address\"},{\"name\":\"_bs32\",\"type\":\"bytes32\"},{\"name\":\"_s\",\"type\":\"string\"},{\"name\":\"_bs\",\"type\":\"bytes\"}],\"name\":\"test\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"},{\"name\":\"\",\"type\":\"int256\"},{\"name\":\"\",\"type\":\"bool\"},{\"name\":\"\",\"type\":\"address\"},{\"name\":\"\",\"type\":\"bytes32\"},{\"name\":\"\",\"type\":\"string\"},{\"name\":\"\",\"type\":\"bytes\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_u\",\"type\":\"uint256[]\"},{\"name\":\"_i\",\"type\":\"int256[]\"},{\"name\":\"_b\",\"type\":\"bool[]\"},{\"name\":\"_addr\",\"type\":\"address[]\"},{\"name\":\"_bs32\",\"type\":\"bytes32[]\"},{\"name\":\"_s\",\"type\":\"string[]\"},{\"name\":\"_bs\",\"type\":\"bytes[]\"}],\"name\":\"test\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256[]\"},{\"name\":\"\",\"type\":\"int256[]\"},{\"name\":\"\",\"type\":\"bool[]\"},{\"name\":\"\",\"type\":\"address[]\"},{\"name\":\"\",\"type\":\"bytes32[]\"},{\"name\":\"\",\"type\":\"string[]\"},{\"name\":\"\",\"type\":\"bytes[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_u\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"_i\",\"type\":\"int256\"},{\"indexed\":false,\"name\":\"_b\",\"type\":\"bool\"},{\"indexed\":false,\"name\":\"_addr\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_bs32\",\"type\":\"bytes32\"},{\"indexed\":false,\"name\":\"_s\",\"type\":\"string\"},{\"indexed\":false,\"name\":\"_bs\",\"type\":\"bytes\"}],\"name\":\"TestEventSimpleParams\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_u\",\"type\":\"uint256[]\"},{\"indexed\":false,\"name\":\"_i\",\"type\":\"int256[]\"},{\"indexed\":false,\"name\":\"_b\",\"type\":\"bool[]\"},{\"indexed\":false,\"name\":\"_addr\",\"type\":\"address[]\"},{\"indexed\":false,\"name\":\"_bs32\",\"type\":\"bytes32[]\"},{\"indexed\":false,\"name\":\"_s\",\"type\":\"string[]\"},{\"indexed\":false,\"name\":\"_bs\",\"type\":\"bytes[]\"}],\"name\":\"TestEventDArrayParams\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_u\",\"type\":\"uint256[4]\"},{\"indexed\":false,\"name\":\"_i\",\"type\":\"int256[4]\"},{\"indexed\":false,\"name\":\"_b\",\"type\":\"bool[4]\"},{\"indexed\":false,\"name\":\"_addr\",\"type\":\"address[4]\"},{\"indexed\":false,\"name\":\"_bs32\",\"type\":\"bytes32[4]\"},{\"indexed\":false,\"name\":\"_s\",\"type\":\"string[4]\"},{\"indexed\":false,\"name\":\"_bs\",\"type\":\"bytes[4]\"}],\"name\":\"TestEventSArrayParams\",\"type\":\"event\"}]",
                    "");

    List<Type> test1Params =
            Arrays.asList(
                    new StaticArray4<Uint256>(
                            new Uint256(0), new Uint256(0), new Uint256(0), new Uint256(0)),
                    new StaticArray4<Int256>(
                            new Int256(0), new Int256(0), new Int256(0), new Int256(0)),
                    new StaticArray4<Bool>(
                            new Bool(true), new Bool(false), new Bool(true), new Bool(false)),
                    new StaticArray4<Address>(
                            new Address("0x0"),
                            new Address("0x0"),
                            new Address("0x0"),
                            new Address("0x0")),
                    new StaticArray4<Bytes32>(
                            new Bytes32("                                ".getBytes()),
                            new Bytes32("                                ".getBytes()),
                            new Bytes32("                                ".getBytes()),
                            new Bytes32("                                ".getBytes())),
                    new StaticArray4<Utf8String>(
                            new Utf8String(""),
                            new Utf8String(""),
                            new Utf8String(""),
                            new Utf8String("")),
                    new StaticArray4<DynamicBytes>(
                            new DynamicBytes("".getBytes()),
                            new DynamicBytes("".getBytes()),
                            new DynamicBytes("".getBytes()),
                            new DynamicBytes("".getBytes())));

    Function test1 =
            new Function(
                    "test",
                    test1Params,
                    Arrays.asList(
                            new TypeReference<Uint256>() {},
                            new TypeReference<Int256>() {},
                            new TypeReference<Address>() {},
                            new TypeReference<Utf8String>() {},
                            new TypeReference<DynamicBytes>() {},
                            new TypeReference<Bytes32>() {}));
    assertThat(
            decode.decodeInputReturnJson(FunctionEncoder.encode(test1)),
            is(
                    "{\"function\":\"test(uint256[4],int256[4],bool[4],address[4],bytes32[4],string[4],bytes[4])\",\"methodID\":\"0x5682504e\",\"result\":[{\"name\":\"_u\",\"type\":\"uint256[4]\",\"data\":[0,0,0,0]},{\"name\":\"_i\",\"type\":\"int256[4]\",\"data\":[0,0,0,0]},{\"name\":\"_b\",\"type\":\"bool[4]\",\"data\":[true,false,true,false]},{\"name\":\"_addr\",\"type\":\"address[4]\",\"data\":[\"0x0000000000000000000000000000000000000000\",\"0x0000000000000000000000000000000000000000\",\"0x0000000000000000000000000000000000000000\",\"0x0000000000000000000000000000000000000000\"]},{\"name\":\"_bs32\",\"type\":\"bytes32[4]\",\"data\":[\"\",\"\",\"\",\"\"]},{\"name\":\"_s\",\"type\":\"string[4]\",\"data\":[\"\",\"\",\"\",\"\"]},{\"name\":\"_bs\",\"type\":\"bytes[4]\",\"data\":[\"\",\"\",\"\",\"\"]}]}"));
    InputAndOutputResult inputAndOutputResult1 =
            decode.decodeInputReturnObject(FunctionEncoder.encode(test1));
    List<ResultEntity> resultInputList = inputAndOutputResult1.getResult();
    assertThat(transEntitytoType(resultInputList), is(test1Params));

    List<Type> test1Output =
            Arrays.asList(
                    new StaticArray2<Uint256>(new Uint256(0), new Uint256(0)),
                    new StaticArray2<Int256>(new Int256(0), new Int256(0)),
                    new StaticArray2<Bool>(new Bool(true), new Bool(false)),
                    new StaticArray2<Address>(new Address("0x0"), new Address("0x0")),
                    new StaticArray2<Bytes32>(
                            new Bytes32("                                ".getBytes()),
                            new Bytes32("                                ".getBytes())),
                    new StaticArray2<Utf8String>(new Utf8String(""), new Utf8String("")),
                    new StaticArray2<DynamicBytes>(
                            new DynamicBytes("".getBytes()), new DynamicBytes("".getBytes())));

    assertThat(
            decode.decodeOutputReturnJson(
                    FunctionEncoder.encode(test1),
                    FunctionEncoder.encodeConstructor(test1Output)),
            is(
                    "{\"function\":\"test(uint256[4],int256[4],bool[4],address[4],bytes32[4],string[4],bytes[4])\",\"methodID\":\"0x5682504e\",\"result\":[{\"name\":\"\",\"type\":\"uint256[2]\",\"data\":[0,0]},{\"name\":\"\",\"type\":\"int256[2]\",\"data\":[0,0]},{\"name\":\"\",\"type\":\"bool[2]\",\"data\":[true,false]},{\"name\":\"\",\"type\":\"address[2]\",\"data\":[\"0x0000000000000000000000000000000000000000\",\"0x0000000000000000000000000000000000000000\"]},{\"name\":\"\",\"type\":\"bytes32[2]\",\"data\":[\"\",\"\"]},{\"name\":\"\",\"type\":\"string[2]\",\"data\":[\"\",\"\"]},{\"name\":\"\",\"type\":\"bytes[2]\",\"data\":[\"\",\"\"]}]}"));

    InputAndOutputResult inputAndOutputResult =
            decode.decodeOutputReturnObject(
                    FunctionEncoder.encode(test1),
                    FunctionEncoder.encodeConstructor(test1Output));
    List<ResultEntity> resultOutputList = inputAndOutputResult.getResult();
    assertThat(transEntitytoType(resultOutputList), is(test1Output));
}
 
Example #13
Source File: StaticArrayReference.java    From web3sdk with Apache License 2.0 4 votes vote down vote up
private static TypeReference<?> create26(String type, boolean indexed) throws BaseException {

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

        switch (type) {
            case "address":
                return new TypeReference<StaticArray26<Address>>(indexed) {};
            case "bool":
                return new TypeReference<StaticArray26<Bool>>(indexed) {};
            case "string":
                return new TypeReference<StaticArray26<Utf8String>>(indexed) {};
            case "bytes":
                return new TypeReference<StaticArray26<DynamicBytes>>(indexed) {};
            case "bytes1":
                return new TypeReference<StaticArray26<Bytes1>>(indexed) {};
            case "bytes2":
                return new TypeReference<StaticArray26<Bytes2>>(indexed) {};
            case "bytes3":
                return new TypeReference<StaticArray26<Bytes3>>(indexed) {};
            case "bytes4":
                return new TypeReference<StaticArray26<Bytes4>>(indexed) {};
            case "bytes5":
                return new TypeReference<StaticArray26<Bytes5>>(indexed) {};
            case "bytes6":
                return new TypeReference<StaticArray26<Bytes6>>(indexed) {};
            case "bytes7":
                return new TypeReference<StaticArray26<Bytes7>>(indexed) {};
            case "bytes8":
                return new TypeReference<StaticArray26<Bytes8>>(indexed) {};
            case "bytes9":
                return new TypeReference<StaticArray26<Bytes9>>(indexed) {};
            case "bytes10":
                return new TypeReference<StaticArray26<Bytes10>>(indexed) {};
            case "bytes11":
                return new TypeReference<StaticArray26<Bytes11>>(indexed) {};
            case "bytes12":
                return new TypeReference<StaticArray26<Bytes12>>(indexed) {};
            case "bytes13":
                return new TypeReference<StaticArray26<Bytes13>>(indexed) {};
            case "bytes14":
                return new TypeReference<StaticArray26<Bytes14>>(indexed) {};
            case "bytes15":
                return new TypeReference<StaticArray26<Bytes15>>(indexed) {};
            case "bytes16":
                return new TypeReference<StaticArray26<Bytes16>>(indexed) {};
            case "bytes17":
                return new TypeReference<StaticArray26<Bytes17>>(indexed) {};
            case "bytes18":
                return new TypeReference<StaticArray26<Bytes18>>(indexed) {};
            case "bytes19":
                return new TypeReference<StaticArray26<Bytes19>>(indexed) {};
            case "bytes20":
                return new TypeReference<StaticArray26<Bytes20>>(indexed) {};
            case "bytes21":
                return new TypeReference<StaticArray26<Bytes21>>(indexed) {};
            case "bytes22":
                return new TypeReference<StaticArray26<Bytes22>>(indexed) {};
            case "bytes23":
                return new TypeReference<StaticArray26<Bytes23>>(indexed) {};
            case "bytes24":
                return new TypeReference<StaticArray26<Bytes24>>(indexed) {};
            case "bytes25":
                return new TypeReference<StaticArray26<Bytes25>>(indexed) {};
            case "bytes26":
                return new TypeReference<StaticArray26<Bytes26>>(indexed) {};
            case "bytes27":
                return new TypeReference<StaticArray26<Bytes27>>(indexed) {};
            case "bytes28":
                return new TypeReference<StaticArray26<Bytes28>>(indexed) {};
            case "bytes29":
                return new TypeReference<StaticArray26<Bytes29>>(indexed) {};
            case "bytes30":
                return new TypeReference<StaticArray26<Bytes30>>(indexed) {};
            case "bytes31":
                return new TypeReference<StaticArray26<Bytes31>>(indexed) {};
            case "bytes32":
                return new TypeReference<StaticArray26<Bytes32>>(indexed) {};
            default:
                throw new BaseException(
                        201201, String.format(" %s[26] unsupported encoding array type ", type));
        }
    }
 
Example #14
Source File: StaticArrayReference.java    From web3sdk with Apache License 2.0 4 votes vote down vote up
private static TypeReference<?> create27(String type, boolean indexed) throws BaseException {

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

        switch (type) {
            case "address":
                return new TypeReference<StaticArray27<Address>>(indexed) {};
            case "bool":
                return new TypeReference<StaticArray27<Bool>>(indexed) {};
            case "string":
                return new TypeReference<StaticArray27<Utf8String>>(indexed) {};
            case "bytes":
                return new TypeReference<StaticArray27<DynamicBytes>>(indexed) {};
            case "bytes1":
                return new TypeReference<StaticArray27<Bytes1>>(indexed) {};
            case "bytes2":
                return new TypeReference<StaticArray27<Bytes2>>(indexed) {};
            case "bytes3":
                return new TypeReference<StaticArray27<Bytes3>>(indexed) {};
            case "bytes4":
                return new TypeReference<StaticArray27<Bytes4>>(indexed) {};
            case "bytes5":
                return new TypeReference<StaticArray27<Bytes5>>(indexed) {};
            case "bytes6":
                return new TypeReference<StaticArray27<Bytes6>>(indexed) {};
            case "bytes7":
                return new TypeReference<StaticArray27<Bytes7>>(indexed) {};
            case "bytes8":
                return new TypeReference<StaticArray27<Bytes8>>(indexed) {};
            case "bytes9":
                return new TypeReference<StaticArray27<Bytes9>>(indexed) {};
            case "bytes10":
                return new TypeReference<StaticArray27<Bytes10>>(indexed) {};
            case "bytes11":
                return new TypeReference<StaticArray27<Bytes11>>(indexed) {};
            case "bytes12":
                return new TypeReference<StaticArray27<Bytes12>>(indexed) {};
            case "bytes13":
                return new TypeReference<StaticArray27<Bytes13>>(indexed) {};
            case "bytes14":
                return new TypeReference<StaticArray27<Bytes14>>(indexed) {};
            case "bytes15":
                return new TypeReference<StaticArray27<Bytes15>>(indexed) {};
            case "bytes16":
                return new TypeReference<StaticArray27<Bytes16>>(indexed) {};
            case "bytes17":
                return new TypeReference<StaticArray27<Bytes17>>(indexed) {};
            case "bytes18":
                return new TypeReference<StaticArray27<Bytes18>>(indexed) {};
            case "bytes19":
                return new TypeReference<StaticArray27<Bytes19>>(indexed) {};
            case "bytes20":
                return new TypeReference<StaticArray27<Bytes20>>(indexed) {};
            case "bytes21":
                return new TypeReference<StaticArray27<Bytes21>>(indexed) {};
            case "bytes22":
                return new TypeReference<StaticArray27<Bytes22>>(indexed) {};
            case "bytes23":
                return new TypeReference<StaticArray27<Bytes23>>(indexed) {};
            case "bytes24":
                return new TypeReference<StaticArray27<Bytes24>>(indexed) {};
            case "bytes25":
                return new TypeReference<StaticArray27<Bytes25>>(indexed) {};
            case "bytes26":
                return new TypeReference<StaticArray27<Bytes26>>(indexed) {};
            case "bytes27":
                return new TypeReference<StaticArray27<Bytes27>>(indexed) {};
            case "bytes28":
                return new TypeReference<StaticArray27<Bytes28>>(indexed) {};
            case "bytes29":
                return new TypeReference<StaticArray27<Bytes29>>(indexed) {};
            case "bytes30":
                return new TypeReference<StaticArray27<Bytes30>>(indexed) {};
            case "bytes31":
                return new TypeReference<StaticArray27<Bytes31>>(indexed) {};
            case "bytes32":
                return new TypeReference<StaticArray27<Bytes32>>(indexed) {};
            default:
                throw new BaseException(
                        201201, String.format(" %s[27] unsupported encoding array type ", type));
        }
    }
 
Example #15
Source File: StaticArrayReference.java    From web3sdk with Apache License 2.0 4 votes vote down vote up
private static TypeReference<?> create28(String type, boolean indexed) throws BaseException {

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

        switch (type) {
            case "address":
                return new TypeReference<StaticArray28<Address>>(indexed) {};
            case "bool":
                return new TypeReference<StaticArray28<Bool>>(indexed) {};
            case "string":
                return new TypeReference<StaticArray28<Utf8String>>(indexed) {};
            case "bytes":
                return new TypeReference<StaticArray28<DynamicBytes>>(indexed) {};
            case "bytes1":
                return new TypeReference<StaticArray28<Bytes1>>(indexed) {};
            case "bytes2":
                return new TypeReference<StaticArray28<Bytes2>>(indexed) {};
            case "bytes3":
                return new TypeReference<StaticArray28<Bytes3>>(indexed) {};
            case "bytes4":
                return new TypeReference<StaticArray28<Bytes4>>(indexed) {};
            case "bytes5":
                return new TypeReference<StaticArray28<Bytes5>>(indexed) {};
            case "bytes6":
                return new TypeReference<StaticArray28<Bytes6>>(indexed) {};
            case "bytes7":
                return new TypeReference<StaticArray28<Bytes7>>(indexed) {};
            case "bytes8":
                return new TypeReference<StaticArray28<Bytes8>>(indexed) {};
            case "bytes9":
                return new TypeReference<StaticArray28<Bytes9>>(indexed) {};
            case "bytes10":
                return new TypeReference<StaticArray28<Bytes10>>(indexed) {};
            case "bytes11":
                return new TypeReference<StaticArray28<Bytes11>>(indexed) {};
            case "bytes12":
                return new TypeReference<StaticArray28<Bytes12>>(indexed) {};
            case "bytes13":
                return new TypeReference<StaticArray28<Bytes13>>(indexed) {};
            case "bytes14":
                return new TypeReference<StaticArray28<Bytes14>>(indexed) {};
            case "bytes15":
                return new TypeReference<StaticArray28<Bytes15>>(indexed) {};
            case "bytes16":
                return new TypeReference<StaticArray28<Bytes16>>(indexed) {};
            case "bytes17":
                return new TypeReference<StaticArray28<Bytes17>>(indexed) {};
            case "bytes18":
                return new TypeReference<StaticArray28<Bytes18>>(indexed) {};
            case "bytes19":
                return new TypeReference<StaticArray28<Bytes19>>(indexed) {};
            case "bytes20":
                return new TypeReference<StaticArray28<Bytes20>>(indexed) {};
            case "bytes21":
                return new TypeReference<StaticArray28<Bytes21>>(indexed) {};
            case "bytes22":
                return new TypeReference<StaticArray28<Bytes22>>(indexed) {};
            case "bytes23":
                return new TypeReference<StaticArray28<Bytes23>>(indexed) {};
            case "bytes24":
                return new TypeReference<StaticArray28<Bytes24>>(indexed) {};
            case "bytes25":
                return new TypeReference<StaticArray28<Bytes25>>(indexed) {};
            case "bytes26":
                return new TypeReference<StaticArray28<Bytes26>>(indexed) {};
            case "bytes27":
                return new TypeReference<StaticArray28<Bytes27>>(indexed) {};
            case "bytes28":
                return new TypeReference<StaticArray28<Bytes28>>(indexed) {};
            case "bytes29":
                return new TypeReference<StaticArray28<Bytes29>>(indexed) {};
            case "bytes30":
                return new TypeReference<StaticArray28<Bytes30>>(indexed) {};
            case "bytes31":
                return new TypeReference<StaticArray28<Bytes31>>(indexed) {};
            case "bytes32":
                return new TypeReference<StaticArray28<Bytes32>>(indexed) {};
            default:
                throw new BaseException(
                        201201, String.format(" %s[28] unsupported encoding array type ", type));
        }
    }
 
Example #16
Source File: StaticArrayReference.java    From web3sdk with Apache License 2.0 4 votes vote down vote up
private static TypeReference<?> create29(String type, boolean indexed) throws BaseException {

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

        switch (type) {
            case "address":
                return new TypeReference<StaticArray29<Address>>(indexed) {};
            case "bool":
                return new TypeReference<StaticArray29<Bool>>(indexed) {};
            case "string":
                return new TypeReference<StaticArray29<Utf8String>>(indexed) {};
            case "bytes":
                return new TypeReference<StaticArray29<DynamicBytes>>(indexed) {};
            case "bytes1":
                return new TypeReference<StaticArray29<Bytes1>>(indexed) {};
            case "bytes2":
                return new TypeReference<StaticArray29<Bytes2>>(indexed) {};
            case "bytes3":
                return new TypeReference<StaticArray29<Bytes3>>(indexed) {};
            case "bytes4":
                return new TypeReference<StaticArray29<Bytes4>>(indexed) {};
            case "bytes5":
                return new TypeReference<StaticArray29<Bytes5>>(indexed) {};
            case "bytes6":
                return new TypeReference<StaticArray29<Bytes6>>(indexed) {};
            case "bytes7":
                return new TypeReference<StaticArray29<Bytes7>>(indexed) {};
            case "bytes8":
                return new TypeReference<StaticArray29<Bytes8>>(indexed) {};
            case "bytes9":
                return new TypeReference<StaticArray29<Bytes9>>(indexed) {};
            case "bytes10":
                return new TypeReference<StaticArray29<Bytes10>>(indexed) {};
            case "bytes11":
                return new TypeReference<StaticArray29<Bytes11>>(indexed) {};
            case "bytes12":
                return new TypeReference<StaticArray29<Bytes12>>(indexed) {};
            case "bytes13":
                return new TypeReference<StaticArray29<Bytes13>>(indexed) {};
            case "bytes14":
                return new TypeReference<StaticArray29<Bytes14>>(indexed) {};
            case "bytes15":
                return new TypeReference<StaticArray29<Bytes15>>(indexed) {};
            case "bytes16":
                return new TypeReference<StaticArray29<Bytes16>>(indexed) {};
            case "bytes17":
                return new TypeReference<StaticArray29<Bytes17>>(indexed) {};
            case "bytes18":
                return new TypeReference<StaticArray29<Bytes18>>(indexed) {};
            case "bytes19":
                return new TypeReference<StaticArray29<Bytes19>>(indexed) {};
            case "bytes20":
                return new TypeReference<StaticArray29<Bytes20>>(indexed) {};
            case "bytes21":
                return new TypeReference<StaticArray29<Bytes21>>(indexed) {};
            case "bytes22":
                return new TypeReference<StaticArray29<Bytes22>>(indexed) {};
            case "bytes23":
                return new TypeReference<StaticArray29<Bytes23>>(indexed) {};
            case "bytes24":
                return new TypeReference<StaticArray29<Bytes24>>(indexed) {};
            case "bytes25":
                return new TypeReference<StaticArray29<Bytes25>>(indexed) {};
            case "bytes26":
                return new TypeReference<StaticArray29<Bytes26>>(indexed) {};
            case "bytes27":
                return new TypeReference<StaticArray29<Bytes27>>(indexed) {};
            case "bytes28":
                return new TypeReference<StaticArray29<Bytes28>>(indexed) {};
            case "bytes29":
                return new TypeReference<StaticArray29<Bytes29>>(indexed) {};
            case "bytes30":
                return new TypeReference<StaticArray29<Bytes30>>(indexed) {};
            case "bytes31":
                return new TypeReference<StaticArray29<Bytes31>>(indexed) {};
            case "bytes32":
                return new TypeReference<StaticArray29<Bytes32>>(indexed) {};
            default:
                throw new BaseException(
                        201201, String.format(" %s[29] unsupported encoding array type ", type));
        }
    }
 
Example #17
Source File: StaticArrayReference.java    From web3sdk with Apache License 2.0 4 votes vote down vote up
private static TypeReference<?> create30(String type, boolean indexed) throws BaseException {

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

        switch (type) {
            case "address":
                return new TypeReference<StaticArray30<Address>>(indexed) {};
            case "bool":
                return new TypeReference<StaticArray30<Bool>>(indexed) {};
            case "string":
                return new TypeReference<StaticArray30<Utf8String>>(indexed) {};
            case "bytes":
                return new TypeReference<StaticArray30<DynamicBytes>>(indexed) {};
            case "bytes1":
                return new TypeReference<StaticArray30<Bytes1>>(indexed) {};
            case "bytes2":
                return new TypeReference<StaticArray30<Bytes2>>(indexed) {};
            case "bytes3":
                return new TypeReference<StaticArray30<Bytes3>>(indexed) {};
            case "bytes4":
                return new TypeReference<StaticArray30<Bytes4>>(indexed) {};
            case "bytes5":
                return new TypeReference<StaticArray30<Bytes5>>(indexed) {};
            case "bytes6":
                return new TypeReference<StaticArray30<Bytes6>>(indexed) {};
            case "bytes7":
                return new TypeReference<StaticArray30<Bytes7>>(indexed) {};
            case "bytes8":
                return new TypeReference<StaticArray30<Bytes8>>(indexed) {};
            case "bytes9":
                return new TypeReference<StaticArray30<Bytes9>>(indexed) {};
            case "bytes10":
                return new TypeReference<StaticArray30<Bytes10>>(indexed) {};
            case "bytes11":
                return new TypeReference<StaticArray30<Bytes11>>(indexed) {};
            case "bytes12":
                return new TypeReference<StaticArray30<Bytes12>>(indexed) {};
            case "bytes13":
                return new TypeReference<StaticArray30<Bytes13>>(indexed) {};
            case "bytes14":
                return new TypeReference<StaticArray30<Bytes14>>(indexed) {};
            case "bytes15":
                return new TypeReference<StaticArray30<Bytes15>>(indexed) {};
            case "bytes16":
                return new TypeReference<StaticArray30<Bytes16>>(indexed) {};
            case "bytes17":
                return new TypeReference<StaticArray30<Bytes17>>(indexed) {};
            case "bytes18":
                return new TypeReference<StaticArray30<Bytes18>>(indexed) {};
            case "bytes19":
                return new TypeReference<StaticArray30<Bytes19>>(indexed) {};
            case "bytes20":
                return new TypeReference<StaticArray30<Bytes20>>(indexed) {};
            case "bytes21":
                return new TypeReference<StaticArray30<Bytes21>>(indexed) {};
            case "bytes22":
                return new TypeReference<StaticArray30<Bytes22>>(indexed) {};
            case "bytes23":
                return new TypeReference<StaticArray30<Bytes23>>(indexed) {};
            case "bytes24":
                return new TypeReference<StaticArray30<Bytes24>>(indexed) {};
            case "bytes25":
                return new TypeReference<StaticArray30<Bytes25>>(indexed) {};
            case "bytes26":
                return new TypeReference<StaticArray30<Bytes26>>(indexed) {};
            case "bytes27":
                return new TypeReference<StaticArray30<Bytes27>>(indexed) {};
            case "bytes28":
                return new TypeReference<StaticArray30<Bytes28>>(indexed) {};
            case "bytes29":
                return new TypeReference<StaticArray30<Bytes29>>(indexed) {};
            case "bytes30":
                return new TypeReference<StaticArray30<Bytes30>>(indexed) {};
            case "bytes31":
                return new TypeReference<StaticArray30<Bytes31>>(indexed) {};
            case "bytes32":
                return new TypeReference<StaticArray30<Bytes32>>(indexed) {};
            default:
                throw new BaseException(
                        201201, String.format(" %s[30] unsupported encoding array type ", type));
        }
    }
 
Example #18
Source File: StaticArrayReference.java    From web3sdk with Apache License 2.0 4 votes vote down vote up
private static TypeReference<?> create31(String type, boolean indexed) throws BaseException {

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

        switch (type) {
            case "address":
                return new TypeReference<StaticArray31<Address>>(indexed) {};
            case "bool":
                return new TypeReference<StaticArray31<Bool>>(indexed) {};
            case "string":
                return new TypeReference<StaticArray31<Utf8String>>(indexed) {};
            case "bytes":
                return new TypeReference<StaticArray31<DynamicBytes>>(indexed) {};
            case "bytes1":
                return new TypeReference<StaticArray31<Bytes1>>(indexed) {};
            case "bytes2":
                return new TypeReference<StaticArray31<Bytes2>>(indexed) {};
            case "bytes3":
                return new TypeReference<StaticArray31<Bytes3>>(indexed) {};
            case "bytes4":
                return new TypeReference<StaticArray31<Bytes4>>(indexed) {};
            case "bytes5":
                return new TypeReference<StaticArray31<Bytes5>>(indexed) {};
            case "bytes6":
                return new TypeReference<StaticArray31<Bytes6>>(indexed) {};
            case "bytes7":
                return new TypeReference<StaticArray31<Bytes7>>(indexed) {};
            case "bytes8":
                return new TypeReference<StaticArray31<Bytes8>>(indexed) {};
            case "bytes9":
                return new TypeReference<StaticArray31<Bytes9>>(indexed) {};
            case "bytes10":
                return new TypeReference<StaticArray31<Bytes10>>(indexed) {};
            case "bytes11":
                return new TypeReference<StaticArray31<Bytes11>>(indexed) {};
            case "bytes12":
                return new TypeReference<StaticArray31<Bytes12>>(indexed) {};
            case "bytes13":
                return new TypeReference<StaticArray31<Bytes13>>(indexed) {};
            case "bytes14":
                return new TypeReference<StaticArray31<Bytes14>>(indexed) {};
            case "bytes15":
                return new TypeReference<StaticArray31<Bytes15>>(indexed) {};
            case "bytes16":
                return new TypeReference<StaticArray31<Bytes16>>(indexed) {};
            case "bytes17":
                return new TypeReference<StaticArray31<Bytes17>>(indexed) {};
            case "bytes18":
                return new TypeReference<StaticArray31<Bytes18>>(indexed) {};
            case "bytes19":
                return new TypeReference<StaticArray31<Bytes19>>(indexed) {};
            case "bytes20":
                return new TypeReference<StaticArray31<Bytes20>>(indexed) {};
            case "bytes21":
                return new TypeReference<StaticArray31<Bytes21>>(indexed) {};
            case "bytes22":
                return new TypeReference<StaticArray31<Bytes22>>(indexed) {};
            case "bytes23":
                return new TypeReference<StaticArray31<Bytes23>>(indexed) {};
            case "bytes24":
                return new TypeReference<StaticArray31<Bytes24>>(indexed) {};
            case "bytes25":
                return new TypeReference<StaticArray31<Bytes25>>(indexed) {};
            case "bytes26":
                return new TypeReference<StaticArray31<Bytes26>>(indexed) {};
            case "bytes27":
                return new TypeReference<StaticArray31<Bytes27>>(indexed) {};
            case "bytes28":
                return new TypeReference<StaticArray31<Bytes28>>(indexed) {};
            case "bytes29":
                return new TypeReference<StaticArray31<Bytes29>>(indexed) {};
            case "bytes30":
                return new TypeReference<StaticArray31<Bytes30>>(indexed) {};
            case "bytes31":
                return new TypeReference<StaticArray31<Bytes31>>(indexed) {};
            case "bytes32":
                return new TypeReference<StaticArray31<Bytes32>>(indexed) {};
            default:
                throw new BaseException(
                        201201, String.format(" %s[31] unsupported encoding array type ", type));
        }
    }
 
Example #19
Source File: StaticArrayReference.java    From web3sdk with Apache License 2.0 4 votes vote down vote up
private static TypeReference<?> create32(String type, boolean indexed) throws BaseException {

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

        switch (type) {
            case "address":
                return new TypeReference<StaticArray32<Address>>(indexed) {};
            case "bool":
                return new TypeReference<StaticArray32<Bool>>(indexed) {};
            case "string":
                return new TypeReference<StaticArray32<Utf8String>>(indexed) {};
            case "bytes":
                return new TypeReference<StaticArray32<DynamicBytes>>(indexed) {};
            case "bytes1":
                return new TypeReference<StaticArray32<Bytes1>>(indexed) {};
            case "bytes2":
                return new TypeReference<StaticArray32<Bytes2>>(indexed) {};
            case "bytes3":
                return new TypeReference<StaticArray32<Bytes3>>(indexed) {};
            case "bytes4":
                return new TypeReference<StaticArray32<Bytes4>>(indexed) {};
            case "bytes5":
                return new TypeReference<StaticArray32<Bytes5>>(indexed) {};
            case "bytes6":
                return new TypeReference<StaticArray32<Bytes6>>(indexed) {};
            case "bytes7":
                return new TypeReference<StaticArray32<Bytes7>>(indexed) {};
            case "bytes8":
                return new TypeReference<StaticArray32<Bytes8>>(indexed) {};
            case "bytes9":
                return new TypeReference<StaticArray32<Bytes9>>(indexed) {};
            case "bytes10":
                return new TypeReference<StaticArray32<Bytes10>>(indexed) {};
            case "bytes11":
                return new TypeReference<StaticArray32<Bytes11>>(indexed) {};
            case "bytes12":
                return new TypeReference<StaticArray32<Bytes12>>(indexed) {};
            case "bytes13":
                return new TypeReference<StaticArray32<Bytes13>>(indexed) {};
            case "bytes14":
                return new TypeReference<StaticArray32<Bytes14>>(indexed) {};
            case "bytes15":
                return new TypeReference<StaticArray32<Bytes15>>(indexed) {};
            case "bytes16":
                return new TypeReference<StaticArray32<Bytes16>>(indexed) {};
            case "bytes17":
                return new TypeReference<StaticArray32<Bytes17>>(indexed) {};
            case "bytes18":
                return new TypeReference<StaticArray32<Bytes18>>(indexed) {};
            case "bytes19":
                return new TypeReference<StaticArray32<Bytes19>>(indexed) {};
            case "bytes20":
                return new TypeReference<StaticArray32<Bytes20>>(indexed) {};
            case "bytes21":
                return new TypeReference<StaticArray32<Bytes21>>(indexed) {};
            case "bytes22":
                return new TypeReference<StaticArray32<Bytes22>>(indexed) {};
            case "bytes23":
                return new TypeReference<StaticArray32<Bytes23>>(indexed) {};
            case "bytes24":
                return new TypeReference<StaticArray32<Bytes24>>(indexed) {};
            case "bytes25":
                return new TypeReference<StaticArray32<Bytes25>>(indexed) {};
            case "bytes26":
                return new TypeReference<StaticArray32<Bytes26>>(indexed) {};
            case "bytes27":
                return new TypeReference<StaticArray32<Bytes27>>(indexed) {};
            case "bytes28":
                return new TypeReference<StaticArray32<Bytes28>>(indexed) {};
            case "bytes29":
                return new TypeReference<StaticArray32<Bytes29>>(indexed) {};
            case "bytes30":
                return new TypeReference<StaticArray32<Bytes30>>(indexed) {};
            case "bytes31":
                return new TypeReference<StaticArray32<Bytes31>>(indexed) {};
            case "bytes32":
                return new TypeReference<StaticArray32<Bytes32>>(indexed) {};
            default:
                throw new BaseException(
                        201201, String.format(" %s[32] unsupported encoding array type ", type));
        }
    }
 
Example #20
Source File: StaticArrayReference.java    From web3sdk with Apache License 2.0 4 votes vote down vote up
private static TypeReference<?> create128(String type, boolean indexed) throws BaseException {

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

        switch (type) {
            case "address":
                return new TypeReference<StaticArray128<Address>>(indexed) {};
            case "bool":
                return new TypeReference<StaticArray128<Bool>>(indexed) {};
            case "string":
                return new TypeReference<StaticArray128<Utf8String>>(indexed) {};
            case "bytes":
                return new TypeReference<StaticArray128<DynamicBytes>>(indexed) {};
            case "bytes1":
                return new TypeReference<StaticArray128<Bytes1>>(indexed) {};
            case "bytes2":
                return new TypeReference<StaticArray128<Bytes2>>(indexed) {};
            case "bytes3":
                return new TypeReference<StaticArray128<Bytes3>>(indexed) {};
            case "bytes4":
                return new TypeReference<StaticArray128<Bytes4>>(indexed) {};
            case "bytes5":
                return new TypeReference<StaticArray128<Bytes5>>(indexed) {};
            case "bytes6":
                return new TypeReference<StaticArray128<Bytes6>>(indexed) {};
            case "bytes7":
                return new TypeReference<StaticArray128<Bytes7>>(indexed) {};
            case "bytes8":
                return new TypeReference<StaticArray128<Bytes8>>(indexed) {};
            case "bytes9":
                return new TypeReference<StaticArray128<Bytes9>>(indexed) {};
            case "bytes10":
                return new TypeReference<StaticArray128<Bytes10>>(indexed) {};
            case "bytes11":
                return new TypeReference<StaticArray128<Bytes11>>(indexed) {};
            case "bytes12":
                return new TypeReference<StaticArray128<Bytes12>>(indexed) {};
            case "bytes13":
                return new TypeReference<StaticArray128<Bytes13>>(indexed) {};
            case "bytes14":
                return new TypeReference<StaticArray128<Bytes14>>(indexed) {};
            case "bytes15":
                return new TypeReference<StaticArray128<Bytes15>>(indexed) {};
            case "bytes16":
                return new TypeReference<StaticArray128<Bytes16>>(indexed) {};
            case "bytes17":
                return new TypeReference<StaticArray128<Bytes17>>(indexed) {};
            case "bytes18":
                return new TypeReference<StaticArray128<Bytes18>>(indexed) {};
            case "bytes19":
                return new TypeReference<StaticArray128<Bytes19>>(indexed) {};
            case "bytes20":
                return new TypeReference<StaticArray128<Bytes20>>(indexed) {};
            case "bytes21":
                return new TypeReference<StaticArray128<Bytes21>>(indexed) {};
            case "bytes22":
                return new TypeReference<StaticArray128<Bytes22>>(indexed) {};
            case "bytes23":
                return new TypeReference<StaticArray128<Bytes23>>(indexed) {};
            case "bytes24":
                return new TypeReference<StaticArray128<Bytes24>>(indexed) {};
            case "bytes25":
                return new TypeReference<StaticArray128<Bytes25>>(indexed) {};
            case "bytes26":
                return new TypeReference<StaticArray128<Bytes26>>(indexed) {};
            case "bytes27":
                return new TypeReference<StaticArray128<Bytes27>>(indexed) {};
            case "bytes28":
                return new TypeReference<StaticArray128<Bytes28>>(indexed) {};
            case "bytes29":
                return new TypeReference<StaticArray128<Bytes29>>(indexed) {};
            case "bytes30":
                return new TypeReference<StaticArray128<Bytes30>>(indexed) {};
            case "bytes31":
                return new TypeReference<StaticArray128<Bytes31>>(indexed) {};
            case "bytes32":
                return new TypeReference<StaticArray128<Bytes32>>(indexed) {};
            default:
                throw new BaseException(
                        201201, String.format(" %s[128] unsupported encoding array type ", type));
        }
    }
 
Example #21
Source File: TypeDecoder.java    From web3sdk with Apache License 2.0 4 votes vote down vote up
static Utf8String decodeUtf8String(String input, int offset) {
    DynamicBytes dynamicBytesResult = decodeDynamicBytes(input, offset);
    byte[] bytes = dynamicBytesResult.getValue();

    return new Utf8String(new String(bytes, StandardCharsets.UTF_8));
}
 
Example #22
Source File: TransactionDecoderTest.java    From web3sdk with Apache License 2.0 4 votes vote down vote up
@Test
public void testDynamicParams1()
        throws JsonProcessingException, TransactionException, BaseException {

    /*
    function test(uint256[] _u,int256[] _i,bool[] _b,address[] _addr,bytes32[] _bs32,string[] _s,bytes[] _bs) public constant returns (uint256[],int256[],bool[],address[],bytes32[],string[],bytes[]) {

    }
       */

    TransactionDecoder decode =
            TransactionDecoderFactory.buildTransactionDecoder(
                    "[{\"constant\":true,\"inputs\":[{\"name\":\"_u\",\"type\":\"uint256[4]\"},{\"name\":\"_i\",\"type\":\"int256[4]\"},{\"name\":\"_b\",\"type\":\"bool[4]\"},{\"name\":\"_addr\",\"type\":\"address[4]\"},{\"name\":\"_bs32\",\"type\":\"bytes32[4]\"},{\"name\":\"_s\",\"type\":\"string[4]\"},{\"name\":\"_bs\",\"type\":\"bytes[4]\"}],\"name\":\"test\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256[2]\"},{\"name\":\"\",\"type\":\"int256[2]\"},{\"name\":\"\",\"type\":\"bool[2]\"},{\"name\":\"\",\"type\":\"address[2]\"},{\"name\":\"\",\"type\":\"bytes32[2]\"},{\"name\":\"\",\"type\":\"string[2]\"},{\"name\":\"\",\"type\":\"bytes[2]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_u\",\"type\":\"uint256\"},{\"name\":\"_i\",\"type\":\"int256\"},{\"name\":\"_b\",\"type\":\"bool\"},{\"name\":\"_addr\",\"type\":\"address\"},{\"name\":\"_bs32\",\"type\":\"bytes32\"},{\"name\":\"_s\",\"type\":\"string\"},{\"name\":\"_bs\",\"type\":\"bytes\"}],\"name\":\"test\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"},{\"name\":\"\",\"type\":\"int256\"},{\"name\":\"\",\"type\":\"bool\"},{\"name\":\"\",\"type\":\"address\"},{\"name\":\"\",\"type\":\"bytes32\"},{\"name\":\"\",\"type\":\"string\"},{\"name\":\"\",\"type\":\"bytes\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_u\",\"type\":\"uint256[]\"},{\"name\":\"_i\",\"type\":\"int256[]\"},{\"name\":\"_b\",\"type\":\"bool[]\"},{\"name\":\"_addr\",\"type\":\"address[]\"},{\"name\":\"_bs32\",\"type\":\"bytes32[]\"},{\"name\":\"_s\",\"type\":\"string[]\"},{\"name\":\"_bs\",\"type\":\"bytes[]\"}],\"name\":\"test\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256[]\"},{\"name\":\"\",\"type\":\"int256[]\"},{\"name\":\"\",\"type\":\"bool[]\"},{\"name\":\"\",\"type\":\"address[]\"},{\"name\":\"\",\"type\":\"bytes32[]\"},{\"name\":\"\",\"type\":\"string[]\"},{\"name\":\"\",\"type\":\"bytes[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_u\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"_i\",\"type\":\"int256\"},{\"indexed\":false,\"name\":\"_b\",\"type\":\"bool\"},{\"indexed\":false,\"name\":\"_addr\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_bs32\",\"type\":\"bytes32\"},{\"indexed\":false,\"name\":\"_s\",\"type\":\"string\"},{\"indexed\":false,\"name\":\"_bs\",\"type\":\"bytes\"}],\"name\":\"TestEventSimpleParams\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_u\",\"type\":\"uint256[]\"},{\"indexed\":false,\"name\":\"_i\",\"type\":\"int256[]\"},{\"indexed\":false,\"name\":\"_b\",\"type\":\"bool[]\"},{\"indexed\":false,\"name\":\"_addr\",\"type\":\"address[]\"},{\"indexed\":false,\"name\":\"_bs32\",\"type\":\"bytes32[]\"},{\"indexed\":false,\"name\":\"_s\",\"type\":\"string[]\"},{\"indexed\":false,\"name\":\"_bs\",\"type\":\"bytes[]\"}],\"name\":\"TestEventDArrayParams\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_u\",\"type\":\"uint256[4]\"},{\"indexed\":false,\"name\":\"_i\",\"type\":\"int256[4]\"},{\"indexed\":false,\"name\":\"_b\",\"type\":\"bool[4]\"},{\"indexed\":false,\"name\":\"_addr\",\"type\":\"address[4]\"},{\"indexed\":false,\"name\":\"_bs32\",\"type\":\"bytes32[4]\"},{\"indexed\":false,\"name\":\"_s\",\"type\":\"string[4]\"},{\"indexed\":false,\"name\":\"_bs\",\"type\":\"bytes[4]\"}],\"name\":\"TestEventSArrayParams\",\"type\":\"event\"}]",
                    "");

    List<Type> test1Params =
            Arrays.asList(
                    new DynamicArray<Uint256>(new Uint256(0), new Uint256(0), new Uint256(0)),
                    new DynamicArray<Int256>(new Int256(0), new Int256(0), new Int256(0)),
                    new DynamicArray<Bool>(new Bool(false), new Bool(true), new Bool(false)),
                    new DynamicArray<Address>(new Address("0x0"), new Address("0x0")),
                    new DynamicArray<Bytes32>(
                            new Bytes32("                                ".getBytes()),
                            new Bytes32("                                ".getBytes())),
                    new DynamicArray<Utf8String>(
                            new Utf8String(""), new Utf8String(""), new Utf8String("")),
                    new DynamicArray<DynamicBytes>(
                            new DynamicBytes("".getBytes()),
                            new DynamicBytes("".getBytes()),
                            new DynamicBytes("".getBytes())));

    Function test1 =
            new Function("test", test1Params, Collections.<TypeReference<?>>emptyList());

    String resultInputJson = decode.decodeInputReturnJson(FunctionEncoder.encode(test1));
    InputAndOutputResult inputAndOutputResult1 =
            decode.decodeInputReturnObject(FunctionEncoder.encode(test1));
    List<ResultEntity> resultInputList = inputAndOutputResult1.getResult();
    List<Type> resultInputListType = transEntitytoType(resultInputList);

    assertThat(
            resultInputJson,
            is(
                    "{\"function\":\"test(uint256[],int256[],bool[],address[],bytes32[],string[],bytes[])\",\"methodID\":\"0x6dd9902a\",\"result\":[{\"name\":\"_u\",\"type\":\"uint256[]\",\"data\":[0,0,0]},{\"name\":\"_i\",\"type\":\"int256[]\",\"data\":[0,0,0]},{\"name\":\"_b\",\"type\":\"bool[]\",\"data\":[false,true,false]},{\"name\":\"_addr\",\"type\":\"address[]\",\"data\":[\"0x0000000000000000000000000000000000000000\",\"0x0000000000000000000000000000000000000000\"]},{\"name\":\"_bs32\",\"type\":\"bytes32[]\",\"data\":[\"\",\"\"]},{\"name\":\"_s\",\"type\":\"string[]\",\"data\":[\"\",\"\",\"\"]},{\"name\":\"_bs\",\"type\":\"bytes[]\",\"data\":[\"\",\"\",\"\"]}]}"));
    assertThat(resultInputListType, is(test1Params));

    String resultOutputJson =
            decode.decodeOutputReturnJson(
                    FunctionEncoder.encode(test1),
                    FunctionEncoder.encodeConstructor(test1Params));
    InputAndOutputResult inputAndOutputResult =
            decode.decodeOutputReturnObject(
                    FunctionEncoder.encode(test1),
                    FunctionEncoder.encodeConstructor(test1Params));
    List<ResultEntity> resultOutputList = inputAndOutputResult.getResult();
    assertThat(
            resultOutputJson,
            is(
                    "{\"function\":\"test(uint256[],int256[],bool[],address[],bytes32[],string[],bytes[])\",\"methodID\":\"0x6dd9902a\",\"result\":[{\"name\":\"\",\"type\":\"uint256[]\",\"data\":[0,0,0]},{\"name\":\"\",\"type\":\"int256[]\",\"data\":[0,0,0]},{\"name\":\"\",\"type\":\"bool[]\",\"data\":[false,true,false]},{\"name\":\"\",\"type\":\"address[]\",\"data\":[\"0x0000000000000000000000000000000000000000\",\"0x0000000000000000000000000000000000000000\"]},{\"name\":\"\",\"type\":\"bytes32[]\",\"data\":[\"\",\"\"]},{\"name\":\"\",\"type\":\"string[]\",\"data\":[\"\",\"\",\"\"]},{\"name\":\"\",\"type\":\"bytes[]\",\"data\":[\"\",\"\",\"\"]}]}"));
    assertThat(transEntitytoType(resultOutputList), is(test1Params));
}
 
Example #23
Source File: TransactionDecoderTest.java    From web3sdk with Apache License 2.0 4 votes vote down vote up
@Test
public void testDynamicParams0()
        throws JsonProcessingException, TransactionException, BaseException {

    /*
    function test(uint256[] _u,int256[] _i,bool[] _b,address[] _addr,bytes32[] _bs32,string[] _s,bytes[] _bs) public constant returns (uint256[],int256[],bool[],address[],bytes32[],string[],bytes[]) {

    }
       */

    TransactionDecoder decode =
            TransactionDecoderFactory.buildTransactionDecoder(
                    "[{\"constant\":true,\"inputs\":[{\"name\":\"_u\",\"type\":\"uint256[4]\"},{\"name\":\"_i\",\"type\":\"int256[4]\"},{\"name\":\"_b\",\"type\":\"bool[4]\"},{\"name\":\"_addr\",\"type\":\"address[4]\"},{\"name\":\"_bs32\",\"type\":\"bytes32[4]\"},{\"name\":\"_s\",\"type\":\"string[4]\"},{\"name\":\"_bs\",\"type\":\"bytes[4]\"}],\"name\":\"test\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256[2]\"},{\"name\":\"\",\"type\":\"int256[2]\"},{\"name\":\"\",\"type\":\"bool[2]\"},{\"name\":\"\",\"type\":\"address[2]\"},{\"name\":\"\",\"type\":\"bytes32[2]\"},{\"name\":\"\",\"type\":\"string[2]\"},{\"name\":\"\",\"type\":\"bytes[2]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_u\",\"type\":\"uint256\"},{\"name\":\"_i\",\"type\":\"int256\"},{\"name\":\"_b\",\"type\":\"bool\"},{\"name\":\"_addr\",\"type\":\"address\"},{\"name\":\"_bs32\",\"type\":\"bytes32\"},{\"name\":\"_s\",\"type\":\"string\"},{\"name\":\"_bs\",\"type\":\"bytes\"}],\"name\":\"test\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"},{\"name\":\"\",\"type\":\"int256\"},{\"name\":\"\",\"type\":\"bool\"},{\"name\":\"\",\"type\":\"address\"},{\"name\":\"\",\"type\":\"bytes32\"},{\"name\":\"\",\"type\":\"string\"},{\"name\":\"\",\"type\":\"bytes\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_u\",\"type\":\"uint256[]\"},{\"name\":\"_i\",\"type\":\"int256[]\"},{\"name\":\"_b\",\"type\":\"bool[]\"},{\"name\":\"_addr\",\"type\":\"address[]\"},{\"name\":\"_bs32\",\"type\":\"bytes32[]\"},{\"name\":\"_s\",\"type\":\"string[]\"},{\"name\":\"_bs\",\"type\":\"bytes[]\"}],\"name\":\"test\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256[]\"},{\"name\":\"\",\"type\":\"int256[]\"},{\"name\":\"\",\"type\":\"bool[]\"},{\"name\":\"\",\"type\":\"address[]\"},{\"name\":\"\",\"type\":\"bytes32[]\"},{\"name\":\"\",\"type\":\"string[]\"},{\"name\":\"\",\"type\":\"bytes[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_u\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"_i\",\"type\":\"int256\"},{\"indexed\":false,\"name\":\"_b\",\"type\":\"bool\"},{\"indexed\":false,\"name\":\"_addr\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_bs32\",\"type\":\"bytes32\"},{\"indexed\":false,\"name\":\"_s\",\"type\":\"string\"},{\"indexed\":false,\"name\":\"_bs\",\"type\":\"bytes\"}],\"name\":\"TestEventSimpleParams\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_u\",\"type\":\"uint256[]\"},{\"indexed\":false,\"name\":\"_i\",\"type\":\"int256[]\"},{\"indexed\":false,\"name\":\"_b\",\"type\":\"bool[]\"},{\"indexed\":false,\"name\":\"_addr\",\"type\":\"address[]\"},{\"indexed\":false,\"name\":\"_bs32\",\"type\":\"bytes32[]\"},{\"indexed\":false,\"name\":\"_s\",\"type\":\"string[]\"},{\"indexed\":false,\"name\":\"_bs\",\"type\":\"bytes[]\"}],\"name\":\"TestEventDArrayParams\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_u\",\"type\":\"uint256[4]\"},{\"indexed\":false,\"name\":\"_i\",\"type\":\"int256[4]\"},{\"indexed\":false,\"name\":\"_b\",\"type\":\"bool[4]\"},{\"indexed\":false,\"name\":\"_addr\",\"type\":\"address[4]\"},{\"indexed\":false,\"name\":\"_bs32\",\"type\":\"bytes32[4]\"},{\"indexed\":false,\"name\":\"_s\",\"type\":\"string[4]\"},{\"indexed\":false,\"name\":\"_bs\",\"type\":\"bytes[4]\"}],\"name\":\"TestEventSArrayParams\",\"type\":\"event\"}]",
                    "");

    List<Type> test1Params =
            Arrays.asList(
                    new DynamicArray<Uint256>(
                            new Uint256(11111), new Uint256(22222), new Uint256(33333)),
                    new DynamicArray<Int256>(
                            new Int256(-1111111), new Int256(-3333333), new Int256(-2222222)),
                    new DynamicArray<Bool>(new Bool(false), new Bool(true), new Bool(false)),
                    new DynamicArray<Address>(
                            new Address("0x692a70d2e424a56d2c6c27aa97d1a86395877b3a"),
                            new Address("0x692a70d2e424a56d2c6c27aa97d1a86395877b3a")),
                    new DynamicArray<Bytes32>(
                            new Bytes32("abcdefghiabcdefghiabcdefghiabhji".getBytes()),
                            new Bytes32("abcdefghiabcdefghiabcdefghiabhji".getBytes())),
                    new DynamicArray<Utf8String>(
                            new Utf8String(""),
                            new Utf8String("章鱼小丸子ljjkl;adjsfkljlkjl"),
                            new Utf8String("章鱼小丸子ljjkl;adjsfkljlkjl")),
                    new DynamicArray<DynamicBytes>(
                            new DynamicBytes("".getBytes()),
                            new DynamicBytes("sadfljkjkljkl".getBytes()),
                            new DynamicBytes("章鱼小丸子ljjkl;adjsfkljlkjl".getBytes())));

    Function test1 =
            new Function("test", test1Params, Collections.<TypeReference<?>>emptyList());

    String resultInputJson = decode.decodeInputReturnJson(FunctionEncoder.encode(test1));
    InputAndOutputResult inputAndOutputResult =
            decode.decodeInputReturnObject(FunctionEncoder.encode(test1));
    List<ResultEntity> resultInputList = inputAndOutputResult.getResult();
    List<Type> resultInputListType = transEntitytoType(resultInputList);
    assertThat(
            resultInputJson,
            is(
                    "{\"function\":\"test(uint256[],int256[],bool[],address[],bytes32[],string[],bytes[])\",\"methodID\":\"0x6dd9902a\",\"result\":[{\"name\":\"_u\",\"type\":\"uint256[]\",\"data\":[11111,22222,33333]},{\"name\":\"_i\",\"type\":\"int256[]\",\"data\":[-1111111,-3333333,-2222222]},{\"name\":\"_b\",\"type\":\"bool[]\",\"data\":[false,true,false]},{\"name\":\"_addr\",\"type\":\"address[]\",\"data\":[\"0x692a70d2e424a56d2c6c27aa97d1a86395877b3a\",\"0x692a70d2e424a56d2c6c27aa97d1a86395877b3a\"]},{\"name\":\"_bs32\",\"type\":\"bytes32[]\",\"data\":[\"abcdefghiabcdefghiabcdefghiabhji\",\"abcdefghiabcdefghiabcdefghiabhji\"]},{\"name\":\"_s\",\"type\":\"string[]\",\"data\":[\"\",\"章鱼小丸子ljjkl;adjsfkljlkjl\",\"章鱼小丸子ljjkl;adjsfkljlkjl\"]},{\"name\":\"_bs\",\"type\":\"bytes[]\",\"data\":[\"\",\"sadfljkjkljkl\",\"章鱼小丸子ljjkl;adjsfkljlkjl\"]}]}"));
    assertThat(resultInputListType, is(test1Params));

    String resultOutputJson =
            decode.decodeOutputReturnJson(
                    FunctionEncoder.encode(test1),
                    FunctionEncoder.encodeConstructor(test1Params));
    InputAndOutputResult inputAndOutputResult2 =
            decode.decodeOutputReturnObject(
                    FunctionEncoder.encode(test1),
                    FunctionEncoder.encodeConstructor(test1Params));
    List<ResultEntity> resultOutputList = inputAndOutputResult2.getResult();
    assertThat(
            resultOutputJson,
            is(
                    "{\"function\":\"test(uint256[],int256[],bool[],address[],bytes32[],string[],bytes[])\",\"methodID\":\"0x6dd9902a\",\"result\":[{\"name\":\"\",\"type\":\"uint256[]\",\"data\":[11111,22222,33333]},{\"name\":\"\",\"type\":\"int256[]\",\"data\":[-1111111,-3333333,-2222222]},{\"name\":\"\",\"type\":\"bool[]\",\"data\":[false,true,false]},{\"name\":\"\",\"type\":\"address[]\",\"data\":[\"0x692a70d2e424a56d2c6c27aa97d1a86395877b3a\",\"0x692a70d2e424a56d2c6c27aa97d1a86395877b3a\"]},{\"name\":\"\",\"type\":\"bytes32[]\",\"data\":[\"abcdefghiabcdefghiabcdefghiabhji\",\"abcdefghiabcdefghiabcdefghiabhji\"]},{\"name\":\"\",\"type\":\"string[]\",\"data\":[\"\",\"章鱼小丸子ljjkl;adjsfkljlkjl\",\"章鱼小丸子ljjkl;adjsfkljlkjl\"]},{\"name\":\"\",\"type\":\"bytes[]\",\"data\":[\"\",\"sadfljkjkljkl\",\"章鱼小丸子ljjkl;adjsfkljlkjl\"]}]}"));
    assertThat(transEntitytoType(resultOutputList), is(test1Params));
}
 
Example #24
Source File: StaticArrayReference.java    From web3sdk with Apache License 2.0 4 votes vote down vote up
private static TypeReference<?> create24(String type, boolean indexed) throws BaseException {

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

        switch (type) {
            case "address":
                return new TypeReference<StaticArray24<Address>>(indexed) {};
            case "bool":
                return new TypeReference<StaticArray24<Bool>>(indexed) {};
            case "string":
                return new TypeReference<StaticArray24<Utf8String>>(indexed) {};
            case "bytes":
                return new TypeReference<StaticArray24<DynamicBytes>>(indexed) {};
            case "bytes1":
                return new TypeReference<StaticArray24<Bytes1>>(indexed) {};
            case "bytes2":
                return new TypeReference<StaticArray24<Bytes2>>(indexed) {};
            case "bytes3":
                return new TypeReference<StaticArray24<Bytes3>>(indexed) {};
            case "bytes4":
                return new TypeReference<StaticArray24<Bytes4>>(indexed) {};
            case "bytes5":
                return new TypeReference<StaticArray24<Bytes5>>(indexed) {};
            case "bytes6":
                return new TypeReference<StaticArray24<Bytes6>>(indexed) {};
            case "bytes7":
                return new TypeReference<StaticArray24<Bytes7>>(indexed) {};
            case "bytes8":
                return new TypeReference<StaticArray24<Bytes8>>(indexed) {};
            case "bytes9":
                return new TypeReference<StaticArray24<Bytes9>>(indexed) {};
            case "bytes10":
                return new TypeReference<StaticArray24<Bytes10>>(indexed) {};
            case "bytes11":
                return new TypeReference<StaticArray24<Bytes11>>(indexed) {};
            case "bytes12":
                return new TypeReference<StaticArray24<Bytes12>>(indexed) {};
            case "bytes13":
                return new TypeReference<StaticArray24<Bytes13>>(indexed) {};
            case "bytes14":
                return new TypeReference<StaticArray24<Bytes14>>(indexed) {};
            case "bytes15":
                return new TypeReference<StaticArray24<Bytes15>>(indexed) {};
            case "bytes16":
                return new TypeReference<StaticArray24<Bytes16>>(indexed) {};
            case "bytes17":
                return new TypeReference<StaticArray24<Bytes17>>(indexed) {};
            case "bytes18":
                return new TypeReference<StaticArray24<Bytes18>>(indexed) {};
            case "bytes19":
                return new TypeReference<StaticArray24<Bytes19>>(indexed) {};
            case "bytes20":
                return new TypeReference<StaticArray24<Bytes20>>(indexed) {};
            case "bytes21":
                return new TypeReference<StaticArray24<Bytes21>>(indexed) {};
            case "bytes22":
                return new TypeReference<StaticArray24<Bytes22>>(indexed) {};
            case "bytes23":
                return new TypeReference<StaticArray24<Bytes23>>(indexed) {};
            case "bytes24":
                return new TypeReference<StaticArray24<Bytes24>>(indexed) {};
            case "bytes25":
                return new TypeReference<StaticArray24<Bytes25>>(indexed) {};
            case "bytes26":
                return new TypeReference<StaticArray24<Bytes26>>(indexed) {};
            case "bytes27":
                return new TypeReference<StaticArray24<Bytes27>>(indexed) {};
            case "bytes28":
                return new TypeReference<StaticArray24<Bytes28>>(indexed) {};
            case "bytes29":
                return new TypeReference<StaticArray24<Bytes29>>(indexed) {};
            case "bytes30":
                return new TypeReference<StaticArray24<Bytes30>>(indexed) {};
            case "bytes31":
                return new TypeReference<StaticArray24<Bytes31>>(indexed) {};
            case "bytes32":
                return new TypeReference<StaticArray24<Bytes32>>(indexed) {};
            default:
                throw new BaseException(
                        201201, String.format(" %s[24] unsupported encoding array type ", type));
        }
    }
 
Example #25
Source File: TransactionDecoderTest.java    From web3sdk with Apache License 2.0 4 votes vote down vote up
@Test
public void testSimpleParams1()
        throws JsonProcessingException, TransactionException, BaseException {

    /*
    function test(uint256 _u,int256 _i,bool _b,address _addr,bytes32 _bs32, string _s,bytes _bs) public constant returns (uint256,int256,bool,address,bytes32,string,bytes)
    */

    TransactionDecoder decode =
            TransactionDecoderFactory.buildTransactionDecoder(
                    "[{\"constant\":true,\"inputs\":[{\"name\":\"_u\",\"type\":\"uint256[4]\"},{\"name\":\"_i\",\"type\":\"int256[4]\"},{\"name\":\"_b\",\"type\":\"bool[4]\"},{\"name\":\"_addr\",\"type\":\"address[4]\"},{\"name\":\"_bs32\",\"type\":\"bytes32[4]\"},{\"name\":\"_s\",\"type\":\"string[4]\"},{\"name\":\"_bs\",\"type\":\"bytes[4]\"}],\"name\":\"test\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256[2]\"},{\"name\":\"\",\"type\":\"int256[2]\"},{\"name\":\"\",\"type\":\"bool[2]\"},{\"name\":\"\",\"type\":\"address[2]\"},{\"name\":\"\",\"type\":\"bytes32[2]\"},{\"name\":\"\",\"type\":\"string[2]\"},{\"name\":\"\",\"type\":\"bytes[2]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_u\",\"type\":\"uint256\"},{\"name\":\"_i\",\"type\":\"int256\"},{\"name\":\"_b\",\"type\":\"bool\"},{\"name\":\"_addr\",\"type\":\"address\"},{\"name\":\"_bs32\",\"type\":\"bytes32\"},{\"name\":\"_s\",\"type\":\"string\"},{\"name\":\"_bs\",\"type\":\"bytes\"}],\"name\":\"test\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"},{\"name\":\"\",\"type\":\"int256\"},{\"name\":\"\",\"type\":\"bool\"},{\"name\":\"\",\"type\":\"address\"},{\"name\":\"\",\"type\":\"bytes32\"},{\"name\":\"\",\"type\":\"string\"},{\"name\":\"\",\"type\":\"bytes\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_u\",\"type\":\"uint256[]\"},{\"name\":\"_i\",\"type\":\"int256[]\"},{\"name\":\"_b\",\"type\":\"bool[]\"},{\"name\":\"_addr\",\"type\":\"address[]\"},{\"name\":\"_bs32\",\"type\":\"bytes32[]\"},{\"name\":\"_s\",\"type\":\"string[]\"},{\"name\":\"_bs\",\"type\":\"bytes[]\"}],\"name\":\"test\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256[]\"},{\"name\":\"\",\"type\":\"int256[]\"},{\"name\":\"\",\"type\":\"bool[]\"},{\"name\":\"\",\"type\":\"address[]\"},{\"name\":\"\",\"type\":\"bytes32[]\"},{\"name\":\"\",\"type\":\"string[]\"},{\"name\":\"\",\"type\":\"bytes[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_u\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"_i\",\"type\":\"int256\"},{\"indexed\":false,\"name\":\"_b\",\"type\":\"bool\"},{\"indexed\":false,\"name\":\"_addr\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_bs32\",\"type\":\"bytes32\"},{\"indexed\":false,\"name\":\"_s\",\"type\":\"string\"},{\"indexed\":false,\"name\":\"_bs\",\"type\":\"bytes\"}],\"name\":\"TestEventSimpleParams\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_u\",\"type\":\"uint256[]\"},{\"indexed\":false,\"name\":\"_i\",\"type\":\"int256[]\"},{\"indexed\":false,\"name\":\"_b\",\"type\":\"bool[]\"},{\"indexed\":false,\"name\":\"_addr\",\"type\":\"address[]\"},{\"indexed\":false,\"name\":\"_bs32\",\"type\":\"bytes32[]\"},{\"indexed\":false,\"name\":\"_s\",\"type\":\"string[]\"},{\"indexed\":false,\"name\":\"_bs\",\"type\":\"bytes[]\"}],\"name\":\"TestEventDArrayParams\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_u\",\"type\":\"uint256[4]\"},{\"indexed\":false,\"name\":\"_i\",\"type\":\"int256[4]\"},{\"indexed\":false,\"name\":\"_b\",\"type\":\"bool[4]\"},{\"indexed\":false,\"name\":\"_addr\",\"type\":\"address[4]\"},{\"indexed\":false,\"name\":\"_bs32\",\"type\":\"bytes32[4]\"},{\"indexed\":false,\"name\":\"_s\",\"type\":\"string[4]\"},{\"indexed\":false,\"name\":\"_bs\",\"type\":\"bytes[4]\"}],\"name\":\"TestEventSArrayParams\",\"type\":\"event\"}]",
                    "");

    List<Type> test1Params =
            Arrays.asList(
                    new Uint256(0),
                    new Int256(0),
                    new Bool(false),
                    new Address("0x0"),
                    new Bytes32("                                ".getBytes()),
                    new Utf8String(""),
                    new DynamicBytes("".getBytes()));

    Function test1 =
            new Function("test", test1Params, Collections.<TypeReference<?>>emptyList());

    String resultInputJson = decode.decodeInputReturnJson(FunctionEncoder.encode(test1));
    InputAndOutputResult inputAndOutputResult =
            decode.decodeInputReturnObject(FunctionEncoder.encode(test1));
    List<ResultEntity> resultInputList = inputAndOutputResult.getResult();
    List<Type> resultInputListType = transEntitytoType(resultInputList);
    assertThat(
            resultInputJson,
            is(
                    "{\"function\":\"test(uint256,int256,bool,address,bytes32,string,bytes)\",\"methodID\":\"0x58a12c20\",\"result\":[{\"name\":\"_u\",\"type\":\"uint256\",\"data\":0},{\"name\":\"_i\",\"type\":\"int256\",\"data\":0},{\"name\":\"_b\",\"type\":\"bool\",\"data\":false},{\"name\":\"_addr\",\"type\":\"address\",\"data\":\"0x0000000000000000000000000000000000000000\"},{\"name\":\"_bs32\",\"type\":\"bytes32\",\"data\":\"\"},{\"name\":\"_s\",\"type\":\"string\",\"data\":\"\"},{\"name\":\"_bs\",\"type\":\"bytes\",\"data\":\"\"}]}"));
    assertThat(resultInputListType, is(test1Params));

    String resultOutputJson =
            decode.decodeOutputReturnJson(
                    FunctionEncoder.encode(test1),
                    FunctionEncoder.encodeConstructor(test1Params));

    InputAndOutputResult inputAndOutputResult2 =
            decode.decodeOutputReturnObject(
                    FunctionEncoder.encode(test1),
                    FunctionEncoder.encodeConstructor(test1Params));
    List<ResultEntity> resultOutputList = inputAndOutputResult2.getResult();

    List<Type> resultOutputListType = transEntitytoType(resultOutputList);
    assertThat(
            resultOutputJson,
            is(
                    "{\"function\":\"test(uint256,int256,bool,address,bytes32,string,bytes)\",\"methodID\":\"0x58a12c20\",\"result\":[{\"name\":\"\",\"type\":\"uint256\",\"data\":0},{\"name\":\"\",\"type\":\"int256\",\"data\":0},{\"name\":\"\",\"type\":\"bool\",\"data\":false},{\"name\":\"\",\"type\":\"address\",\"data\":\"0x0000000000000000000000000000000000000000\"},{\"name\":\"\",\"type\":\"bytes32\",\"data\":\"\"},{\"name\":\"\",\"type\":\"string\",\"data\":\"\"},{\"name\":\"\",\"type\":\"bytes\",\"data\":\"\"}]}"));
    assertThat(resultOutputListType, is(test1Params));
}
 
Example #26
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);
}
 
Example #27
Source File: TransactionDecoderTest.java    From web3sdk with Apache License 2.0 4 votes vote down vote up
@Test
public void testSimpleParams0()
        throws JsonProcessingException, TransactionException, BaseException {

    /*
    function test(uint256 _u,int256 _i,bool _b,address _addr,bytes32 _bs32, string _s,bytes _bs) public constant returns (uint256,int256,bool,address,bytes32,string,bytes)
    */

    TransactionDecoder decode =
            TransactionDecoderFactory.buildTransactionDecoder(
                    "[{\"constant\":true,\"inputs\":[{\"name\":\"_u\",\"type\":\"uint256[4]\"},{\"name\":\"_i\",\"type\":\"int256[4]\"},{\"name\":\"_b\",\"type\":\"bool[4]\"},{\"name\":\"_addr\",\"type\":\"address[4]\"},{\"name\":\"_bs32\",\"type\":\"bytes32[4]\"},{\"name\":\"_s\",\"type\":\"string[4]\"},{\"name\":\"_bs\",\"type\":\"bytes[4]\"}],\"name\":\"test\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256[2]\"},{\"name\":\"\",\"type\":\"int256[2]\"},{\"name\":\"\",\"type\":\"bool[2]\"},{\"name\":\"\",\"type\":\"address[2]\"},{\"name\":\"\",\"type\":\"bytes32[2]\"},{\"name\":\"\",\"type\":\"string[2]\"},{\"name\":\"\",\"type\":\"bytes[2]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_u\",\"type\":\"uint256\"},{\"name\":\"_i\",\"type\":\"int256\"},{\"name\":\"_b\",\"type\":\"bool\"},{\"name\":\"_addr\",\"type\":\"address\"},{\"name\":\"_bs32\",\"type\":\"bytes32\"},{\"name\":\"_s\",\"type\":\"string\"},{\"name\":\"_bs\",\"type\":\"bytes\"}],\"name\":\"test\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"},{\"name\":\"\",\"type\":\"int256\"},{\"name\":\"\",\"type\":\"bool\"},{\"name\":\"\",\"type\":\"address\"},{\"name\":\"\",\"type\":\"bytes32\"},{\"name\":\"\",\"type\":\"string\"},{\"name\":\"\",\"type\":\"bytes\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_u\",\"type\":\"uint256[]\"},{\"name\":\"_i\",\"type\":\"int256[]\"},{\"name\":\"_b\",\"type\":\"bool[]\"},{\"name\":\"_addr\",\"type\":\"address[]\"},{\"name\":\"_bs32\",\"type\":\"bytes32[]\"},{\"name\":\"_s\",\"type\":\"string[]\"},{\"name\":\"_bs\",\"type\":\"bytes[]\"}],\"name\":\"test\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256[]\"},{\"name\":\"\",\"type\":\"int256[]\"},{\"name\":\"\",\"type\":\"bool[]\"},{\"name\":\"\",\"type\":\"address[]\"},{\"name\":\"\",\"type\":\"bytes32[]\"},{\"name\":\"\",\"type\":\"string[]\"},{\"name\":\"\",\"type\":\"bytes[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_u\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"_i\",\"type\":\"int256\"},{\"indexed\":false,\"name\":\"_b\",\"type\":\"bool\"},{\"indexed\":false,\"name\":\"_addr\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_bs32\",\"type\":\"bytes32\"},{\"indexed\":false,\"name\":\"_s\",\"type\":\"string\"},{\"indexed\":false,\"name\":\"_bs\",\"type\":\"bytes\"}],\"name\":\"TestEventSimpleParams\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_u\",\"type\":\"uint256[]\"},{\"indexed\":false,\"name\":\"_i\",\"type\":\"int256[]\"},{\"indexed\":false,\"name\":\"_b\",\"type\":\"bool[]\"},{\"indexed\":false,\"name\":\"_addr\",\"type\":\"address[]\"},{\"indexed\":false,\"name\":\"_bs32\",\"type\":\"bytes32[]\"},{\"indexed\":false,\"name\":\"_s\",\"type\":\"string[]\"},{\"indexed\":false,\"name\":\"_bs\",\"type\":\"bytes[]\"}],\"name\":\"TestEventDArrayParams\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_u\",\"type\":\"uint256[4]\"},{\"indexed\":false,\"name\":\"_i\",\"type\":\"int256[4]\"},{\"indexed\":false,\"name\":\"_b\",\"type\":\"bool[4]\"},{\"indexed\":false,\"name\":\"_addr\",\"type\":\"address[4]\"},{\"indexed\":false,\"name\":\"_bs32\",\"type\":\"bytes32[4]\"},{\"indexed\":false,\"name\":\"_s\",\"type\":\"string[4]\"},{\"indexed\":false,\"name\":\"_bs\",\"type\":\"bytes[4]\"}],\"name\":\"TestEventSArrayParams\",\"type\":\"event\"}]",
                    "");

    List<Type> test1Params =
            Arrays.asList(
                    new Uint256(111111),
                    new Int256(-1111111),
                    new Bool(false),
                    new Address("0x692a70d2e424a56d2c6c27aa97d1a86395877b3a"),
                    new Bytes32("abcdefghiabcdefghiabcdefghiabhji".getBytes()),
                    new Utf8String("章鱼小丸子ljjkl;adjsfkljlkjl"),
                    new DynamicBytes("sadfljkjkljkl".getBytes()));

    Function test1 =
            new Function("test", test1Params, Collections.<TypeReference<?>>emptyList());

    String resultInputJson = decode.decodeInputReturnJson(FunctionEncoder.encode(test1));
    InputAndOutputResult inputAndOutputResult =
            decode.decodeInputReturnObject(FunctionEncoder.encode(test1));
    List<ResultEntity> resultInputList = inputAndOutputResult.getResult();
    List<Type> resultInputListType = transEntitytoType(resultInputList);
    assertThat(
            resultInputJson,
            is(
                    "{\"function\":\"test(uint256,int256,bool,address,bytes32,string,bytes)\",\"methodID\":\"0x58a12c20\",\"result\":[{\"name\":\"_u\",\"type\":\"uint256\",\"data\":111111},{\"name\":\"_i\",\"type\":\"int256\",\"data\":-1111111},{\"name\":\"_b\",\"type\":\"bool\",\"data\":false},{\"name\":\"_addr\",\"type\":\"address\",\"data\":\"0x692a70d2e424a56d2c6c27aa97d1a86395877b3a\"},{\"name\":\"_bs32\",\"type\":\"bytes32\",\"data\":\"abcdefghiabcdefghiabcdefghiabhji\"},{\"name\":\"_s\",\"type\":\"string\",\"data\":\"章鱼小丸子ljjkl;adjsfkljlkjl\"},{\"name\":\"_bs\",\"type\":\"bytes\",\"data\":\"sadfljkjkljkl\"}]}"));
    assertThat(resultInputListType, is(test1Params));

    String resultOutputJson =
            decode.decodeOutputReturnJson(
                    FunctionEncoder.encode(test1),
                    FunctionEncoder.encodeConstructor(test1Params));

    InputAndOutputResult inputAndOutputResult2 =
            decode.decodeOutputReturnObject(
                    FunctionEncoder.encode(test1),
                    FunctionEncoder.encodeConstructor(test1Params));
    List<ResultEntity> resultOutputList = inputAndOutputResult2.getResult();

    List<Type> resultOutputListType = transEntitytoType(resultOutputList);
    assertThat(
            resultOutputJson,
            is(
                    "{\"function\":\"test(uint256,int256,bool,address,bytes32,string,bytes)\",\"methodID\":\"0x58a12c20\",\"result\":[{\"name\":\"\",\"type\":\"uint256\",\"data\":111111},{\"name\":\"\",\"type\":\"int256\",\"data\":-1111111},{\"name\":\"\",\"type\":\"bool\",\"data\":false},{\"name\":\"\",\"type\":\"address\",\"data\":\"0x692a70d2e424a56d2c6c27aa97d1a86395877b3a\"},{\"name\":\"\",\"type\":\"bytes32\",\"data\":\"abcdefghiabcdefghiabcdefghiabhji\"},{\"name\":\"\",\"type\":\"string\",\"data\":\"章鱼小丸子ljjkl;adjsfkljlkjl\"},{\"name\":\"\",\"type\":\"bytes\",\"data\":\"sadfljkjkljkl\"}]}"));
    assertThat(resultOutputListType, is(test1Params));
}
 
Example #28
Source File: ResultEntityTest.java    From web3sdk with Apache License 2.0 4 votes vote down vote up
@Test
public void typeToObjectArrayTest() throws JsonProcessingException {
    ResultEntity r0 = new ResultEntity("string", "string", new Utf8String("章鱼丸子"));
    assertThat(r0.toJson(), is("{\"name\":\"string\",\"type\":\"string\",\"data\":\"章鱼丸子\"}"));
    ResultEntity r1 = new ResultEntity("uint256", "uint256", new Uint256(247809787));
    assertThat(
            r1.toJson(), is("{\"name\":\"uint256\",\"type\":\"uint256\",\"data\":247809787}"));
    ResultEntity r2 = new ResultEntity("int256", "int256", new Int256(-247809787));
    assertThat(
            r2.toJson(), is("{\"name\":\"int256\",\"type\":\"int256\",\"data\":-247809787}"));
    ResultEntity r3 = new ResultEntity("bool", "bool", new Bool(true));
    assertThat(r3.toJson(), is("{\"name\":\"bool\",\"type\":\"bool\",\"data\":true}"));
    ResultEntity r4 =
            new ResultEntity("bytes", "bytes", new DynamicBytes("dasfjl;kljadfkl".getBytes()));
    assertThat(
            r4.toJson(),
            is("{\"name\":\"bytes\",\"type\":\"bytes\",\"data\":\"dasfjl;kljadfkl\"}"));

    ResultEntity r5 =
            new ResultEntity(
                    "StaticArray1", "StaticArray1", new StaticArray1<Uint256>(new Uint256(22)));
    assertThat(
            r5.toJson(),
            is("{\"name\":\"StaticArray1\",\"type\":\"StaticArray1\",\"data\":[22]}"));
    ResultEntity r6 =
            new ResultEntity(
                    "StaticArray3",
                    "StaticArray3",
                    new StaticArray3<Uint256>(new Uint256(1), new Uint256(2), new Uint256(3)));
    assertThat(
            r6.toJson(),
            is("{\"name\":\"StaticArray3\",\"type\":\"StaticArray3\",\"data\":[1,2,3]}"));
    ResultEntity r7 =
            new ResultEntity(
                    "DynamicArray",
                    "DynamicArray",
                    new DynamicArray<Bool>(new Bool(true), new Bool(false), new Bool(true)));
    assertThat(
            r7.toJson(),
            is(
                    "{\"name\":\"DynamicArray\",\"type\":\"DynamicArray\",\"data\":[true,false,true]}"));
    ResultEntity r8 =
            new ResultEntity(
                    "DynamicArray",
                    "DynamicArray",
                    new DynamicArray<Bytes7>(
                            new Bytes7("sdafljk".getBytes()),
                            new Bytes7("sdafljk".getBytes()),
                            new Bytes7("sdafljk".getBytes())));
    assertThat(
            r8.toJson(),
            is(
                    "{\"name\":\"DynamicArray\",\"type\":\"DynamicArray\",\"data\":[\"sdafljk\",\"sdafljk\",\"sdafljk\"]}"));
}
 
Example #29
Source File: StaticArrayReference.java    From web3sdk with Apache License 2.0 4 votes vote down vote up
private static TypeReference<?> create12(String type, boolean indexed) throws BaseException {

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

        switch (type) {
            case "address":
                return new TypeReference<StaticArray12<Address>>(indexed) {};
            case "bool":
                return new TypeReference<StaticArray12<Bool>>(indexed) {};
            case "string":
                return new TypeReference<StaticArray12<Utf8String>>(indexed) {};
            case "bytes":
                return new TypeReference<StaticArray12<DynamicBytes>>(indexed) {};
            case "bytes1":
                return new TypeReference<StaticArray12<Bytes1>>(indexed) {};
            case "bytes2":
                return new TypeReference<StaticArray12<Bytes2>>(indexed) {};
            case "bytes3":
                return new TypeReference<StaticArray12<Bytes3>>(indexed) {};
            case "bytes4":
                return new TypeReference<StaticArray12<Bytes4>>(indexed) {};
            case "bytes5":
                return new TypeReference<StaticArray12<Bytes5>>(indexed) {};
            case "bytes6":
                return new TypeReference<StaticArray12<Bytes6>>(indexed) {};
            case "bytes7":
                return new TypeReference<StaticArray12<Bytes7>>(indexed) {};
            case "bytes8":
                return new TypeReference<StaticArray12<Bytes8>>(indexed) {};
            case "bytes9":
                return new TypeReference<StaticArray12<Bytes9>>(indexed) {};
            case "bytes10":
                return new TypeReference<StaticArray12<Bytes10>>(indexed) {};
            case "bytes11":
                return new TypeReference<StaticArray12<Bytes11>>(indexed) {};
            case "bytes12":
                return new TypeReference<StaticArray12<Bytes12>>(indexed) {};
            case "bytes13":
                return new TypeReference<StaticArray12<Bytes13>>(indexed) {};
            case "bytes14":
                return new TypeReference<StaticArray12<Bytes14>>(indexed) {};
            case "bytes15":
                return new TypeReference<StaticArray12<Bytes15>>(indexed) {};
            case "bytes16":
                return new TypeReference<StaticArray12<Bytes16>>(indexed) {};
            case "bytes17":
                return new TypeReference<StaticArray12<Bytes17>>(indexed) {};
            case "bytes18":
                return new TypeReference<StaticArray12<Bytes18>>(indexed) {};
            case "bytes19":
                return new TypeReference<StaticArray12<Bytes19>>(indexed) {};
            case "bytes20":
                return new TypeReference<StaticArray12<Bytes20>>(indexed) {};
            case "bytes21":
                return new TypeReference<StaticArray12<Bytes21>>(indexed) {};
            case "bytes22":
                return new TypeReference<StaticArray12<Bytes22>>(indexed) {};
            case "bytes23":
                return new TypeReference<StaticArray12<Bytes23>>(indexed) {};
            case "bytes24":
                return new TypeReference<StaticArray12<Bytes24>>(indexed) {};
            case "bytes25":
                return new TypeReference<StaticArray12<Bytes25>>(indexed) {};
            case "bytes26":
                return new TypeReference<StaticArray12<Bytes26>>(indexed) {};
            case "bytes27":
                return new TypeReference<StaticArray12<Bytes27>>(indexed) {};
            case "bytes28":
                return new TypeReference<StaticArray12<Bytes28>>(indexed) {};
            case "bytes29":
                return new TypeReference<StaticArray12<Bytes29>>(indexed) {};
            case "bytes30":
                return new TypeReference<StaticArray12<Bytes30>>(indexed) {};
            case "bytes31":
                return new TypeReference<StaticArray12<Bytes31>>(indexed) {};
            case "bytes32":
                return new TypeReference<StaticArray12<Bytes32>>(indexed) {};
            default:
                throw new BaseException(
                        201201, String.format(" %s[12] unsupported encoding array type ", type));
        }
    }
 
Example #30
Source File: BytesUtils.java    From WeBASE-Collect-Bee with Apache License 2.0 4 votes vote down vote up
public static String dynamicBytesListToString(List<DynamicBytes> list) {
    return JacksonUtils
            .toJson(list.stream().map(b -> b.getValue()).map(b -> new String(b)).collect(Collectors.toList()));
}