use of com.hedera.services.state.merkle.MerkleAccountTokens in project hedera-services by hashgraph.
the class HederaLedger method allTokenBalancesVanish.
public boolean allTokenBalancesVanish(AccountID aId) {
if (tokenRelsLedger == null) {
throw new IllegalStateException("Ledger has no manageable token relationships!");
}
var tokens = (MerkleAccountTokens) accountsLedger.get(aId, TOKENS);
for (TokenID tId : tokens.asTokenIds()) {
if (tokenStore.get(tId).isDeleted()) {
continue;
}
var relationship = asTokenRel(aId, tId);
var balance = (long) tokenRelsLedger.get(relationship, TOKEN_BALANCE);
if (balance > 0) {
return false;
}
}
return true;
}
use of com.hedera.services.state.merkle.MerkleAccountTokens 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);
}
use of com.hedera.services.state.merkle.MerkleAccountTokens in project hedera-services by hashgraph.
the class BaseHederaLedgerTestHelper method addToLedger.
protected void addToLedger(AccountID id, long balance, Map<TokenID, TokenInfo> tokenInfo) {
when(accountsLedger.get(id, EXPIRY)).thenReturn(1_234_567_890L);
when(accountsLedger.get(id, PROXY)).thenReturn(new EntityId(0, 0, 1_234L));
when(accountsLedger.get(id, AUTO_RENEW_PERIOD)).thenReturn(7776000L);
when(accountsLedger.get(id, BALANCE)).thenReturn(balance);
when(accountsLedger.get(id, IS_DELETED)).thenReturn(false);
when(accountsLedger.get(id, IS_RECEIVER_SIG_REQUIRED)).thenReturn(true);
when(accountsLedger.get(id, IS_SMART_CONTRACT)).thenReturn(false);
when(accountsLedger.get(id, MAX_AUTOMATIC_ASSOCIATIONS)).thenReturn(8);
when(accountsLedger.get(id, ALREADY_USED_AUTOMATIC_ASSOCIATIONS)).thenReturn(5);
when(accountsLedger.exists(id)).thenReturn(true);
var tokens = new MerkleAccountTokens();
tokens.associateAll(tokenInfo.keySet());
when(accountsLedger.get(id, TOKENS)).thenReturn(tokens);
// and:
for (TokenID tId : tokenInfo.keySet()) {
var info = tokenInfo.get(tId);
var relationship = BackingTokenRels.asTokenRel(id, tId);
when(tokenRelsLedger.get(relationship, TOKEN_BALANCE)).thenReturn(info.balance);
}
}
use of com.hedera.services.state.merkle.MerkleAccountTokens in project hedera-services by hashgraph.
the class ToStringAccountsExporterTest method producesExpectedText.
@Test
void producesExpectedText() throws Exception {
// setup:
TreeMap<EntityNum, Long> cryptoAllowances = new TreeMap();
cryptoAllowances.put(EntityNum.fromLong(1L), 10L);
account1.setBalance(1L);
account1.setTokens(new MerkleAccountTokens(new CopyOnWriteIds(new long[] { 1L, 2L, 3L, 3L, 2L, 1L })));
account1.setMaxAutomaticAssociations(10);
account1.setAlreadyUsedAutomaticAssociations(7);
account1.setCryptoAllowances(cryptoAllowances);
account2.setBalance(2L);
account2.setTokens(new MerkleAccountTokens(new CopyOnWriteIds(new long[] { 0L, 0L, 1234L })));
// and:
var desired = "0.0.1\n" + "---\n" + "MerkleAccount{state=MerkleAccountState{number=1 <-> 0.0.1, key=ed25519: \"first-fake\"\n" + ", expiry=1234567, balance=1, autoRenewSecs=555555, memo=This ecstasy doth unperplex, deleted=false, " + "smartContract=true, numContractKvPairs=0, receiverSigRequired=true, " + "proxy=EntityId{shard=0, realm=0, num=0}, nftsOwned=0, " + "alreadyUsedAutoAssociations=7, maxAutoAssociations=10, alias=, " + "cryptoAllowances={EntityNum{value=1}=10}, " + "fungibleTokenAllowances={}, nftAllowances={}}, # records=0, tokens=[3.2.1, 1.2.3]}\n\n0.0.2\n---\n" + "MerkleAccount{state=MerkleAccountState{number=2 <-> 0.0.2, key=ed25519: \"second-fake\"\n" + ", expiry=7654321, balance=2, autoRenewSecs=444444, memo=We said, and show us what we love, " + "deleted=true, smartContract=false, numContractKvPairs=0, receiverSigRequired=false, " + "proxy=EntityId{shard=0, realm=0, num=0}, nftsOwned=0, alreadyUsedAutoAssociations=0, " + "maxAutoAssociations=0, alias=, cryptoAllowances={}, fungibleTokenAllowances={}, nftAllowances={}}, #" + " records=0, tokens=[1234.0.0]}\n";
// given:
MerkleMap<EntityNum, MerkleAccount> accounts = new MerkleMap<>();
// and:
accounts.put(EntityNum.fromInt(2), account2);
accounts.put(EntityNum.fromInt(1), account1);
// and:
given(nodeLocalProperties.exportAccountsOnStartup()).willReturn(true);
given(nodeLocalProperties.accountsExportPath()).willReturn(testExportLoc);
// when:
subject.toFile(accounts);
// and:
var result = Files.readString(Paths.get(testExportLoc));
// then:
assertEquals(desired, result);
}
use of com.hedera.services.state.merkle.MerkleAccountTokens in project hedera-services by hashgraph.
the class MerkleAccountFactory method get.
public MerkleAccount get() {
MerkleAccount value = new MerkleAccount();
memo.ifPresent(value::setMemo);
alias.ifPresent(value::setAlias);
proxy.ifPresent(p -> value.setProxy(EntityId.fromGrpcAccountId(p)));
balance.ifPresent(b -> {
try {
value.setBalance(b);
} catch (Exception ignore) {
}
});
deleted.ifPresent(value::setDeleted);
accountKeys.ifPresent(value::setAccountKey);
expirationTime.ifPresent(value::setExpiry);
autoRenewPeriod.ifPresent(value::setAutoRenewSecs);
isSmartContract.ifPresent(value::setSmartContract);
receiverSigRequired.ifPresent(value::setReceiverSigRequired);
maxAutoAssociations.ifPresent(value::setMaxAutomaticAssociations);
alreadyUsedAutoAssociations.ifPresent(value::setAlreadyUsedAutomaticAssociations);
var tokens = new MerkleAccountTokens();
if (useNewStyleTokenIds) {
tokens.associate(assocTokens);
} else {
tokens.associateAll(associatedTokens);
}
value.setTokens(tokens);
value.setNumContractKvPairs(numKvPairs);
value.setCryptoAllowances(cryptoAllowances);
value.setFungibleTokenAllowances(fungibleTokenAllowances);
value.setNftAllowances(nftAllowances);
return value;
}
Aggregations