Search in sources :

Example 1 with CryptoUpdateTransactionBody

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

the class RequestBuilder method getAccountUpdateRequest.

/**
 * Generates a transaction with a CryptoUpdateTransactionBody object pre-built by caller
 *
 * @param payerAccountNum
 * 		payer account number
 * @param payerRealmNum
 * 		payer realm number
 * @param payerShardNum
 * 		payer shard number
 * @param nodeAccountNum
 * 		node account number
 * @param nodeRealmNum
 * 		node realm number
 * @param nodeShardNum
 * 		node shard number
 * @param transactionFee
 * 		transaction fee
 * @param startTime
 * 		start time
 * @param transactionDuration
 * 		transaction duration
 * @param generateRecord
 * 		generate record boolean
 * @param memo
 * 		memo
 * @param cryptoUpdate
 * 		crypto update transaction body
 * @return transaction for account update
 */
public static Transaction getAccountUpdateRequest(Long payerAccountNum, Long payerRealmNum, Long payerShardNum, Long nodeAccountNum, Long nodeRealmNum, Long nodeShardNum, long transactionFee, Timestamp startTime, Duration transactionDuration, boolean generateRecord, String memo, CryptoUpdateTransactionBody cryptoUpdate) {
    TransactionBody.Builder body = getTransactionBody(payerAccountNum, payerRealmNum, payerShardNum, nodeAccountNum, nodeRealmNum, nodeShardNum, transactionFee, startTime, transactionDuration, generateRecord, memo);
    body.setCryptoUpdateAccount(cryptoUpdate);
    byte[] bodyBytesArr = body.build().toByteArray();
    ByteString bodyBytes = ByteString.copyFrom(bodyBytesArr);
    return Transaction.newBuilder().setBodyBytes(bodyBytes).build();
}
Also used : FileDeleteTransactionBody(com.hederahashgraph.api.proto.java.FileDeleteTransactionBody) ContractUpdateTransactionBody(com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody) FileAppendTransactionBody(com.hederahashgraph.api.proto.java.FileAppendTransactionBody) ContractCallTransactionBody(com.hederahashgraph.api.proto.java.ContractCallTransactionBody) CryptoCreateTransactionBody(com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody) CryptoUpdateTransactionBody(com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody) CryptoTransferTransactionBody(com.hederahashgraph.api.proto.java.CryptoTransferTransactionBody) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) FileUpdateTransactionBody(com.hederahashgraph.api.proto.java.FileUpdateTransactionBody) FileCreateTransactionBody(com.hederahashgraph.api.proto.java.FileCreateTransactionBody) ContractCreateTransactionBody(com.hederahashgraph.api.proto.java.ContractCreateTransactionBody) ByteString(com.google.protobuf.ByteString)

Example 2 with CryptoUpdateTransactionBody

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

the class CryptoUpdateTransitionLogic method validate.

private ResponseCodeEnum validate(TransactionBody cryptoUpdateTxn) {
    CryptoUpdateTransactionBody op = cryptoUpdateTxn.getCryptoUpdateAccount();
    var memoValidity = !op.hasMemo() ? OK : validator.memoCheck(op.getMemo().getValue());
    if (memoValidity != OK) {
        return memoValidity;
    }
    if (op.hasKey()) {
        try {
            JKey fcKey = JKey.mapKey(op.getKey());
            /* Note that an empty key is never valid. */
            if (!fcKey.isValid()) {
                return BAD_ENCODING;
            }
        } catch (DecoderException e) {
            return BAD_ENCODING;
        }
    }
    if (op.hasAutoRenewPeriod() && !validator.isValidAutoRenewPeriod(op.getAutoRenewPeriod())) {
        return AUTORENEW_DURATION_NOT_IN_RANGE;
    }
    return OK;
}
Also used : DecoderException(org.apache.commons.codec.DecoderException) JKey(com.hedera.services.legacy.core.jproto.JKey) CryptoUpdateTransactionBody(com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody)

Example 3 with CryptoUpdateTransactionBody

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

the class HapiCryptoUpdate method opBodyDef.

@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
    try {
        updKey = updKeyName.map(spec.registry()::getKey);
    } catch (Exception ignore) {
    }
    AccountID id;
    if (referenceType == ReferenceType.REGISTRY_NAME) {
        id = TxnUtils.asId(account, spec);
    } else {
        id = asIdForKeyLookUp(aliasKeySource, spec);
        account = asAccountString(id);
    }
    CryptoUpdateTransactionBody opBody = spec.txns().<CryptoUpdateTransactionBody, CryptoUpdateTransactionBody.Builder>body(CryptoUpdateTransactionBody.class, builder -> {
        builder.setAccountIDToUpdate(id);
        newProxy.ifPresent(p -> {
            var proxyId = TxnUtils.asId(p, spec);
            builder.setProxyAccountID(proxyId);
        });
        updSigRequired.ifPresent(u -> builder.setReceiverSigRequiredWrapper(BoolValue.of(u)));
        if (useContractKey) {
            builder.setKey(Key.newBuilder().setContractID(HapiPropertySource.asContract("0.0.1234")));
        } else {
            updKey.ifPresent(builder::setKey);
        }
        newAutoRenewPeriod.ifPresent(p -> builder.setAutoRenewPeriod(Duration.newBuilder().setSeconds(p)));
        entityMemo.ifPresent(m -> builder.setMemo(StringValue.newBuilder().setValue(m).build()));
        sendThreshold.ifPresent(v -> builder.setSendRecordThresholdWrapper(UInt64Value.newBuilder().setValue(v).build()));
        newExpiry.ifPresent(l -> builder.setExpirationTime(Timestamp.newBuilder().setSeconds(l).build()));
        newMaxAutomaticAssociations.ifPresent(p -> builder.setMaxAutomaticTokenAssociations(Int32Value.of(p)));
    });
    return builder -> builder.setCryptoUpdateAccount(opBody);
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) CryptoGetInfoResponse(com.hederahashgraph.api.proto.java.CryptoGetInfoResponse) BoolValue(com.google.protobuf.BoolValue) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) UInt64Value(com.google.protobuf.UInt64Value) StringValue(com.google.protobuf.StringValue) Duration(com.hederahashgraph.api.proto.java.Duration) Function(java.util.function.Function) TxnUtils.defaultUpdateSigners(com.hedera.services.bdd.spec.transactions.TxnUtils.defaultUpdateSigners) OptionalLong(java.util.OptionalLong) PropertySource.asAccountString(com.hedera.services.bdd.spec.PropertySource.asAccountString) BaseTransactionMeta(com.hedera.services.usage.BaseTransactionMeta) QueryVerbs.getAccountInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountInfo) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) UsageAccumulator(com.hedera.services.usage.state.UsageAccumulator) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) CryptoUpdateMeta(com.hedera.services.usage.crypto.CryptoUpdateMeta) ReferenceType(com.hedera.services.bdd.spec.queries.crypto.ReferenceType) AccountID(com.hederahashgraph.api.proto.java.AccountID) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) CryptoUpdateTransactionBody(com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody) Int32Value(com.google.protobuf.Int32Value) MoreObjects(com.google.common.base.MoreObjects) HapiPropertySource(com.hedera.services.bdd.spec.HapiPropertySource) ExtantCryptoContext(com.hedera.services.usage.crypto.ExtantCryptoContext) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) HapiGetAccountInfo(com.hedera.services.bdd.spec.queries.crypto.HapiGetAccountInfo) Consumer(java.util.function.Consumer) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) Logger(org.apache.logging.log4j.Logger) TxnUtils.asIdForKeyLookUp(com.hedera.services.bdd.spec.transactions.TxnUtils.asIdForKeyLookUp) AdapterUtils(com.hedera.services.bdd.spec.fees.AdapterUtils) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) Optional(java.util.Optional) TxnUtils.suFrom(com.hedera.services.bdd.spec.transactions.TxnUtils.suFrom) FeeCalculator(com.hedera.services.bdd.spec.fees.FeeCalculator) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) AccountID(com.hederahashgraph.api.proto.java.AccountID) CryptoUpdateTransactionBody(com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody)

Example 4 with CryptoUpdateTransactionBody

use of com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody in project hedera-mirror-node by hashgraph.

the class EntityRecordItemListenerCryptoTest method cryptoUpdateSuccessfulTransaction.

@Test
void cryptoUpdateSuccessfulTransaction() {
    createAccount();
    // now update
    Transaction transaction = cryptoUpdateTransaction(accountId1);
    TransactionBody transactionBody = getTransactionBody(transaction);
    CryptoUpdateTransactionBody cryptoUpdateTransactionBody = transactionBody.getCryptoUpdateAccount();
    TransactionRecord record = transactionRecordSuccess(transactionBody);
    parseRecordItemAndCommit(new RecordItem(transaction, record));
    Entity dbAccountEntity = getTransactionEntity(record.getConsensusTimestamp());
    assertAll(() -> assertEquals(2, transactionRepository.count()), () -> assertEntities(EntityId.of(accountId1)), () -> assertEquals(6, cryptoTransferRepository.count()), () -> assertCryptoTransaction(transactionBody, record), // transaction body inputs
    () -> assertEquals(cryptoUpdateTransactionBody.getAutoRenewPeriod().getSeconds(), dbAccountEntity.getAutoRenewPeriod()), () -> assertEquals(DomainUtils.getPublicKey(cryptoUpdateTransactionBody.getKey().toByteArray()), dbAccountEntity.getPublicKey()), () -> assertEquals(EntityId.of(cryptoUpdateTransactionBody.getProxyAccountID()), dbAccountEntity.getProxyAccountId()), () -> assertArrayEquals(cryptoUpdateTransactionBody.getKey().toByteArray(), dbAccountEntity.getKey()), () -> assertEquals(cryptoUpdateTransactionBody.getMaxAutomaticTokenAssociations().getValue(), dbAccountEntity.getMaxAutomaticTokenAssociations()), () -> assertEquals(cryptoUpdateTransactionBody.getMemo().getValue(), dbAccountEntity.getMemo()), () -> assertEquals(DomainUtils.timeStampInNanos(cryptoUpdateTransactionBody.getExpirationTime()), dbAccountEntity.getExpirationTimestamp()), () -> assertEquals(DomainUtils.timestampInNanosMax(record.getConsensusTimestamp()), dbAccountEntity.getTimestampLower()), () -> assertFalse(dbAccountEntity.getReceiverSigRequired()), () -> assertFalse(dbAccountEntity.isDeclineReward()), () -> assertEquals(cryptoUpdateTransactionBody.getStakedNodeId(), dbAccountEntity.getStakedNodeId()), () -> assertEquals(-1L, dbAccountEntity.getStakedAccountId()), () -> assertEquals(Utility.getEpochDay(DomainUtils.timestampInNanosMax(record.getConsensusTimestamp())), dbAccountEntity.getStakePeriodStart()));
}
Also used : Entity(com.hedera.mirror.common.domain.entity.Entity) CryptoDeleteLiveHashTransactionBody(com.hederahashgraph.api.proto.java.CryptoDeleteLiveHashTransactionBody) CryptoCreateTransactionBody(com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody) CryptoUpdateTransactionBody(com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) CryptoAddLiveHashTransactionBody(com.hederahashgraph.api.proto.java.CryptoAddLiveHashTransactionBody) Transaction(com.hederahashgraph.api.proto.java.Transaction) SignedTransaction(com.hederahashgraph.api.proto.java.SignedTransaction) CryptoUpdateTransactionBody(com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) UtilityTest(com.hedera.mirror.importer.util.UtilityTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

CryptoUpdateTransactionBody (com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody)4 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)3 CryptoCreateTransactionBody (com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody)2 Transaction (com.hederahashgraph.api.proto.java.Transaction)2 MoreObjects (com.google.common.base.MoreObjects)1 BoolValue (com.google.protobuf.BoolValue)1 ByteString (com.google.protobuf.ByteString)1 Int32Value (com.google.protobuf.Int32Value)1 StringValue (com.google.protobuf.StringValue)1 UInt64Value (com.google.protobuf.UInt64Value)1 Entity (com.hedera.mirror.common.domain.entity.Entity)1 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)1 UtilityTest (com.hedera.mirror.importer.util.UtilityTest)1 HapiApiSpec (com.hedera.services.bdd.spec.HapiApiSpec)1 HapiPropertySource (com.hedera.services.bdd.spec.HapiPropertySource)1 PropertySource.asAccountString (com.hedera.services.bdd.spec.PropertySource.asAccountString)1 AdapterUtils (com.hedera.services.bdd.spec.fees.AdapterUtils)1 FeeCalculator (com.hedera.services.bdd.spec.fees.FeeCalculator)1 QueryVerbs.getAccountInfo (com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountInfo)1 HapiGetAccountInfo (com.hedera.services.bdd.spec.queries.crypto.HapiGetAccountInfo)1