Search in sources :

Example 1 with TupleType

use of com.esaulpaugh.headlong.abi.TupleType in project headlong-cli by esaulpaugh.

the class Main method encodeABIPacked.

private static String encodeABIPacked(String[] args, boolean machine) {
    final String signature = args[DATA_FIRST.ordinal()];
    final String values = parseVals(args[DATA_SECOND.ordinal()], machine, true);
    final TupleType tt = TupleType.parse(signature);
    return Strings.encode(tt.encodePacked(SuperSerial.deserialize(tt, values, machine)).array());
}
Also used : TupleType(com.esaulpaugh.headlong.abi.TupleType)

Example 2 with TupleType

use of com.esaulpaugh.headlong.abi.TupleType in project headlong-cli by esaulpaugh.

the class Main method encodeABI.

private static String encodeABI(String[] args, boolean machine, boolean function) {
    final String signature = args[DATA_FIRST.ordinal()];
    final String values = parseVals(args[DATA_SECOND.ordinal()], machine, true);
    final ByteBuffer abi;
    if (function) {
        Function f = Function.parse(signature);
        abi = f.encodeCall(SuperSerial.deserialize(f.getInputs(), values, machine));
    } else {
        TupleType tt = TupleType.parse(signature);
        abi = tt.encode(SuperSerial.deserialize(tt, values, machine));
    }
    return Strings.encode(abi.array());
}
Also used : Function(com.esaulpaugh.headlong.abi.Function) TupleType(com.esaulpaugh.headlong.abi.TupleType) ByteBuffer(java.nio.ByteBuffer)

Example 3 with TupleType

use of com.esaulpaugh.headlong.abi.TupleType in project headlong-cli by esaulpaugh.

the class Main method decodeABI.

private static String decodeABI(String[] args, boolean machine, boolean function, boolean compact) {
    final String signature = args[DATA_FIRST.ordinal()];
    final byte[] abiBytes = Strings.decode(args[DATA_SECOND.ordinal()]);
    final TupleType tt;
    final Tuple values;
    if (function) {
        Function f = Function.parse(signature);
        tt = f.getInputs();
        values = f.decodeCall(abiBytes);
    } else {
        tt = TupleType.parse(signature);
        values = tt.decode(abiBytes);
    }
    return compacted(SuperSerial.serialize(tt, values, machine), compact);
}
Also used : Function(com.esaulpaugh.headlong.abi.Function) TupleType(com.esaulpaugh.headlong.abi.TupleType) Tuple(com.esaulpaugh.headlong.abi.Tuple)

Example 4 with TupleType

use of com.esaulpaugh.headlong.abi.TupleType in project headlong-cli by esaulpaugh.

the class Main method decodeABIPacked.

private static String decodeABIPacked(String[] args, boolean compact) {
    final TupleType tt = TupleType.parse(args[DATA_FIRST.ordinal()]);
    final byte[] packedAbi = Strings.decode(args[DATA_SECOND.ordinal()]);
    return compacted(SuperSerial.serialize(tt, tt.decodePacked(packedAbi), false), compact);
}
Also used : TupleType(com.esaulpaugh.headlong.abi.TupleType)

Example 5 with TupleType

use of com.esaulpaugh.headlong.abi.TupleType in project headlong-cli by esaulpaugh.

the class MainTest method testSerial.

@Test
public void testSerial() {
    TupleType tt = TupleType.parse(SIGNATURE);
    byte[] func = Strings.decode("191c766e29a65787b7155dd05f41292438467db93420cade");
    Object[] argsIn = new Object[] { new byte[][][][] { new byte[][][] { new byte[][] { func, func } } }, func, new String[][] { new String[] { "z" } }, new Address[] { Address.wrap("0xFF00eE01dd02cC03cafEBAbe9906880777086609") }, BigInteger.valueOf(Long.MAX_VALUE).multiply(BigInteger.valueOf(Byte.MAX_VALUE << 2)), new Tuple(7), new Tuple[][][] { new Tuple[][] { new Tuple[] { new Tuple(9), new Tuple(-11) } } }, new Tuple[] { new Tuple(17), new Tuple(-19) }, Long.MAX_VALUE / 8_500_000, new Tuple[] { new Tuple((long) 0x7e), new Tuple((long) -0x7e) }, new Tuple(BigInteger.TEN), true, "farout", new boolean[] { true, true }, new int[] { 3, 20, -6 }, new long[] { Integer.MAX_VALUE * 2L } };
    Tuple tuple = new Tuple(argsIn);
    String str = SuperSerial.serialize(tt, tuple, false);
    Tuple deserial = SuperSerial.deserialize(tt, str, false);
    assertEquals(tuple, deserial);
    str = SuperSerial.serialize(tt, tuple, true);
    deserial = SuperSerial.deserialize(tt, str, true);
    assertEquals(tuple, deserial);
}
Also used : Address(com.esaulpaugh.headlong.abi.Address) TupleType(com.esaulpaugh.headlong.abi.TupleType) Tuple(com.esaulpaugh.headlong.abi.Tuple) Test(org.junit.jupiter.api.Test)

Aggregations

TupleType (com.esaulpaugh.headlong.abi.TupleType)7 Tuple (com.esaulpaugh.headlong.abi.Tuple)3 Test (org.junit.jupiter.api.Test)3 Function (com.esaulpaugh.headlong.abi.Function)2 ByteBuffer (java.nio.ByteBuffer)2 Address (com.esaulpaugh.headlong.abi.Address)1 BooleanType (com.esaulpaugh.headlong.abi.BooleanType)1 IntType (com.esaulpaugh.headlong.abi.IntType)1