Search in sources :

Example 1 with Tuple

use of com.esaulpaugh.headlong.abi.Tuple in project hedera-services by hashgraph.

the class DecodingFacade method decodeTransferToken.

public List<TokenTransferWrapper> decodeTransferToken(final Bytes input, final UnaryOperator<byte[]> aliasResolver) {
    final Tuple decodedArguments = decodeFunctionCall(input, TRANSFER_TOKEN_SELECTOR, TRANSFER_TOKEN_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 amount = (long) decodedArguments.get(3);
    return Collections.singletonList(new TokenTransferWrapper(NO_NFT_EXCHANGES, List.of(new SyntheticTxnFactory.FungibleTokenTransfer(amount, tokenID, sender, receiver))));
}
Also used : Tuple(com.esaulpaugh.headlong.abi.Tuple)

Example 2 with Tuple

use of com.esaulpaugh.headlong.abi.Tuple in project hedera-services by hashgraph.

the class DecodingFacade method decodeMultipleAssociations.

public Association decodeMultipleAssociations(final Bytes input, final UnaryOperator<byte[]> aliasResolver) {
    final Tuple decodedArguments = decodeFunctionCall(input, ASSOCIATE_TOKENS_SELECTOR, ASSOCIATE_TOKENS_DECODER);
    final var accountID = convertLeftPaddedAddressToAccountId((byte[]) decodedArguments.get(0), aliasResolver);
    final var tokenIDs = decodeTokenIDsFromBytesArray((byte[][]) decodedArguments.get(1));
    return Association.multiAssociation(accountID, tokenIDs);
}
Also used : Tuple(com.esaulpaugh.headlong.abi.Tuple)

Example 3 with Tuple

use of com.esaulpaugh.headlong.abi.Tuple in project hedera-services by hashgraph.

the class DecodingFacade method decodeMultipleDissociations.

public Dissociation decodeMultipleDissociations(final Bytes input, final UnaryOperator<byte[]> aliasResolver) {
    final Tuple decodedArguments = decodeFunctionCall(input, DISSOCIATE_TOKENS_SELECTOR, DISSOCIATE_TOKENS_DECODER);
    final var accountID = convertLeftPaddedAddressToAccountId((byte[]) decodedArguments.get(0), aliasResolver);
    final var tokenIDs = decodeTokenIDsFromBytesArray((byte[][]) decodedArguments.get(1));
    return Dissociation.multiDissociation(accountID, tokenIDs);
}
Also used : Tuple(com.esaulpaugh.headlong.abi.Tuple)

Example 4 with Tuple

use of com.esaulpaugh.headlong.abi.Tuple in project hedera-services by hashgraph.

the class DecodingFacade method decodeErcTransfer.

public List<TokenTransferWrapper> decodeErcTransfer(final Bytes input, final TokenID token, final AccountID caller, final UnaryOperator<byte[]> aliasResolver) {
    final Tuple decodedArguments = decodeFunctionCall(input, ERC_TRANSFER_SELECTOR, ERC_TRANSFER_DECODER);
    final var recipient = convertLeftPaddedAddressToAccountId((byte[]) decodedArguments.get(0), aliasResolver);
    final var amount = (BigInteger) decodedArguments.get(1);
    final List<SyntheticTxnFactory.FungibleTokenTransfer> fungibleTransfers = new ArrayList<>();
    addAdjustmentAsTransfer(fungibleTransfers, token, recipient, amount.longValue());
    addAdjustmentAsTransfer(fungibleTransfers, token, caller, -amount.longValue());
    return Collections.singletonList(new TokenTransferWrapper(NO_NFT_EXCHANGES, fungibleTransfers));
}
Also used : ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) Tuple(com.esaulpaugh.headlong.abi.Tuple)

Example 5 with Tuple

use of com.esaulpaugh.headlong.abi.Tuple in project hedera-services by hashgraph.

the class DecodingFacade method decodeMint.

public MintWrapper decodeMint(final Bytes input) {
    final Tuple decodedArguments = decodeFunctionCall(input, MINT_TOKEN_SELECTOR, MINT_TOKEN_DECODER);
    final var tokenID = convertAddressBytesToTokenID((byte[]) decodedArguments.get(0));
    final var fungibleAmount = (long) decodedArguments.get(1);
    final var metadataList = (byte[][]) decodedArguments.get(2);
    final List<ByteString> metadata = Arrays.stream(metadataList).map(ByteString::copyFrom).toList();
    if (fungibleAmount > 0) {
        return MintWrapper.forFungible(tokenID, fungibleAmount);
    } else {
        return MintWrapper.forNonFungible(tokenID, metadata);
    }
}
Also used : ByteString(com.google.protobuf.ByteString) Tuple(com.esaulpaugh.headlong.abi.Tuple)

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