/******************************************************************************
* 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.Attachment;
import nxt.Currency;
import nxt.NxtException;
import org.json.simple.JSONStreamAware;
import javax.servlet.http.HttpServletRequest;
/**
* Claim currency units and receive back NXT invested into this currency before it became active
* <p>
* Parameters
* <ul>
* <li>currency - currency id
* <li>units - the number of currency units claimed<br>
* This value is multiplied by current currency rate and the result is added to the sender NXT account balance.
* </ul>
* <p>
* Constraints
* <p>This transaction is allowed only when the currency is {@link nxt.CurrencyType#CLAIMABLE} and is already active.<br>
*/
public final class CurrencyReserveClaim extends CreateTransaction {
static final CurrencyReserveClaim instance = new CurrencyReserveClaim();
private CurrencyReserveClaim() {
super(new APITag[] {APITag.MS, APITag.CREATE_TRANSACTION}, "currency", "units");
}
@Override
JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
Currency currency = ParameterParser.getCurrency(req);
long units = ParameterParser.getLong(req, "units", 0, currency.getReserveSupply(), false);
Account account = ParameterParser.getSenderAccount(req);
Attachment attachment = new Attachment.MonetarySystemReserveClaim(currency.getId(), units);
return createTransaction(req, account, attachment);
}
}