/****************************************************************************** * 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.AssetDelete; import nxt.NxtException; import nxt.db.DbIterator; import nxt.db.DbUtils; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.JSONStreamAware; import javax.servlet.http.HttpServletRequest; public final class GetAssetDeletes extends APIServlet.APIRequestHandler { static final GetAssetDeletes instance = new GetAssetDeletes(); private GetAssetDeletes() { super(new APITag[] {APITag.AE}, "asset", "account", "firstIndex", "lastIndex", "timestamp", "includeAssetInfo"); } @Override JSONStreamAware processRequest(HttpServletRequest req) throws NxtException { long assetId = ParameterParser.getUnsignedLong(req, "asset", false); long accountId = ParameterParser.getAccountId(req, false); if (assetId == 0 && accountId == 0) { return JSONResponses.MISSING_ASSET_ACCOUNT; } int timestamp = ParameterParser.getTimestamp(req); int firstIndex = ParameterParser.getFirstIndex(req); int lastIndex = ParameterParser.getLastIndex(req); boolean includeAssetInfo = "true".equalsIgnoreCase(req.getParameter("includeAssetInfo")); JSONObject response = new JSONObject(); JSONArray deletesData = new JSONArray(); DbIterator<AssetDelete> deletes = null; try { if (accountId == 0) { deletes = AssetDelete.getAssetDeletes(assetId, firstIndex, lastIndex); } else if (assetId == 0) { deletes = AssetDelete.getAccountAssetDeletes(accountId, firstIndex, lastIndex); } else { deletes = AssetDelete.getAccountAssetDeletes(accountId, assetId, firstIndex, lastIndex); } while (deletes.hasNext()) { AssetDelete assetDelete = deletes.next(); if (assetDelete.getTimestamp() < timestamp) { break; } deletesData.add(JSONData.assetDelete(assetDelete, includeAssetInfo)); } } finally { DbUtils.close(deletes); } response.put("deletes", deletesData); return response; } @Override boolean startDbTransaction() { return true; } }