use of org.fisco.bcos.web3j.abi.datatypes.generated.Uint256 in project web3sdk by FISCO-BCOS.
the class FunctionReturnDecoderTest method testMixTypeDecode6.
@Test
public void testMixTypeDecode6() {
// function function() constant returns(uint256[][3])
Function function = new Function("function", Collections.<Type>emptyList(), Arrays.asList(new TypeReference<StaticArray3<DynamicArray<Uint256>>>() {
}));
assertThat(FunctionReturnDecoder.decode("000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000" + "000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000" + "0000000000a0000000000000000000000000000000000000000000000000000000000000010000000000000000" + "000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000" + "000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200" + "000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000" + "000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000" + "000000000300000000000000000000000000000000000000000000000000000000000000040000000000000000" + "000000000000000000000000000000000000000000000005000000000000000000000000000000000000000000" + "0000000000000000000006", function.getOutputParameters()), equalTo(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))))));
}
use of org.fisco.bcos.web3j.abi.datatypes.generated.Uint256 in project web3sdk by FISCO-BCOS.
the class FunctionReturnDecoderTest method testMixTypeDecode8.
@Test
public void testMixTypeDecode8() {
// function function(uint256[][3])
Function function = new Function("function", Collections.<Type>emptyList(), Arrays.asList(new TypeReference<Uint256>() {
}, new TypeReference<Int256>() {
}, new TypeReference<Utf8String>() {
}, new TypeReference<DynamicArray<Utf8String>>() {
}, new TypeReference<StaticArray3<Utf8String>>() {
}));
assertThat(FunctionReturnDecoder.decode("0000000000000000000000000000000000000000000000000000000000000064ffffffffffffffffffffffffff" + "ffffffffffffffffffffffffffffffffffff9c0000000000000000000000000000000000000000000000000000" + "0000000000a000000000000000000000000000000000000000000000000000000000000000e000000000000000" + "000000000000000000000000000000000000000000000002200000000000000000000000000000000000000000" + "000000000000000000000003616263000000000000000000000000000000000000000000000000000000000000" + "000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000" + "000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000" + "00000000a000000000000000000000000000000000000000000000000000000000000000e00000000000000000" + "000000000000000000000000000000000000000000000003616263000000000000000000000000000000000000" + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000036162" + "630000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + "000000000000000000000000000000000361626300000000000000000000000000000000000000000000000000" + "000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000" + "00000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000" + "000000000000000000e00000000000000000000000000000000000000000000000000000000000000003616263" + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + "000000000000000000000000000000036162630000000000000000000000000000000000000000000000000000" + "000000000000000000000000000000000000000000000000000000000000000000000361626300000000000000" + "00000000000000000000000000000000000000000000", function.getOutputParameters()), equalTo(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")))));
}
use of org.fisco.bcos.web3j.abi.datatypes.generated.Uint256 in project web3sdk by FISCO-BCOS.
the class FunctionReturnDecoderTest method testMixTypeDecode4.
@Test
public void testMixTypeDecode4() {
// function function(string,address,uint256,int256) constant
// returns(string,address,uint256,int256)
Function function = new Function("function", Collections.<Type>emptyList(), Arrays.asList(new TypeReference<Utf8String>() {
}, new TypeReference<Address>() {
}, new TypeReference<Uint256>() {
}, new TypeReference<Int256>() {
}));
assertThat(FunctionReturnDecoder.decode("00000000000000000000000000000000000000000000000000000000000000800000000" + "0000000000000000035ef07393b57464e93deb59175ff72e6499450cf000000000000000000000000" + "0000000000000000000000000000000000002b67fffffffffffffffffffffffffffffffffffffffff" + "fffffffffffffffffffd4990000000000000000000000000000000000000000000000000000000000" + "0000126161616661647366736661647366646173660000000000000000000000000000", function.getOutputParameters()), equalTo(Arrays.asList(new Utf8String("aaafadsfsfadsfdasf"), new Address("0x35ef07393b57464e93deb59175ff72e6499450cf"), new Uint256(11111), new Int256(-11111))));
}
use of org.fisco.bcos.web3j.abi.datatypes.generated.Uint256 in project web3sdk by FISCO-BCOS.
the class ABICodecJsonWrapper method encodeNode.
private ABIObject encodeNode(String path, ABIObject template, JsonNode node) {
ABIObject abiObject = template.newObject();
switch(abiObject.getType()) {
case VALUE:
{
if (!node.isValueNode()) {
errorReport(path, abiObject.getType().toString(), node.getNodeType().toString());
}
switch(template.getValueType()) {
case BOOL:
{
if (!node.isBoolean()) {
errorReport(path, template.getValueType().toString(), node.getNodeType().toString());
}
abiObject.setBoolValue(new Bool(node.asBoolean()));
break;
}
case INT:
{
if (!node.isNumber() && !node.isBigInteger()) {
errorReport(path, template.getValueType().toString(), node.getNodeType().toString());
}
if (node.isNumber()) {
abiObject.setNumericValue(new Int256(node.asLong()));
} else {
abiObject.setNumericValue(new Int256(node.bigIntegerValue()));
}
break;
}
case UINT:
{
if (!node.isNumber() && !node.isBigInteger()) {
errorReport(path, template.getValueType().toString(), node.getNodeType().toString());
}
if (node.isNumber()) {
abiObject.setNumericValue(new Uint256(node.asLong()));
} else {
abiObject.setNumericValue(new Uint256(node.bigIntegerValue()));
}
break;
}
case ADDRESS:
{
if (!node.isTextual()) {
errorReport(path, template.getValueType().toString(), node.getNodeType().toString());
}
try {
abiObject.setAddressValue(new Address(node.asText()));
} catch (Exception e) {
errorReport(path, "Invalid address, address value: " + node.asText());
}
break;
}
case BYTES:
{
if (!node.isTextual()) {
errorReport(path, template.getValueType().toString(), node.getNodeType().toString());
}
// Binary data requires base64 encoding
byte[] bytesValue = Base64.getDecoder().decode(node.asText());
abiObject.setBytesValue(new Bytes(bytesValue.length, bytesValue));
break;
}
case DBYTES:
{
if (!node.isTextual()) {
errorReport(path, template.getValueType().toString(), node.getNodeType().toString());
}
byte[] bytesValue = Base64.getDecoder().decode(node.asText());
abiObject.setDynamicBytesValue(new DynamicBytes(bytesValue));
break;
}
case STRING:
{
if (!node.isTextual()) {
errorReport(path, template.getValueType().toString(), node.getNodeType().toString());
}
abiObject.setStringValue(new Utf8String(node.asText()));
break;
}
}
break;
}
case LIST:
{
if (!node.isArray()) {
errorReport(path, abiObject.getType().toString(), node.getNodeType().toString());
}
if ((abiObject.getListType() == ListType.FIXED) && (node.size() != abiObject.getListLength())) {
errorReport("fixed list arguments size", String.valueOf(abiObject.getListLength()), String.valueOf(node.size()));
}
int i = 0;
Iterator<JsonNode> iterator = node.iterator();
while (iterator.hasNext()) {
abiObject.getListValues().add(encodeNode(path + ".<" + String.valueOf(i) + ">", abiObject.getListValueType(), iterator.next()));
}
break;
}
case STRUCT:
{
if (!node.isArray() && !node.isObject()) {
errorReport(path, abiObject.getType().toString(), node.getNodeType().toString());
}
if (node.size() != abiObject.getStructFields().size()) {
errorReport("struct arguments size", String.valueOf(abiObject.getListLength()), String.valueOf(node.size()));
}
if (node.isArray()) {
for (int i = 0; i < abiObject.getStructFields().size(); i++) {
ABIObject field = abiObject.getStructFields().get(i);
abiObject.getStructFields().set(i, encodeNode(path + "." + field.getName(), field, node.get(i)));
}
} else {
for (int i = 0; i < abiObject.getStructFields().size(); ++i) {
ABIObject field = abiObject.getStructFields().get(i);
JsonNode structNode = node.get(field.getName());
if (structNode == null) {
errorReport(path, " Missing struct field, field name: " + field.getName());
}
abiObject.getStructFields().set(i, encodeNode(path + "." + field.getName(), field, structNode));
}
}
break;
}
}
return abiObject;
}
use of org.fisco.bcos.web3j.abi.datatypes.generated.Uint256 in project web3sdk by FISCO-BCOS.
the class TransactionDecoderTest method testDynamicParams1.
@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));
}
Aggregations