@Override
  JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {

    long accountId = ParameterParser.getAccount(req).getId();
    long assetId = 0;
    try {
      assetId = Convert.parseUnsignedLong(req.getParameter("asset"));
    } catch (RuntimeException e) {
      // ignore
    }
    int firstIndex = ParameterParser.getFirstIndex(req);
    int lastIndex = ParameterParser.getLastIndex(req);

    DbIterator<Order.Ask> askOrders;
    if (assetId == 0) {
      askOrders = Order.Ask.getAskOrdersByAccount(accountId, firstIndex, lastIndex);
    } else {
      askOrders = Order.Ask.getAskOrdersByAccountAsset(accountId, assetId, firstIndex, lastIndex);
    }
    JSONArray orderIds = new JSONArray();
    try {
      while (askOrders.hasNext()) {
        orderIds.add(Convert.toUnsignedLong(askOrders.next().getId()));
      }
    } finally {
      askOrders.close();
    }
    JSONObject response = new JSONObject();
    response.put("askOrderIds", orderIds);
    return response;
  }
Ejemplo n.º 2
0
 @Override
 JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
   long orderId = ParameterParser.getUnsignedLong(req, "order", true);
   Account account = ParameterParser.getSenderAccount(req);
   Order.Ask orderData = Order.Ask.getAskOrder(orderId);
   if (orderData == null || orderData.getAccountId() != account.getId()) {
     return UNKNOWN_ORDER;
   }
   Attachment attachment = new Attachment.ColoredCoinsAskOrderCancellation(orderId);
   return createTransaction(req, account, attachment);
 }
 @Override
 JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
   Long orderId = ParameterParser.getOrderId(req);
   Order.Ask askOrder = Order.Ask.getAskOrder(orderId);
   if (askOrder == null) {
     return UNKNOWN_ORDER;
   }
   return JSONData.askOrder(askOrder);
 }
  public static Transaction create(
      IAccount sender,
      Long order,
      short deadline,
      int fee,
      Long referencedTransaction,
      NXTService nxt)
      throws TransactionException, ValidationException {

    String secretPhrase = sender.getPrivateKey();
    byte[] publicKey = Crypto.getPublicKey(secretPhrase);

    if ((fee <= 0) || (fee >= 1000000000L))
      throw new TransactionException(TransactionException.INCORRECT_FEE);

    if ((deadline < 1) || (deadline > 1440))
      throw new TransactionException(TransactionException.INCORRECT_DEADLINE);

    Account account = Account.getAccount(publicKey);
    if (account == null) throw new TransactionException(TransactionException.INTERNAL_ERROR);

    Order.Ask orderData = Order.Ask.getAskOrder(order);
    if (orderData == null || !orderData.getAccount().getId().equals(account.getId()))
      throw new TransactionException(TransactionException.UNKNOWN_ORDER);

    Attachment attachment = new Attachment.ColoredCoinsAskOrderCancellation(order);

    Transaction transaction =
        Nxt.getTransactionProcessor()
            .newTransaction(
                deadline, publicKey, Genesis.CREATOR_ID, 0, fee, referencedTransaction, attachment);
    transaction.sign(secretPhrase);

    nxt.broacastTransaction(transaction);

    return transaction;
  }