Search in sources :

Example 1 with CryptoTransferMeta

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

the class AccessorBasedUsagesTest method worksAsExpectedForCryptoTransfer.

@Test
void worksAsExpectedForCryptoTransfer() {
    int multiplier = 30;
    final var baseMeta = new BaseTransactionMeta(100, 2);
    final var xferMeta = new CryptoTransferMeta(1, 3, 7, 4);
    final var usageAccumulator = new UsageAccumulator();
    given(dynamicProperties.feesTokenTransferUsageMultiplier()).willReturn(multiplier);
    given(txnAccessor.getFunction()).willReturn(CryptoTransfer);
    given(txnAccessor.availXferUsageMeta()).willReturn(xferMeta);
    given(txnAccessor.baseUsageMeta()).willReturn(baseMeta);
    subject.assess(sigUsage, txnAccessor, usageAccumulator);
    verify(cryptoOpsUsage).cryptoTransferUsage(sigUsage, xferMeta, baseMeta, usageAccumulator);
    assertEquals(multiplier, xferMeta.getTokenMultiplier());
}
Also used : BaseTransactionMeta(com.hedera.services.usage.BaseTransactionMeta) CryptoTransferMeta(com.hedera.services.usage.crypto.CryptoTransferMeta) UsageAccumulator(com.hedera.services.usage.state.UsageAccumulator) TokenMint(com.hederahashgraph.api.proto.java.HederaFunctionality.TokenMint) Test(org.junit.jupiter.api.Test)

Example 2 with CryptoTransferMeta

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

the class SignedTxnAccessor method setXferUsageMeta.

private void setXferUsageMeta() {
    var totalTokensInvolved = 0;
    var totalTokenTransfers = 0;
    var numNftOwnershipChanges = 0;
    final var op = txn.getCryptoTransfer();
    for (var tokenTransfers : op.getTokenTransfersList()) {
        totalTokensInvolved++;
        totalTokenTransfers += tokenTransfers.getTransfersCount();
        numNftOwnershipChanges += tokenTransfers.getNftTransfersCount();
    }
    xferUsageMeta = new CryptoTransferMeta(1, totalTokensInvolved, totalTokenTransfers, numNftOwnershipChanges);
}
Also used : CryptoTransferMeta(com.hedera.services.usage.crypto.CryptoTransferMeta)

Aggregations

CryptoTransferMeta (com.hedera.services.usage.crypto.CryptoTransferMeta)2 BaseTransactionMeta (com.hedera.services.usage.BaseTransactionMeta)1 UsageAccumulator (com.hedera.services.usage.state.UsageAccumulator)1 TokenMint (com.hederahashgraph.api.proto.java.HederaFunctionality.TokenMint)1 Test (org.junit.jupiter.api.Test)1