<commit_before>package nxt.http;

import nxt.Account;
import nxt.NxtException;
import nxt.util.Convert;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONStreamAware;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

public final class GetAccount extends APIServlet.APIRequestHandler {

    static final GetAccount instance = new GetAccount();

    private GetAccount() {
        super(new APITag[] {APITag.ACCOUNTS}, "account");
    }

    @Override
    JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {

        Account account = ParameterParser.getAccount(req);

        synchronized (account) {
            JSONObject response = JSONData.accountBalance(account);
            response.put("account", Convert.toUnsignedLong(account.getId()));
            response.put("accountRS", Convert.rsAccount(account.getId()));

            if (account.getPublicKey() != null) {
                response.put("publicKey", Convert.toHexString(account.getPublicKey()));
            }
            if (account.getName() != null) {
                response.put("name", account.getName());
            }
            if (account.getDescription() != null) {
                response.put("description", account.getDescription());
            }
            if (account.getCurrentLesseeId() != null) {
                response.put("currentLessee", Convert.toUnsignedLong(account.getCurrentLesseeId()));
                response.put("currentLeasingHeightFrom", account.getCurrentLeasingHeightFrom());
                response.put("currentLeasingHeightTo", account.getCurrentLeasingHeightTo());
                if (account.getNextLesseeId() != null) {
                    response.put("nextLessee", Convert.toUnsignedLong(account.getNextLesseeId()));
                    response.put("nextLeasingHeightFrom", account.getNextLeasingHeightFrom());
                    response.put("nextLeasingHeightTo", account.getNextLeasingHeightTo());
                }
            }
            if (!account.getLessorIds().isEmpty()) {
                JSONArray lessorIds = new JSONArray();
                for (Long lessorId : account.getLessorIds()) {
                    lessorIds.add(Convert.toUnsignedLong(lessorId));
                }
                response.put("lessors", lessorIds);
            }

            JSONArray assetBalances = new JSONArray();
            for (Map.Entry<Long, Long> assetBalanceEntry : account.getAssetBalancesQNT().entrySet()) {

                JSONObject assetBalance = new JSONObject();
                assetBalance.put("asset", Convert.toUnsignedLong(assetBalanceEntry.getKey()));
                assetBalance.put("balanceQNT", String.valueOf(assetBalanceEntry.getValue()));
                assetBalances.add(assetBalance);

            }
            if (assetBalances.size() > 0) {
                response.put("assetBalances", assetBalances);
            }

            JSONArray unconfirmedAssetBalances = new JSONArray();
            for (Map.Entry<Long, Long> unconfirmedAssetBalanceEntry : account.getUnconfirmedAssetBalancesQNT().entrySet()) {

                JSONObject unconfirmedAssetBalance = new JSONObject();
                unconfirmedAssetBalance.put("asset", Convert.toUnsignedLong(unconfirmedAssetBalanceEntry.getKey()));
                unconfirmedAssetBalance.put("unconfirmedBalanceQNT", String.valueOf(unconfirmedAssetBalanceEntry.getValue()));
                unconfirmedAssetBalances.add(unconfirmedAssetBalance);

            }
            if (unconfirmedAssetBalances.size() > 0) {
                response.put("unconfirmedAssetBalances", unconfirmedAssetBalances);
            }
            return response;
        }<commit_msg>also show leasing accounts in RS format<commit_after>package nxt.http;

import nxt.Account;
import nxt.NxtException;
import nxt.util.Convert;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONStreamAware;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;
import java.util.Set;

public final class GetAccount extends APIServlet.APIRequestHandler {

    static final GetAccount instance = new GetAccount();

    private GetAccount() {
        super(new APITag[] {APITag.ACCOUNTS}, "account");
    }

    @Override
    JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {

        Account account = ParameterParser.getAccount(req);

        synchronized (account) {
            JSONObject response = JSONData.accountBalance(account);
            response.put("account", Convert.toUnsignedLong(account.getId()));
            response.put("accountRS", Convert.rsAccount(account.getId()));

            if (account.getPublicKey() != null) {
                response.put("publicKey", Convert.toHexString(account.getPublicKey()));
            }
            if (account.getName() != null) {
                response.put("name", account.getName());
            }
            if (account.getDescription() != null) {
                response.put("description", account.getDescription());
            }
            if (account.getCurrentLesseeId() != null) {
                response.put("currentLessee", Convert.toUnsignedLong(account.getCurrentLesseeId()));
                response.put("currentLesseeRS", Convert.rsAccount(account.getCurrentLesseeId()));
                response.put("currentLeasingHeightFrom", account.getCurrentLeasingHeightFrom());
                response.put("currentLeasingHeightTo", account.getCurrentLeasingHeightTo());
                if (account.getNextLesseeId() != null) {
                    response.put("nextLessee", Convert.toUnsignedLong(account.getNextLesseeId()));
                    response.put("nextLesseeRS", Convert.rsAccount(account.getNextLesseeId()));
                    response.put("nextLeasingHeightFrom", account.getNextLeasingHeightFrom());
                    response.put("nextLeasingHeightTo", account.getNextLeasingHeightTo());
                }
            }
            Set<Long> lessors = account.getLessorIds();
            if (!lessors.isEmpty()) {

                JSONArray lessorIds = new JSONArray();
                JSONArray lessorIdsRS = new JSONArray();
                for (Long lessorId : lessors) {
                    lessorIds.add(Convert.toUnsignedLong(lessorId));
                    lessorIdsRS.add(Convert.rsAccount(lessorId));
                }
                response.put("lessors", lessorIds);
                response.put("lessorsRS", lessorIdsRS);
            }

            JSONArray assetBalances = new JSONArray();
            for (Map.Entry<Long, Long> assetBalanceEntry : account.getAssetBalancesQNT().entrySet()) {

                JSONObject assetBalance = new JSONObject();
                assetBalance.put("asset", Convert.toUnsignedLong(assetBalanceEntry.getKey()));
                assetBalance.put("balanceQNT", String.valueOf(assetBalanceEntry.getValue()));
                assetBalances.add(assetBalance);

            }
            if (assetBalances.size() > 0) {
                response.put("assetBalances", assetBalances);
            }

            JSONArray unconfirmedAssetBalances = new JSONArray();
            for (Map.Entry<Long, Long> unconfirmedAssetBalanceEntry : account.getUnconfirmedAssetBalancesQNT().entrySet()) {

                JSONObject unconfirmedAssetBalance = new JSONObject();
                unconfirmedAssetBalance.put("asset", Convert.toUnsignedLong(unconfirmedAssetBalanceEntry.getKey()));
                unconfirmedAssetBalance.put("unconfirmedBalanceQNT", String.valueOf(unconfirmedAssetBalanceEntry.getValue()));
                unconfirmedAssetBalances.add(unconfirmedAssetBalance);

            }
            if (unconfirmedAssetBalances.size() > 0) {
                response.put("unconfirmedAssetBalances", unconfirmedAssetBalances);
            }
            return response;
        }
{'fraction_non_alphanumeric': 0.11010558069381599, 'fraction_numerical': 0.0005027652086475615, 'mean_word_length': 2.511473962930274, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '344523', 'n_tokens_mistral': 2048, 'n_tokens_neox': 1986, 'n_words': 318}