Search in sources :

Example 1 with RawTokenRelationship

use of com.hedera.services.state.submerkle.RawTokenRelationship 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 RawTokenRelationship

use of com.hedera.services.state.submerkle.RawTokenRelationship in project hedera-services by hashgraph.

the class GetAccountInfoAnswerTest method getsTheAccountInfo.

@Test
void getsTheAccountInfo() throws Throwable {
    given(token.hasKycKey()).willReturn(true);
    given(token.hasFreezeKey()).willReturn(true);
    given(token.decimals()).willReturn(1).willReturn(2).willReturn(3).willReturn(1).willReturn(2).willReturn(3);
    given(deletedToken.decimals()).willReturn(4);
    given(tokenStore.exists(firstToken)).willReturn(true);
    given(tokenStore.exists(secondToken)).willReturn(true);
    given(tokenStore.exists(thirdToken)).willReturn(true);
    given(tokenStore.exists(fourthToken)).willReturn(true);
    given(tokenStore.exists(missingToken)).willReturn(false);
    given(tokenStore.get(firstToken)).willReturn(token);
    given(tokenStore.get(secondToken)).willReturn(token);
    given(tokenStore.get(thirdToken)).willReturn(token);
    given(tokenStore.get(fourthToken)).willReturn(deletedToken);
    given(token.symbol()).willReturn("HEYMA");
    given(deletedToken.symbol()).willReturn("THEWAY");
    given(accounts.get(EntityNum.fromAccountId(asAccount(target)))).willReturn(payerAccount);
    given(networkInfo.ledgerId()).willReturn(ledgerId);
    // setup:
    Query query = validQuery(ANSWER_ONLY, fee, target);
    // when:
    Response response = subject.responseGiven(query, view, OK, fee);
    // then:
    assertTrue(response.hasCryptoGetInfo());
    assertTrue(response.getCryptoGetInfo().hasHeader(), "Missing response header!");
    assertEquals(OK, response.getCryptoGetInfo().getHeader().getNodeTransactionPrecheckCode());
    assertEquals(ANSWER_ONLY, response.getCryptoGetInfo().getHeader().getResponseType());
    assertEquals(0, response.getCryptoGetInfo().getHeader().getCost());
    // and:
    CryptoGetInfoResponse.AccountInfo info = response.getCryptoGetInfo().getAccountInfo();
    assertEquals(asAccount(payer), info.getAccountID());
    String address = CommonUtils.hex(asEvmAddress(0, 0L, 12_345L));
    assertEquals(address, info.getContractAccountID());
    assertEquals(payerAccount.getBalance(), info.getBalance());
    assertEquals(payerAccount.getAutoRenewSecs(), info.getAutoRenewPeriod().getSeconds());
    assertEquals(payerAccount.getProxy(), EntityId.fromGrpcAccountId(info.getProxyAccountID()));
    assertEquals(JKey.mapJKey(payerAccount.getAccountKey()), info.getKey());
    assertEquals(payerAccount.isReceiverSigRequired(), info.getReceiverSigRequired());
    assertEquals(payerAccount.getExpiry(), info.getExpirationTime().getSeconds());
    assertEquals(memo, info.getMemo());
    assertEquals(1, info.getGrantedCryptoAllowancesCount());
    assertEquals(1, info.getGrantedTokenAllowancesCount());
    assertEquals(1, info.getGrantedNftAllowancesCount());
    assertEquals(GrantedCryptoAllowance.newBuilder().setAmount(10L).setSpender(EntityNum.fromLong(1L).toGrpcAccountId()).build(), info.getGrantedCryptoAllowances(0));
    assertEquals(GrantedTokenAllowance.newBuilder().setAmount(20L).setSpender(EntityNum.fromLong(2000L).toGrpcAccountId()).setTokenId(EntityNum.fromLong(1000L).toGrpcTokenId()).build(), info.getGrantedTokenAllowances(0));
    assertEquals(GrantedNftAllowance.newBuilder().setApprovedForAll(false).addAllSerialNumbers(List.of(1L, 2L)).setSpender(EntityNum.fromLong(2000L).toGrpcAccountId()).setTokenId(EntityNum.fromLong(1000L).toGrpcTokenId()).build(), info.getGrantedNftAllowances(0));
    // and:
    assertEquals(List.of(new RawTokenRelationship(firstBalance, 0, 0, firstToken.getTokenNum(), true, true, true).asGrpcFor(token), new RawTokenRelationship(secondBalance, 0, 0, secondToken.getTokenNum(), false, false, true).asGrpcFor(token), new RawTokenRelationship(thirdBalance, 0, 0, thirdToken.getTokenNum(), true, true, false).asGrpcFor(token), new RawTokenRelationship(fourthBalance, 0, 0, fourthToken.getTokenNum(), false, false, true).asGrpcFor(deletedToken), new RawTokenRelationship(missingBalance, 0, 0, missingToken.getTokenNum(), false, false, false).asGrpcFor(REMOVED_TOKEN)), info.getTokenRelationshipsList());
}
Also used : CryptoGetInfoResponse(com.hederahashgraph.api.proto.java.CryptoGetInfoResponse) Response(com.hederahashgraph.api.proto.java.Response) CryptoGetInfoResponse(com.hederahashgraph.api.proto.java.CryptoGetInfoResponse) CryptoGetInfoQuery(com.hederahashgraph.api.proto.java.CryptoGetInfoQuery) Query(com.hederahashgraph.api.proto.java.Query) ByteString(com.google.protobuf.ByteString) RawTokenRelationship(com.hedera.services.state.submerkle.RawTokenRelationship) Test(org.junit.jupiter.api.Test)

Aggregations

RawTokenRelationship (com.hedera.services.state.submerkle.RawTokenRelationship)2 ByteString (com.google.protobuf.ByteString)1 CryptoGetInfoQuery (com.hederahashgraph.api.proto.java.CryptoGetInfoQuery)1 CryptoGetInfoResponse (com.hederahashgraph.api.proto.java.CryptoGetInfoResponse)1 Query (com.hederahashgraph.api.proto.java.Query)1 Response (com.hederahashgraph.api.proto.java.Response)1 TokenID (com.hederahashgraph.api.proto.java.TokenID)1 TokenRelationship (com.hederahashgraph.api.proto.java.TokenRelationship)1 ArrayList (java.util.ArrayList)1 Test (org.junit.jupiter.api.Test)1