@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;
  }
Example #2
0
 private long getLessorsGuaranteedBalanceNQT() {
   long lessorsGuaranteedBalanceNQT = 0;
   try (DbIterator<Account> lessors = getLessors()) {
     while (lessors.hasNext()) {
       lessorsGuaranteedBalanceNQT += lessors.next().getGuaranteedBalanceNQT(1440);
     }
   }
   return lessorsGuaranteedBalanceNQT;
 }
  @Override
  JSONStreamAware processRequest(JSONObject request, Peer peer) {

    JSONObject response = new JSONObject();

    JSONArray transactionsData = new JSONArray();
    try (DbIterator<? extends Transaction> transactions =
        Nxt.getTransactionProcessor().getAllUnconfirmedTransactions()) {
      while (transactions.hasNext()) {
        Transaction transaction = transactions.next();
        transactionsData.add(transaction.getJSONObject());
      }
    }
    response.put("unconfirmedTransactions", transactionsData);

    return response;
  }
  @Override
  JSONStreamAware processRequest(HttpServletRequest req) throws ParameterException {
    String query = Convert.nullToEmpty(req.getParameter("query"));
    int firstIndex = ParameterParser.getFirstIndex(req);
    int lastIndex = ParameterParser.getLastIndex(req);
    boolean includeCounts = !"false".equalsIgnoreCase(req.getParameter("includeCounts"));

    JSONObject response = new JSONObject();
    JSONArray jsonArray = new JSONArray();
    try (DbIterator<Currency> currencies =
        Currency.searchCurrencies(query, firstIndex, lastIndex)) {
      while (currencies.hasNext()) {
        jsonArray.add(JSONData.currency(currencies.next(), includeCounts));
      }
    }
    response.put("currencies", jsonArray);
    return response;
  }
  @Override
  JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {

    long sellerId = ParameterParser.getAccountId(req, "seller", true);
    int firstIndex = ParameterParser.getFirstIndex(req);
    int lastIndex = ParameterParser.getLastIndex(req);

    JSONObject response = new JSONObject();
    JSONArray purchasesJSON = new JSONArray();

    try (DbIterator<DigitalGoodsStore.Purchase> purchases =
        DigitalGoodsStore.Purchase.getExpiredSellerPurchases(sellerId, firstIndex, lastIndex)) {
      while (purchases.hasNext()) {
        purchasesJSON.add(JSONData.purchase(purchases.next()));
      }
    }

    response.put("purchases", purchasesJSON);
    return response;
  }
Example #6
0
  @Override
  JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
    long accountId = ParameterParser.getAccountId(req, "account", false);
    boolean includeFinished = "true".equalsIgnoreCase(req.getParameter("includeFinished"));
    int firstIndex = ParameterParser.getFirstIndex(req);
    int lastIndex = ParameterParser.getLastIndex(req);
    final int timestamp = ParameterParser.getTimestamp(req);

    JSONArray pollsJson = new JSONArray();
    DbIterator<Poll> polls = null;
    try {
      if (accountId == 0) {
        if (includeFinished) {
          polls = Poll.getAllPolls(firstIndex, lastIndex);
        } else {
          polls = Poll.getActivePolls(firstIndex, lastIndex);
        }
      } else {
        polls = Poll.getPollsByAccount(accountId, includeFinished, firstIndex, lastIndex);
      }

      while (polls.hasNext()) {
        Poll poll = polls.next();
        if (poll.getTimestamp() < timestamp) {
          break;
        }
        pollsJson.add(JSONData.poll(poll));
      }
    } finally {
      DbUtils.close(polls);
    }

    JSONObject response = new JSONObject();
    response.put("polls", pollsJson);
    return response;
  }