Search in sources :

Example 1 with TokenRelationship

use of com.hederahashgraph.api.proto.java.TokenRelationship 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 TokenRelationship

use of com.hederahashgraph.api.proto.java.TokenRelationship in project hedera-services by hashgraph.

the class ExpectedTokenRel method assertNoUnexpectedRels.

public static void assertNoUnexpectedRels(String account, List<String> expectedAbsent, List<TokenRelationship> actualRels, HapiApiSpec spec) {
    for (String unexpectedToken : expectedAbsent) {
        for (TokenRelationship actualRel : actualRels) {
            var unexpectedId = spec.registry().getTokenID(unexpectedToken);
            if (actualRel.getTokenId().equals(unexpectedId)) {
                String errMsg = String.format("Account '%s' should have had no relationship with token '%s'!", account, unexpectedToken);
                log.error(errMsg);
                throw new HapiQueryCheckStateException(errMsg);
            }
        }
    }
}
Also used : HapiQueryCheckStateException(com.hedera.services.bdd.spec.exceptions.HapiQueryCheckStateException) TokenRelationship(com.hederahashgraph.api.proto.java.TokenRelationship)

Example 3 with TokenRelationship

use of com.hederahashgraph.api.proto.java.TokenRelationship in project hedera-services by hashgraph.

the class ExpectedTokenRel method assertExpectedRels.

public static void assertExpectedRels(String account, List<ExpectedTokenRel> expectedRels, List<TokenRelationship> actualRels, HapiApiSpec spec) {
    for (ExpectedTokenRel rel : expectedRels) {
        boolean found = false;
        var expectedId = spec.registry().getTokenID(rel.getToken());
        for (TokenRelationship actualRel : actualRels) {
            if (actualRel.getTokenId().equals(expectedId)) {
                found = true;
                rel.getDecimals().ifPresent(d -> assertEquals(d, actualRel.getDecimals()));
                rel.getBalance().ifPresent(a -> assertEquals(a, actualRel.getBalance()));
                rel.getKycStatus().ifPresent(s -> assertEquals(s, actualRel.getKycStatus()));
                rel.getFreezeStatus().ifPresent(s -> assertEquals(s, actualRel.getFreezeStatus()));
            }
        }
        if (!found) {
            String errMsg = String.format("Account '%s' had no relationship with token '%s'!", account, rel.getToken());
            log.error(errMsg);
            throw new HapiQueryCheckStateException(errMsg);
        }
    }
}
Also used : HapiQueryCheckStateException(com.hedera.services.bdd.spec.exceptions.HapiQueryCheckStateException) TokenRelationship(com.hederahashgraph.api.proto.java.TokenRelationship)

Aggregations

TokenRelationship (com.hederahashgraph.api.proto.java.TokenRelationship)3 HapiQueryCheckStateException (com.hedera.services.bdd.spec.exceptions.HapiQueryCheckStateException)2 RawTokenRelationship (com.hedera.services.state.submerkle.RawTokenRelationship)1 TokenID (com.hederahashgraph.api.proto.java.TokenID)1 ArrayList (java.util.ArrayList)1