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);
}
});
}
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());
}
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);
}
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();
}
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;
}
}
Aggregations