/****************************************************************************** * 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.Constants; import nxt.HoldingType; import nxt.NxtException; import org.json.simple.JSONStreamAware; import javax.servlet.http.HttpServletRequest; public final class ShufflingCreate extends CreateTransaction { static final ShufflingCreate instance = new ShufflingCreate(); private ShufflingCreate() { super(new APITag[] {APITag.SHUFFLING, APITag.CREATE_TRANSACTION}, "holding", "holdingType", "amount", "participantCount", "registrationPeriod"); } @Override JSONStreamAware processRequest(HttpServletRequest req) throws NxtException { HoldingType holdingType = HoldingType.get(ParameterParser.getByte(req, "holdingType", (byte) 0, (byte) 2, false)); long amount = ParameterParser.getLong(req, "amount", holdingType == HoldingType.NXT ? Constants.SHUFFLING_DEPOSIT_NQT : 1L, Long.MAX_VALUE, true); long holdingId = ParameterParser.getUnsignedLong(req, "holding", holdingType != HoldingType.NXT); if (holdingType == HoldingType.NXT && holdingId != 0) { return JSONResponses.incorrect("holding", "holding only used for currency or asset shuffling"); } byte participantCount = ParameterParser.getByte(req, "participantCount", Constants.MIN_NUMBER_OF_SHUFFLING_PARTICIPANTS, Constants.MAX_NUMBER_OF_SHUFFLING_PARTICIPANTS, true); short registrationPeriod = (short)ParameterParser.getInt(req, "registrationPeriod", 0, Constants.MAX_SHUFFLING_REGISTRATION_PERIOD, true); Attachment attachment = new Attachment.ShufflingCreation(holdingId, holdingType, amount, participantCount, registrationPeriod); Account account = ParameterParser.getSenderAccount(req); if (account.getControls().contains(Account.ControlType.PHASING_ONLY)) { return JSONResponses.error("Accounts under phasing only control cannot start a shuffling"); } try { return createTransaction(req, account, attachment); } catch (NxtException.InsufficientBalanceException e) { return JSONResponses.notEnoughHolding(holdingType); } } }