Search in sources :

Example 71 with HapiApiSpec

use of com.hedera.services.bdd.spec.HapiApiSpec 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);
    }
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) StringValue(com.google.protobuf.StringValue) EMPTY_KEY(com.hedera.services.bdd.suites.HapiApiSuite.EMPTY_KEY) Function(java.util.function.Function) ArrayList(java.util.ArrayList) ConsensusUpdateTopic(com.hederahashgraph.api.proto.java.HederaFunctionality.ConsensusUpdateTopic) OptionalLong(java.util.OptionalLong) TxnUtils.asId(com.hedera.services.bdd.spec.transactions.TxnUtils.asId) CommonUtils(com.hedera.services.legacy.proto.utils.CommonUtils) TxnUtils.asTopicId(com.hedera.services.bdd.spec.transactions.TxnUtils.asTopicId) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) TxnUtils.asTimestamp(com.hedera.services.bdd.spec.transactions.TxnUtils.asTimestamp) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) ConsensusServiceFeeBuilder(com.hederahashgraph.fee.ConsensusServiceFeeBuilder) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) MoreObjects(com.google.common.base.MoreObjects) ConsensusUpdateTopicTransactionBody(com.hederahashgraph.api.proto.java.ConsensusUpdateTopicTransactionBody) TxnUtils.asDuration(com.hedera.services.bdd.spec.transactions.TxnUtils.asDuration) Consumer(java.util.function.Consumer) ConsensusCreateTopicTransactionBody(com.hederahashgraph.api.proto.java.ConsensusCreateTopicTransactionBody) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) Optional(java.util.Optional) FeeCalculator(com.hedera.services.bdd.spec.fees.FeeCalculator) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) FeeCalculator(com.hedera.services.bdd.spec.fees.FeeCalculator) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) ConsensusUpdateTopicTransactionBody(com.hederahashgraph.api.proto.java.ConsensusUpdateTopicTransactionBody) ConsensusCreateTopicTransactionBody(com.hederahashgraph.api.proto.java.ConsensusCreateTopicTransactionBody) ConsensusCreateTopicTransactionBody(com.hederahashgraph.api.proto.java.ConsensusCreateTopicTransactionBody)

Example 72 with HapiApiSpec

use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.

the class HapiContractCall method opBodyDef.

@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
    if (details.isPresent()) {
        ActionableContractCall actionable = spec.registry().getActionableCall(details.get());
        contract = actionable.getContract();
        abi = actionable.getDetails().getAbi();
        params = actionable.getDetails().getExampleArgs();
    } else if (paramsFn.isPresent()) {
        params = paramsFn.get().apply(spec);
    }
    byte[] callData;
    if (explicitHexedParams.isPresent()) {
        callData = explicitHexedParams.map(Supplier::get).map(CommonUtils::unhex).get();
    } else {
        final var paramsList = Arrays.asList(params);
        final var tupleExist = paramsList.stream().anyMatch(p -> p instanceof Tuple || p instanceof Tuple[]);
        if (tupleExist) {
            callData = encodeParametersWithTuple(params);
        } else {
            callData = (!abi.equals(FALLBACK_ABI)) ? CallTransaction.Function.fromJsonInterface(abi).encode(params) : new byte[] {};
        }
    }
    ContractCallTransactionBody opBody = spec.txns().<ContractCallTransactionBody, ContractCallTransactionBody.Builder>body(ContractCallTransactionBody.class, builder -> {
        if (!tryAsHexedAddressIfLenMatches) {
            builder.setContractID(spec.registry().getContractId(contract));
        } else {
            builder.setContractID(TxnUtils.asContractId(contract, spec));
        }
        builder.setFunctionParameters(ByteString.copyFrom(callData));
        sentTinyHbars.ifPresent(builder::setAmount);
        gas.ifPresent(builder::setGas);
    });
    return b -> b.setContractCall(opBody);
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) Arrays(java.util.Arrays) TrieSigMapGenerator.uniqueWithFullPrefixesFor(com.hedera.services.bdd.spec.keys.TrieSigMapGenerator.uniqueWithFullPrefixesFor) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) CallTransaction(org.ethereum.core.CallTransaction) Function(java.util.function.Function) Supplier(java.util.function.Supplier) DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) ArrayList(java.util.ArrayList) Tuple(com.esaulpaugh.headlong.abi.Tuple) QueryVerbs.getTxnRecord(com.hedera.services.bdd.spec.queries.QueryVerbs.getTxnRecord) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) ContractCallTransactionBody(com.hederahashgraph.api.proto.java.ContractCallTransactionBody) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) HashUtil.sha3(org.ethereum.crypto.HashUtil.sha3) GENESIS(com.hedera.services.bdd.suites.HapiApiSuite.GENESIS) TupleType(com.esaulpaugh.headlong.abi.TupleType) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) ActionableContractCall(com.hedera.services.bdd.spec.infrastructure.meta.ActionableContractCall) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MoreObjects(com.google.common.base.MoreObjects) CustomSpecAssert.allRunFor(com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor) LongConsumer(java.util.function.LongConsumer) ByteString(com.google.protobuf.ByteString) Consumer(java.util.function.Consumer) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) CommonUtils(com.swirlds.common.CommonUtils) ByteUtil(org.ethereum.util.ByteUtil) ObjLongConsumer(java.util.function.ObjLongConsumer) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) Optional(java.util.Optional) TxnUtils.extractTxnId(com.hedera.services.bdd.spec.transactions.TxnUtils.extractTxnId) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) Collections(java.util.Collections) ActionableContractCall(com.hedera.services.bdd.spec.infrastructure.meta.ActionableContractCall) CommonUtils(com.swirlds.common.CommonUtils) ContractCallTransactionBody(com.hederahashgraph.api.proto.java.ContractCallTransactionBody) Tuple(com.esaulpaugh.headlong.abi.Tuple)

Example 73 with HapiApiSpec

use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.

the class HapiContractDelete method opBodyDef.

@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
    ContractDeleteTransactionBody opBody = spec.txns().<ContractDeleteTransactionBody, ContractDeleteTransactionBody.Builder>body(ContractDeleteTransactionBody.class, builder -> {
        builder.setContractID(TxnUtils.asContractId(contract, spec));
        transferContract.ifPresent(c -> builder.setTransferContractID(TxnUtils.asContractId(c, spec)));
        transferAccount.ifPresent(a -> builder.setTransferAccountID(spec.registry().getAccountID(a)));
    });
    return builder -> builder.setContractDeleteInstance(opBody);
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) Arrays(java.util.Arrays) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) MoreObjects(com.google.common.base.MoreObjects) SupportedContract(com.hedera.services.bdd.spec.infrastructure.meta.SupportedContract) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) Function(java.util.function.Function) Consumer(java.util.function.Consumer) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) ContractDeleteTransactionBody(com.hederahashgraph.api.proto.java.ContractDeleteTransactionBody) Optional(java.util.Optional) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) ContractDeleteTransactionBody(com.hederahashgraph.api.proto.java.ContractDeleteTransactionBody)

Example 74 with HapiApiSpec

use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.

the class HapiContractUpdate method opBodyDef.

@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
    Optional<Key> key = newKey.map(spec.registry()::getKey);
    ContractUpdateTransactionBody opBody = spec.txns().<ContractUpdateTransactionBody, ContractUpdateTransactionBody.Builder>body(ContractUpdateTransactionBody.class, b -> {
        if (contract.length() == HEXED_EVM_ADDRESS_LEN) {
            b.setContractID(ContractID.newBuilder().setEvmAddress(ByteString.copyFrom(CommonUtils.unhex(contract))));
        } else {
            b.setContractID(TxnUtils.asContractId(contract, spec));
        }
        if (useDeprecatedAdminKey) {
            b.setAdminKey(DEPRECATED_CID_ADMIN_KEY);
        } else if (wipeToThresholdKey) {
            b.setAdminKey(TxnUtils.EMPTY_THRESHOLD_KEY);
        } else if (useEmptyAdminKeyList) {
            b.setAdminKey(TxnUtils.EMPTY_KEY_LIST);
        } else {
            key.ifPresent(b::setAdminKey);
        }
        newExpirySecs.ifPresent(t -> b.setExpirationTime(Timestamp.newBuilder().setSeconds(t).build()));
        newMemo.ifPresent(s -> {
            if (useDeprecatedMemoField) {
                b.setMemo(s);
            } else {
                b.setMemoWrapper(StringValue.newBuilder().setValue(s).build());
            }
        });
        newAutoRenew.ifPresent(autoRenew -> b.setAutoRenewPeriod(Duration.newBuilder().setSeconds(autoRenew).build()));
        bytecode.ifPresent(f -> b.setFileID(TxnUtils.asFileId(bytecode.get(), spec)).build());
    });
    return builder -> builder.setContractUpdateInstance(opBody);
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) StringValue(com.google.protobuf.StringValue) HEXED_EVM_ADDRESS_LEN(com.hedera.services.bdd.spec.transactions.contract.HapiContractCall.HEXED_EVM_ADDRESS_LEN) ContractUpdateTransactionBody(com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody) Duration(com.hederahashgraph.api.proto.java.Duration) Function(java.util.function.Function) ArrayList(java.util.ArrayList) ContractID(com.hederahashgraph.api.proto.java.ContractID) OptionalLong(java.util.OptionalLong) TxnFactory(com.hedera.services.bdd.spec.transactions.TxnFactory) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) MoreObjects(com.google.common.base.MoreObjects) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) ByteString(com.google.protobuf.ByteString) Consumer(java.util.function.Consumer) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) Logger(org.apache.logging.log4j.Logger) CommonUtils(com.swirlds.common.CommonUtils) DEPRECATED_CID_ADMIN_KEY(com.hedera.services.bdd.spec.transactions.contract.HapiContractCreate.DEPRECATED_CID_ADMIN_KEY) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) Optional(java.util.Optional) FeeCalculator(com.hedera.services.bdd.spec.fees.FeeCalculator) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) ContractUpdateTransactionBody(com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody) Key(com.hederahashgraph.api.proto.java.Key)

Example 75 with HapiApiSpec

use of com.hedera.services.bdd.spec.HapiApiSpec 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);
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) StringValue(com.google.protobuf.StringValue) HEXED_EVM_ADDRESS_LEN(com.hedera.services.bdd.spec.transactions.contract.HapiContractCall.HEXED_EVM_ADDRESS_LEN) ContractUpdateTransactionBody(com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody) Duration(com.hederahashgraph.api.proto.java.Duration) Function(java.util.function.Function) ArrayList(java.util.ArrayList) ContractID(com.hederahashgraph.api.proto.java.ContractID) OptionalLong(java.util.OptionalLong) TxnFactory(com.hedera.services.bdd.spec.transactions.TxnFactory) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) MoreObjects(com.google.common.base.MoreObjects) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) ByteString(com.google.protobuf.ByteString) Consumer(java.util.function.Consumer) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) Logger(org.apache.logging.log4j.Logger) CommonUtils(com.swirlds.common.CommonUtils) DEPRECATED_CID_ADMIN_KEY(com.hedera.services.bdd.spec.transactions.contract.HapiContractCreate.DEPRECATED_CID_ADMIN_KEY) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) Optional(java.util.Optional) 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) Timestamp(com.hederahashgraph.api.proto.java.Timestamp)

Aggregations

HapiApiSpec (com.hedera.services.bdd.spec.HapiApiSpec)140 List (java.util.List)134 LogManager (org.apache.logging.log4j.LogManager)125 Logger (org.apache.logging.log4j.Logger)125 HapiApiSuite (com.hedera.services.bdd.suites.HapiApiSuite)84 UtilVerbs.withOpContext (com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext)78 HapiApiSpec.defaultHapiSpec (com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec)76 TxnVerbs.cryptoCreate (com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate)69 SUCCESS (com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS)65 Function (java.util.function.Function)63 HapiSpecOperation (com.hedera.services.bdd.spec.HapiSpecOperation)58 TxnVerbs.cryptoTransfer (com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer)56 ByteString (com.google.protobuf.ByteString)53 Key (com.hederahashgraph.api.proto.java.Key)52 CustomSpecAssert.allRunFor (com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor)51 Optional (java.util.Optional)50 UtilVerbs.newKeyNamed (com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyNamed)49 Consumer (java.util.function.Consumer)49 QueryVerbs.getAccountBalance (com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountBalance)47 TxnVerbs.fileCreate (com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate)46