Ejemplo n.º 1
0
 public long getGuaranteedBalanceNQT(final int numberOfConfirmations, final int currentHeight) {
   if (numberOfConfirmations >= Nxt.getBlockchain().getHeight()) {
     return 0;
   }
   if (numberOfConfirmations > 2880 || numberOfConfirmations < 0) {
     throw new IllegalArgumentException(
         "Number of required confirmations must be between 0 and " + 2880);
   }
   int height = currentHeight - numberOfConfirmations;
   try (Connection con = Db.getConnection();
       PreparedStatement pstmt =
           con.prepareStatement(
               "SELECT SUM (additions) AS additions "
                   + "FROM account_guaranteed_balance WHERE account_id = ? AND height > ? AND height <= ?")) {
     pstmt.setLong(1, this.id);
     pstmt.setInt(2, height);
     pstmt.setInt(3, currentHeight);
     try (ResultSet rs = pstmt.executeQuery()) {
       if (!rs.next()) {
         return balanceNQT;
       }
       return Math.max(Convert.safeSubtract(balanceNQT, rs.getLong("additions")), 0);
     }
   } catch (SQLException e) {
     throw new RuntimeException(e.toString(), e);
   }
 }