Search in sources :

Example 1 with Int256

use of org.fisco.bcos.web3j.abi.datatypes.generated.Int256 in project web3sdk by FISCO-BCOS.

the class ABICodecJsonWrapper method encode.

public ABIObject encode(ABIObject template, List<String> inputs) throws IOException {
    ABIObject abiObject = template.newObject();
    // check parameters match
    if (inputs.size() != abiObject.getStructFields().size()) {
        errorReport("arguments size", String.valueOf(abiObject.getStructFields().size()), String.valueOf(inputs.size()));
    }
    for (int i = 0; i < abiObject.getStructFields().size(); ++i) {
        ABIObject argObject = abiObject.getStructFields().get(i).newObject();
        String value = inputs.get(i);
        switch(argObject.getType()) {
            case VALUE:
                {
                    try {
                        switch(argObject.getValueType()) {
                            case BOOL:
                                {
                                    argObject.setBoolValue(new Bool(Boolean.valueOf(value)));
                                    break;
                                }
                            case UINT:
                                {
                                    argObject.setNumericValue(new Uint256(Numeric.decodeQuantity(value)));
                                    break;
                                }
                            case INT:
                                {
                                    argObject.setNumericValue(new Int256(Numeric.decodeQuantity(value)));
                                    break;
                                }
                            case ADDRESS:
                                {
                                    argObject.setAddressValue(new Address(value));
                                    break;
                                }
                            case BYTES:
                                {
                                    // Binary data requires base64 encoding
                                    byte[] bytesValue = Base64.getDecoder().decode(value);
                                    argObject.setBytesValue(new Bytes(bytesValue.length, bytesValue));
                                    break;
                                }
                            case DBYTES:
                                {
                                    // Binary data requires base64 encoding
                                    byte[] bytesValue = Base64.getDecoder().decode(value);
                                    argObject.setDynamicBytesValue(new DynamicBytes(bytesValue));
                                    break;
                                }
                            case STRING:
                                {
                                    argObject.setStringValue(new Utf8String(value));
                                    break;
                                }
                            default:
                                {
                                    throw new UnsupportedOperationException("Unrecognized valueType: " + argObject.getValueType());
                                }
                        }
                    } catch (Exception e) {
                        logger.error(" e: ", e);
                        errorReport("ROOT", e.getMessage());
                    }
                    break;
                }
            case STRUCT:
            case LIST:
                {
                    JsonNode argNode = objectMapper.readTree(value.getBytes());
                    argObject = encodeNode("ROOT", argObject, argNode);
                    break;
                }
        }
        abiObject.getStructFields().set(i, argObject);
    }
    return abiObject;
}
Also used : Address(org.fisco.bcos.web3j.abi.datatypes.Address) JsonNode(com.fasterxml.jackson.databind.JsonNode) Utf8String(org.fisco.bcos.web3j.abi.datatypes.Utf8String) IOException(java.io.IOException) InvalidParameterException(java.security.InvalidParameterException) Int256(org.fisco.bcos.web3j.abi.datatypes.generated.Int256) DynamicBytes(org.fisco.bcos.web3j.abi.datatypes.DynamicBytes) Bytes(org.fisco.bcos.web3j.abi.datatypes.Bytes) Utf8String(org.fisco.bcos.web3j.abi.datatypes.Utf8String) DynamicBytes(org.fisco.bcos.web3j.abi.datatypes.DynamicBytes) Bool(org.fisco.bcos.web3j.abi.datatypes.Bool) Uint256(org.fisco.bcos.web3j.abi.datatypes.generated.Uint256)

Example 2 with Int256

use of org.fisco.bcos.web3j.abi.datatypes.generated.Int256 in project web3sdk by FISCO-BCOS.

the class FunctionEncoderTest method testEncodeInt.

@Test
public void testEncodeInt() {
    assertThat(FunctionEncoder.encodeParameters(Arrays.asList(new Int256(0)), new StringBuilder()), is("0000000000000000000000000000000000000000000000000000000000000000"));
    assertThat(FunctionEncoder.encodeParameters(Arrays.asList(new Int256(1111)), new StringBuilder()), is("0000000000000000000000000000000000000000000000000000000000000457"));
    assertThat(FunctionEncoder.encodeParameters(Arrays.asList(new Int256(new BigInteger("-1"))), new StringBuilder()), is("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"));
    assertThat(FunctionEncoder.encodeParameters(Arrays.asList(new Uint256(Long.MAX_VALUE)), new StringBuilder()), is("0000000000000000000000000000000000000000000000007fffffffffffffff"));
}
Also used : Int256(org.fisco.bcos.web3j.abi.datatypes.generated.Int256) BigInteger(java.math.BigInteger) Uint256(org.fisco.bcos.web3j.abi.datatypes.generated.Uint256) Test(org.junit.Test)

Example 3 with Int256

use of org.fisco.bcos.web3j.abi.datatypes.generated.Int256 in project web3sdk by FISCO-BCOS.

the class FunctionEncoderTest method testBuildMessageSignature.

@Test
public void testBuildMessageSignature() {
    assertThat(FunctionEncoder.buildMethodSignature("empty", Collections.emptyList()), is("empty()"));
    assertThat(FunctionEncoder.buildMethodSignature("baz", Arrays.asList(new Uint32(BigInteger.valueOf(69)), new Bool(true))), is("baz(uint32,bool)"));
    assertThat(FunctionEncoder.buildMethodSignature("test", Arrays.asList(new DynamicArray<DynamicArray<Uint256>>(new DynamicArray<Uint256>(new Uint256(1), new Uint256(2)), new DynamicArray<Uint256>(new Uint256(3))), new DynamicArray<Utf8String>(new Utf8String("one"), new Utf8String("two"), new Utf8String("three")))), is("test(uint256[][],string[])"));
    assertThat(FunctionEncoder.buildMethodSignature("test", Arrays.asList(new Uint256(0x123), new DynamicArray<Uint32>(new Uint32(0x456), new Uint32(0x789)), new Bytes10("1234567890".getBytes()), new DynamicBytes("Hello, world!".getBytes()))), is("test(uint256,uint32[],bytes10,bytes)"));
    assertThat(FunctionEncoder.buildMethodSignature("sam", Arrays.asList(new DynamicBytes("dave".getBytes()), new Bool(true), new DynamicArray<Uint256>(new Uint256(1), new Uint256(2), new Uint256(3)))), is("sam(bytes,bool,uint256[])"));
    Arrays.asList(new DynamicArray<DynamicArray<DynamicArray<DynamicArray<Utf8String>>>>(new DynamicArray(new DynamicArray(new DynamicArray(new Utf8String("adfsafjljkl"), new Utf8String("dsafhjk;jlk;jadfl;kjkl"), new Utf8String("ada"))))));
    assertThat(FunctionEncoder.buildMethodSignature("dave", Arrays.asList(new DynamicArray<DynamicArray<DynamicArray<DynamicArray<Utf8String>>>>(new DynamicArray(new DynamicArray(new DynamicArray(new Utf8String("adfsafjljkl"), new Utf8String("dsafhjk;jlk;jadfl;kjkl"), new Utf8String("ada"))))))), is("dave(string[][][][])"));
    assertThat(FunctionEncoder.buildMethodSignature("test", Arrays.asList(new Uint256(100), new Int256(-100), new Utf8String("abc"), new DynamicArray<Type>(new Utf8String("abc"), new Utf8String("abc"), new Utf8String("abc")), new StaticArray3<Type>(new Utf8String("abc"), new Utf8String("abc"), new Utf8String("abc")))), is("test(uint256,int256,string,string[],string[3])"));
    Arrays.asList(new StaticArray3<>(new DynamicArray<Type>(new Uint256(1)), new DynamicArray<Type>(new Uint256(2), new Uint256(3)), new DynamicArray<Type>(new Uint256(4), new Uint256(5), new Uint256(6))));
    assertThat(FunctionEncoder.buildMethodSignature("test", Arrays.asList(new StaticArray3<>(new DynamicArray<Type>(new Uint256(1)), new DynamicArray<Type>(new Uint256(2), new Uint256(3)), new DynamicArray<Type>(new Uint256(4), new Uint256(5), new Uint256(6))))), is("test(uint256[][3])"));
    assertThat(FunctionEncoder.buildMethodSignature("set", Arrays.asList(new Uint256(123), new Address("0x692a70d2e424a56d2c6c27aa97d1a86395877b3a"), new Utf8String("string c"), new DynamicArray<>(new Uint256(1), new Uint256(2), new Uint256(3)), new StaticArray3<>(new Uint256(4), new Uint256(5), new Uint256(6)), new DynamicArray<>(new Utf8String("abc"), new Utf8String("def"), new Utf8String("ghi")), new StaticArray3<>(new Utf8String("abc"), new Utf8String("def"), new Utf8String("ghi")), new DynamicArray<>(new DynamicArray<>(new Uint256(1), new Uint256(1), new Uint256(1)), new DynamicArray<>(new Uint256(2), new Uint256(2), new Uint256(2)), new DynamicArray<>(new Uint256(3), new Uint256(3), new Uint256(3))), new DynamicArray<>(new StaticArray3<>(new Uint256(4), new Uint256(4), new Uint256(4)), new StaticArray3<>(new Uint256(5), new Uint256(5), new Uint256(5))))), is("set(uint256,address,string,uint256[],uint256[3],string[],string[3],uint256[][],uint256[3][])"));
    assertThat(FunctionEncoder.buildMethodSignature("set", Arrays.asList(new Utf8String("aaafadsfsfadsfdasf"), new Address("0x35ef07393b57464e93deb59175ff72e6499450cf"), new Uint256(11111), new Int256(-11111))), is("set(string,address,uint256,int256)"));
    assertThat(FunctionEncoder.buildMethodSignature("set", Arrays.asList(new Utf8String("daslfjaklfdaskl"), new Uint256(1111), new StaticArray6<>(new Uint256(1), new Uint256(2), new Uint256(3), new Uint256(4), new Uint256(5), new Uint256(6)), new DynamicArray<>(new Uint256(1), new Uint256(2), new Uint256(3), new Uint256(4), new Uint256(5), new Uint256(6)), new Bool(false), new Address("0x692a70d2e424a56d2c6c27aa97d1a86395877b3a"))), is("set(string,uint256,uint256[6],uint256[],bool,address)"));
}
Also used : Bytes10(org.fisco.bcos.web3j.abi.datatypes.generated.Bytes10) Int256(org.fisco.bcos.web3j.abi.datatypes.generated.Int256) StaticArray3(org.fisco.bcos.web3j.abi.datatypes.generated.StaticArray3) Uint256(org.fisco.bcos.web3j.abi.datatypes.generated.Uint256) Uint32(org.fisco.bcos.web3j.abi.datatypes.generated.Uint32) Test(org.junit.Test)

Example 4 with Int256

use of org.fisco.bcos.web3j.abi.datatypes.generated.Int256 in project web3sdk by FISCO-BCOS.

the class TransactionDecoderTest method main.

public static void main(String[] args) throws BaseException, IOException {
    /*
         	event TestEventDArrayParams(uint256[] _u,int256[] _i,bool[] _b,address[] _addr,bytes32[] _bs32, string[] _s,bytes[] _bs);
        */
    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<TypeReference<?>> eventTypeList = Arrays.asList(new TypeReference<DynamicArray<Uint256>>() {
    }, new TypeReference<DynamicArray<Int256>>() {
    }, new TypeReference<DynamicArray<Bool>>() {
    }, new TypeReference<DynamicArray<Address>>() {
    }, new TypeReference<DynamicArray<Bytes32>>() {
    }, new TypeReference<DynamicArray<Utf8String>>() {
    }, new TypeReference<DynamicArray<DynamicBytes>>() {
    });
    Event event = new Event("TestEventDArrayParams", eventTypeList);
    List<Type> eventDataParams1 = 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())));
    List<Type> eventDataParams2 = 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())));
    List<Type> eventDataParams3 = Arrays.asList(new DynamicArray<Uint256>(new Uint256(0), new Uint256(0), new Uint256(0), new Uint256(11111), new Uint256(22222), new Uint256(33333)), new DynamicArray<Int256>(new Int256(0), new Int256(0), new Int256(0), new Int256(-1111111), new Int256(-3333333), new Int256(-2222222)), new DynamicArray<Bool>(new Bool(false), new Bool(true), new Bool(false), new Bool(false)), new DynamicArray<Address>(new Address("0x0"), new Address("0x0"), new Address("0x692a70d2e424a56d2c6c27aa97d1a86395877b3a"), new Address("0x692a70d2e424a56d2c6c27aa97d1a86395877b3a")), new DynamicArray<Bytes32>(new Bytes32("abcdefghiabcdefghiabcdefghiabhji".getBytes()), new Bytes32("abcdefghiabcdefghiabcdefghiabhji".getBytes()), new Bytes32("                                ".getBytes()), new Bytes32("                                ".getBytes())), new DynamicArray<Utf8String>(new Utf8String(""), new Utf8String("章鱼小丸子ljjkl;adjsfkljlkjl"), new Utf8String("章鱼小丸子ljjkl;adjsfkljlkjl"), new Utf8String(""), new Utf8String(""), new Utf8String("")), new DynamicArray<DynamicBytes>(new DynamicBytes("".getBytes()), new DynamicBytes("sadfljkjkljkl".getBytes()), new DynamicBytes("章鱼小丸子ljjkl;adjsfkljlkjl".getBytes()), new DynamicBytes("".getBytes()), new DynamicBytes("".getBytes()), new DynamicBytes("".getBytes())));
    List<String> topics = new ArrayList<String>();
    topics.add(EventEncoder.encode(event));
    Log log1 = new Log();
    log1.setData(FunctionEncoder.encodeConstructor(eventDataParams1));
    log1.setTopics(topics);
    Log log2 = new Log();
    log2.setData(FunctionEncoder.encodeConstructor(eventDataParams2));
    log2.setTopics(topics);
    Log log3 = new Log();
    log3.setData(FunctionEncoder.encodeConstructor(eventDataParams3));
    log3.setTopics(topics);
    AbiDefinition abiDefinition = null;
    Tuple2<AbiDefinition, List<EventResultEntity>> tupleResult1 = decode.decodeEventReturnObject(log1);
    assertThat(transEntitytoType0(tupleResult1.getValue2()), is(eventDataParams1));
    abiDefinition = tupleResult1.getValue1();
    Tuple2<AbiDefinition, List<EventResultEntity>> tupleResult2 = decode.decodeEventReturnObject(log2);
    assertThat(transEntitytoType0(tupleResult2.getValue2()), is(eventDataParams2));
    Tuple2<AbiDefinition, List<EventResultEntity>> tupleResult3 = decode.decodeEventReturnObject(log3);
    assertThat(transEntitytoType0(tupleResult3.getValue2()), is(eventDataParams3));
    List<Log> logList1 = new ArrayList<Log>();
    logList1.add(log1);
    Map<String, List<List<EventResultEntity>>> mapResult1 = decode.decodeEventReturnObject(logList1);
    assertThat(transEntitytoType0(mapResult1.get(decodeMethodSign(abiDefinition)).get(0)), is(eventDataParams1));
    // System.out.println("111 => " + decode.decodeEventReturnJson(logList1));
    assertThat(decode.decodeEventReturnJson(logList1), is("{\"TestEventDArrayParams(uint256[],int256[],bool[],address[],bytes32[],string[],bytes[])\":[[{\"name\":\"_u\",\"type\":\"uint256[]\",\"data\":[11111,22222,33333],\"indexed\":false},{\"name\":\"_i\",\"type\":\"int256[]\",\"data\":[-1111111,-3333333,-2222222],\"indexed\":false},{\"name\":\"_b\",\"type\":\"bool[]\",\"data\":[false,true,false],\"indexed\":false},{\"name\":\"_addr\",\"type\":\"address[]\",\"data\":[\"0x692a70d2e424a56d2c6c27aa97d1a86395877b3a\",\"0x692a70d2e424a56d2c6c27aa97d1a86395877b3a\"],\"indexed\":false},{\"name\":\"_bs32\",\"type\":\"bytes32[]\",\"data\":[\"abcdefghiabcdefghiabcdefghiabhji\",\"abcdefghiabcdefghiabcdefghiabhji\"],\"indexed\":false},{\"name\":\"_s\",\"type\":\"string[]\",\"data\":[\"\",\"章鱼小丸子ljjkl;adjsfkljlkjl\",\"章鱼小丸子ljjkl;adjsfkljlkjl\"],\"indexed\":false},{\"name\":\"_bs\",\"type\":\"bytes[]\",\"data\":[\"\",\"sadfljkjkljkl\",\"章鱼小丸子ljjkl;adjsfkljlkjl\"],\"indexed\":false}]]}"));
    List<Log> logList2 = new ArrayList<Log>();
    logList2.add(log1);
    logList2.add(log2);
    Map<String, List<List<EventResultEntity>>> mapResult2 = decode.decodeEventReturnObject(logList2);
    assertThat(transEntitytoType0(mapResult2.get(decodeMethodSign(abiDefinition)).get(0)), is(eventDataParams1));
    assertThat(transEntitytoType0(mapResult2.get(decodeMethodSign(abiDefinition)).get(1)), is(eventDataParams2));
    // System.out.println("222 => " + decode.decodeEventReturnJson(logList2));
    assertThat(decode.decodeEventReturnJson(logList2), is("{\"TestEventDArrayParams(uint256[],int256[],bool[],address[],bytes32[],string[],bytes[])\":[[{\"name\":\"_u\",\"type\":\"uint256[]\",\"data\":[11111,22222,33333],\"indexed\":false},{\"name\":\"_i\",\"type\":\"int256[]\",\"data\":[-1111111,-3333333,-2222222],\"indexed\":false},{\"name\":\"_b\",\"type\":\"bool[]\",\"data\":[false,true,false],\"indexed\":false},{\"name\":\"_addr\",\"type\":\"address[]\",\"data\":[\"0x692a70d2e424a56d2c6c27aa97d1a86395877b3a\",\"0x692a70d2e424a56d2c6c27aa97d1a86395877b3a\"],\"indexed\":false},{\"name\":\"_bs32\",\"type\":\"bytes32[]\",\"data\":[\"abcdefghiabcdefghiabcdefghiabhji\",\"abcdefghiabcdefghiabcdefghiabhji\"],\"indexed\":false},{\"name\":\"_s\",\"type\":\"string[]\",\"data\":[\"\",\"章鱼小丸子ljjkl;adjsfkljlkjl\",\"章鱼小丸子ljjkl;adjsfkljlkjl\"],\"indexed\":false},{\"name\":\"_bs\",\"type\":\"bytes[]\",\"data\":[\"\",\"sadfljkjkljkl\",\"章鱼小丸子ljjkl;adjsfkljlkjl\"],\"indexed\":false}],[{\"name\":\"_u\",\"type\":\"uint256[]\",\"data\":[0,0,0],\"indexed\":false},{\"name\":\"_i\",\"type\":\"int256[]\",\"data\":[0,0,0],\"indexed\":false},{\"name\":\"_b\",\"type\":\"bool[]\",\"data\":[false,true,false],\"indexed\":false},{\"name\":\"_addr\",\"type\":\"address[]\",\"data\":[\"0x0000000000000000000000000000000000000000\",\"0x0000000000000000000000000000000000000000\"],\"indexed\":false},{\"name\":\"_bs32\",\"type\":\"bytes32[]\",\"data\":[\"\",\"\"],\"indexed\":false},{\"name\":\"_s\",\"type\":\"string[]\",\"data\":[\"\",\"\",\"\"],\"indexed\":false},{\"name\":\"_bs\",\"type\":\"bytes[]\",\"data\":[\"\",\"\",\"\"],\"indexed\":false}],[{\"name\":\"_u\",\"type\":\"uint256[]\",\"data\":[0,0,0],\"indexed\":false},{\"name\":\"_i\",\"type\":\"int256[]\",\"data\":[0,0,0],\"indexed\":false},{\"name\":\"_b\",\"type\":\"bool[]\",\"data\":[false,true,false],\"indexed\":false},{\"name\":\"_addr\",\"type\":\"address[]\",\"data\":[\"0x0000000000000000000000000000000000000000\",\"0x0000000000000000000000000000000000000000\"],\"indexed\":false},{\"name\":\"_bs32\",\"type\":\"bytes32[]\",\"data\":[\"\",\"\"],\"indexed\":false},{\"name\":\"_s\",\"type\":\"string[]\",\"data\":[\"\",\"\",\"\"],\"indexed\":false},{\"name\":\"_bs\",\"type\":\"bytes[]\",\"data\":[\"\",\"\",\"\"],\"indexed\":false}]]}"));
    List<Log> logList3 = new ArrayList<Log>();
    logList3.add(log1);
    logList3.add(log2);
    logList3.add(log3);
    Map<String, List<List<EventResultEntity>>> mapResult3 = decode.decodeEventReturnObject(logList3);
    assertThat(transEntitytoType0(mapResult3.get(decodeMethodSign(abiDefinition)).get(0)), is(eventDataParams1));
    assertThat(transEntitytoType0(mapResult3.get(decodeMethodSign(abiDefinition)).get(1)), is(eventDataParams2));
    assertThat(transEntitytoType0(mapResult3.get(decodeMethodSign(abiDefinition)).get(2)), is(eventDataParams3));
    // System.out.println("333 => " + decode.decodeEventReturnJson(logList3));
    assertThat(decode.decodeEventReturnJson(logList3), is("{\"TestEventDArrayParams(uint256[],int256[],bool[],address[],bytes32[],string[],bytes[])\":[[{\"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\"]}],[{\"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\":[\"\",\"\",\"\"]}],[{\"name\":\"_u\",\"type\":\"uint256[]\",\"data\":[0,0,0,11111,22222,33333]},{\"name\":\"_i\",\"type\":\"int256[]\",\"data\":[0,0,0,-1111111,-3333333,-2222222]},{\"name\":\"_b\",\"type\":\"bool[]\",\"data\":[false,true,false,false]},{\"name\":\"_addr\",\"type\":\"address[]\",\"data\":[\"0x0000000000000000000000000000000000000000\",\"0x0000000000000000000000000000000000000000\",\"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\",\"\",\"\",\"\"]}]]}"));
}
Also used : Address(org.fisco.bcos.web3j.abi.datatypes.Address) ArrayList(java.util.ArrayList) Utf8String(org.fisco.bcos.web3j.abi.datatypes.Utf8String) Bytes32(org.fisco.bcos.web3j.abi.datatypes.generated.Bytes32) DynamicBytes(org.fisco.bcos.web3j.abi.datatypes.DynamicBytes) Bool(org.fisco.bcos.web3j.abi.datatypes.Bool) AbiDefinition(org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition) ArrayList(java.util.ArrayList) List(java.util.List) TypeReference(org.fisco.bcos.web3j.abi.TypeReference) Log(org.fisco.bcos.web3j.protocol.core.methods.response.Log) Int256(org.fisco.bcos.web3j.abi.datatypes.generated.Int256) Utf8String(org.fisco.bcos.web3j.abi.datatypes.Utf8String) Type(org.fisco.bcos.web3j.abi.datatypes.Type) NamedType(org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition.NamedType) DynamicArray(org.fisco.bcos.web3j.abi.datatypes.DynamicArray) Event(org.fisco.bcos.web3j.abi.datatypes.Event) Uint256(org.fisco.bcos.web3j.abi.datatypes.generated.Uint256)

Example 5 with Int256

use of org.fisco.bcos.web3j.abi.datatypes.generated.Int256 in project web3sdk by FISCO-BCOS.

the class TransactionDecoderTest method testSimpleParams1.

@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));
}
Also used : Address(org.fisco.bcos.web3j.abi.datatypes.Address) Utf8String(org.fisco.bcos.web3j.abi.datatypes.Utf8String) Bytes32(org.fisco.bcos.web3j.abi.datatypes.generated.Bytes32) Int256(org.fisco.bcos.web3j.abi.datatypes.generated.Int256) Utf8String(org.fisco.bcos.web3j.abi.datatypes.Utf8String) Function(org.fisco.bcos.web3j.abi.datatypes.Function) Type(org.fisco.bcos.web3j.abi.datatypes.Type) NamedType(org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition.NamedType) DynamicBytes(org.fisco.bcos.web3j.abi.datatypes.DynamicBytes) Bool(org.fisco.bcos.web3j.abi.datatypes.Bool) Uint256(org.fisco.bcos.web3j.abi.datatypes.generated.Uint256) Test(org.junit.Test)

Aggregations

Int256 (org.fisco.bcos.web3j.abi.datatypes.generated.Int256)24 Uint256 (org.fisco.bcos.web3j.abi.datatypes.generated.Uint256)21 Utf8String (org.fisco.bcos.web3j.abi.datatypes.Utf8String)19 Test (org.junit.Test)19 Bool (org.fisco.bcos.web3j.abi.datatypes.Bool)17 DynamicBytes (org.fisco.bcos.web3j.abi.datatypes.DynamicBytes)17 Address (org.fisco.bcos.web3j.abi.datatypes.Address)15 Type (org.fisco.bcos.web3j.abi.datatypes.Type)13 Bytes32 (org.fisco.bcos.web3j.abi.datatypes.generated.Bytes32)13 NamedType (org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition.NamedType)11 TypeReference (org.fisco.bcos.web3j.abi.TypeReference)10 DynamicArray (org.fisco.bcos.web3j.abi.datatypes.DynamicArray)7 Function (org.fisco.bcos.web3j.abi.datatypes.Function)7 ArrayList (java.util.ArrayList)6 List (java.util.List)5 Event (org.fisco.bcos.web3j.abi.datatypes.Event)5 Log (org.fisco.bcos.web3j.protocol.core.methods.response.Log)5 BigInteger (java.math.BigInteger)4 AbiDefinition (org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition)4 Bytes10 (org.fisco.bcos.web3j.abi.datatypes.generated.Bytes10)3