Search in sources :

Example 11 with FeeComponents

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

the class FileFeeBuilder method getSystemUnDeleteFileTxFeeMatrices.

public FeeData getSystemUnDeleteFileTxFeeMatrices(TransactionBody txBody, SigValueObj numSignatures) throws InvalidTxBodyException {
    if (txBody == null || !txBody.hasSystemUndelete()) {
        throw new InvalidTxBodyException("System UnDelete 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 12 with FeeComponents

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

the class SmartContractFeeBuilder method getContractCreateTxFeeMatrices.

/**
 * This method returns fee matrices for contract create transaction
 *
 * @param txBody
 * 		transaction body
 * @param sigValObj
 * 		signature value object
 * @return fee data
 * @throws InvalidTxBodyException
 * 		when transaction body is invalid
 */
public FeeData getContractCreateTxFeeMatrices(TransactionBody txBody, SigValueObj sigValObj) throws InvalidTxBodyException {
    if (txBody == null || !txBody.hasContractCreateInstance()) {
        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;
    // calculate BPT - Total Bytes in Transaction
    long txBodySize = 0;
    txBodySize = getCommonTransactionBodyBytes(txBody);
    bpt = txBodySize + getContractCreateTransactionBodySize(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() + BASIC_ENTITY_ID_SIZE * (RECEIPT_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 13 with FeeComponents

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

the class SmartContractFeeBuilder method getContractDeleteTxFeeMatrices.

public FeeData getContractDeleteTxFeeMatrices(TransactionBody txBody, SigValueObj sigValObj) throws InvalidTxBodyException {
    if (txBody == null || !txBody.hasContractDeleteInstance()) {
        throw new InvalidTxBodyException("ContractDelete 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;
    // calculate BPT - Total Bytes in Transaction
    long txBodySize = 0;
    txBodySize = getCommonTransactionBodyBytes(txBody);
    /*
		 * ContractID contractID = BASIC_ENTITY_ID_SIZE oneof obtainers { AccountID transferAccountID =
		 * BASIC_ENTITY_ID_SIZE
		 * ContractID transferContractID = BASIC_ENTITY_ID_SIZE }
		 */
    bpt = txBodySize + BASIC_ENTITY_ID_SIZE + BASIC_ENTITY_ID_SIZE + sigValObj.getSignatureSize();
    // vpt - verifications per transactions
    vpt = sigValObj.getTotalSigCount();
    bpr = INT_SIZE;
    rbs = calculateRBS(txBody);
    long rbsNetwork = getDefaultRBHNetworkSize() + BASIC_ENTITY_ID_SIZE * (RECEIPT_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 14 with FeeComponents

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

the class FeeCalcUtilsTest method sumsAsExpected.

@Test
void sumsAsExpected() {
    final var aComp = FeeComponents.newBuilder().setMin(2).setMax(1_234_567).setConstant(1).setBpt(2).setVpt(3).setRbh(4).setSbh(5).setGas(6).setTv(7).setBpr(8).setSbpr(9);
    final var bComp = FeeComponents.newBuilder().setMin(1).setMax(1_234_566).setConstant(9).setBpt(8).setVpt(7).setRbh(6).setSbh(5).setGas(4).setTv(3).setBpr(2).setSbpr(1);
    final var a = FeeData.newBuilder().setNetworkdata(aComp).setNodedata(aComp).setServicedata(aComp).build();
    final var b = FeeData.newBuilder().setNetworkdata(bComp).setNodedata(bComp).setServicedata(bComp).build();
    final var c = sumOfUsages(a, b);
    final var scopedUsages = new FeeComponents[] { c.getNodedata(), c.getNetworkdata(), c.getServicedata() };
    for (FeeComponents scopedUsage : scopedUsages) {
        assertEquals(1, scopedUsage.getMin());
        assertEquals(1_234_567, scopedUsage.getMax());
        assertEquals(10, scopedUsage.getConstant());
        assertEquals(10, scopedUsage.getBpt());
        assertEquals(10, scopedUsage.getVpt());
        assertEquals(10, scopedUsage.getRbh());
        assertEquals(10, scopedUsage.getSbh());
        assertEquals(10, scopedUsage.getGas());
        assertEquals(10, scopedUsage.getTv());
        assertEquals(10, scopedUsage.getBpr());
        assertEquals(10, scopedUsage.getSbpr());
    }
}
Also used : FeeComponents(com.hederahashgraph.api.proto.java.FeeComponents) Test(org.junit.jupiter.api.Test)

Aggregations

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