Search in sources :

Example 6 with Tuple

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

the class DecodingFacade method decodeERCTransferFrom.

public List<TokenTransferWrapper> decodeERCTransferFrom(final Bytes input, final TokenID token, final boolean isFungible, final UnaryOperator<byte[]> aliasResolver) {
    final Tuple decodedArguments = decodeFunctionCall(input, ERC_TRANSFER_FROM_SELECTOR, ERC_TRANSFER_FROM_DECODER);
    final var from = convertLeftPaddedAddressToAccountId((byte[]) decodedArguments.get(0), aliasResolver);
    final var to = convertLeftPaddedAddressToAccountId((byte[]) decodedArguments.get(1), aliasResolver);
    if (isFungible) {
        final List<SyntheticTxnFactory.FungibleTokenTransfer> fungibleTransfers = new ArrayList<>();
        final var amount = (BigInteger) decodedArguments.get(2);
        addAdjustmentAsTransfer(fungibleTransfers, token, to, amount.longValue());
        addAdjustmentAsTransfer(fungibleTransfers, token, from, -amount.longValue());
        return Collections.singletonList(new TokenTransferWrapper(NO_NFT_EXCHANGES, fungibleTransfers));
    } else {
        final List<SyntheticTxnFactory.NftExchange> nonFungibleTransfers = new ArrayList<>();
        final var serialNumber = (BigInteger) decodedArguments.get(2);
        nonFungibleTransfers.add(new SyntheticTxnFactory.NftExchange(serialNumber.longValue(), token, from, to));
        return Collections.singletonList(new TokenTransferWrapper(nonFungibleTransfers, NO_FUNGIBLE_TRANSFERS));
    }
}
Also used : ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) Tuple(com.esaulpaugh.headlong.abi.Tuple)

Example 7 with Tuple

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

the class DecodingFacade method decodeBalanceOf.

public BalanceOfWrapper decodeBalanceOf(final Bytes input, final UnaryOperator<byte[]> aliasResolver) {
    final Tuple decodedArguments = decodeFunctionCall(input, BALANCE_OF_TOKEN_SELECTOR, BALANCE_OF_TOKEN_DECODER);
    final var account = convertLeftPaddedAddressToAccountId((byte[]) decodedArguments.get(0), aliasResolver);
    return new BalanceOfWrapper(account);
}
Also used : Tuple(com.esaulpaugh.headlong.abi.Tuple)

Example 8 with Tuple

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

the class HapiContractCall method opBodyDef.

@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
    if (details.isPresent()) {
        ActionableContractCall actionable = spec.registry().getActionableCall(details.get());
        contract = actionable.getContract();
        abi = actionable.getDetails().getAbi();
        params = actionable.getDetails().getExampleArgs();
    } else if (paramsFn.isPresent()) {
        params = paramsFn.get().apply(spec);
    }
    byte[] callData;
    if (explicitHexedParams.isPresent()) {
        callData = explicitHexedParams.map(Supplier::get).map(CommonUtils::unhex).get();
    } else {
        final var paramsList = Arrays.asList(params);
        final var tupleExist = paramsList.stream().anyMatch(p -> p instanceof Tuple || p instanceof Tuple[]);
        if (tupleExist) {
            callData = encodeParametersWithTuple(params);
        } else {
            callData = (!abi.equals(FALLBACK_ABI)) ? CallTransaction.Function.fromJsonInterface(abi).encode(params) : new byte[] {};
        }
    }
    ContractCallTransactionBody opBody = spec.txns().<ContractCallTransactionBody, ContractCallTransactionBody.Builder>body(ContractCallTransactionBody.class, builder -> {
        if (!tryAsHexedAddressIfLenMatches) {
            builder.setContractID(spec.registry().getContractId(contract));
        } else {
            builder.setContractID(TxnUtils.asContractId(contract, spec));
        }
        builder.setFunctionParameters(ByteString.copyFrom(callData));
        sentTinyHbars.ifPresent(builder::setAmount);
        gas.ifPresent(builder::setGas);
    });
    return b -> b.setContractCall(opBody);
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) Arrays(java.util.Arrays) TrieSigMapGenerator.uniqueWithFullPrefixesFor(com.hedera.services.bdd.spec.keys.TrieSigMapGenerator.uniqueWithFullPrefixesFor) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) CallTransaction(org.ethereum.core.CallTransaction) Function(java.util.function.Function) Supplier(java.util.function.Supplier) DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) ArrayList(java.util.ArrayList) Tuple(com.esaulpaugh.headlong.abi.Tuple) QueryVerbs.getTxnRecord(com.hedera.services.bdd.spec.queries.QueryVerbs.getTxnRecord) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) ContractCallTransactionBody(com.hederahashgraph.api.proto.java.ContractCallTransactionBody) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) HashUtil.sha3(org.ethereum.crypto.HashUtil.sha3) GENESIS(com.hedera.services.bdd.suites.HapiApiSuite.GENESIS) TupleType(com.esaulpaugh.headlong.abi.TupleType) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) ActionableContractCall(com.hedera.services.bdd.spec.infrastructure.meta.ActionableContractCall) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MoreObjects(com.google.common.base.MoreObjects) CustomSpecAssert.allRunFor(com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor) LongConsumer(java.util.function.LongConsumer) ByteString(com.google.protobuf.ByteString) Consumer(java.util.function.Consumer) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) CommonUtils(com.swirlds.common.CommonUtils) ByteUtil(org.ethereum.util.ByteUtil) ObjLongConsumer(java.util.function.ObjLongConsumer) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) Optional(java.util.Optional) TxnUtils.extractTxnId(com.hedera.services.bdd.spec.transactions.TxnUtils.extractTxnId) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) Collections(java.util.Collections) ActionableContractCall(com.hedera.services.bdd.spec.infrastructure.meta.ActionableContractCall) CommonUtils(com.swirlds.common.CommonUtils) ContractCallTransactionBody(com.hederahashgraph.api.proto.java.ContractCallTransactionBody) Tuple(com.esaulpaugh.headlong.abi.Tuple)

Example 9 with Tuple

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

the class DecodingFacade method decodeAssociation.

public Association decodeAssociation(final Bytes input, final UnaryOperator<byte[]> aliasResolver) {
    final Tuple decodedArguments = decodeFunctionCall(input, ASSOCIATE_TOKEN_SELECTOR, ASSOCIATE_TOKEN_DECODER);
    final var accountID = convertLeftPaddedAddressToAccountId((byte[]) decodedArguments.get(0), aliasResolver);
    final var tokenID = convertAddressBytesToTokenID((byte[]) decodedArguments.get(1));
    return Association.singleAssociation(accountID, tokenID);
}
Also used : Tuple(com.esaulpaugh.headlong.abi.Tuple)

Example 10 with Tuple

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

the class DecodingFacade method decodeTokenUriNFT.

public OwnerOfAndTokenURIWrapper decodeTokenUriNFT(final Bytes input) {
    final Tuple decodedArguments = decodeFunctionCall(input, TOKEN_URI_NFT_SELECTOR, TOKEN_URI_NFT_DECODER);
    final var tokenId = (BigInteger) decodedArguments.get(0);
    return new OwnerOfAndTokenURIWrapper(tokenId.longValue());
}
Also used : BigInteger(java.math.BigInteger) 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