Search in sources :

Example 1 with InvalidTxBodyException

use of com.hederahashgraph.exception.InvalidTxBodyException in project hedera-services by hashgraph.

the class FileFeeBuilder method getSystemDeleteFileTxFeeMatrices.

public FeeData getSystemDeleteFileTxFeeMatrices(TransactionBody txBody, SigValueObj numSignatures) throws InvalidTxBodyException {
    if (txBody == null || !txBody.hasSystemDelete()) {
        throw new InvalidTxBodyException("System Delete Tx Body not available for Fee Calculation");
    }
    long bpt = 0;
    long vpt = 0;
    long rbs = 0;
    long sbs = 0;
    long gas = 0;
    long tv = 0;
    long bpr = 0;
    long sbpr = 0;
    // get the bytes per second
    bpt = getCommonTransactionBodyBytes(txBody);
    bpt = bpt + BASIC_ENTITY_ID_SIZE + LONG_SIZE;
    vpt = numSignatures.getTotalSigCount();
    rbs = calculateRBS(txBody);
    long rbsNetwork = getDefaultRBHNetworkSize();
    // sbs should not be charged as the fee for storage was already paid. What if expiration is changed though?
    FeeComponents feeMatricesForTx = FeeComponents.newBuilder().setBpt(bpt).setVpt(vpt).setRbh(rbs).setSbh(sbs).setGas(gas).setTv(tv).setBpr(bpr).setSbpr(sbpr).build();
    return getFeeDataMatrices(feeMatricesForTx, numSignatures.getPayerAcctSigCount(), rbsNetwork);
}
Also used : InvalidTxBodyException(com.hederahashgraph.exception.InvalidTxBodyException) FeeComponents(com.hederahashgraph.api.proto.java.FeeComponents)

Example 2 with InvalidTxBodyException

use of com.hederahashgraph.exception.InvalidTxBodyException in project hedera-services by hashgraph.

the class FileFeeBuilder method getFileDeleteTxFeeMatrices.

public FeeData getFileDeleteTxFeeMatrices(TransactionBody txBody, SigValueObj sigValObj) throws InvalidTxBodyException {
    if (txBody == null || !txBody.hasFileDelete()) {
        throw new InvalidTxBodyException("FileDelete Tx Body not available for Fee Calculation");
    }
    long bpt = 0;
    long vpt = 0;
    long rbs = 0;
    long sbs = 0;
    long gas = 0;
    long tv = 0;
    long bpr = 0;
    long sbpr = 0;
    final long txBodySize = getCommonTransactionBodyBytes(txBody);
    // bpt - Bytes per Transaction
    bpt = txBodySize + BASIC_ENTITY_ID_SIZE + sigValObj.getSignatureSize();
    // vpt - verifications per transactions
    vpt = sigValObj.getTotalSigCount();
    bpr = INT_SIZE;
    rbs = calculateRBS(txBody);
    long rbsNetwork = getDefaultRBHNetworkSize();
    FeeComponents feeMatricesForTx = FeeComponents.newBuilder().setBpt(bpt).setVpt(vpt).setRbh(rbs).setSbh(sbs).setGas(gas).setTv(tv).setBpr(bpr).setSbpr(sbpr).build();
    return getFeeDataMatrices(feeMatricesForTx, sigValObj.getPayerAcctSigCount(), rbsNetwork);
}
Also used : InvalidTxBodyException(com.hederahashgraph.exception.InvalidTxBodyException) FeeComponents(com.hederahashgraph.api.proto.java.FeeComponents)

Example 3 with InvalidTxBodyException

use of com.hederahashgraph.exception.InvalidTxBodyException in project hedera-services by hashgraph.

the class SmartContractFeeBuilder method getContractCallTxFeeMatrices.

/**
 * This method returns fee matrices for contract call transaction
 *
 * @param txBody
 * 		transaction body
 * @param sigValObj
 * 		signature value object
 * @return fee data
 * @throws InvalidTxBodyException
 * 		when transaction body is invalid
 */
public FeeData getContractCallTxFeeMatrices(TransactionBody txBody, SigValueObj sigValObj) throws InvalidTxBodyException {
    if (txBody == null || !txBody.hasContractCall()) {
        throw new InvalidTxBodyException("ContractCreateInstance Tx Body not available for Fee Calculation");
    }
    long bpt = 0;
    long vpt = 0;
    long rbs = 0;
    long sbs = 0;
    long gas = 0;
    long tv = 0;
    long bpr = 0;
    long sbpr = 0;
    long txBodySize = 0;
    txBodySize = getCommonTransactionBodyBytes(txBody);
    // bpt - Bytes per Transaction
    bpt = txBodySize + getContractCallBodyTxSize(txBody) + sigValObj.getSignatureSize();
    // vpt - verifications per transactions
    vpt = sigValObj.getTotalSigCount();
    bpr = INT_SIZE;
    rbs = getBaseTransactionRecordSize(txBody) * (RECEIPT_STORAGE_TIME_SEC + THRESHOLD_STORAGE_TIME_SEC);
    long rbsNetwork = getDefaultRBHNetworkSize();
    FeeComponents feeMatricesForTx = FeeComponents.newBuilder().setBpt(bpt).setVpt(vpt).setRbh(rbs).setSbh(sbs).setGas(gas).setTv(tv).setBpr(bpr).setSbpr(sbpr).build();
    return getFeeDataMatrices(feeMatricesForTx, sigValObj.getPayerAcctSigCount(), rbsNetwork);
}
Also used : InvalidTxBodyException(com.hederahashgraph.exception.InvalidTxBodyException) FeeComponents(com.hederahashgraph.api.proto.java.FeeComponents)

Example 4 with InvalidTxBodyException

use of com.hederahashgraph.exception.InvalidTxBodyException in project hedera-services by hashgraph.

the class SmartContractFeeBuilder method getContractUpdateTxFeeMatrices.

/**
 * This method returns fee matrices for contract update transaction
 *
 * @param txBody
 * 		transaction body
 * @param contractExpiryTime
 * 		contract expiration time
 * @param sigValObj
 * 		signature value object
 * @return fee data
 * @throws InvalidTxBodyException
 * 		when transaction body is invalid
 */
public FeeData getContractUpdateTxFeeMatrices(TransactionBody txBody, Timestamp contractExpiryTime, SigValueObj sigValObj) throws InvalidTxBodyException {
    if (txBody == null || !txBody.hasContractUpdateInstance()) {
        throw new InvalidTxBodyException("ContractUpdateInstance Tx Body not available for Fee Calculation");
    }
    long bpt = 0;
    long vpt = 0;
    long rbs = 0;
    long sbs = 0;
    long gas = 0;
    long tv = 0;
    long bpr = 0;
    long sbpr = 0;
    long txBodySize = 0;
    txBodySize = getCommonTransactionBodyBytes(txBody);
    // bpt - Bytes per Transaction
    bpt = txBodySize + getContractUpdateBodyTxSize(txBody) + sigValObj.getSignatureSize();
    // vpt - verifications per transactions
    vpt = sigValObj.getTotalSigCount();
    bpr = INT_SIZE;
    if (contractExpiryTime != null && contractExpiryTime.getSeconds() > 0) {
        sbs = getContractUpdateStorageBytesSec(txBody, contractExpiryTime);
    }
    long rbsNetwork = getDefaultRBHNetworkSize();
    rbs = getBaseTransactionRecordSize(txBody) * (RECEIPT_STORAGE_TIME_SEC + THRESHOLD_STORAGE_TIME_SEC);
    FeeComponents feeMatricesForTx = FeeComponents.newBuilder().setBpt(bpt).setVpt(vpt).setRbh(rbs).setSbh(sbs).setGas(gas).setTv(tv).setBpr(bpr).setSbpr(sbpr).build();
    return getFeeDataMatrices(feeMatricesForTx, sigValObj.getPayerAcctSigCount(), rbsNetwork);
}
Also used : InvalidTxBodyException(com.hederahashgraph.exception.InvalidTxBodyException) FeeComponents(com.hederahashgraph.api.proto.java.FeeComponents)

Example 5 with InvalidTxBodyException

use of com.hederahashgraph.exception.InvalidTxBodyException in project hedera-services by hashgraph.

the class UpdateTopicResourceUsage method usageGiven.

@Override
public FeeData usageGiven(@Nullable final TransactionBody txnBody, final SigValueObj sigUsage, @Nullable final StateView view) throws InvalidTxBodyException, IllegalStateException {
    if (txnBody == null || !txnBody.hasConsensusUpdateTopic()) {
        throw new InvalidTxBodyException("consensusUpdateTopic field not available for Fee Calculation");
    }
    if (view == null) {
        throw new IllegalStateException("No StateView present !!");
    }
    long rbsIncrease = 0;
    final var merkleTopic = view.topics().get(EntityNum.fromTopicId(txnBody.getConsensusUpdateTopic().getTopicID()));
    if (merkleTopic != null && merkleTopic.hasAdminKey()) {
        final var expiry = Timestamp.newBuilder().setSeconds(merkleTopic.getExpirationTimestamp().getSeconds()).build();
        try {
            rbsIncrease = getUpdateTopicRbsIncrease(txnBody.getTransactionID().getTransactionValidStart(), JKey.mapJKey(merkleTopic.getAdminKey()), JKey.mapJKey(merkleTopic.getSubmitKey()), merkleTopic.getMemo(), merkleTopic.hasAutoRenewAccountId(), expiry, txnBody.getConsensusUpdateTopic());
        } catch (final DecoderException illegal) {
            log.warn("Usage estimation unexpectedly failed for {}!", txnBody, illegal);
            throw new InvalidTxBodyException(illegal);
        }
    }
    return getConsensusUpdateTopicFee(txnBody, rbsIncrease, sigUsage);
}
Also used : DecoderException(org.apache.commons.codec.DecoderException) InvalidTxBodyException(com.hederahashgraph.exception.InvalidTxBodyException)

Aggregations

InvalidTxBodyException (com.hederahashgraph.exception.InvalidTxBodyException)9 FeeComponents (com.hederahashgraph.api.proto.java.FeeComponents)7 Timestamp (com.hederahashgraph.api.proto.java.Timestamp)1 DecoderException (org.apache.commons.codec.DecoderException)1