use of com.hederahashgraph.api.proto.java.TransactionBody in project hedera-services by hashgraph.
the class OpUsageCtxHelperTest method getMetaForTokenBurnWorks.
@Test
void getMetaForTokenBurnWorks() {
TokenBurnTransactionBody burnTxnBody = getFungibleCommonTokenBurnOp();
TransactionBody txn = getTxnBody(burnTxnBody);
given(accessor.getTxn()).willReturn(txn);
given(accessor.getSubType()).willReturn(TOKEN_FUNGIBLE_COMMON);
final var tokenBurnMeta = subject.metaForTokenBurn(accessor);
// then:
assertEquals(32, tokenBurnMeta.getBpt());
assertEquals(SubType.TOKEN_FUNGIBLE_COMMON, tokenBurnMeta.getSubType());
assertEquals(0, tokenBurnMeta.getSerialNumsCount());
assertEquals(56, tokenBurnMeta.getTransferRecordDb());
}
use of com.hederahashgraph.api.proto.java.TransactionBody in project hedera-services by hashgraph.
the class TransactionThrottlingTest method delegatesExpectedFunction.
@Test
void delegatesExpectedFunction() {
// setup:
TransactionBody createTxn = TransactionBody.newBuilder().setConsensusCreateTopic(ConsensusCreateTopicTransactionBody.newBuilder().setMemo("Hi!")).build();
final var accessor = SignedTxnAccessor.uncheckedFrom(Transaction.newBuilder().setSignedTransactionBytes(SignedTransaction.newBuilder().setBodyBytes(createTxn.toByteString()).build().toByteString()).build());
given(functionalThrottling.shouldThrottleTxn(accessor)).willReturn(true);
// when:
boolean should = subject.shouldThrottle(accessor);
// then:
assertTrue(should);
verify(functionalThrottling).shouldThrottleTxn(accessor);
}
use of com.hederahashgraph.api.proto.java.TransactionBody in project hedera-services by hashgraph.
the class CryptoApproveAllowanceTransitionLogic method doStateTransition.
@Override
public void doStateTransition() {
/* --- Extract gRPC --- */
final TransactionBody cryptoApproveAllowanceTxn = txnCtx.accessor().getTxn();
final AccountID payer = cryptoApproveAllowanceTxn.getTransactionID().getAccountID();
final var op = cryptoApproveAllowanceTxn.getCryptoApproveAllowance();
entitiesChanged.clear();
/* --- Use models --- */
final Id payerId = Id.fromGrpcAccount(payer);
final var payerAccount = accountStore.loadAccount(payerId);
/* --- Do the business logic --- */
applyCryptoAllowances(op.getCryptoAllowancesList(), payerAccount);
applyFungibleTokenAllowances(op.getTokenAllowancesList(), payerAccount);
applyNftAllowances(op.getNftAllowancesList(), payerAccount);
/* --- Persist the payer account --- */
for (final var entry : entitiesChanged.entrySet()) {
accountStore.commitAccount(entry.getValue());
}
txnCtx.setStatus(SUCCESS);
}
use of com.hederahashgraph.api.proto.java.TransactionBody in project hedera-services by hashgraph.
the class HapiTopicCreate method updateStateOf.
@Override
protected void updateStateOf(HapiApiSpec spec) {
if (actualStatus != SUCCESS) {
return;
}
spec.registry().saveKey(topic, adminKey);
submitKey.ifPresent(key -> spec.registry().saveKey(topic + "Submit", key));
spec.registry().saveTopicId(topic, lastReceipt.getTopicID());
spec.registry().saveBytes(topic, ByteString.copyFrom(new byte[48]));
try {
TransactionBody txn = CommonUtils.extractTransactionBody(txnSubmitted);
long approxConsensusTime = txn.getTransactionID().getTransactionValidStart().getSeconds() + 1;
spec.registry().saveTopicMeta(topic, txn.getConsensusCreateTopic(), approxConsensusTime);
} catch (Exception impossible) {
throw new IllegalStateException(impossible);
}
if (advertiseCreation) {
String banner = "\n\n" + bannerWith(String.format("Created topic '%s' with id '0.0.%d'.", topic, lastReceipt.getTopicID().getTopicNum()));
log.info(banner);
}
}
use of com.hederahashgraph.api.proto.java.TransactionBody in project hedera-services by hashgraph.
the class HapiTopicUpdate method updateStateOf.
@Override
protected void updateStateOf(HapiApiSpec spec) {
if (actualStatus != ResponseCodeEnum.SUCCESS) {
return;
}
newAdminKey.ifPresent(k -> {
if (newAdminKey.get() == EMPTY_KEY) {
spec.registry().removeKey(topic);
} else {
spec.registry().saveKey(topic, k);
}
});
newSubmitKey.ifPresent(k -> {
if (newSubmitKey.get() == EMPTY_KEY) {
spec.registry().removeKey(submitKeyName());
} else {
spec.registry().saveKey(submitKeyName(), k);
}
});
try {
TransactionBody txn = CommonUtils.extractTransactionBody(txnSubmitted);
spec.registry().saveTopicMeta(topic, txn.getConsensusUpdateTopic());
} catch (Exception impossible) {
throw new IllegalStateException(impossible);
}
}
Aggregations