use of com.hederahashgraph.api.proto.java.TokenID in project hedera-services by hashgraph.
the class StateView method tokenRels.
static List<TokenRelationship> tokenRels(final StateView view, final EntityNum id) {
final var account = view.accounts().get(id);
final List<TokenRelationship> relationships = new ArrayList<>();
final var tokenIds = account.tokens().asTokenIds();
for (TokenID tId : tokenIds) {
final var optionalToken = view.tokenWith(tId);
final var effectiveToken = optionalToken.orElse(REMOVED_TOKEN);
final var relKey = fromAccountTokenRel(id.toGrpcAccountId(), tId);
final var relationship = view.tokenAssociations().get(relKey);
relationships.add(new RawTokenRelationship(relationship.getBalance(), tId.getShardNum(), tId.getRealmNum(), tId.getTokenNum(), relationship.isFrozen(), relationship.isKycGranted(), relationship.isAutomaticAssociation()).asGrpcFor(effectiveToken));
}
return relationships;
}
use of com.hederahashgraph.api.proto.java.TokenID in project hedera-services by hashgraph.
the class BaseHederaLedgerTestHelper method commonSetup.
protected void commonSetup() {
sideEffectsTracker = mock(SideEffectsTracker.class);
creator = mock(ExpiringCreations.class);
historian = mock(AccountRecordsHistorian.class);
ids = new EntityIdSource() {
long nextId = NEXT_ID;
@Override
public TopicID newTopicId(final AccountID sponsor) {
return TopicID.newBuilder().setTopicNum(nextId++).build();
}
@Override
public AccountID newAccountId(AccountID newAccountSponsor) {
return AccountID.newBuilder().setAccountNum(nextId++).build();
}
@Override
public ContractID newContractId(AccountID newContractSponsor) {
return ContractID.newBuilder().setContractNum(nextId++).build();
}
@Override
public FileID newFileId(AccountID newFileSponsor) {
return FileID.newBuilder().setFileNum(nextId++).build();
}
@Override
public TokenID newTokenId(AccountID sponsor) {
return TokenID.newBuilder().setTokenNum(nextId++).build();
}
@Override
public ScheduleID newScheduleId(AccountID sponsor) {
return ScheduleID.newBuilder().setScheduleNum(nextId++).build();
}
@Override
public void reclaimLastId() {
nextId--;
}
@Override
public void reclaimProvisionalIds() {
}
@Override
public void resetProvisionalIds() {
}
};
}
use of com.hederahashgraph.api.proto.java.TokenID 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();
}
use of com.hederahashgraph.api.proto.java.TokenID 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.hederahashgraph.api.proto.java.TokenID 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;
}
Aggregations