Exemplo n.º 1
0
  public Request(Command command, int assignedId, Client client) {
    this.client = client;
    cmd = command;
    id = assignedId;
    json = new JSONObject();

    json("command", cmd.toString());
    json("id", assignedId);
  }
Exemplo n.º 2
0
 public void json(JSONObject jsonObject) {
   Iterator keys = jsonObject.keys();
   while (keys.hasNext()) {
     String next = (String) keys.next();
     json(next, jsonObject.opt(next));
   }
 }
  private static void walkAccountTx(final Client c, final Object marker, final int pages) {
    Request request = c.newRequest(Command.account_tx);
    request.json("binary", true);
    request.json("account", theAccount);

    if (marker != null) {
      request.json("marker", marker);
    }
    request.json("ledger_index_max", -1);

    request.once(
        Request.OnSuccess.class,
        new Request.OnSuccess() {
          @Override
          public void called(Response response) {
            JSONObject result = response.result;
            try {
              JSONArray transactions = result.getJSONArray("transactions");
              System.out.printf("Found %d (more) transactions %n", transactions.length());
              appendTo(outputFile, result.toString());

              Object newMarker = result.opt("marker");
              System.out.printf("Marker %s%n", newMarker);
              if (marker != null
                  && newMarker != null
                  && marker.toString().equals(newMarker.toString())) {
                // This shouldn't happen since Stef's patch but who knows how
                // pervasively it's been deployed ?
                //                        return;
                newMarker = null;
              }
              if ((newMarker != null) && (pages - 1 > 0) && transactions.length() > 0) {
                System.out.printf("Found new marker %s%n", newMarker);
                walkAccountTx(c, newMarker, pages - 1);
              } else {
                System.out.printf("Found all transactions");
              }

            } catch (Exception e) {
              throw new RuntimeException(e);
            }
          }
        });

    request.request();
  }
Exemplo n.º 4
0
 public Request subscribeAccount(AccountID... accounts) {
   Request request = newRequest(Command.subscribe);
   JSONArray accounts_arr = new JSONArray();
   for (AccountID acc : accounts) {
     accounts_arr.put(acc);
   }
   request.json("accounts", accounts_arr);
   return request;
 }
Exemplo n.º 5
0
 public Request subscribeBookOffers(Issue get, Issue pay) {
   Request request = newRequest(Command.subscribe);
   JSONObject book = new JSONObject();
   JSONArray books = new JSONArray(new Object[] {book});
   book.put("snapshot", true);
   book.put("taker_gets", get.toJSON());
   book.put("taker_pays", pay.toJSON());
   request.json("books", books);
   return request;
 }
Exemplo n.º 6
0
 private void logRetry(Request request, String reason) {
   if (logger.isLoggable(Level.WARNING)) {
     log(
         Level.WARNING,
         previousUri
             + ": "
             + reason
             + ", muting listeners "
             + "for "
             + request.json()
             + "and trying again");
   }
 }
Exemplo n.º 7
0
  private void subscribe(JSONObject subscription) {
    Request request = newRequest(Command.subscribe);

    request.json(subscription);
    request.on(
        Request.OnSuccess.class,
        new Request.OnSuccess() {
          @Override
          public void called(Response response) {
            // TODO ... make sure this isn't just an account subscription
            serverInfo.update(response.result);
            emit(OnSubscribed.class, serverInfo);
          }
        });
    request.request();
  }
Exemplo n.º 8
0
 public Request requestBookOffers(Issue get, Issue pay) {
   Request request = newRequest(Command.book_offers);
   request.json("taker_gets", get.toJSON());
   request.json("taker_pays", pay.toJSON());
   return request;
 }
Exemplo n.º 9
0
 public Request accountInfo(AccountID account) {
   Request req = newRequest(Command.account_info);
   req.json("account", account.address);
   return req;
 }
Exemplo n.º 10
0
 public Request accountLines(AccountID account) {
   Request req = newRequest(Command.account_lines);
   req.json("account", account.address);
   return req;
 }
Exemplo n.º 11
0
 public Request submit(String tx_blob, boolean fail_hard) {
   Request req = newRequest(Command.submit);
   req.json("tx_blob", tx_blob);
   req.json("fail_hard", fail_hard);
   return req;
 }