Search in sources :

Example 6 with FeeComponents

use of com.hederahashgraph.api.proto.java.FeeComponents 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 7 with FeeComponents

use of com.hederahashgraph.api.proto.java.FeeComponents in project hedera-services by hashgraph.

the class SmartContractFeeBuilder method getContractByteCodeQueryFeeMatrices.

/**
 * This method returns the fee matrices for contract byte code query
 *
 * @param byteCodeSize
 * 		byte code size
 * @param responseType
 * 		response type
 * @return fee data
 */
public FeeData getContractByteCodeQueryFeeMatrices(int byteCodeSize, ResponseType responseType) {
    // get the Fee Matrices
    long bpt = 0;
    long vpt = 0;
    long rbs = 0;
    long sbs = 0;
    long gas = 0;
    long tv = 0;
    long bpr = 0;
    long sbpr = 0;
    /*
		 * ContractGetBytecodeQuery QueryHeader Transaction - CryptoTransfer - (will be taken care in
		 * Transaction processing) ResponseType - INT_SIZE ContractID - BASIC_ENTITY_ID_SIZE
		 */
    bpt = calculateBPT();
    /*
		 *
		 * Response header NodeTransactionPrecheckCode - 4 bytes ResponseType - 4 bytes
		 *
		 * bytes bytescode - calculated value
		 *
		 */
    bpr = BASIC_QUERY_RES_HEADER + getStateProofSize(responseType);
    sbpr = byteCodeSize;
    FeeComponents feeMatrices = FeeComponents.newBuilder().setBpt(bpt).setVpt(vpt).setRbh(rbs).setSbh(sbs).setGas(gas).setTv(tv).setBpr(bpr).setSbpr(sbpr).build();
    return getQueryFeeDataMatrices(feeMatrices);
}
Also used : FeeComponents(com.hederahashgraph.api.proto.java.FeeComponents)

Example 8 with FeeComponents

use of com.hederahashgraph.api.proto.java.FeeComponents in project hedera-services by hashgraph.

the class SmartContractFeeBuilder method getContractCallLocalFeeMatrices.

/**
 * This method returns fee matrices for contract call local
 *
 * @param funcParamSize
 * 		function parameter size
 * @param contractFuncResult
 * 		contract function result
 * @param responseType
 * 		response type
 * @return fee data
 */
public FeeData getContractCallLocalFeeMatrices(int funcParamSize, ContractFunctionResult contractFuncResult, ResponseType responseType) {
    // get the Fee Matrices
    long bpt = 0;
    long vpt = 0;
    long rbs = 0;
    long sbs = 0;
    long gas = 0;
    long tv = 0;
    long bpr = 0;
    long sbpr = 0;
    /*
		 * QueryHeader header Transaction - CryptoTransfer - (will be taken care in Transaction
		 * processing) ResponseType - INT_SIZE ContractID contractID - BASIC_ENTITY_ID_SIZE int64 gas -
		 * LONG_SIZE bytes functionParameters - calculated value int64 maxResultSize - LONG_SIZE
		 */
    bpt = BASIC_QUERY_HEADER + BASIC_ENTITY_ID_SIZE + LONG_SIZE + funcParamSize + LONG_SIZE;
    /*
		 *
		 * Response header NodeTransactionPrecheckCode - 4 bytes ResponseType - 4 bytes
		 * ContractFunctionResult ContractID contractID - BASIC_ENTITY_ID_SIZE bytes contractCallResult -
		 * Calculated Value string errorMessage - Calculated value bytes bloom - Calculated value uint64
		 * gasUsed - LONG_SIZE repeated ContractLoginfo ContractID contractID - BASIC_ENTITY_ID_SIZE bytes
		 * bloom - Calculated Value repeated bytes - Calculated Value bytes data - Calculated Value
		 *
		 */
    long errorMessageSize = 0;
    int contractFuncResultSize = 0;
    if (contractFuncResult != null) {
        if (contractFuncResult.getContractCallResult() != null) {
            contractFuncResultSize = contractFuncResult.getContractCallResult().size();
        }
        if (contractFuncResult.getErrorMessage() != null) {
            errorMessageSize = contractFuncResult.getErrorMessage().length();
        }
    }
    bpr = BASIC_QUERY_RES_HEADER + getStateProofSize(responseType);
    sbpr = BASIC_ENTITY_ID_SIZE + errorMessageSize + LONG_SIZE + contractFuncResultSize;
    FeeComponents feeMatrices = FeeComponents.newBuilder().setBpt(bpt).setVpt(vpt).setRbh(rbs).setSbh(sbs).setGas(gas).setTv(tv).setBpr(bpr).setSbpr(sbpr).build();
    return getQueryFeeDataMatrices(feeMatrices);
}
Also used : FeeComponents(com.hederahashgraph.api.proto.java.FeeComponents)

Example 9 with FeeComponents

use of com.hederahashgraph.api.proto.java.FeeComponents 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 10 with FeeComponents

use of com.hederahashgraph.api.proto.java.FeeComponents in project hedera-services by hashgraph.

the class TopicResourceUsageTestBase method checkFeeComponents.

protected void checkFeeComponents(FeeComponents actual, int bpt, int vpt, int rbh, int bpr) {
    FeeComponents expected = FeeComponents.newBuilder().setConstant(1).setBpt(bpt).setVpt(vpt).setRbh(rbh).setBpr(bpr).build();
    assertEquals(expected, actual);
}
Also used : FeeComponents(com.hederahashgraph.api.proto.java.FeeComponents)

Aggregations

FeeComponents (com.hederahashgraph.api.proto.java.FeeComponents)14 InvalidTxBodyException (com.hederahashgraph.exception.InvalidTxBodyException)7 Test (org.junit.jupiter.api.Test)1