Ejemplo n.º 1
0
  public static LazyList getBlocks(Boolean orderAscending, INxtService nxt) {
    Connection con = null;

    /* Count number of records */
    // int available = nxt.getSmartBlockCount();
    int available = Nxt.getBlockchain().getBlockCount();

    /* Create the record iterator */
    try {
      con = Db.getConnection();
      StringBuilder buf = new StringBuilder();
      buf.append("SELECT * FROM block ");
      if (orderAscending != null) {
        if (Boolean.TRUE.equals(orderAscending)) {
          buf.append("ORDER BY db_id ASC");
        } else if (Boolean.FALSE.equals(orderAscending)) {
          buf.append("ORDER BY db_id DESC");
        }
      }
      PreparedStatement pstmt = con.prepareStatement(buf.toString());
      DbIterator<? extends Block> iterator = Nxt.getBlockchain().getBlocks(con, pstmt);
      LazyList lazyList = new LazyList(iterator, available);
      return lazyList;
    } catch (SQLException e) {
      logger.error("SQL Error", e);
      if (con != null) {
        DbUtils.close(con);
      }
    }
    return null;
  }
Ejemplo n.º 2
0
  public static List<Block> getGeneratedBlocks(Long accountId) {
    Connection con = null;
    try {
      con = Db.getConnection();
      PreparedStatement pstmt =
          con.prepareStatement("SELECT * FROM block WHERE generator_id = ? ORDER BY db_id ASC");
      pstmt.setLong(1, accountId);

      List<Block> result = new ArrayList<Block>();
      DbIterator<? extends Block> iterator = Nxt.getBlockchain().getBlocks(con, pstmt);
      while (iterator.hasNext()) {
        result.add(iterator.next());
      }
      return result;
    } catch (SQLException e) {
      DbUtils.close(con);
      throw new RuntimeException(e.toString(), e);
    }
  }