use of org.fisco.bcos.web3j.abi.datatypes.generated.Uint256 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;
}
use of org.fisco.bcos.web3j.abi.datatypes.generated.Uint256 in project web3sdk by FISCO-BCOS.
the class FunctionEncoderTest method testMixTypeEncode2.
@Test
public void testMixTypeEncode2() {
Function function = new Function("set0", Arrays.asList(new Utf8String("dave"), new Bool(true), new DynamicArray<>(new Uint256(1), new Uint256(2), new Uint256(3))), Collections.singletonList(new TypeReference<DynamicArray<Utf8String>>() {
}));
assertThat(FunctionEncoder.encodeParameters(function.getInputParameters(), new StringBuilder()), is("0000000000000000000000000000000000000000000000000000000000000060" + "0000000000000000000000000000000000000000000000000000000000000001" + "00000000000000000000000000000000000000000000000000000000000000a0" + "0000000000000000000000000000000000000000000000000000000000000004" + "6461766500000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000003" + "0000000000000000000000000000000000000000000000000000000000000001" + "0000000000000000000000000000000000000000000000000000000000000002" + "0000000000000000000000000000000000000000000000000000000000000003"));
}
use of org.fisco.bcos.web3j.abi.datatypes.generated.Uint256 in project web3sdk by FISCO-BCOS.
the class FunctionEncoderTest method testMixTypeEncode5.
@Test
public void testMixTypeEncode5() {
// function
// set0(uint256,address,string,uint256[],uint256[3],string[],string[3],uint256[][],uint256[3][])
Function function = new Function("set0", 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)))), Collections.singletonList(new TypeReference<DynamicArray<Utf8String>>() {
}));
assertThat(FunctionEncoder.encodeParameters(function.getInputParameters(), new StringBuilder()), is("000000000000000000000000000000000000000000000000000000000000007b00000000000000000000000069" + "2a70d2e424a56d2c6c27aa97d1a86395877b3a0000000000000000000000000000000000000000000000000000" + "00000000016000000000000000000000000000000000000000000000000000000000000001a000000000000000" + "000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000" + "000000000000000000000005000000000000000000000000000000000000000000000000000000000000000600" + "000000000000000000000000000000000000000000000000000000000002200000000000000000000000000000" + "000000000000000000000000000000000360000000000000000000000000000000000000000000000000000000" + "000000048000000000000000000000000000000000000000000000000000000000000006800000000000000000" + "000000000000000000000000000000000000000000000008737472696e67206300000000000000000000000000" + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000030000" + "000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000" + "000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000" + "000000030000000000000000000000000000000000000000000000000000000000000003000000000000000000" + "000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000" + "000000000000000000a000000000000000000000000000000000000000000000000000000000000000e0000000" + "000000000000000000000000000000000000000000000000000000000361626300000000000000000000000000" + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + "000003646566000000000000000000000000000000000000000000000000000000000000000000000000000000" + "000000000000000000000000000000000000000000036768690000000000000000000000000000000000000000" + "000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000" + "000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000" + "0000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000" + "000361626300000000000000000000000000000000000000000000000000000000000000000000000000000000" + "000000000000000000000000000000000000000003646566000000000000000000000000000000000000000000" + "000000000000000000000000000000000000000000000000000000000000000000000000000000036768690000" + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + "000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000" + "6000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000" + "000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000" + "000000000000030000000000000000000000000000000000000000000000000000000000000001000000000000" + "000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000" + "000000000000000000000000010000000000000000000000000000000000000000000000000000000000000003" + "000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000" + "000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000" + "000000000002000000000000000000000000000000000000000000000000000000000000000300000000000000" + "000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000" + "000000000000000000000003000000000000000000000000000000000000000000000000000000000000000300" + "000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000" + "000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000" + "000000000400000000000000000000000000000000000000000000000000000000000000040000000000000000" + "000000000000000000000000000000000000000000000005000000000000000000000000000000000000000000" + "00000000000000000000050000000000000000000000000000000000000000000000000000000000000005"));
}
use of org.fisco.bcos.web3j.abi.datatypes.generated.Uint256 in project web3sdk by FISCO-BCOS.
the class FunctionEncoderTest method testMixTypeEncode3.
@Test
public void testMixTypeEncode3() {
// function set0(string,uint256,uint256[6],uint256[],bool,address)
Function function = new Function("set0", 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")), Collections.singletonList(new TypeReference<DynamicArray<Utf8String>>() {
}));
assertThat(FunctionEncoder.encodeParameters(function.getInputParameters(), new StringBuilder()), is("00000000000000000000000000000000000000000000000000000000000001600000000000000000" + "00000000000000000000000000000000000000000000045700000000000000000000000000000000" + "00000000000000000000000000000001000000000000000000000000000000000000000000000000" + "00000000000000020000000000000000000000000000000000000000000000000000000000000003" + "00000000000000000000000000000000000000000000000000000000000000040000000000000000" + "00000000000000000000000000000000000000000000000500000000000000000000000000000000" + "00000000000000000000000000000006000000000000000000000000000000000000000000000000" + "00000000000001a00000000000000000000000000000000000000000000000000000000000000000" + "000000000000000000000000692a70d2e424a56d2c6c27aa97d1a86395877b3a0000000000000000" + "00000000000000000000000000000000000000000000000f6461736c666a616b6c666461736b6c00" + "00000000000000000000000000000000000000000000000000000000000000000000000000000000" + "00000000000000060000000000000000000000000000000000000000000000000000000000000001" + "00000000000000000000000000000000000000000000000000000000000000020000000000000000" + "00000000000000000000000000000000000000000000000300000000000000000000000000000000" + "00000000000000000000000000000004000000000000000000000000000000000000000000000000" + "00000000000000050000000000000000000000000000000000000000000000000000000000000006"));
}
use of org.fisco.bcos.web3j.abi.datatypes.generated.Uint256 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"));
}
Aggregations