Search in sources :

Example 1 with MerkleAccount

use of com.hedera.services.state.merkle.MerkleAccount in project hedera-services by hashgraph.

the class HederaTokenStoreTest method setup.

@BeforeEach
void setup() {
    token = mock(MerkleToken.class);
    given(token.expiry()).willReturn(expiry);
    given(token.symbol()).willReturn(symbol);
    given(token.hasAutoRenewAccount()).willReturn(true);
    given(token.adminKey()).willReturn(Optional.of(TOKEN_ADMIN_KT.asJKeyUnchecked()));
    given(token.name()).willReturn(name);
    given(token.hasAdminKey()).willReturn(true);
    given(token.hasFeeScheduleKey()).willReturn(true);
    given(token.treasury()).willReturn(EntityId.fromGrpcAccountId(treasury));
    given(token.tokenType()).willReturn(TokenType.FUNGIBLE_COMMON);
    given(token.decimals()).willReturn(2);
    nonfungibleToken = mock(MerkleToken.class);
    given(nonfungibleToken.hasAdminKey()).willReturn(true);
    given(nonfungibleToken.tokenType()).willReturn(TokenType.NON_FUNGIBLE_UNIQUE);
    ids = mock(EntityIdSource.class);
    given(ids.newTokenId(sponsor)).willReturn(created);
    hederaLedger = mock(HederaLedger.class);
    nftsLedger = (TransactionalLedger<NftId, NftProperty, MerkleUniqueToken>) mock(TransactionalLedger.class);
    given(nftsLedger.get(aNft, NftProperty.OWNER)).willReturn(EntityId.fromGrpcAccountId(sponsor));
    given(nftsLedger.get(tNft, NftProperty.OWNER)).willReturn(EntityId.fromGrpcAccountId(primaryTreasury));
    given(nftsLedger.exists(aNft)).willReturn(true);
    given(nftsLedger.exists(tNft)).willReturn(true);
    accountsLedger = (TransactionalLedger<AccountID, AccountProperty, MerkleAccount>) mock(TransactionalLedger.class);
    given(accountsLedger.exists(treasury)).willReturn(true);
    given(accountsLedger.exists(anotherFeeCollector)).willReturn(true);
    given(accountsLedger.exists(autoRenewAccount)).willReturn(true);
    given(accountsLedger.exists(newAutoRenewAccount)).willReturn(true);
    given(accountsLedger.exists(primaryTreasury)).willReturn(true);
    given(accountsLedger.exists(sponsor)).willReturn(true);
    given(accountsLedger.exists(counterparty)).willReturn(true);
    given(accountsLedger.get(treasury, IS_DELETED)).willReturn(false);
    given(accountsLedger.get(autoRenewAccount, IS_DELETED)).willReturn(false);
    given(accountsLedger.get(newAutoRenewAccount, IS_DELETED)).willReturn(false);
    given(accountsLedger.get(sponsor, IS_DELETED)).willReturn(false);
    given(accountsLedger.get(counterparty, IS_DELETED)).willReturn(false);
    given(accountsLedger.get(primaryTreasury, IS_DELETED)).willReturn(false);
    backingTokens = mock(BackingTokens.class);
    given(backingTokens.contains(misc)).willReturn(true);
    given(backingTokens.contains(nonfungible)).willReturn(true);
    given(backingTokens.getRef(created)).willReturn(token);
    given(backingTokens.getImmutableRef(created)).willReturn(token);
    given(backingTokens.getRef(misc)).willReturn(token);
    given(backingTokens.getImmutableRef(misc)).willReturn(token);
    given(backingTokens.getRef(nonfungible)).willReturn(nonfungibleToken);
    given(backingTokens.getImmutableRef(tNft.tokenId())).willReturn(nonfungibleToken);
    given(backingTokens.getImmutableRef(tNft.tokenId()).treasury()).willReturn(EntityId.fromGrpcAccountId(primaryTreasury));
    given(backingTokens.idSet()).willReturn(Set.of(created));
    tokenRelsLedger = mock(TransactionalLedger.class);
    given(tokenRelsLedger.exists(sponsorMisc)).willReturn(true);
    given(tokenRelsLedger.exists(treasuryNft)).willReturn(true);
    given(tokenRelsLedger.exists(sponsorNft)).willReturn(true);
    given(tokenRelsLedger.exists(counterpartyNft)).willReturn(true);
    given(tokenRelsLedger.get(sponsorMisc, TOKEN_BALANCE)).willReturn(sponsorBalance);
    given(tokenRelsLedger.get(sponsorMisc, IS_FROZEN)).willReturn(false);
    given(tokenRelsLedger.get(sponsorMisc, IS_KYC_GRANTED)).willReturn(true);
    given(tokenRelsLedger.exists(treasuryMisc)).willReturn(true);
    given(tokenRelsLedger.exists(anotherFeeCollectorMisc)).willReturn(true);
    given(tokenRelsLedger.get(treasuryMisc, TOKEN_BALANCE)).willReturn(treasuryBalance);
    given(tokenRelsLedger.get(treasuryMisc, IS_FROZEN)).willReturn(false);
    given(tokenRelsLedger.get(treasuryMisc, IS_KYC_GRANTED)).willReturn(true);
    given(tokenRelsLedger.get(treasuryNft, TOKEN_BALANCE)).willReturn(123L);
    given(tokenRelsLedger.get(treasuryNft, IS_FROZEN)).willReturn(false);
    given(tokenRelsLedger.get(treasuryNft, IS_KYC_GRANTED)).willReturn(true);
    given(tokenRelsLedger.get(sponsorNft, TOKEN_BALANCE)).willReturn(123L);
    given(tokenRelsLedger.get(sponsorNft, IS_FROZEN)).willReturn(false);
    given(tokenRelsLedger.get(sponsorNft, IS_KYC_GRANTED)).willReturn(true);
    given(tokenRelsLedger.get(counterpartyNft, TOKEN_BALANCE)).willReturn(123L);
    given(tokenRelsLedger.get(counterpartyNft, IS_FROZEN)).willReturn(false);
    given(tokenRelsLedger.get(counterpartyNft, IS_KYC_GRANTED)).willReturn(true);
    given(tokenRelsLedger.get(newTreasuryNft, TOKEN_BALANCE)).willReturn(1L);
    properties = mock(GlobalDynamicProperties.class);
    given(properties.maxTokensPerAccount()).willReturn(MAX_TOKENS_PER_ACCOUNT);
    given(properties.maxTokenSymbolUtf8Bytes()).willReturn(MAX_TOKEN_SYMBOL_UTF8_BYTES);
    given(properties.maxTokenNameUtf8Bytes()).willReturn(MAX_TOKEN_NAME_UTF8_BYTES);
    given(properties.maxCustomFeesAllowed()).willReturn(maxCustomFees);
    sideEffectsTracker = new SideEffectsTracker();
    subject = new HederaTokenStore(ids, TEST_VALIDATOR, sideEffectsTracker, properties, tokenRelsLedger, nftsLedger, backingTokens);
    subject.setAccountsLedger(accountsLedger);
    subject.setHederaLedger(hederaLedger);
    subject.knownTreasuries.put(treasury, new HashSet<>() {

        {
            add(misc);
        }
    });
}
Also used : BackingTokens(com.hedera.services.ledger.backing.BackingTokens) EntityIdSource(com.hedera.services.ledger.ids.EntityIdSource) AccountID(com.hederahashgraph.api.proto.java.AccountID) HederaLedger(com.hedera.services.ledger.HederaLedger) SideEffectsTracker(com.hedera.services.context.SideEffectsTracker) MerkleToken(com.hedera.services.state.merkle.MerkleToken) MerkleAccount(com.hedera.services.state.merkle.MerkleAccount) GlobalDynamicProperties(com.hedera.services.context.properties.GlobalDynamicProperties) NftId(com.hedera.services.store.models.NftId) NftProperty(com.hedera.services.ledger.properties.NftProperty) AccountProperty(com.hedera.services.ledger.properties.AccountProperty) TransactionalLedger(com.hedera.services.ledger.TransactionalLedger) MerkleUniqueToken(com.hedera.services.state.merkle.MerkleUniqueToken) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with MerkleAccount

use of com.hedera.services.state.merkle.MerkleAccount in project hedera-services by hashgraph.

the class WorldLedgersTest method wrapsAsExpectedWithoutCommitInterceptors.

@Test
void wrapsAsExpectedWithoutCommitInterceptors() {
    final var liveTokenRels = new TransactionalLedger<>(TokenRelProperty.class, MerkleTokenRelStatus::new, new HashMapBackingTokenRels(), new ChangeSummaryManager<>());
    final var liveAccounts = new TransactionalLedger<>(AccountProperty.class, MerkleAccount::new, new HashMapBackingAccounts(), new ChangeSummaryManager<>());
    final var liveNfts = new TransactionalLedger<>(NftProperty.class, MerkleUniqueToken::new, new HashMapBackingNfts(), new ChangeSummaryManager<>());
    final var liveTokens = new TransactionalLedger<>(TokenProperty.class, MerkleToken::new, new HashMapBackingTokens(), new ChangeSummaryManager<>());
    final var liveAliases = new AliasManager();
    final var source = new WorldLedgers(liveAliases, liveTokenRels, liveAccounts, liveNfts, liveTokens);
    assertTrue(source.areMutable());
    final var nullTokenRels = new WorldLedgers(liveAliases, null, liveAccounts, liveNfts, liveTokens);
    final var nullAccounts = new WorldLedgers(liveAliases, liveTokenRels, null, liveNfts, liveTokens);
    final var nullNfts = new WorldLedgers(liveAliases, liveTokenRels, liveAccounts, null, liveTokens);
    final var nullTokens = new WorldLedgers(liveAliases, liveTokenRels, liveAccounts, liveNfts, null);
    assertFalse(nullTokenRels.areMutable());
    assertFalse(nullAccounts.areMutable());
    assertFalse(nullNfts.areMutable());
    assertFalse(nullTokens.areMutable());
    final var wrappedUnusable = nullAccounts.wrapped();
    assertSame(((StackedContractAliases) wrappedUnusable.aliases()).wrappedAliases(), nullAccounts.aliases());
    assertFalse(wrappedUnusable.areMutable());
    final var wrappedSource = source.wrapped();
    assertSame(liveTokenRels, wrappedSource.tokenRels().getEntitiesLedger());
    assertSame(liveAccounts, wrappedSource.accounts().getEntitiesLedger());
    assertSame(liveNfts, wrappedSource.nfts().getEntitiesLedger());
    assertSame(liveTokens, wrappedSource.tokens().getEntitiesLedger());
    final var stackedAliases = (StackedContractAliases) wrappedSource.aliases();
    assertSame(liveAliases, stackedAliases.wrappedAliases());
}
Also used : HashMapBackingTokenRels(com.hedera.services.ledger.backing.HashMapBackingTokenRels) MerkleToken(com.hedera.services.state.merkle.MerkleToken) MerkleAccount(com.hedera.services.state.merkle.MerkleAccount) TransactionalLedger(com.hedera.services.ledger.TransactionalLedger) MerkleTokenRelStatus(com.hedera.services.state.merkle.MerkleTokenRelStatus) HashMapBackingNfts(com.hedera.services.ledger.backing.HashMapBackingNfts) AliasManager(com.hedera.services.ledger.accounts.AliasManager) StackedContractAliases(com.hedera.services.ledger.accounts.StackedContractAliases) HashMapBackingTokens(com.hedera.services.ledger.backing.HashMapBackingTokens) MerkleUniqueToken(com.hedera.services.state.merkle.MerkleUniqueToken) HashMapBackingAccounts(com.hedera.services.ledger.backing.HashMapBackingAccounts) Test(org.junit.jupiter.api.Test)

Example 3 with MerkleAccount

use of com.hedera.services.state.merkle.MerkleAccount in project hedera-services by hashgraph.

the class GetAccountBalanceAnswer method checkValidity.

@Override
public ResponseCodeEnum checkValidity(Query query, StateView view) {
    MerkleMap<EntityNum, MerkleAccount> accounts = view.accounts();
    CryptoGetAccountBalanceQuery op = query.getCryptogetAccountBalance();
    return validityOf(op, accounts);
}
Also used : CryptoGetAccountBalanceQuery(com.hederahashgraph.api.proto.java.CryptoGetAccountBalanceQuery) MerkleAccount(com.hedera.services.state.merkle.MerkleAccount) EntityNum(com.hedera.services.utils.EntityNum)

Example 4 with MerkleAccount

use of com.hedera.services.state.merkle.MerkleAccount in project hedera-services by hashgraph.

the class GetAccountBalanceAnswer method responseGiven.

@Override
public Response responseGiven(Query query, StateView view, ResponseCodeEnum validity, long cost) {
    MerkleMap<EntityNum, MerkleAccount> accounts = view.accounts();
    CryptoGetAccountBalanceQuery op = query.getCryptogetAccountBalance();
    final var id = targetOf(op);
    CryptoGetAccountBalanceResponse.Builder opAnswer = CryptoGetAccountBalanceResponse.newBuilder().setHeader(answerOnlyHeader(validity)).setAccountID(id);
    if (validity == OK) {
        var key = EntityNum.fromAccountId(id);
        var account = accounts.get(key);
        opAnswer.setBalance(account.getBalance());
        for (TokenID tId : account.tokens().asTokenIds()) {
            var relKey = fromAccountTokenRel(id, tId);
            var relationship = view.tokenAssociations().get(relKey);
            var decimals = view.tokenWith(tId).map(MerkleToken::decimals).orElse(0);
            opAnswer.addTokenBalances(TokenBalance.newBuilder().setTokenId(tId).setBalance(relationship.getBalance()).setDecimals(decimals).build());
        }
    }
    return Response.newBuilder().setCryptogetAccountBalance(opAnswer).build();
}
Also used : CryptoGetAccountBalanceQuery(com.hederahashgraph.api.proto.java.CryptoGetAccountBalanceQuery) MerkleAccount(com.hedera.services.state.merkle.MerkleAccount) TokenID(com.hederahashgraph.api.proto.java.TokenID) EntityNum(com.hedera.services.utils.EntityNum) CryptoGetAccountBalanceResponse(com.hederahashgraph.api.proto.java.CryptoGetAccountBalanceResponse)

Example 5 with MerkleAccount

use of com.hedera.services.state.merkle.MerkleAccount 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)

Aggregations

MerkleAccount (com.hedera.services.state.merkle.MerkleAccount)22 Test (org.junit.jupiter.api.Test)10 EntityNum (com.hedera.services.utils.EntityNum)9 MerkleToken (com.hedera.services.state.merkle.MerkleToken)8 MerkleTokenRelStatus (com.hedera.services.state.merkle.MerkleTokenRelStatus)6 TransactionalLedger (com.hedera.services.ledger.TransactionalLedger)5 MerkleUniqueToken (com.hedera.services.state.merkle.MerkleUniqueToken)5 HederaAccountCustomizer (com.hedera.services.ledger.accounts.HederaAccountCustomizer)4 HashMapBackingAccounts (com.hedera.services.ledger.backing.HashMapBackingAccounts)4 HashMapBackingNfts (com.hedera.services.ledger.backing.HashMapBackingNfts)4 HashMapBackingTokenRels (com.hedera.services.ledger.backing.HashMapBackingTokenRels)4 HashMapBackingTokens (com.hedera.services.ledger.backing.HashMapBackingTokens)4 EntityId (com.hedera.services.state.submerkle.EntityId)4 AliasManager (com.hedera.services.ledger.accounts.AliasManager)3 ExpirableTxnRecord (com.hedera.services.state.submerkle.ExpirableTxnRecord)3 ClassConstructorPair (com.swirlds.common.constructable.ClassConstructorPair)3 MerkleMap (com.swirlds.merkle.map.MerkleMap)3 StackedContractAliases (com.hedera.services.ledger.accounts.StackedContractAliases)2 TxnReceipt (com.hedera.services.legacy.core.jproto.TxnReceipt)2 MerkleAccountState (com.hedera.services.state.merkle.MerkleAccountState)2