Search in sources :

Example 1 with TokenID

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;
}
Also used : ArrayList(java.util.ArrayList) TokenID(com.hederahashgraph.api.proto.java.TokenID) RawTokenRelationship(com.hedera.services.state.submerkle.RawTokenRelationship) RawTokenRelationship(com.hedera.services.state.submerkle.RawTokenRelationship) TokenRelationship(com.hederahashgraph.api.proto.java.TokenRelationship)

Example 2 with TokenID

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() {
        }
    };
}
Also used : EntityIdSource(com.hedera.services.ledger.ids.EntityIdSource) AccountID(com.hederahashgraph.api.proto.java.AccountID) SideEffectsTracker(com.hedera.services.context.SideEffectsTracker) TopicID(com.hederahashgraph.api.proto.java.TopicID) FileID(com.hederahashgraph.api.proto.java.FileID) ContractID(com.hederahashgraph.api.proto.java.ContractID) ExpiringCreations(com.hedera.services.state.expiry.ExpiringCreations) TokenID(com.hederahashgraph.api.proto.java.TokenID) ScheduleID(com.hederahashgraph.api.proto.java.ScheduleID) AccountRecordsHistorian(com.hedera.services.records.AccountRecordsHistorian)

Example 3 with TokenID

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();
}
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 4 with TokenID

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

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;
}
Also used : MerkleAccountTokens(com.hedera.services.state.merkle.MerkleAccountTokens) TokenID(com.hederahashgraph.api.proto.java.TokenID)

Aggregations

TokenID (com.hederahashgraph.api.proto.java.TokenID)24 AccountID (com.hederahashgraph.api.proto.java.AccountID)11 Test (org.junit.jupiter.api.Test)9 TokenTransferList (com.hederahashgraph.api.proto.java.TokenTransferList)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)5 TokenUpdateTransactionBody (com.hederahashgraph.api.proto.java.TokenUpdateTransactionBody)5 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)5 ByteString (com.google.protobuf.ByteString)4 AbstractEntity (com.hedera.mirror.common.domain.entity.AbstractEntity)4 EntityId (com.hedera.mirror.common.domain.entity.EntityId)4 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)4 Transaction (com.hedera.mirror.common.domain.transaction.Transaction)4 TransactionRecord (com.hederahashgraph.api.proto.java.TransactionRecord)4 Range (com.google.common.collect.Range)3 Entity (com.hedera.mirror.common.domain.entity.Entity)3 EntityIdEndec (com.hedera.mirror.common.domain.entity.EntityIdEndec)3 EntityType (com.hedera.mirror.common.domain.entity.EntityType)3 ACCOUNT (com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT)3 NftTransferId (com.hedera.mirror.common.domain.token.NftTransferId)3