Search in sources :

Example 1 with CurrencyAdjustments

use of com.hedera.services.state.submerkle.CurrencyAdjustments in project hedera-services by hashgraph.

the class RenewalHelper method doReturnToTreasury.

private void doReturnToTreasury(AccountID expired, TokenID scopedToken, Pair<List<EntityId>, List<CurrencyAdjustments>> displacements, MerkleMap<EntityNum, MerkleToken> currentTokens) {
    final var currentTokenRels = tokenRels.get();
    final var expiredRel = fromAccountTokenRel(expired, scopedToken);
    final var relStatus = currentTokenRels.get(expiredRel);
    final long balance = relStatus.getBalance();
    currentTokenRels.remove(expiredRel);
    final var tKey = EntityNum.fromTokenId(scopedToken);
    if (!currentTokens.containsKey(tKey)) {
        return;
    }
    final var token = currentTokens.get(tKey);
    if (token.isDeleted()) {
        return;
    }
    if (balance == 0L) {
        return;
    }
    final var treasury = token.treasury().toGrpcAccountId();
    final boolean expiredFirst = ACCOUNT_ID_COMPARATOR.compare(expired, treasury) < 0;
    displacements.getLeft().add(EntityId.fromGrpcTokenId(scopedToken));
    final var expiredId = EntityId.fromGrpcAccountId(expired);
    final var treasuryId = EntityId.fromGrpcAccountId(treasury);
    displacements.getRight().add(new CurrencyAdjustments(expiredFirst ? new long[] { -balance, +balance } : new long[] { +balance, -balance }, expiredFirst ? List.of(expiredId, treasuryId) : List.of(treasuryId, expiredId)));
    final var treasuryRel = fromAccountTokenRel(treasury, scopedToken);
    final var mutableTreasuryRelStatus = currentTokenRels.getForModify(treasuryRel);
    final long newTreasuryBalance = mutableTreasuryRelStatus.getBalance() + balance;
    mutableTreasuryRelStatus.setBalance(newTreasuryBalance);
}
Also used : CurrencyAdjustments(com.hedera.services.state.submerkle.CurrencyAdjustments)

Example 2 with CurrencyAdjustments

use of com.hedera.services.state.submerkle.CurrencyAdjustments in project hedera-services by hashgraph.

the class AccountsReader method from.

public static MerkleMap<EntityNum, MerkleAccount> from(String loc) throws Exception {
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(MerkleLong.class, MerkleLong::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(FCQueue.class, FCQueue::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(MerkleMap.class, MerkleMap::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(MerkleEntityId.class, MerkleEntityId::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(EntityId.class, EntityId::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(MerkleAccount.class, MerkleAccount::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(MerkleAccountState.class, MerkleAccountState::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(ExpirableTxnRecord.class, ExpirableTxnRecord::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(TxnReceipt.class, TxnReceipt::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(TxnId.class, TxnId::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(CurrencyAdjustments.class, CurrencyAdjustments::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(EvmFnResult.class, EvmFnResult::new));
    try (MerkleDataInputStream in = new MerkleDataInputStream(Files.newInputStream(Path.of(loc)))) {
        MerkleMap<EntityNum, MerkleAccount> fcm = in.readMerkleTree(Integer.MAX_VALUE);
        return fcm;
    }
}
Also used : ExpirableTxnRecord(com.hedera.services.state.submerkle.ExpirableTxnRecord) FCQueue(com.swirlds.fcqueue.FCQueue) MerkleDataInputStream(com.swirlds.common.merkle.io.MerkleDataInputStream) TxnReceipt(com.hedera.services.legacy.core.jproto.TxnReceipt) MerkleAccount(com.hedera.services.state.merkle.MerkleAccount) MerkleEntityId(com.hedera.services.state.merkle.MerkleEntityId) MerkleAccountState(com.hedera.services.state.merkle.MerkleAccountState) EntityNum(com.hedera.services.utils.EntityNum) MerkleLong(com.swirlds.common.merkle.utility.MerkleLong) EntityId(com.hedera.services.state.submerkle.EntityId) MerkleEntityId(com.hedera.services.state.merkle.MerkleEntityId) TxnId(com.hedera.services.state.submerkle.TxnId) EvmFnResult(com.hedera.services.state.submerkle.EvmFnResult) MerkleMap(com.swirlds.merkle.map.MerkleMap) CurrencyAdjustments(com.hedera.services.state.submerkle.CurrencyAdjustments) ClassConstructorPair(com.swirlds.common.constructable.ClassConstructorPair)

Example 3 with CurrencyAdjustments

use of com.hedera.services.state.submerkle.CurrencyAdjustments in project hedera-services by hashgraph.

the class FcmToJsonUtil method convertAccountsToJson.

@Test
void convertAccountsToJson() throws Exception {
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(MerkleLong.class, MerkleLong::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(FCQueue.class, FCQueue::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(MerkleEntityId.class, MerkleEntityId::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(EntityId.class, EntityId::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(MerkleAccount.class, MerkleAccount::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(MerkleAccountState.class, MerkleAccountState::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(ExpirableTxnRecord.class, ExpirableTxnRecord::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(TxnReceipt.class, TxnReceipt::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(TxnId.class, TxnId::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(CurrencyAdjustments.class, CurrencyAdjustments::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(EvmFnResult.class, EvmFnResult::new));
    for (String dumpLoc : accountsLocs) {
        PojoLedger.fromDisk(dumpLoc).asJsonTo(jsonSuffixed(dumpLoc));
    }
}
Also used : ExpirableTxnRecord(com.hedera.services.state.submerkle.ExpirableTxnRecord) FCQueue(com.swirlds.fcqueue.FCQueue) TxnReceipt(com.hedera.services.legacy.core.jproto.TxnReceipt) MerkleAccount(com.hedera.services.state.merkle.MerkleAccount) MerkleEntityId(com.hedera.services.state.merkle.MerkleEntityId) MerkleAccountState(com.hedera.services.state.merkle.MerkleAccountState) MerkleLong(com.swirlds.common.merkle.utility.MerkleLong) EntityId(com.hedera.services.state.submerkle.EntityId) MerkleEntityId(com.hedera.services.state.merkle.MerkleEntityId) TxnId(com.hedera.services.state.submerkle.TxnId) EvmFnResult(com.hedera.services.state.submerkle.EvmFnResult) CurrencyAdjustments(com.hedera.services.state.submerkle.CurrencyAdjustments) ClassConstructorPair(com.swirlds.common.constructable.ClassConstructorPair) Test(org.junit.jupiter.api.Test)

Example 4 with CurrencyAdjustments

use of com.hedera.services.state.submerkle.CurrencyAdjustments in project hedera-services by hashgraph.

the class BasicTransactionContextTest method buildExpectedRecord.

private ExpirableTxnRecord.Builder buildExpectedRecord(long otherNonThresholdFees, byte[] hash, TxnAccessor accessor, Instant consensusTime, TxnReceipt receipt) {
    long amount = narratedCharging.totalFeesChargedToPayer() + otherNonThresholdFees;
    TransferList transfersList = transfers;
    List<TokenTransferList> tokenTransferList = List.of(tokenTransfers);
    var builder = ExpirableTxnRecord.newBuilder().setReceipt(receipt).setTxnHash(hash).setTxnId(TxnId.fromGrpc(accessor.getTxnId())).setConsensusTime(RichInstant.fromJava(consensusTime)).setMemo(accessor.getTxn().getMemo()).setFee(amount).setTransferList(!transfersList.getAccountAmountsList().isEmpty() ? CurrencyAdjustments.fromGrpc(transfersList) : null).setScheduleRef(accessor.isTriggeredTxn() ? fromGrpcScheduleId(accessor.getScheduleRef()) : null).setNewTokenAssociations(newTokenAssociations);
    List<EntityId> tokens = new ArrayList<>();
    List<CurrencyAdjustments> tokenAdjustments = new ArrayList<>();
    for (TokenTransferList tokenTransfers : tokenTransferList) {
        tokens.add(EntityId.fromGrpcTokenId(tokenTransfers.getToken()));
        tokenAdjustments.add(CurrencyAdjustments.fromGrpc(tokenTransfers.getTransfersList()));
    }
    builder.setTokens(tokens).setTokenAdjustments(tokenAdjustments);
    return builder;
}
Also used : EntityId(com.hedera.services.state.submerkle.EntityId) TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) ArrayList(java.util.ArrayList) CurrencyAdjustments(com.hedera.services.state.submerkle.CurrencyAdjustments) TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) TransferList(com.hederahashgraph.api.proto.java.TransferList)

Aggregations

CurrencyAdjustments (com.hedera.services.state.submerkle.CurrencyAdjustments)4 EntityId (com.hedera.services.state.submerkle.EntityId)3 TxnReceipt (com.hedera.services.legacy.core.jproto.TxnReceipt)2 MerkleAccount (com.hedera.services.state.merkle.MerkleAccount)2 MerkleAccountState (com.hedera.services.state.merkle.MerkleAccountState)2 MerkleEntityId (com.hedera.services.state.merkle.MerkleEntityId)2 EvmFnResult (com.hedera.services.state.submerkle.EvmFnResult)2 ExpirableTxnRecord (com.hedera.services.state.submerkle.ExpirableTxnRecord)2 TxnId (com.hedera.services.state.submerkle.TxnId)2 ClassConstructorPair (com.swirlds.common.constructable.ClassConstructorPair)2 MerkleLong (com.swirlds.common.merkle.utility.MerkleLong)2 FCQueue (com.swirlds.fcqueue.FCQueue)2 EntityNum (com.hedera.services.utils.EntityNum)1 TokenTransferList (com.hederahashgraph.api.proto.java.TokenTransferList)1 TransferList (com.hederahashgraph.api.proto.java.TransferList)1 MerkleDataInputStream (com.swirlds.common.merkle.io.MerkleDataInputStream)1 MerkleMap (com.swirlds.merkle.map.MerkleMap)1 ArrayList (java.util.ArrayList)1 Test (org.junit.jupiter.api.Test)1