Search in sources :

Example 16 with Tuple

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));
}
Also used : Tuple(com.esaulpaugh.headlong.abi.Tuple)

Example 17 with Tuple

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));
}
Also used : ArrayList(java.util.ArrayList) Tuple(com.esaulpaugh.headlong.abi.Tuple)

Example 18 with Tuple

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);
}
Also used : Function(com.esaulpaugh.headlong.abi.Function) TupleType(com.esaulpaugh.headlong.abi.TupleType) Tuple(com.esaulpaugh.headlong.abi.Tuple)

Example 19 with Tuple

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);
}
Also used : BigInteger(java.math.BigInteger) Tuple(com.esaulpaugh.headlong.abi.Tuple) Test(org.junit.jupiter.api.Test)

Example 20 with 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);
}
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

Tuple (com.esaulpaugh.headlong.abi.Tuple)23 ArrayList (java.util.ArrayList)6 BigInteger (java.math.BigInteger)5 TupleType (com.esaulpaugh.headlong.abi.TupleType)4 Test (org.junit.jupiter.api.Test)4 Function (com.esaulpaugh.headlong.abi.Function)2 ByteString (com.google.protobuf.ByteString)2 Address (com.esaulpaugh.headlong.abi.Address)1 BooleanType (com.esaulpaugh.headlong.abi.BooleanType)1 IntType (com.esaulpaugh.headlong.abi.IntType)1 DeserializationFeature (com.fasterxml.jackson.databind.DeserializationFeature)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 MoreObjects (com.google.common.base.MoreObjects)1 HapiApiSpec (com.hedera.services.bdd.spec.HapiApiSpec)1 ActionableContractCall (com.hedera.services.bdd.spec.infrastructure.meta.ActionableContractCall)1 TrieSigMapGenerator.uniqueWithFullPrefixesFor (com.hedera.services.bdd.spec.keys.TrieSigMapGenerator.uniqueWithFullPrefixesFor)1 QueryVerbs.getTxnRecord (com.hedera.services.bdd.spec.queries.QueryVerbs.getTxnRecord)1 HapiTxnOp (com.hedera.services.bdd.spec.transactions.HapiTxnOp)1 TxnUtils (com.hedera.services.bdd.spec.transactions.TxnUtils)1 TxnUtils.extractTxnId (com.hedera.services.bdd.spec.transactions.TxnUtils.extractTxnId)1