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();
}
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;
}
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);
}
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()));
}
Aggregations