/****************************************************************************** * 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.Nxt; import nxt.NxtException; import nxt.PrunableMessage; import nxt.crypto.Crypto; import nxt.util.Convert; import nxt.util.JSON; import org.json.simple.JSONStreamAware; import javax.servlet.http.HttpServletRequest; import static nxt.http.JSONResponses.PRUNED_TRANSACTION; public final class GetPrunableMessage extends APIServlet.APIRequestHandler { static final GetPrunableMessage instance = new GetPrunableMessage(); private GetPrunableMessage() { super(new APITag[] {APITag.MESSAGES}, "transaction", "secretPhrase", "retrieve"); } @Override JSONStreamAware processRequest(HttpServletRequest req) throws NxtException { long transactionId = ParameterParser.getUnsignedLong(req, "transaction", true); String secretPhrase = Convert.emptyToNull(req.getParameter("secretPhrase")); boolean retrieve = "true".equalsIgnoreCase(req.getParameter("retrieve")); long readerAccountId = secretPhrase == null ? 0 : Account.getId(Crypto.getPublicKey(secretPhrase)); PrunableMessage prunableMessage = PrunableMessage.getPrunableMessage(transactionId); if (prunableMessage == null && retrieve) { if (Nxt.getBlockchainProcessor().restorePrunedTransaction(transactionId) == null) { return PRUNED_TRANSACTION; } prunableMessage = PrunableMessage.getPrunableMessage(transactionId); } if (prunableMessage != null) { return JSONData.prunableMessage(prunableMessage, readerAccountId, secretPhrase); } return JSON.emptyJSON; } }