public static List<BetInfo> getPending(String source) { Database db = Database.getInstance(); ResultSet rs = db.executeQuery( "select * from transactions where block_index<0 and source='" + source + "' order by tx_index desc;"); List<BetInfo> bets = new ArrayList<BetInfo>(); Blocks blocks = Blocks.getInstance(); try { while (rs.next()) { String destination = rs.getString("destination"); BigInteger btcAmount = BigInteger.valueOf(rs.getLong("btc_amount")); BigInteger fee = BigInteger.valueOf(rs.getLong("fee")); Integer blockIndex = rs.getInt("block_index"); String txHash = rs.getString("tx_hash"); Integer txIndex = rs.getInt("tx_index"); String dataString = rs.getString("data"); ResultSet rsCheck = db.executeQuery("select * from bets where tx_index='" + txIndex.toString() + "'"); if (!rsCheck.next()) { List<Byte> messageType = blocks.getMessageTypeFromTransaction(dataString); List<Byte> message = blocks.getMessageFromTransaction(dataString); if (messageType.get(3) == Bet.id.byteValue() && message.size() == length) { ByteBuffer byteBuffer = ByteBuffer.allocate(length); for (byte b : message) { byteBuffer.put(b); } BigInteger bet = BigInteger.valueOf(byteBuffer.getLong(0)); Double chance = byteBuffer.getDouble(8); Double payout = byteBuffer.getDouble(16); Double houseEdge = Config.houseEdge; // PROTOCOL CHANGE Double oldHouseEdge = 0.02; Boolean payoutChanceCongruent = Util.roundOff(chance, 6) == Util.roundOff(100.0 / (payout / (1.0 - houseEdge)), 6) || Util.roundOff(chance, 6) == Util.roundOff(100.0 / (payout / (1.0 - oldHouseEdge)), 6); BigInteger chaSupply = Util.chaSupplyForBetting(); String validity = "invalid"; if (!source.equals("") && bet.compareTo(BigInteger.ZERO) > 0 && chance > 0.0 && chance < 100.0 && payout > 1.0 && payoutChanceCongruent) { if (bet.compareTo(Util.getBalance(source, "CHA")) <= 0) { if ((payout - 1.0) * bet.doubleValue() < chaSupply.doubleValue() * Config.maxProfit) { BetInfo betInfo = new BetInfo(); betInfo.bet = bet; betInfo.chance = chance; betInfo.payout = payout; betInfo.source = source; betInfo.txHash = txHash; bets.add(betInfo); } } } } } } } catch (SQLException e) { } return bets; }