@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 transactions = new JSONArray();
    for (Transaction transaction : Nhz.getTransactionProcessor().getAllUnconfirmedTransactions()) {
      if (accountId != null
          && !(accountId.equals(transaction.getSenderId())
              || accountId.equals(transaction.getRecipientId()))) {
        continue;
      }
      transactions.add(JSONData.unconfirmedTransaction(transaction));
    }

    JSONObject response = new JSONObject();
    response.put("unconfirmedTransactions", transactions);
    return response;
  }
예제 #2
0
 public static String readString(ByteBuffer buffer, int numBytes, int maxLength)
     throws NhzException.NotValidException {
   if (numBytes > 3 * maxLength) {
     throw new NhzException.NotValidException("Max parameter length exceeded");
   }
   byte[] bytes = new byte[numBytes];
   buffer.get(bytes);
   return Convert.toString(bytes);
 }
예제 #3
0
  @Override
  JSONStreamAware processRequest(HttpServletRequest req) {

    JSONArray pollIds = new JSONArray();
    for (Poll poll : Poll.getAllPolls()) {
      pollIds.add(Convert.toUnsignedLong(poll.getId()));
    }

    JSONObject response = new JSONObject();
    response.put("pollIds", pollIds);
    return response;
  }
예제 #4
0
  @Override
  JSONStreamAware processRequest(HttpServletRequest req) {

    JSONArray assetIds = new JSONArray();
    for (Asset asset : Asset.getAllAssets()) {
      assetIds.add(Convert.toUnsignedLong(asset.getId()));
    }

    JSONObject response = new JSONObject();
    response.put("assetIds", assetIds);
    return response;
  }
예제 #5
0
 public static Long fullHashToId(String hash) {
   if (hash == null) {
     return null;
   }
   return fullHashToId(Convert.parseHexString(hash));
 }