use of com.hederahashgraph.api.proto.java.Transaction in project hedera-services by hashgraph.
the class HapiScheduleSign method feeFor.
@Override
protected long feeFor(HapiApiSpec spec, Transaction txn, int numPayerKeys) throws Throwable {
try {
final ScheduleInfo info = ScheduleFeeUtils.lookupInfo(spec, schedule, loggingOff);
FeeCalculator.ActivityMetrics metricsCalc = (_txn, svo) -> scheduleOpsUsage.scheduleSignUsage(_txn, suFrom(svo), info.getExpirationTime().getSeconds());
return spec.fees().forActivityBasedOp(HederaFunctionality.ScheduleSign, metricsCalc, txn, numPayerKeys);
} catch (Throwable ignore) {
return HapiApiSuite.ONE_HBAR;
}
}
use of com.hederahashgraph.api.proto.java.Transaction in project hedera-services by hashgraph.
the class HapiTxnOp method submitOp.
@Override
protected boolean submitOp(HapiApiSpec spec) throws Throwable {
stats = new TxnObs(type());
fixNodeFor(spec);
configureTlsFor(spec);
int retryCount = 1;
while (true) {
Transaction txn = finalizedTxn(spec, opBodyDef(spec));
if (!loggingOff) {
log.info(spec.logPrefix() + " submitting " + this + " via " + txnToString(txn));
}
TransactionResponse response = null;
try {
if (fiddler.isPresent()) {
txn = fiddler.get().apply(txn);
}
response = timedCall(spec, txn);
} catch (StatusRuntimeException e) {
var msg = e.toString();
if (isRecognizedRecoverable(msg)) {
log.info("Recognized recoverable runtime exception {}, retrying status resolution...", msg);
continue;
} else {
if (spec.setup().suppressUnrecoverableNetworkFailures()) {
return false;
}
log.error("{} Status resolution failed due to unrecoverable runtime exception, " + "possibly network connection lost.", TxnUtils.toReadableString(txn));
throw new HapiTxnCheckStateException("Unable to resolve txn status!");
}
}
/* Used by superclass to perform standard housekeeping. */
txnSubmitted = txn;
actualPrecheck = response.getNodeTransactionPrecheckCode();
if (retryPrechecks.isPresent() && retryPrechecks.get().contains(actualPrecheck) && isWithInRetryLimit(retryCount)) {
retryCount++;
sleep(10);
} else {
break;
}
}
spec.updatePrecheckCounts(actualPrecheck);
stats.setAccepted(actualPrecheck == OK);
if (actualPrecheck == INSUFFICIENT_PAYER_BALANCE || actualPrecheck == INSUFFICIENT_TX_FEE) {
if (payerIsRechargingFor(spec)) {
addIpbToPermissiblePrechecks();
if (payerNotRecentlyRecharged(spec)) {
rechargePayerFor(spec);
}
}
}
if (!acceptAnyPrecheck) {
if (permissiblePrechecks.isPresent()) {
if (permissiblePrechecks.get().contains(actualPrecheck)) {
expectedPrecheck = Optional.of(actualPrecheck);
} else {
// permissiblePrechecks.get());
throw new HapiTxnPrecheckStateException(String.format("Wrong precheck status! Expected one of %s, actual %s", permissiblePrechecks.get(), actualPrecheck));
}
} else {
if (getExpectedPrecheck() != actualPrecheck) {
// Change to an info until HapiClientValidator can be modified and can understand new errors
log.info("{} {} Wrong actual precheck status {}, expecting {}", spec.logPrefix(), this, actualPrecheck, getExpectedPrecheck());
throw new HapiTxnPrecheckStateException(String.format("Wrong precheck status! Expected %s, actual %s", getExpectedPrecheck(), actualPrecheck));
}
}
}
if (actualPrecheck != OK) {
considerRecording(spec, stats);
return false;
}
spec.adhocIncrement();
if (!deferStatusResolution) {
resolveStatus(spec);
if (!hasStatsToCollectDuringFinalization(spec)) {
considerRecording(spec, stats);
}
}
if (requiresFinalization(spec)) {
spec.offerFinisher(new DelegatingOpFinisher(this));
}
return !deferStatusResolution;
}
use of com.hederahashgraph.api.proto.java.Transaction in project hedera-services by hashgraph.
the class TxnUtils method replaceTxnPayerAccount.
public static Transaction replaceTxnPayerAccount(Transaction txn, AccountID accountID) {
Transaction newTxn = Transaction.getDefaultInstance();
try {
TransactionBody.Builder txnBody = TransactionBody.newBuilder().mergeFrom(txn.getBodyBytes());
txnBody.setTransactionID(TransactionID.newBuilder().setAccountID(accountID).setTransactionValidStart(txnBody.getTransactionID().getTransactionValidStart()).build());
return txn.toBuilder().setBodyBytes(txnBody.build().toByteString()).build();
} catch (Exception e) {
log.warn("Transaction's body can't be parsed: {}", txnToString(txn), e);
}
return null;
}
use of com.hederahashgraph.api.proto.java.Transaction in project hedera-services by hashgraph.
the class HapiTopicUpdate method feeFor.
@Override
protected long feeFor(HapiApiSpec spec, Transaction txn, int numPayerKeys) throws Throwable {
if (!spec.registry().hasTopicMeta(topic)) {
return spec.fees().maxFeeTinyBars();
} else {
/* Lookup topic metadata saved during creation. */
long oldExpiry = spec.registry().getTopicExpiry(topic);
ConsensusCreateTopicTransactionBody oldMeta = spec.registry().getTopicMeta(topic);
/* Computed the increase in RBS due to this update. */
long tentativeRbsIncrease = 0;
try {
TransactionBody updateTxn = CommonUtils.extractTransactionBody(txn);
tentativeRbsIncrease = ConsensusServiceFeeBuilder.getUpdateTopicRbsIncrease(updateTxn.getTransactionID().getTransactionValidStart(), oldMeta.getAdminKey(), oldMeta.getSubmitKey(), oldMeta.getMemo(), oldMeta.hasAutoRenewAccount(), Timestamp.newBuilder().setSeconds(oldExpiry).build(), updateTxn.getConsensusUpdateTopic());
} catch (Exception impossible) {
throw new IllegalStateException(impossible);
}
/* Create a custom activity metrics calculator based on the rbsIncrease. */
final long rbsIncrease = tentativeRbsIncrease;
FeeCalculator.ActivityMetrics metricsCalc = (txBody, sigUsage) -> ConsensusServiceFeeBuilder.getConsensusUpdateTopicFee(txBody, rbsIncrease, sigUsage);
/* Return the net fee. */
return spec.fees().forActivityBasedOp(ConsensusUpdateTopic, metricsCalc, txn, numPayerKeys);
}
}
use of com.hederahashgraph.api.proto.java.Transaction in project hedera-services by hashgraph.
the class HapiContractUpdate method feeFor.
@Override
protected long feeFor(HapiApiSpec spec, Transaction txn, int numPayerKeys) throws Throwable {
Timestamp newExpiry = TxnFactory.expiryGiven(newExpirySecs.orElse(spec.setup().defaultExpirationSecs()));
Timestamp oldExpiry = TxnUtils.currContractExpiry(contract, spec);
final Timestamp expiry = TxnUtils.inConsensusOrder(oldExpiry, newExpiry) ? newExpiry : oldExpiry;
FeeCalculator.ActivityMetrics metricsCalc = (txBody, sigUsage) -> scFees.getContractUpdateTxFeeMatrices(txBody, expiry, sigUsage);
return spec.fees().forActivityBasedOp(HederaFunctionality.ContractUpdate, metricsCalc, txn, numPayerKeys);
}
Aggregations