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