Search in sources :

Example 1 with EntityNum

use of com.hedera.services.utils.EntityNum in project hedera-services by hashgraph.

the class GetAccountBalanceAnswer method checkValidity.

@Override
public ResponseCodeEnum checkValidity(Query query, StateView view) {
    MerkleMap<EntityNum, MerkleAccount> accounts = view.accounts();
    CryptoGetAccountBalanceQuery op = query.getCryptogetAccountBalance();
    return validityOf(op, accounts);
}
Also used : CryptoGetAccountBalanceQuery(com.hederahashgraph.api.proto.java.CryptoGetAccountBalanceQuery) MerkleAccount(com.hedera.services.state.merkle.MerkleAccount) EntityNum(com.hedera.services.utils.EntityNum)

Example 2 with EntityNum

use of com.hedera.services.utils.EntityNum 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 3 with EntityNum

use of com.hedera.services.utils.EntityNum in project hedera-services by hashgraph.

the class GetAccountInfoAnswerTest method setup.

@BeforeEach
private void setup() throws Throwable {
    tokenRels = new MerkleMap<>();
    tokenRels.put(fromAccountTokenRel(payerId, firstToken), new MerkleTokenRelStatus(firstBalance, true, true, true));
    tokenRels.put(fromAccountTokenRel(payerId, secondToken), new MerkleTokenRelStatus(secondBalance, false, false, true));
    tokenRels.put(fromAccountTokenRel(payerId, thirdToken), new MerkleTokenRelStatus(thirdBalance, true, true, false));
    tokenRels.put(fromAccountTokenRel(payerId, fourthToken), new MerkleTokenRelStatus(fourthBalance, false, false, true));
    tokenRels.put(fromAccountTokenRel(payerId, missingToken), new MerkleTokenRelStatus(missingBalance, false, false, false));
    var tokens = new MerkleAccountTokens();
    tokens.associateAll(Set.of(firstToken, secondToken, thirdToken, fourthToken, missingToken));
    var tokenAllowanceKey = FcTokenAllowanceId.from(EntityNum.fromLong(1000L), EntityNum.fromLong(2000L));
    var tokenAllowanceValue = FcTokenAllowance.from(false, List.of(1L, 2L));
    TreeMap<EntityNum, Long> cryptoAllowances = new TreeMap();
    TreeMap<FcTokenAllowanceId, Long> fungibleTokenAllowances = new TreeMap();
    TreeMap<FcTokenAllowanceId, FcTokenAllowance> nftAllowances = new TreeMap();
    cryptoAllowances.put(EntityNum.fromLong(1L), 10L);
    fungibleTokenAllowances.put(tokenAllowanceKey, 20L);
    nftAllowances.put(tokenAllowanceKey, tokenAllowanceValue);
    payerAccount = MerkleAccountFactory.newAccount().accountKeys(COMPLEX_KEY_ACCOUNT_KT).memo(memo).proxy(asAccount("1.2.3")).senderThreshold(1_234L).receiverThreshold(4_321L).receiverSigRequired(true).balance(555L).autoRenewPeriod(1_000_000L).expirationTime(9_999_999L).cryptoAllowances(cryptoAllowances).fungibleTokenAllowances(fungibleTokenAllowances).nftAllowances(nftAllowances).get();
    payerAccount.setTokens(tokens);
    final MutableStateChildren children = new MutableStateChildren();
    children.setAccounts(accounts);
    children.setTokenAssociations(tokenRels);
    view = new StateView(tokenStore, scheduleStore, children, networkInfo);
    subject = new GetAccountInfoAnswer(optionValidator, aliasManager);
}
Also used : MerkleAccountTokens(com.hedera.services.state.merkle.MerkleAccountTokens) StateView(com.hedera.services.context.primitives.StateView) TreeMap(java.util.TreeMap) EntityNum(com.hedera.services.utils.EntityNum) MerkleTokenRelStatus(com.hedera.services.state.merkle.MerkleTokenRelStatus) FcTokenAllowanceId(com.hedera.services.state.submerkle.FcTokenAllowanceId) MutableStateChildren(com.hedera.services.context.MutableStateChildren) FcTokenAllowance(com.hedera.services.state.submerkle.FcTokenAllowance) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with EntityNum

use of com.hedera.services.utils.EntityNum in project hedera-services by hashgraph.

the class AccountsReader method from.

public static MerkleMap<EntityNum, MerkleAccount> from(String loc) throws Exception {
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(MerkleLong.class, MerkleLong::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(FCQueue.class, FCQueue::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(MerkleMap.class, MerkleMap::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(MerkleEntityId.class, MerkleEntityId::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(EntityId.class, EntityId::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(MerkleAccount.class, MerkleAccount::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(MerkleAccountState.class, MerkleAccountState::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(ExpirableTxnRecord.class, ExpirableTxnRecord::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(TxnReceipt.class, TxnReceipt::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(TxnId.class, TxnId::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(CurrencyAdjustments.class, CurrencyAdjustments::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(EvmFnResult.class, EvmFnResult::new));
    try (MerkleDataInputStream in = new MerkleDataInputStream(Files.newInputStream(Path.of(loc)))) {
        MerkleMap<EntityNum, MerkleAccount> fcm = in.readMerkleTree(Integer.MAX_VALUE);
        return fcm;
    }
}
Also used : ExpirableTxnRecord(com.hedera.services.state.submerkle.ExpirableTxnRecord) FCQueue(com.swirlds.fcqueue.FCQueue) MerkleDataInputStream(com.swirlds.common.merkle.io.MerkleDataInputStream) TxnReceipt(com.hedera.services.legacy.core.jproto.TxnReceipt) MerkleAccount(com.hedera.services.state.merkle.MerkleAccount) MerkleEntityId(com.hedera.services.state.merkle.MerkleEntityId) MerkleAccountState(com.hedera.services.state.merkle.MerkleAccountState) EntityNum(com.hedera.services.utils.EntityNum) MerkleLong(com.swirlds.common.merkle.utility.MerkleLong) EntityId(com.hedera.services.state.submerkle.EntityId) MerkleEntityId(com.hedera.services.state.merkle.MerkleEntityId) TxnId(com.hedera.services.state.submerkle.TxnId) EvmFnResult(com.hedera.services.state.submerkle.EvmFnResult) MerkleMap(com.swirlds.merkle.map.MerkleMap) CurrencyAdjustments(com.hedera.services.state.submerkle.CurrencyAdjustments) ClassConstructorPair(com.swirlds.common.constructable.ClassConstructorPair)

Example 5 with EntityNum

use of com.hedera.services.utils.EntityNum in project hedera-services by hashgraph.

the class PojoLedger method fromDisk.

public static PojoLedger fromDisk(String dumpLoc) throws Exception {
    try (MerkleDataInputStream in = new MerkleDataInputStream(Files.newInputStream(Path.of(dumpLoc)))) {
        MerkleMap<EntityNum, MerkleAccount> fcm = in.readMerkleTree(Integer.MAX_VALUE);
        var pojo = from(fcm);
        return pojo;
    }
}
Also used : MerkleDataInputStream(com.swirlds.common.merkle.io.MerkleDataInputStream) MerkleAccount(com.hedera.services.state.merkle.MerkleAccount) EntityNum(com.hedera.services.utils.EntityNum)

Aggregations

EntityNum (com.hedera.services.utils.EntityNum)23 Test (org.junit.jupiter.api.Test)15 MerkleAccount (com.hedera.services.state.merkle.MerkleAccount)9 MerkleMap (com.swirlds.merkle.map.MerkleMap)5 FcTokenAllowanceId (com.hedera.services.state.submerkle.FcTokenAllowanceId)4 MerkleToken (com.hedera.services.state.merkle.MerkleToken)3 EntityId (com.hedera.services.state.submerkle.EntityId)3 FcTokenAllowance (com.hedera.services.state.submerkle.FcTokenAllowance)3 ArrayList (java.util.ArrayList)3 TreeMap (java.util.TreeMap)3 ByteString (com.google.protobuf.ByteString)2 MutableStateChildren (com.hedera.services.context.MutableStateChildren)2 MerkleAccountTokens (com.hedera.services.state.merkle.MerkleAccountTokens)2 MerkleTokenRelStatus (com.hedera.services.state.merkle.MerkleTokenRelStatus)2 MerkleTopic (com.hedera.services.state.merkle.MerkleTopic)2 ExpirableTxnRecord (com.hedera.services.state.submerkle.ExpirableTxnRecord)2 AccountID (com.hederahashgraph.api.proto.java.AccountID)2 CryptoGetAccountBalanceQuery (com.hederahashgraph.api.proto.java.CryptoGetAccountBalanceQuery)2 MerkleDataInputStream (com.swirlds.common.merkle.io.MerkleDataInputStream)2 NetworkInfo (com.hedera.services.config.NetworkInfo)1