Search in sources :

Example 1 with MerkleTokenRelStatus

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

the class LedgerBalanceChangesTest method givenInitialBalancesAndOwnership.

private void givenInitialBalancesAndOwnership() {
    final var aAccount = MerkleAccountFactory.newAccount().balance(aStartBalance).get();
    backingAccounts.put(aModel, aAccount);
    final var bAccount = MerkleAccountFactory.newAccount().balance(bStartBalance).get();
    backingAccounts.put(bModel, bAccount);
    final var cAccount = MerkleAccountFactory.newAccount().balance(cStartBalance).get();
    backingAccounts.put(cModel, cAccount);
    Pair<AccountID, TokenID> bTokenKey = rel(bModel, token);
    final var bTokenRel = new MerkleTokenRelStatus(bTokenStartBalance, false, true, false);
    backingRels.put(bTokenKey, bTokenRel);
    Pair<AccountID, TokenID> cTokenKey = rel(cModel, token);
    final var cTokenRel = new MerkleTokenRelStatus(cTokenStartBalance, false, true, false);
    backingRels.put(cTokenKey, cTokenRel);
    Pair<AccountID, TokenID> aAnotherTokenKey = rel(aModel, anotherToken);
    final var aAnotherTokenRel = new MerkleTokenRelStatus(aAnotherTokenStartBalance, false, true, true);
    backingRels.put(aAnotherTokenKey, aAnotherTokenRel);
    Pair<AccountID, TokenID> bAnotherTokenKey = rel(bModel, anotherToken);
    final var bAnotherTokenRel = new MerkleTokenRelStatus(bAnotherTokenStartBalance, false, true, false);
    backingRels.put(bAnotherTokenKey, bAnotherTokenRel);
    Pair<AccountID, TokenID> cAnotherTokenKey = rel(cModel, anotherToken);
    final var cAnotherTokenRel = new MerkleTokenRelStatus(cAnotherTokenStartBalance, false, true, true);
    backingRels.put(cAnotherTokenKey, cAnotherTokenRel);
    Pair<AccountID, TokenID> aYaTokenKey = rel(aModel, yetAnotherToken);
    final var aYaTokenRel = new MerkleTokenRelStatus(aYetAnotherTokenBalance, false, true, false);
    backingRels.put(aYaTokenKey, aYaTokenRel);
    Pair<AccountID, TokenID> bYaTokenKey = rel(bModel, yetAnotherToken);
    final var bYaTokenRel = new MerkleTokenRelStatus(bYetAnotherTokenBalance, false, true, false);
    backingRels.put(bYaTokenKey, bYaTokenRel);
    Pair<AccountID, TokenID> aaNftTokenKey = rel(aModel, aNft);
    final var aaNftTokenRel = new MerkleTokenRelStatus(2, false, true, false);
    backingRels.put(aaNftTokenKey, aaNftTokenRel);
    Pair<AccountID, TokenID> abNftTokenKey = rel(aModel, bNft);
    final var abNftTokenRel = new MerkleTokenRelStatus(2, false, true, true);
    backingRels.put(abNftTokenKey, abNftTokenRel);
    Pair<AccountID, TokenID> baNftTokenKey = rel(bModel, aNft);
    final var baNftTokenRel = new MerkleTokenRelStatus(2, false, true, false);
    backingRels.put(baNftTokenKey, baNftTokenRel);
    Pair<AccountID, TokenID> bbNftTokenKey = rel(bModel, bNft);
    final var bbNftTokenRel = new MerkleTokenRelStatus(2, false, true, true);
    backingRels.put(bbNftTokenKey, bbNftTokenRel);
    Pair<AccountID, TokenID> caNftTokenKey = rel(cModel, aNft);
    final var caNftTokenRel = new MerkleTokenRelStatus(2, false, true, true);
    backingRels.put(caNftTokenKey, caNftTokenRel);
    Pair<AccountID, TokenID> cbNftTokenKey = rel(cModel, bNft);
    final var cbNftTokenRel = new MerkleTokenRelStatus(2, false, true, false);
    backingRels.put(cbNftTokenKey, cbNftTokenRel);
    backingNfts.put(aaNft, new MerkleUniqueToken(EntityId.fromGrpcAccountId(aModel), "aa".getBytes(), MISSING_INSTANT));
    backingNfts.put(baNft, new MerkleUniqueToken(EntityId.fromGrpcAccountId(bModel), "ba".getBytes(), MISSING_INSTANT));
    backingNfts.put(bbNft, new MerkleUniqueToken(EntityId.fromGrpcAccountId(cModel), "bb".getBytes(), MISSING_INSTANT));
    backingRels.rebuildFromSources();
}
Also used : MerkleTokenRelStatus(com.hedera.services.state.merkle.MerkleTokenRelStatus) AccountID(com.hederahashgraph.api.proto.java.AccountID) MerkleUniqueToken(com.hedera.services.state.merkle.MerkleUniqueToken) TokenID(com.hederahashgraph.api.proto.java.TokenID)

Example 2 with MerkleTokenRelStatus

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

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

the class GetAccountBalanceAnswerTest method setup.

@BeforeEach
private void setup() {
    deleted = mock(MerkleToken.class);
    given(deleted.isDeleted()).willReturn(true);
    given(deleted.decimals()).willReturn(123);
    notDeleted = mock(MerkleToken.class);
    given(notDeleted.isDeleted()).willReturn(false);
    given(notDeleted.decimals()).willReturn(1).willReturn(2);
    tokenRels = new MerkleMap<>();
    tokenRels.put(fromAccountTokenRel(target, aToken), new MerkleTokenRelStatus(aBalance, true, true, true));
    tokenRels.put(fromAccountTokenRel(target, bToken), new MerkleTokenRelStatus(bBalance, false, false, false));
    tokenRels.put(fromAccountTokenRel(target, cToken), new MerkleTokenRelStatus(cBalance, false, false, true));
    tokenRels.put(fromAccountTokenRel(target, dToken), new MerkleTokenRelStatus(dBalance, false, false, true));
    accounts = mock(MerkleMap.class);
    nodeProps = mock(NodeLocalProperties.class);
    given(accounts.get(fromAccountId(asAccount(accountIdLit)))).willReturn(accountV);
    given(accounts.get(fromContractId(asContract(contractIdLit)))).willReturn(contractV);
    tokenStore = mock(TokenStore.class);
    given(tokenStore.exists(aToken)).willReturn(true);
    given(tokenStore.exists(bToken)).willReturn(true);
    given(tokenStore.exists(cToken)).willReturn(true);
    given(tokenStore.exists(dToken)).willReturn(false);
    given(tokenStore.get(aToken)).willReturn(notDeleted);
    given(tokenStore.get(bToken)).willReturn(notDeleted);
    given(tokenStore.get(cToken)).willReturn(deleted);
    scheduleStore = mock(ScheduleStore.class);
    final MutableStateChildren children = new MutableStateChildren();
    children.setAccounts(accounts);
    children.setTokenAssociations(tokenRels);
    view = new StateView(tokenStore, scheduleStore, children, null);
    optionValidator = mock(OptionValidator.class);
    aliasManager = mock(AliasManager.class);
    subject = new GetAccountBalanceAnswer(aliasManager, optionValidator);
}
Also used : MerkleTokenRelStatus(com.hedera.services.state.merkle.MerkleTokenRelStatus) AliasManager(com.hedera.services.ledger.accounts.AliasManager) MutableStateChildren(com.hedera.services.context.MutableStateChildren) OptionValidator(com.hedera.services.txns.validation.OptionValidator) MerkleToken(com.hedera.services.state.merkle.MerkleToken) MerkleMap(com.swirlds.merkle.map.MerkleMap) StateView(com.hedera.services.context.primitives.StateView) NodeLocalProperties(com.hedera.services.context.properties.NodeLocalProperties) TokenStore(com.hedera.services.store.tokens.TokenStore) ScheduleStore(com.hedera.services.store.schedule.ScheduleStore) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with MerkleTokenRelStatus

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

the class GetAccountInfoAnswerTest method setup.

@BeforeEach
private void setup() throws Throwable {
    tokenRels = new MerkleMap<>();
    tokenRels.put(fromAccountTokenRel(payerId, firstToken), new MerkleTokenRelStatus(firstBalance, true, true, true));
    tokenRels.put(fromAccountTokenRel(payerId, secondToken), new MerkleTokenRelStatus(secondBalance, false, false, true));
    tokenRels.put(fromAccountTokenRel(payerId, thirdToken), new MerkleTokenRelStatus(thirdBalance, true, true, false));
    tokenRels.put(fromAccountTokenRel(payerId, fourthToken), new MerkleTokenRelStatus(fourthBalance, false, false, true));
    tokenRels.put(fromAccountTokenRel(payerId, missingToken), new MerkleTokenRelStatus(missingBalance, false, false, false));
    var tokens = new MerkleAccountTokens();
    tokens.associateAll(Set.of(firstToken, secondToken, thirdToken, fourthToken, missingToken));
    var tokenAllowanceKey = FcTokenAllowanceId.from(EntityNum.fromLong(1000L), EntityNum.fromLong(2000L));
    var tokenAllowanceValue = FcTokenAllowance.from(false, List.of(1L, 2L));
    TreeMap<EntityNum, Long> cryptoAllowances = new TreeMap();
    TreeMap<FcTokenAllowanceId, Long> fungibleTokenAllowances = new TreeMap();
    TreeMap<FcTokenAllowanceId, FcTokenAllowance> nftAllowances = new TreeMap();
    cryptoAllowances.put(EntityNum.fromLong(1L), 10L);
    fungibleTokenAllowances.put(tokenAllowanceKey, 20L);
    nftAllowances.put(tokenAllowanceKey, tokenAllowanceValue);
    payerAccount = MerkleAccountFactory.newAccount().accountKeys(COMPLEX_KEY_ACCOUNT_KT).memo(memo).proxy(asAccount("1.2.3")).senderThreshold(1_234L).receiverThreshold(4_321L).receiverSigRequired(true).balance(555L).autoRenewPeriod(1_000_000L).expirationTime(9_999_999L).cryptoAllowances(cryptoAllowances).fungibleTokenAllowances(fungibleTokenAllowances).nftAllowances(nftAllowances).get();
    payerAccount.setTokens(tokens);
    final MutableStateChildren children = new MutableStateChildren();
    children.setAccounts(accounts);
    children.setTokenAssociations(tokenRels);
    view = new StateView(tokenStore, scheduleStore, children, networkInfo);
    subject = new GetAccountInfoAnswer(optionValidator, aliasManager);
}
Also used : MerkleAccountTokens(com.hedera.services.state.merkle.MerkleAccountTokens) StateView(com.hedera.services.context.primitives.StateView) TreeMap(java.util.TreeMap) EntityNum(com.hedera.services.utils.EntityNum) MerkleTokenRelStatus(com.hedera.services.state.merkle.MerkleTokenRelStatus) FcTokenAllowanceId(com.hedera.services.state.submerkle.FcTokenAllowanceId) MutableStateChildren(com.hedera.services.context.MutableStateChildren) FcTokenAllowance(com.hedera.services.state.submerkle.FcTokenAllowance) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with MerkleTokenRelStatus

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

the class TypedTokenStore method persistNonDestroyed.

private void persistNonDestroyed(TokenRelationship modelRel, EntityNumPair key) {
    final var isNewRel = modelRel.isNotYetPersisted();
    final var mutableTokenRel = isNewRel ? new MerkleTokenRelStatus() : tokenRels.getRef(key.asAccountTokenRel());
    mutableTokenRel.setBalance(modelRel.getBalance());
    mutableTokenRel.setFrozen(modelRel.isFrozen());
    mutableTokenRel.setKycGranted(modelRel.isKycGranted());
    mutableTokenRel.setAutomaticAssociation(modelRel.isAutomaticAssociation());
    tokenRels.put(key.asAccountTokenRel(), mutableTokenRel);
}
Also used : MerkleTokenRelStatus(com.hedera.services.state.merkle.MerkleTokenRelStatus)

Aggregations

MerkleTokenRelStatus (com.hedera.services.state.merkle.MerkleTokenRelStatus)13 MerkleToken (com.hedera.services.state.merkle.MerkleToken)7 MerkleAccount (com.hedera.services.state.merkle.MerkleAccount)6 MerkleUniqueToken (com.hedera.services.state.merkle.MerkleUniqueToken)5 TransactionalLedger (com.hedera.services.ledger.TransactionalLedger)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 BeforeEach (org.junit.jupiter.api.BeforeEach)4 MutableStateChildren (com.hedera.services.context.MutableStateChildren)3 AliasManager (com.hedera.services.ledger.accounts.AliasManager)3 StateView (com.hedera.services.context.primitives.StateView)2 StackedContractAliases (com.hedera.services.ledger.accounts.StackedContractAliases)2 ScheduleStore (com.hedera.services.store.schedule.ScheduleStore)2 TokenStore (com.hedera.services.store.tokens.TokenStore)2 EntityNum (com.hedera.services.utils.EntityNum)2 MerkleMap (com.swirlds.merkle.map.MerkleMap)2 Test (org.junit.jupiter.api.Test)2 ServicesState (com.hedera.services.ServicesState)1