Search in sources :

Example 11 with AccountAmount

use of com.hederahashgraph.api.proto.java.AccountAmount in project hedera-services by hashgraph.

the class RequestBuilder method getCryptoTransferRequest.

public static Transaction getCryptoTransferRequest(Long payerAccountNum, Long payerRealmNum, Long payerShardNum, Long nodeAccountNum, Long nodeRealmNum, Long nodeShardNum, long transactionFee, Timestamp timestamp, Duration transactionDuration, boolean generateRecord, String memo, Long senderActNum, Long amountSend, Long receiverAcctNum, Long amountReceived) {
    AccountAmount a1 = AccountAmount.newBuilder().setAccountID(getAccountIdBuild(senderActNum, 0l, 0l)).setAmount(amountSend).build();
    AccountAmount a2 = AccountAmount.newBuilder().setAccountID(getAccountIdBuild(receiverAcctNum, 0l, 0l)).setAmount(amountReceived).build();
    TransferList transferList = TransferList.newBuilder().addAccountAmounts(a1).addAccountAmounts(a2).build();
    return getCryptoTransferRequest(payerAccountNum, payerRealmNum, payerShardNum, nodeAccountNum, nodeRealmNum, nodeShardNum, transactionFee, timestamp, transactionDuration, generateRecord, memo, transferList);
}
Also used : TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) TransferList(com.hederahashgraph.api.proto.java.TransferList) AccountAmount(com.hederahashgraph.api.proto.java.AccountAmount)

Example 12 with AccountAmount

use of com.hederahashgraph.api.proto.java.AccountAmount in project hedera-services by hashgraph.

the class SigRequirements method cryptoTransfer.

private <T> SigningOrderResult<T> cryptoTransfer(final AccountID payer, final CryptoTransferTransactionBody op, final SigningOrderResultFactory<T> factory, @Nullable final LinkedRefs linkedRefs) {
    List<JKey> required = new ArrayList<>();
    KeyOrderingFailure failure;
    for (TokenTransferList xfers : op.getTokenTransfersList()) {
        for (AccountAmount adjust : xfers.getTransfersList()) {
            if ((failure = includeIfNecessary(payer, adjust, required, false, linkedRefs)) != NONE) {
                return accountFailure(failure, factory);
            }
        }
        final var token = xfers.getToken();
        for (NftTransfer adjust : xfers.getNftTransfersList()) {
            final var sender = adjust.getSenderAccountID();
            if ((failure = nftIncludeIfNecessary(payer, sender, null, adjust.getIsApproval(), required, token, op, linkedRefs)) != NONE) {
                return accountFailure(failure, factory);
            }
            final var receiver = adjust.getReceiverAccountID();
            if ((failure = nftIncludeIfNecessary(payer, receiver, sender, false, required, token, op, linkedRefs)) != NONE) {
                return (failure == MISSING_TOKEN) ? factory.forMissingToken() : accountFailure(failure, factory);
            }
        }
    }
    for (AccountAmount adjust : op.getTransfers().getAccountAmountsList()) {
        if ((failure = includeIfNecessary(payer, adjust, required, true, linkedRefs)) != NONE) {
            return accountFailure(failure, factory);
        }
    }
    return factory.forValidOrder(required);
}
Also used : TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) NftTransfer(com.hederahashgraph.api.proto.java.NftTransfer) JKey(com.hedera.services.legacy.core.jproto.JKey) ArrayList(java.util.ArrayList) AccountAmount(com.hederahashgraph.api.proto.java.AccountAmount)

Example 13 with AccountAmount

use of com.hederahashgraph.api.proto.java.AccountAmount in project hedera-services by hashgraph.

the class AliasResolver method resolveInternalFungible.

private Result resolveInternalFungible(final AliasManager aliasManager, final AccountAmount adjust, final Consumer<AccountAmount> resolvingAction) {
    AccountAmount resolvedAdjust = adjust;
    var isEvmAddress = false;
    var result = Result.KNOWN_ALIAS;
    if (isAlias(adjust.getAccountID())) {
        final var alias = adjust.getAccountID().getAlias();
        if (alias.size() == EntityIdUtils.EVM_ADDRESS_SIZE) {
            final var evmAddress = alias.toByteArray();
            if (aliasManager.isMirror(evmAddress)) {
                offerMirrorId(evmAddress, id -> resolvingAction.accept(adjust.toBuilder().setAccountID(id).build()));
                return Result.KNOWN_ALIAS;
            } else {
                isEvmAddress = true;
            }
        }
        final var resolution = aliasManager.lookupIdBy(alias);
        if (resolution == MISSING_NUM) {
            result = netOf(isEvmAddress, alias);
        } else {
            resolvedAdjust = adjust.toBuilder().setAccountID(resolution.toGrpcAccountId()).build();
        }
        resolutions.put(alias, resolution);
    }
    resolvingAction.accept(resolvedAdjust);
    return result;
}
Also used : AccountAmount(com.hederahashgraph.api.proto.java.AccountAmount)

Example 14 with AccountAmount

use of com.hederahashgraph.api.proto.java.AccountAmount in project hedera-services by hashgraph.

the class HapiCryptoTransfer method aggregateOnTokenIds.

private Map<TokenID, Pair<Integer, List<AccountAmount>>> aggregateOnTokenIds(final HapiApiSpec spec) {
    Map<TokenID, Pair<Integer, List<AccountAmount>>> map = new HashMap<>();
    for (TokenMovement tm : tokenAwareProviders) {
        if (tm.isFungibleToken()) {
            var list = tm.specializedFor(spec);
            if (map.containsKey(list.getToken())) {
                var existingVal = map.get(list.getToken());
                List<AccountAmount> newList = Stream.of(existingVal.getRight(), list.getTransfersList()).flatMap(Collection::stream).collect(Collectors.toList());
                map.put(list.getToken(), Pair.of(existingVal.getLeft(), newList));
            } else {
                map.put(list.getToken(), Pair.of(list.getExpectedDecimals().getValue(), list.getTransfersList()));
            }
        }
    }
    return map;
}
Also used : TokenMovement(com.hedera.services.bdd.spec.transactions.token.TokenMovement) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TokenID(com.hederahashgraph.api.proto.java.TokenID) Pair(org.apache.commons.lang3.tuple.Pair) AccountAmount(com.hederahashgraph.api.proto.java.AccountAmount)

Example 15 with AccountAmount

use of com.hederahashgraph.api.proto.java.AccountAmount in project hedera-services by hashgraph.

the class TokenAssociationSpecs method dissociationFromExpiredTokensAsExpected.

public HapiApiSpec dissociationFromExpiredTokensAsExpected() {
    final String treasury = "accountA";
    final String frozenAccount = "frozen";
    final String unfrozenAccount = "unfrozen";
    final String expiringToken = "expiringToken";
    long lifetimeSecs = 10;
    AtomicLong now = new AtomicLong();
    return defaultHapiSpec("DissociationFromExpiredTokensAsExpected").given(newKeyNamed("freezeKey"), cryptoCreate(treasury), cryptoCreate(frozenAccount).via("creation"), cryptoCreate(unfrozenAccount).via("creation"), withOpContext((spec, opLog) -> {
        var subOp = getTxnRecord("creation");
        allRunFor(spec, subOp);
        var record = subOp.getResponseRecord();
        now.set(record.getConsensusTimestamp().getSeconds());
    }), sourcing(() -> tokenCreate(expiringToken).freezeKey("freezeKey").freezeDefault(true).treasury(treasury).initialSupply(1000L).expiry(now.get() + lifetimeSecs))).when(tokenAssociate(unfrozenAccount, expiringToken), tokenAssociate(frozenAccount, expiringToken), tokenUnfreeze(expiringToken, unfrozenAccount), cryptoTransfer(moving(100L, expiringToken).between(treasury, unfrozenAccount))).then(getAccountBalance(treasury).hasTokenBalance(expiringToken, 900L), sleepFor(lifetimeSecs * 1_000L), tokenDissociate(treasury, expiringToken).hasKnownStatus(ACCOUNT_IS_TREASURY), tokenDissociate(unfrozenAccount, expiringToken).via("dissociateTxn"), getTxnRecord("dissociateTxn").hasPriority(recordWith().tokenTransfers(new BaseErroringAssertsProvider<>() {

        @Override
        public ErroringAsserts<List<TokenTransferList>> assertsFor(HapiApiSpec spec) {
            return tokenXfers -> {
                try {
                    assertEquals(1, tokenXfers.size(), "Wrong number of tokens transferred!");
                    TokenTransferList xfers = tokenXfers.get(0);
                    assertEquals(spec.registry().getTokenID(expiringToken), xfers.getToken(), "Wrong token transferred!");
                    AccountAmount toTreasury = xfers.getTransfers(0);
                    assertEquals(spec.registry().getAccountID(treasury), toTreasury.getAccountID(), "Treasury should come first!");
                    assertEquals(100L, toTreasury.getAmount(), "Treasury should get 100 tokens back!");
                    AccountAmount fromAccount = xfers.getTransfers(1);
                    assertEquals(spec.registry().getAccountID(unfrozenAccount), fromAccount.getAccountID(), "Account should come second!");
                    assertEquals(-100L, fromAccount.getAmount(), "Account should send 100 tokens back!");
                } catch (Throwable error) {
                    return List.of(error);
                }
                return Collections.emptyList();
            };
        }
    })), getAccountBalance(treasury).hasTokenBalance(expiringToken, 1000L), getAccountInfo(frozenAccount).hasToken(relationshipWith(expiringToken).freeze(Frozen)), tokenDissociate(frozenAccount, expiringToken).hasKnownStatus(ACCOUNT_FROZEN_FOR_TOKEN));
}
Also used : TxnVerbs.cryptoCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate) UtilVerbs.sourcing(com.hedera.services.bdd.spec.utilops.UtilVerbs.sourcing) TRANSACTION_REQUIRES_ZERO_TOKEN_BALANCES(com.hederahashgraph.api.proto.java.ResponseCodeEnum.TRANSACTION_REQUIRES_ZERO_TOKEN_BALANCES) TxnVerbs.cryptoTransfer(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer) TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) QueryVerbs.getContractInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getContractInfo) TxnVerbs.tokenDelete(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenDelete) QueryVerbs.getTxnRecord(com.hedera.services.bdd.spec.queries.QueryVerbs.getTxnRecord) UtilVerbs.sleepFor(com.hedera.services.bdd.spec.utilops.UtilVerbs.sleepFor) QueryVerbs.getAccountInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountInfo) ACCOUNT_IS_TREASURY(com.hederahashgraph.api.proto.java.ResponseCodeEnum.ACCOUNT_IS_TREASURY) ExpectedTokenRel.relationshipWith(com.hedera.services.bdd.spec.queries.crypto.ExpectedTokenRel.relationshipWith) HapiApiSpec.defaultHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec) Frozen(com.hederahashgraph.api.proto.java.TokenFreezeStatus.Frozen) SomeFungibleTransfers.changingFungibleBalances(com.hedera.services.bdd.spec.assertions.SomeFungibleTransfers.changingFungibleBalances) UtilVerbs.newKeyNamed(com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyNamed) TransactionRecordAsserts.recordWith(com.hedera.services.bdd.spec.assertions.TransactionRecordAsserts.recordWith) TOKEN_NOT_ASSOCIATED_TO_ACCOUNT(com.hederahashgraph.api.proto.java.ResponseCodeEnum.TOKEN_NOT_ASSOCIATED_TO_ACCOUNT) TokenMovement(com.hedera.services.bdd.spec.transactions.token.TokenMovement) StandardCharsets(java.nio.charset.StandardCharsets) NoTokenTransfers.emptyTokenTransfers(com.hedera.services.bdd.spec.assertions.NoTokenTransfers.emptyTokenTransfers) ByteString(com.google.protobuf.ByteString) BaseErroringAssertsProvider(com.hedera.services.bdd.spec.assertions.BaseErroringAssertsProvider) AccountAmount(com.hederahashgraph.api.proto.java.AccountAmount) List(java.util.List) Logger(org.apache.logging.log4j.Logger) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation) TxnVerbs.tokenDissociate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenDissociate) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) TxnVerbs.tokenAssociate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenAssociate) KycNotApplicable(com.hederahashgraph.api.proto.java.TokenKycStatus.KycNotApplicable) UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) Granted(com.hederahashgraph.api.proto.java.TokenKycStatus.Granted) ErroringAsserts(com.hedera.services.bdd.spec.assertions.ErroringAsserts) Unfrozen(com.hederahashgraph.api.proto.java.TokenFreezeStatus.Unfrozen) INVALID_SIGNATURE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_SIGNATURE) ContractResources(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources) TokenMovement.moving(com.hedera.services.bdd.spec.transactions.token.TokenMovement.moving) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) FreezeNotApplicable(com.hederahashgraph.api.proto.java.TokenFreezeStatus.FreezeNotApplicable) TxnVerbs.mintToken(com.hedera.services.bdd.spec.transactions.TxnVerbs.mintToken) TxnVerbs.tokenCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenCreate) ACCOUNT_FROZEN_FOR_TOKEN(com.hederahashgraph.api.proto.java.ResponseCodeEnum.ACCOUNT_FROZEN_FOR_TOKEN) TxnVerbs.tokenFreeze(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenFreeze) INVALID_TOKEN_ID(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_TOKEN_ID) QueryVerbs.getAccountBalance(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountBalance) CustomSpecAssert.allRunFor(com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor) TokenType(com.hederahashgraph.api.proto.java.TokenType) AtomicLong(java.util.concurrent.atomic.AtomicLong) TxnVerbs.fileCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate) TxnVerbs.contractCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCreate) LogManager(org.apache.logging.log4j.LogManager) Collections(java.util.Collections) TxnVerbs.tokenUnfreeze(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenUnfreeze) TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) AtomicLong(java.util.concurrent.atomic.AtomicLong) ErroringAsserts(com.hedera.services.bdd.spec.assertions.ErroringAsserts) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) ByteString(com.google.protobuf.ByteString) AccountAmount(com.hederahashgraph.api.proto.java.AccountAmount)

Aggregations

AccountAmount (com.hederahashgraph.api.proto.java.AccountAmount)18 TransferList (com.hederahashgraph.api.proto.java.TransferList)5 ByteString (com.google.protobuf.ByteString)4 EntityId (com.hedera.mirror.common.domain.entity.EntityId)4 TokenTransferList (com.hederahashgraph.api.proto.java.TokenTransferList)4 CryptoTransfer (com.hedera.mirror.common.domain.transaction.CryptoTransfer)3 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)2 TokenMovement (com.hedera.services.bdd.spec.transactions.token.TokenMovement)2 AccountID (com.hederahashgraph.api.proto.java.AccountID)2 ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)2 SignedTransaction (com.hederahashgraph.api.proto.java.SignedTransaction)2 TokenID (com.hederahashgraph.api.proto.java.TokenID)2 Transaction (com.hederahashgraph.api.proto.java.Transaction)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Test (org.junit.jupiter.api.Test)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 BoolValue (com.google.protobuf.BoolValue)1 Int32Value (com.google.protobuf.Int32Value)1