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