Search in sources :

Example 66 with AccountID

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

the class TypedTokenStore method commitToken.

/**
 * Persists the given token to the Swirlds state, inviting the injected {@link TransactionRecordService}
 * to update the {@link com.hedera.services.state.submerkle.ExpirableTxnRecord} of the active transaction
 * with these changes.
 *
 * @param token
 * 		the token to save
 */
public void commitToken(Token token) {
    final var mutableToken = tokens.getRef(token.getId().asGrpcToken());
    mapModelChanges(token, mutableToken);
    tokens.put(token.getId().asGrpcToken(), mutableToken);
    if (token.hasMintedUniqueTokens()) {
        persistMinted(token.mintedUniqueTokens());
    }
    if (token.hasRemovedUniqueTokens()) {
        destroyRemoved(token.removedUniqueTokens());
    }
    /* Only needed during HTS refactor. Will be removed once all operations that
		 * refer to the knownTreasuries in-memory structure are refactored */
    if (token.isDeleted()) {
        final AccountID affectedTreasury = token.getTreasury().getId().asGrpcAccount();
        final TokenID mutatedToken = token.getId().asGrpcToken();
        delegate.removeKnownTreasuryForToken(affectedTreasury, mutatedToken);
    }
    sideEffectsTracker.trackTokenChanges(token);
}
Also used : AccountID(com.hederahashgraph.api.proto.java.AccountID) TokenID(com.hederahashgraph.api.proto.java.TokenID)

Example 67 with AccountID

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

the class GetAccountBalanceAnswerTest method answersWithAccountBalance.

@Test
void answersWithAccountBalance() {
    AccountID id = asAccount(accountIdLit);
    // given:
    CryptoGetAccountBalanceQuery op = CryptoGetAccountBalanceQuery.newBuilder().setAccountID(id).build();
    Query query = Query.newBuilder().setCryptogetAccountBalance(op).build();
    // when:
    Response response = subject.responseGiven(query, view, OK);
    ResponseCodeEnum status = response.getCryptogetAccountBalance().getHeader().getNodeTransactionPrecheckCode();
    long answer = response.getCryptogetAccountBalance().getBalance();
    // expect:
    assertTrue(response.getCryptogetAccountBalance().hasHeader(), "Missing response header!");
    assertEquals(List.of(tokenBalanceWith(aToken, aBalance, 1), tokenBalanceWith(bToken, bBalance, 2), tokenBalanceWith(cToken, cBalance, 123), tokenBalanceWith(dToken, dBalance, 0)), response.getCryptogetAccountBalance().getTokenBalancesList());
    assertEquals(OK, status);
    assertEquals(balance, answer);
    assertEquals(id, response.getCryptogetAccountBalance().getAccountID());
}
Also used : Response(com.hederahashgraph.api.proto.java.Response) CryptoGetAccountBalanceResponse(com.hederahashgraph.api.proto.java.CryptoGetAccountBalanceResponse) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) AccountID(com.hederahashgraph.api.proto.java.AccountID) CryptoGetAccountBalanceQuery(com.hederahashgraph.api.proto.java.CryptoGetAccountBalanceQuery) Query(com.hederahashgraph.api.proto.java.Query) CryptoGetAccountBalanceQuery(com.hederahashgraph.api.proto.java.CryptoGetAccountBalanceQuery) Test(org.junit.jupiter.api.Test)

Example 68 with AccountID

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

the class GetAccountBalanceAnswerTest method syntaxCheckValidatesIdIfPresent.

@Test
void syntaxCheckValidatesIdIfPresent() {
    // setup:
    AccountID id = asAccount(accountIdLit);
    // given:
    CryptoGetAccountBalanceQuery op = CryptoGetAccountBalanceQuery.newBuilder().setAccountID(id).build();
    Query query = Query.newBuilder().setCryptogetAccountBalance(op).build();
    // and:
    given(optionValidator.queryableAccountStatus(id, accounts)).willReturn(ACCOUNT_DELETED);
    // when:
    ResponseCodeEnum status = subject.checkValidity(query, view);
    // expect:
    assertEquals(ACCOUNT_DELETED, status);
}
Also used : ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) AccountID(com.hederahashgraph.api.proto.java.AccountID) CryptoGetAccountBalanceQuery(com.hederahashgraph.api.proto.java.CryptoGetAccountBalanceQuery) Query(com.hederahashgraph.api.proto.java.Query) CryptoGetAccountBalanceQuery(com.hederahashgraph.api.proto.java.CryptoGetAccountBalanceQuery) Test(org.junit.jupiter.api.Test)

Example 69 with AccountID

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

the class AccountInfoAsserts method solidityId.

public AccountInfoAsserts solidityId(String cid) {
    registerProvider((spec, o) -> {
        AccountID id = spec.registry().getAccountID(cid);
        final var solidityId = HapiPropertySource.asHexedSolidityAddress(id);
        assertEquals(solidityId, ((AccountInfo) o).getContractAccountID(), "Bad Solidity contract Id!");
    });
    return this;
}
Also used : AccountID(com.hederahashgraph.api.proto.java.AccountID)

Example 70 with AccountID

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

the class UsableTxnId method submitOp.

@Override
protected boolean submitOp(HapiApiSpec spec) {
    TransactionBody.Builder usable = TransactionBody.newBuilder();
    spec.txns().defaultBodySpec().accept(usable);
    if (payerId.isPresent()) {
        String s = payerId.get();
        AccountID id = TxnUtils.isIdLiteral(s) ? HapiPropertySource.asAccount(s) : spec.registry().getAccountID(s);
        usable.setTransactionID(usable.getTransactionIDBuilder().setAccountID(id));
    }
    if (useScheduledInappropriately) {
        usable.setTransactionID(usable.getTransactionIDBuilder().setScheduled(true));
    }
    spec.registry().saveTxnId(name, usable.build().getTransactionID());
    return false;
}
Also used : TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) AccountID(com.hederahashgraph.api.proto.java.AccountID)

Aggregations

AccountID (com.hederahashgraph.api.proto.java.AccountID)71 Test (org.junit.jupiter.api.Test)24 List (java.util.List)21 ByteString (com.google.protobuf.ByteString)20 Assertions (org.junit.jupiter.api.Assertions)20 HapiApiSpec (com.hedera.services.bdd.spec.HapiApiSpec)17 LogManager (org.apache.logging.log4j.LogManager)17 Logger (org.apache.logging.log4j.Logger)17 HapiApiSuite (com.hedera.services.bdd.suites.HapiApiSuite)16 HapiApiSpec.defaultHapiSpec (com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec)15 QueryVerbs.getTxnRecord (com.hedera.services.bdd.spec.queries.QueryVerbs.getTxnRecord)15 SUCCESS (com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS)15 QueryVerbs.getAccountInfo (com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountInfo)14 TransactionRecordAsserts.recordWith (com.hedera.services.bdd.spec.assertions.TransactionRecordAsserts.recordWith)13 QueryVerbs.getAccountBalance (com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountBalance)13 TxnVerbs.cryptoCreate (com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate)13 TxnVerbs.cryptoTransfer (com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer)13 TxnVerbs.mintToken (com.hedera.services.bdd.spec.transactions.TxnVerbs.mintToken)13 HapiSpecSetup (com.hedera.services.bdd.spec.HapiSpecSetup)12 QueryVerbs.getScheduleInfo (com.hedera.services.bdd.spec.queries.QueryVerbs.getScheduleInfo)12