/****************************************************************************** * Copyright © 2013-2016 The Nxt Core Developers. * * * * See the AUTHORS.txt, DEVELOPER-AGREEMENT.txt and LICENSE.txt files at * * the top-level directory of this distribution for the individual copyright * * holder information and the developer policies on copyright and licensing. * * * * Unless otherwise agreed in a custom licensing agreement, no part of the * * Nxt software, including this file, may be copied, modified, propagated, * * or distributed except according to the terms contained in the LICENSE.txt * * file. * * * * Removal or modification of this copyright notice is prohibited. * * * ******************************************************************************/ package nxt.http; import nxt.Account; import nxt.AccountRestrictions; import nxt.Alias; import nxt.Asset; import nxt.AssetTransfer; import nxt.Constants; import nxt.Currency; import nxt.CurrencyBuyOffer; import nxt.CurrencyTransfer; import nxt.DigitalGoodsStore; import nxt.Exchange; import nxt.ExchangeRequest; import nxt.Generator; import nxt.Nxt; import nxt.Order; import nxt.Poll; import nxt.PrunableMessage; import nxt.Shuffling; import nxt.TaggedData; import nxt.Trade; import nxt.Vote; import nxt.peer.Peers; import nxt.util.UPnP; import org.json.simple.JSONObject; import org.json.simple.JSONStreamAware; import javax.servlet.http.HttpServletRequest; import java.net.InetAddress; public final class GetState extends APIServlet.APIRequestHandler { static final GetState instance = new GetState(); private GetState() { super(new APITag[] {APITag.INFO}, "includeCounts", "adminPassword"); } @Override JSONStreamAware processRequest(HttpServletRequest req) { JSONObject response = GetBlockchainStatus.instance.processRequest(req); if ("true".equalsIgnoreCase(req.getParameter("includeCounts")) && API.checkPassword(req)) { response.put("numberOfTransactions", Nxt.getBlockchain().getTransactionCount()); response.put("numberOfAccounts", Account.getCount()); response.put("numberOfAssets", Asset.getCount()); int askCount = Order.Ask.getCount(); int bidCount = Order.Bid.getCount(); response.put("numberOfOrders", askCount + bidCount); response.put("numberOfAskOrders", askCount); response.put("numberOfBidOrders", bidCount); response.put("numberOfTrades", Trade.getCount()); response.put("numberOfTransfers", AssetTransfer.getCount()); response.put("numberOfCurrencies", Currency.getCount()); response.put("numberOfOffers", CurrencyBuyOffer.getCount()); response.put("numberOfExchangeRequests", ExchangeRequest.getCount()); response.put("numberOfExchanges", Exchange.getCount()); response.put("numberOfCurrencyTransfers", CurrencyTransfer.getCount()); response.put("numberOfAliases", Alias.getCount()); response.put("numberOfGoods", DigitalGoodsStore.Goods.getCount()); response.put("numberOfPurchases", DigitalGoodsStore.Purchase.getCount()); response.put("numberOfTags", DigitalGoodsStore.Tag.getCount()); response.put("numberOfPolls", Poll.getCount()); response.put("numberOfVotes", Vote.getCount()); response.put("numberOfPrunableMessages", PrunableMessage.getCount()); response.put("numberOfTaggedData", TaggedData.getCount()); response.put("numberOfDataTags", TaggedData.Tag.getTagCount()); response.put("numberOfAccountLeases", Account.getAccountLeaseCount()); response.put("numberOfActiveAccountLeases", Account.getActiveLeaseCount()); response.put("numberOfShufflings", Shuffling.getCount()); response.put("numberOfActiveShufflings", Shuffling.getActiveCount()); response.put("numberOfPhasingOnlyAccounts", AccountRestrictions.PhasingOnly.getCount()); } response.put("numberOfPeers", Peers.getAllPeers().size()); response.put("numberOfActivePeers", Peers.getActivePeers().size()); response.put("numberOfUnlockedAccounts", Generator.getAllGenerators().size()); response.put("availableProcessors", Runtime.getRuntime().availableProcessors()); response.put("maxMemory", Runtime.getRuntime().maxMemory()); response.put("totalMemory", Runtime.getRuntime().totalMemory()); response.put("freeMemory", Runtime.getRuntime().freeMemory()); response.put("peerPort", Peers.getDefaultPeerPort()); response.put("isOffline", Constants.isOffline); response.put("needsAdminPassword", !API.disableAdminPassword); InetAddress externalAddress = UPnP.getExternalAddress(); if (externalAddress != null) { response.put("upnpExternalAddress", externalAddress.getHostAddress()); } return response; } @Override boolean allowRequiredBlockParameters() { return false; } }