Search in sources :

Example 46 with AccountID

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

the class ConsensusServiceFeeBuilder method getUpdateTopicRbsIncrease.

/**
 * Computes additional rbs (services) for update topic transaction. If any of the variable sized fields change,
 * or the expiration time changes, rbs for the topic may increase
 *
 * @param txValidStartTimestamp
 *     transaction valid start timestamp
 * @param oldAdminKey
 *     old admin key
 * @param oldSubmitKey
 *     old submit key
 * @param oldMemo
 *     old memo
 * @param hasOldAutoRenewAccount
 *     boolean representing old auto renew account
 * @param oldExpirationTimeStamp
 *     old expiration timestamp
 * @param updateTopicTxBody
 *     update topic transaction body
 *
 * @return long representing rbs increase
 */
public static long getUpdateTopicRbsIncrease(final Timestamp txValidStartTimestamp, final Key oldAdminKey, final Key oldSubmitKey, final String oldMemo, final boolean hasOldAutoRenewAccount, final Timestamp oldExpirationTimeStamp, final ConsensusUpdateTopicTransactionBody updateTopicTxBody) {
    final var oldRamBytes = getTopicRamBytes(computeVariableSizedFieldsUsage(oldAdminKey, oldSubmitKey, oldMemo, hasOldAutoRenewAccount));
    // If value is null, do not update memo field
    final var newMemo = updateTopicTxBody.hasMemo() ? updateTopicTxBody.getMemo().getValue() : oldMemo;
    var hasNewAutoRenewAccount = hasOldAutoRenewAccount;
    if (updateTopicTxBody.hasAutoRenewAccount()) {
        // no change if unspecified
        hasNewAutoRenewAccount = true;
        AccountID account = updateTopicTxBody.getAutoRenewAccount();
        if (account.getAccountNum() == 0 && account.getShardNum() == 0 && account.getRealmNum() == 0) {
            // cleared if set to 0.0.0
            hasNewAutoRenewAccount = false;
        }
    }
    var newAdminKey = oldAdminKey;
    if (updateTopicTxBody.hasAdminKey()) {
        // no change if unspecified
        newAdminKey = updateTopicTxBody.getAdminKey();
        if (newAdminKey.hasKeyList() && newAdminKey.getKeyList().getKeysCount() == 0) {
            // cleared if set to empty KeyList
            newAdminKey = null;
        }
    }
    var newSubmitKey = oldSubmitKey;
    if (updateTopicTxBody.hasSubmitKey()) {
        // no change if unspecified
        newSubmitKey = updateTopicTxBody.getSubmitKey();
        if (newSubmitKey.hasKeyList() && newSubmitKey.getKeyList().getKeysCount() == 0) {
            // cleared if set to empty KeyList
            newSubmitKey = null;
        }
    }
    final var newRamBytes = getTopicRamBytes(computeVariableSizedFieldsUsage(newAdminKey, newSubmitKey, newMemo, hasNewAutoRenewAccount));
    final var newExpirationTimeStamp = updateTopicTxBody.hasExpirationTime() ? updateTopicTxBody.getExpirationTime() : oldExpirationTimeStamp;
    return calculateRbsIncrease(txValidStartTimestamp, oldRamBytes, oldExpirationTimeStamp, newRamBytes, newExpirationTimeStamp);
}
Also used : AccountID(com.hederahashgraph.api.proto.java.AccountID)

Example 47 with AccountID

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

the class GetAccountInfoAnswer method checkValidity.

@Override
public ResponseCodeEnum checkValidity(final Query query, final StateView view) {
    AccountID id = query.getCryptoGetInfo().getAccountID();
    var entityNum = id.getAlias().isEmpty() ? EntityNum.fromAccountId(id) : aliasManager.lookupIdBy(id.getAlias());
    return optionValidator.queryableAccountStatus(entityNum, view.accounts());
}
Also used : AccountID(com.hederahashgraph.api.proto.java.AccountID)

Example 48 with AccountID

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

the class HapiGetAccountBalance method getAccountBalanceQuery.

private Query getAccountBalanceQuery(HapiApiSpec spec, Transaction payment, boolean costOnly) {
    if (entityFn.isPresent()) {
        account = entityFn.get().get();
    }
    Consumer<CryptoGetAccountBalanceQuery.Builder> config;
    if (spec.registry().hasContractId(account)) {
        config = b -> b.setContractID(spec.registry().getContractId(account));
    } else {
        AccountID id;
        if (referenceType == ReferenceType.REGISTRY_NAME) {
            id = TxnUtils.asId(account, spec);
        } else {
            id = spec.registry().aliasIdFor(aliasKeySource);
        }
        config = b -> b.setAccountID(id);
        accountID = Optional.of(id);
    }
    CryptoGetAccountBalanceQuery.Builder query = CryptoGetAccountBalanceQuery.newBuilder().setHeader(costOnly ? answerCostHeader(payment) : answerHeader(payment));
    config.accept(query);
    return Query.newBuilder().setCryptogetAccountBalance(query).build();
}
Also used : AccountID(com.hederahashgraph.api.proto.java.AccountID) CryptoGetAccountBalanceQuery(com.hederahashgraph.api.proto.java.CryptoGetAccountBalanceQuery)

Example 49 with AccountID

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

the class HapiGetAccountInfo method getAccountInfoQuery.

private Query getAccountInfoQuery(HapiApiSpec spec, Transaction payment, boolean costOnly) {
    AccountID target;
    if (referenceType == ReferenceType.ALIAS_KEY_NAME) {
        target = AccountID.newBuilder().setAlias(spec.registry().getKey(aliasKeySource).toByteString()).build();
    } else {
        target = TxnUtils.asId(account, spec);
    }
    CryptoGetInfoQuery query = CryptoGetInfoQuery.newBuilder().setHeader(costOnly ? answerCostHeader(payment) : answerHeader(payment)).setAccountID(target).build();
    return Query.newBuilder().setCryptoGetInfo(query).build();
}
Also used : AccountID(com.hederahashgraph.api.proto.java.AccountID) CryptoGetInfoQuery(com.hederahashgraph.api.proto.java.CryptoGetInfoQuery)

Example 50 with AccountID

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

the class DissociatePrecompileSuite method dissociatePrecompileHasExpectedSemanticsForDeletedTokens.

/* -- Not specifically required in the HTS Precompile Test Plan -- */
public HapiApiSpec dissociatePrecompileHasExpectedSemanticsForDeletedTokens() {
    final String tbdUniqToken = "UniqToBeDeleted";
    final String zeroBalanceFrozen = "0bFrozen";
    final String zeroBalanceUnfrozen = "0bUnfrozen";
    final String nonZeroBalanceFrozen = "1bFrozen";
    final String nonZeroBalanceUnfrozen = "1bUnfrozen";
    final long initialSupply = 100L;
    final long nonZeroXfer = 10L;
    final var firstMeta = ByteString.copyFrom("FIRST".getBytes(StandardCharsets.UTF_8));
    final var secondMeta = ByteString.copyFrom("SECOND".getBytes(StandardCharsets.UTF_8));
    final var thirdMeta = ByteString.copyFrom("THIRD".getBytes(StandardCharsets.UTF_8));
    final AtomicReference<AccountID> accountID = new AtomicReference<>();
    final AtomicReference<AccountID> treasuryID = new AtomicReference<>();
    final AtomicReference<AccountID> zeroBalanceFrozenID = new AtomicReference<>();
    final AtomicReference<AccountID> zeroBalanceUnfrozenID = new AtomicReference<>();
    final AtomicReference<AccountID> nonZeroBalanceFrozenID = new AtomicReference<>();
    final AtomicReference<AccountID> nonZeroBalanceUnfrozenID = new AtomicReference<>();
    final AtomicReference<TokenID> tbdTokenID = new AtomicReference<>();
    final AtomicReference<TokenID> tbdUniqueTokenID = new AtomicReference<>();
    return defaultHapiSpec("DissociatePrecompileHasExpectedSemanticsForDeletedTokens").given(newKeyNamed(MULTI_KEY), cryptoCreate(ACCOUNT).balance(10 * ONE_HUNDRED_HBARS).exposingCreatedIdTo(accountID::set), fileCreate(THE_CONTRACT), updateLargeFile(ACCOUNT, THE_CONTRACT, extractByteCode(ContractResources.ASSOCIATE_DISSOCIATE_CONTRACT)), cryptoCreate(TOKEN_TREASURY).balance(10 * ONE_HUNDRED_HBARS).exposingCreatedIdTo(treasuryID::set), tokenCreate(TBD_TOKEN).adminKey(MULTI_KEY).supplyKey(MULTI_KEY).initialSupply(initialSupply).treasury(TOKEN_TREASURY).freezeKey(MULTI_KEY).freezeDefault(true).exposingCreatedIdTo(id -> tbdTokenID.set(asToken(id))), tokenCreate(tbdUniqToken).tokenType(TokenType.NON_FUNGIBLE_UNIQUE).treasury(TOKEN_TREASURY).adminKey(MULTI_KEY).supplyKey(MULTI_KEY).initialSupply(0).exposingCreatedIdTo(id -> tbdUniqueTokenID.set(asToken(id))), cryptoCreate(zeroBalanceFrozen).balance(10 * ONE_HUNDRED_HBARS).exposingCreatedIdTo(zeroBalanceFrozenID::set), cryptoCreate(zeroBalanceUnfrozen).balance(10 * ONE_HUNDRED_HBARS).exposingCreatedIdTo(zeroBalanceUnfrozenID::set), cryptoCreate(nonZeroBalanceFrozen).balance(10 * ONE_HUNDRED_HBARS).exposingCreatedIdTo(nonZeroBalanceFrozenID::set), cryptoCreate(nonZeroBalanceUnfrozen).balance(10 * ONE_HUNDRED_HBARS).exposingCreatedIdTo(nonZeroBalanceUnfrozenID::set)).when(withOpContext((spec, opLog) -> allRunFor(spec, contractCreate(THE_CONTRACT).bytecode(THE_CONTRACT).gas(GAS_TO_OFFER), tokenAssociate(zeroBalanceFrozen, TBD_TOKEN), tokenAssociate(zeroBalanceUnfrozen, TBD_TOKEN), tokenAssociate(nonZeroBalanceFrozen, TBD_TOKEN), tokenAssociate(nonZeroBalanceUnfrozen, TBD_TOKEN), mintToken(tbdUniqToken, List.of(firstMeta, secondMeta, thirdMeta)), getAccountInfo(TOKEN_TREASURY).hasOwnedNfts(3), tokenUnfreeze(TBD_TOKEN, zeroBalanceUnfrozen), tokenUnfreeze(TBD_TOKEN, nonZeroBalanceUnfrozen), tokenUnfreeze(TBD_TOKEN, nonZeroBalanceFrozen), cryptoTransfer(moving(nonZeroXfer, TBD_TOKEN).between(TOKEN_TREASURY, nonZeroBalanceFrozen)), cryptoTransfer(moving(nonZeroXfer, TBD_TOKEN).between(TOKEN_TREASURY, nonZeroBalanceUnfrozen)), tokenFreeze(TBD_TOKEN, nonZeroBalanceFrozen), getAccountBalance(TOKEN_TREASURY).hasTokenBalance(TBD_TOKEN, initialSupply - 2 * nonZeroXfer), tokenDelete(TBD_TOKEN), tokenDelete(tbdUniqToken), contractCall(THE_CONTRACT, SINGLE_TOKEN_DISSOCIATE, asAddress(zeroBalanceFrozenID.get()), asAddress(tbdTokenID.get())).payingWith(zeroBalanceFrozen).alsoSigningWithFullPrefix(MULTI_KEY).gas(GAS_TO_OFFER).via("dissociateZeroBalanceFrozenTxn"), getTxnRecord("dissociateZeroBalanceFrozenTxn").andAllChildRecords().logged(), contractCall(THE_CONTRACT, SINGLE_TOKEN_DISSOCIATE, asAddress(zeroBalanceUnfrozenID.get()), asAddress(tbdTokenID.get())).payingWith(zeroBalanceUnfrozen).alsoSigningWithFullPrefix(MULTI_KEY).gas(GAS_TO_OFFER).via("dissociateZeroBalanceUnfrozenTxn"), getTxnRecord("dissociateZeroBalanceUnfrozenTxn").andAllChildRecords().logged(), contractCall(THE_CONTRACT, SINGLE_TOKEN_DISSOCIATE, asAddress(nonZeroBalanceFrozenID.get()), asAddress(tbdTokenID.get())).payingWith(nonZeroBalanceFrozen).alsoSigningWithFullPrefix(MULTI_KEY).gas(GAS_TO_OFFER).via("dissociateNonZeroBalanceFrozenTxn"), getTxnRecord("dissociateNonZeroBalanceFrozenTxn").andAllChildRecords().logged(), contractCall(THE_CONTRACT, SINGLE_TOKEN_DISSOCIATE, asAddress(nonZeroBalanceUnfrozenID.get()), asAddress(tbdTokenID.get())).payingWith(nonZeroBalanceUnfrozen).alsoSigningWithFullPrefix(MULTI_KEY).gas(GAS_TO_OFFER).via("dissociateNonZeroBalanceUnfrozenTxn"), getTxnRecord("dissociateNonZeroBalanceUnfrozenTxn").andAllChildRecords().logged(), contractCall(THE_CONTRACT, SINGLE_TOKEN_DISSOCIATE, asAddress(treasuryID.get()), asAddress(tbdUniqueTokenID.get())).alsoSigningWithFullPrefix(MULTI_KEY).gas(GAS_TO_OFFER).payingWith(TOKEN_TREASURY)))).then(childRecordsCheck("dissociateZeroBalanceFrozenTxn", SUCCESS, recordWith().status(SUCCESS)), childRecordsCheck("dissociateZeroBalanceUnfrozenTxn", SUCCESS, recordWith().status(SUCCESS)), childRecordsCheck("dissociateNonZeroBalanceFrozenTxn", SUCCESS, recordWith().status(SUCCESS)), childRecordsCheck("dissociateNonZeroBalanceUnfrozenTxn", SUCCESS, recordWith().status(SUCCESS)), getAccountInfo(zeroBalanceFrozen).hasNoTokenRelationship(TBD_TOKEN), getAccountInfo(zeroBalanceUnfrozen).hasNoTokenRelationship(TBD_TOKEN), getAccountInfo(nonZeroBalanceFrozen).hasNoTokenRelationship(TBD_TOKEN), getAccountInfo(nonZeroBalanceUnfrozen).hasNoTokenRelationship(TBD_TOKEN), getAccountInfo(TOKEN_TREASURY).hasToken(relationshipWith(TBD_TOKEN)).hasNoTokenRelationship(tbdUniqToken).hasOwnedNfts(0), getAccountBalance(TOKEN_TREASURY).hasTokenBalance(TBD_TOKEN, initialSupply - 2 * nonZeroXfer));
}
Also used : SINGLE_TOKEN_DISSOCIATE(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.SINGLE_TOKEN_DISSOCIATE) TxnVerbs.cryptoCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate) TxnVerbs.cryptoTransfer(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer) TxnVerbs.tokenDelete(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenDelete) QueryVerbs.getTxnRecord(com.hedera.services.bdd.spec.queries.QueryVerbs.getTxnRecord) QueryVerbs.getAccountInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountInfo) ExpectedTokenRel.relationshipWith(com.hedera.services.bdd.spec.queries.crypto.ExpectedTokenRel.relationshipWith) HapiApiSpec.defaultHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec) TBD_TOKEN(com.hedera.services.bdd.suites.token.TokenAssociationSpecs.TBD_TOKEN) TxnVerbs.contractCall(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCall) UtilVerbs.newKeyNamed(com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyNamed) TransactionRecordAsserts.recordWith(com.hedera.services.bdd.spec.assertions.TransactionRecordAsserts.recordWith) MULTIPLE_TOKENS_DISSOCIATE(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.MULTIPLE_TOKENS_DISSOCIATE) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) StandardCharsets(java.nio.charset.StandardCharsets) Utils.extractByteCode(com.hedera.services.bdd.suites.contract.Utils.extractByteCode) ByteString(com.google.protobuf.ByteString) List(java.util.List) Logger(org.apache.logging.log4j.Logger) NotNull(org.jetbrains.annotations.NotNull) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) TxnVerbs.tokenAssociate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenAssociate) UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) FREEZABLE_TOKEN_ON_BY_DEFAULT(com.hedera.services.bdd.suites.token.TokenAssociationSpecs.FREEZABLE_TOKEN_ON_BY_DEFAULT) NESTED_TOKEN_DISSOCIATE(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.NESTED_TOKEN_DISSOCIATE) AtomicReference(java.util.concurrent.atomic.AtomicReference) ContractResources(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources) TokenMovement.moving(com.hedera.services.bdd.spec.transactions.token.TokenMovement.moving) UtilVerbs.childRecordsCheck(com.hedera.services.bdd.spec.utilops.UtilVerbs.childRecordsCheck) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) HapiPropertySource.asDotDelimitedLongArray(com.hedera.services.bdd.spec.HapiPropertySource.asDotDelimitedLongArray) AccountID(com.hederahashgraph.api.proto.java.AccountID) TxnVerbs.mintToken(com.hedera.services.bdd.spec.transactions.TxnVerbs.mintToken) TxnVerbs.tokenCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenCreate) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) TxnVerbs.tokenFreeze(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenFreeze) UtilVerbs.updateLargeFile(com.hedera.services.bdd.spec.utilops.UtilVerbs.updateLargeFile) QueryVerbs.getAccountBalance(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountBalance) VANILLA_TOKEN(com.hedera.services.bdd.suites.token.TokenAssociationSpecs.VANILLA_TOKEN) CustomSpecAssert.allRunFor(com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor) TokenType(com.hederahashgraph.api.proto.java.TokenType) TxnVerbs.fileCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate) KNOWABLE_TOKEN(com.hedera.services.bdd.suites.token.TokenAssociationSpecs.KNOWABLE_TOKEN) TokenID(com.hederahashgraph.api.proto.java.TokenID) Utils.asAddress(com.hedera.services.bdd.suites.contract.Utils.asAddress) TxnVerbs.contractCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCreate) FUNGIBLE_COMMON(com.hederahashgraph.api.proto.java.TokenType.FUNGIBLE_COMMON) LogManager(org.apache.logging.log4j.LogManager) TxnVerbs.tokenUnfreeze(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenUnfreeze) AccountID(com.hederahashgraph.api.proto.java.AccountID) AtomicReference(java.util.concurrent.atomic.AtomicReference) ByteString(com.google.protobuf.ByteString) TokenID(com.hederahashgraph.api.proto.java.TokenID)

Aggregations

AccountID (com.hederahashgraph.api.proto.java.AccountID)71 Test (org.junit.jupiter.api.Test)24 List (java.util.List)21 ByteString (com.google.protobuf.ByteString)20 Assertions (org.junit.jupiter.api.Assertions)20 HapiApiSpec (com.hedera.services.bdd.spec.HapiApiSpec)17 LogManager (org.apache.logging.log4j.LogManager)17 Logger (org.apache.logging.log4j.Logger)17 HapiApiSuite (com.hedera.services.bdd.suites.HapiApiSuite)16 HapiApiSpec.defaultHapiSpec (com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec)15 QueryVerbs.getTxnRecord (com.hedera.services.bdd.spec.queries.QueryVerbs.getTxnRecord)15 SUCCESS (com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS)15 QueryVerbs.getAccountInfo (com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountInfo)14 TransactionRecordAsserts.recordWith (com.hedera.services.bdd.spec.assertions.TransactionRecordAsserts.recordWith)13 QueryVerbs.getAccountBalance (com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountBalance)13 TxnVerbs.cryptoCreate (com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate)13 TxnVerbs.cryptoTransfer (com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer)13 TxnVerbs.mintToken (com.hedera.services.bdd.spec.transactions.TxnVerbs.mintToken)13 HapiSpecSetup (com.hedera.services.bdd.spec.HapiSpecSetup)12 QueryVerbs.getScheduleInfo (com.hedera.services.bdd.spec.queries.QueryVerbs.getScheduleInfo)12