@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) {

    String[] assets = req.getParameterValues("assets");
    boolean includeCounts = !"false".equalsIgnoreCase(req.getParameter("includeCounts"));

    JSONObject response = new JSONObject();
    JSONArray assetsJSONArray = new JSONArray();
    response.put("assets", assetsJSONArray);
    for (String assetIdString : assets) {
      if (assetIdString == null || assetIdString.equals("")) {
        continue;
      }
      try {
        Asset asset = Asset.getAsset(Convert.parseUnsignedLong(assetIdString));
        if (asset == null) {
          return UNKNOWN_ASSET;
        }
        assetsJSONArray.add(JSONData.asset(asset, includeCounts));
      } catch (RuntimeException e) {
        return INCORRECT_ASSET;
      }
    }
    return response;
  }
  @Override
  JSONStreamAware processRequest(HttpServletRequest req) {

    String accountIdString = Convert.emptyToNull(req.getParameter("account"));
    Long accountId = null;

    if (accountIdString != null) {
      try {
        accountId = Convert.parseUnsignedLong(accountIdString);
      } catch (RuntimeException e) {
        return INCORRECT_ACCOUNT;
      }
    }

    JSONArray transactionIds = new JSONArray();
    for (Transaction transaction : Nxt.getTransactionProcessor().getAllUnconfirmedTransactions()) {
      if (accountId != null
          && !(accountId.equals(transaction.getSenderId())
              || accountId.equals(transaction.getRecipientId()))) {
        continue;
      }
      transactionIds.add(transaction.getStringId());
    }

    JSONObject response = new JSONObject();
    response.put("unconfirmedTransactionIds", transactionIds);
    return response;
  }
Ejemplo n.º 4
0
  @Override
  JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {

    String pollValue = req.getParameter("poll");

    if (pollValue == null) {
      return MISSING_POLL;
    }

    Poll pollData;
    int numberOfOptions = 0;
    try {
      pollData = Poll.getPoll(Convert.parseUnsignedLong(pollValue));
      if (pollData != null) {
        numberOfOptions = pollData.getOptions().length;
      } else return INCORRECT_POLL;
    } catch (RuntimeException e) {
      return INCORRECT_POLL;
    }

    byte[] vote = new byte[numberOfOptions];
    try {
      for (int i = 0; i < numberOfOptions; i++) {
        String voteValue = req.getParameter("vote" + i);
        if (voteValue != null) {
          vote[i] = Byte.parseByte(voteValue);
        }
      }
    } catch (NumberFormatException e) {
      return INCORRECT_VOTE;
    }

    Account account = getAccount(req);
    if (account == null) {
      return UNKNOWN_ACCOUNT;
    }

    Attachment attachment = new Attachment.MessagingVoteCasting(pollData.getId(), vote);
    return createTransaction(req, account, attachment);
  }
Ejemplo n.º 5
0
  TransactionImpl parseTransaction(JSONObject transactionData)
      throws NxtException.ValidationException {

    try {

      byte type = ((Long) transactionData.get("type")).byteValue();
      byte subtype = ((Long) transactionData.get("subtype")).byteValue();
      int timestamp = ((Long) transactionData.get("timestamp")).intValue();
      short deadline = ((Long) transactionData.get("deadline")).shortValue();
      byte[] senderPublicKey =
          Convert.parseHexString((String) transactionData.get("senderPublicKey"));
      Long recipientId = Convert.parseUnsignedLong((String) transactionData.get("recipient"));
      if (recipientId == null) recipientId = 0L; // ugly
      long amountNQT;
      long feeNQT;
      if (transactionData.get("amountNQT") != null) {
        amountNQT = ((Long) transactionData.get("amountNQT"));
        feeNQT = ((Long) transactionData.get("feeNQT"));
      } else {
        amountNQT = Convert.safeMultiply(((Long) transactionData.get("amount")), Constants.ONE_NXT);
        feeNQT = Convert.safeMultiply(((Long) transactionData.get("fee")), Constants.ONE_NXT);
      }
      String referencedTransactionFullHash =
          (String) transactionData.get("referencedTransactionFullHash");
      Long referencedTransactionId =
          Convert.parseUnsignedLong((String) transactionData.get("referencedTransaction"));
      byte[] signature = Convert.parseHexString((String) transactionData.get("signature"));

      TransactionType transactionType = TransactionType.findTransactionType(type, subtype);
      TransactionImpl transaction;
      if (referencedTransactionFullHash != null) {
        transaction =
            new TransactionImpl(
                transactionType,
                timestamp,
                deadline,
                senderPublicKey,
                recipientId,
                amountNQT,
                feeNQT,
                referencedTransactionFullHash,
                signature);
      } else {
        transaction =
            new TransactionImpl(
                transactionType,
                timestamp,
                deadline,
                senderPublicKey,
                recipientId,
                amountNQT,
                feeNQT,
                referencedTransactionId,
                signature);
      }

      JSONObject attachmentData = (JSONObject) transactionData.get("attachment");

      transactionType.loadAttachment(transaction, attachmentData);

      return transaction;

    } catch (RuntimeException e) {
      Logger.logDebugMessage(e.toString(), e);
      throw new NxtException.ValidationException(e.toString());
    }
  }