use of com.esaulpaugh.headlong.abi.Tuple in project hedera-services by hashgraph.
the class DecodingFacade method decodeTransferNFT.
public List<TokenTransferWrapper> decodeTransferNFT(final Bytes input, final UnaryOperator<byte[]> aliasResolver) {
final Tuple decodedArguments = decodeFunctionCall(input, TRANSFER_NFT_SELECTOR, TRANSFER_NFT_DECODER);
final var tokenID = convertAddressBytesToTokenID((byte[]) decodedArguments.get(0));
final var sender = convertLeftPaddedAddressToAccountId((byte[]) decodedArguments.get(1), aliasResolver);
final var receiver = convertLeftPaddedAddressToAccountId((byte[]) decodedArguments.get(2), aliasResolver);
final var serialNumber = (long) decodedArguments.get(3);
return Collections.singletonList(new TokenTransferWrapper(List.of(new SyntheticTxnFactory.NftExchange(serialNumber, tokenID, sender, receiver)), NO_FUNGIBLE_TRANSFERS));
}
use of com.esaulpaugh.headlong.abi.Tuple in project hedera-services by hashgraph.
the class DecodingFacade method decodeTransferNFTs.
public List<TokenTransferWrapper> decodeTransferNFTs(final Bytes input, final UnaryOperator<byte[]> aliasResolver) {
final Tuple decodedArguments = decodeFunctionCall(input, TRANSFER_NFTS_SELECTOR, TRANSFER_NFTS_DECODER);
final var tokenID = convertAddressBytesToTokenID((byte[]) decodedArguments.get(0));
final var senders = decodeAccountIds((byte[][]) decodedArguments.get(1), aliasResolver);
final var receivers = decodeAccountIds((byte[][]) decodedArguments.get(2), aliasResolver);
final var serialNumbers = ((long[]) decodedArguments.get(3));
final List<SyntheticTxnFactory.NftExchange> nftExchanges = new ArrayList<>();
for (var i = 0; i < senders.size(); i++) {
final var nftExchange = new SyntheticTxnFactory.NftExchange(serialNumbers[i], tokenID, senders.get(i), receivers.get(i));
nftExchanges.add(nftExchange);
}
return Collections.singletonList(new TokenTransferWrapper(nftExchanges, NO_FUNGIBLE_TRANSFERS));
}
use of com.esaulpaugh.headlong.abi.Tuple 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);
}
use of com.esaulpaugh.headlong.abi.Tuple in project headlong-cli by esaulpaugh.
the class DesugarTest method testVector.
@Test
public void testVector() {
String[] command = new String[] { "-ef", "sam(bytes,bool,uint256[])", "(u'dave', b'true', [ d'1', d'2', d'3' ])" };
String out = Main.eval(command);
assertEquals("a5643bf2" + "0000000000000000000000000000000000000000000000000000000000000060" + "0000000000000000000000000000000000000000000000000000000000000001" + "00000000000000000000000000000000000000000000000000000000000000a0" + "0000000000000000000000000000000000000000000000000000000000000004" + "6461766500000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000003" + "0000000000000000000000000000000000000000000000000000000000000001" + "0000000000000000000000000000000000000000000000000000000000000002" + "0000000000000000000000000000000000000000000000000000000000000003", out);
Tuple tuple = Function.parse("sam(bytes,bool,uint256[])").decodeCall(FastHex.decode(out));
System.out.println(tuple);
assertEquals(Tuple.of("dave".getBytes(StandardCharsets.UTF_8), true, new BigInteger[] { BigInteger.ONE, BigInteger.valueOf(2L), BigInteger.valueOf(3L) }), tuple);
}
use of com.esaulpaugh.headlong.abi.Tuple 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);
}
Aggregations