Search in sources :

Example 1 with CryptoUpdateMeta

use of com.hedera.services.usage.crypto.CryptoUpdateMeta in project hedera-services by hashgraph.

the class HapiCryptoUpdate method feeFor.

@Override
protected long feeFor(HapiApiSpec spec, Transaction txn, int numPayerKeys) throws Throwable {
    try {
        final CryptoGetInfoResponse.AccountInfo info = lookupInfo(spec);
        FeeCalculator.ActivityMetrics metricsCalc = (_txn, svo) -> {
            var ctx = ExtantCryptoContext.newBuilder().setCurrentNumTokenRels(info.getTokenRelationshipsCount()).setCurrentExpiry(info.getExpirationTime().getSeconds()).setCurrentMemo(info.getMemo()).setCurrentKey(info.getKey()).setCurrentlyHasProxy(info.hasProxyAccountID()).setCurrentMaxAutomaticAssociations(info.getMaxAutomaticTokenAssociations()).build();
            var baseMeta = new BaseTransactionMeta(_txn.getMemoBytes().size(), 0);
            var opMeta = new CryptoUpdateMeta(_txn.getCryptoUpdateAccount(), _txn.getTransactionID().getTransactionValidStart().getSeconds());
            var accumulator = new UsageAccumulator();
            cryptoOpsUsage.cryptoUpdateUsage(suFrom(svo), baseMeta, opMeta, ctx, accumulator);
            return AdapterUtils.feeDataFrom(accumulator);
        };
        return spec.fees().forActivityBasedOp(HederaFunctionality.CryptoUpdate, metricsCalc, txn, numPayerKeys);
    } catch (Throwable ignore) {
        return HapiApiSuite.ONE_HBAR;
    }
}
Also used : CryptoGetInfoResponse(com.hederahashgraph.api.proto.java.CryptoGetInfoResponse) 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) FeeCalculator(com.hedera.services.bdd.spec.fees.FeeCalculator) CryptoUpdateMeta(com.hedera.services.usage.crypto.CryptoUpdateMeta) BaseTransactionMeta(com.hedera.services.usage.BaseTransactionMeta) UsageAccumulator(com.hedera.services.usage.state.UsageAccumulator)

Aggregations

MoreObjects (com.google.common.base.MoreObjects)1 BoolValue (com.google.protobuf.BoolValue)1 Int32Value (com.google.protobuf.Int32Value)1 StringValue (com.google.protobuf.StringValue)1 UInt64Value (com.google.protobuf.UInt64Value)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 ReferenceType (com.hedera.services.bdd.spec.queries.crypto.ReferenceType)1 HapiTxnOp (com.hedera.services.bdd.spec.transactions.HapiTxnOp)1 TxnUtils (com.hedera.services.bdd.spec.transactions.TxnUtils)1 TxnUtils.asIdForKeyLookUp (com.hedera.services.bdd.spec.transactions.TxnUtils.asIdForKeyLookUp)1 TxnUtils.defaultUpdateSigners (com.hedera.services.bdd.spec.transactions.TxnUtils.defaultUpdateSigners)1 TxnUtils.suFrom (com.hedera.services.bdd.spec.transactions.TxnUtils.suFrom)1 HapiApiSuite (com.hedera.services.bdd.suites.HapiApiSuite)1 BaseTransactionMeta (com.hedera.services.usage.BaseTransactionMeta)1