public int getProcNo(String blockName){ int i; int j = 0; Block tmpBlock; tmpBlock = this.tail; // begynner med siste blokken (mest sannsynlig(?) at vi finner variabelen deklarer der) if (tmpBlock == this.head){ // tilfelle dersom vi kun har en blokk if (tmpBlock.getName().equals(blockName)) return tmpBlock.getProcNo(); } else { for (i = this.depth(); i>0; i--){ // går baklengs igjennom alle blokker if (tmpBlock.getName().equals(blockName)) // dersom blokken har navnet "blockName" return tmpBlock.getProcNo(); tmpBlock = tmpBlock.getPrevious(); // går en blokk "opp" j++; } } if (endedBlocks.hasBlock(blockName)){ // det kan være at blokken er avsluttet, da finner man den i "endedBlocks" return endedBlocks.getProcNo(blockName); } return -1; // returnerer ett negativt tall dersom blokknavnet ikke finnes }
public static BigInteger getBalance(String address, String asset) { Database db = Database.getInstance(); Blocks blocks = Blocks.getInstance(); if (asset.equals("BTC")) { /* BigInteger totalBalance = BigInteger.ZERO; LinkedList<TransactionOutput> unspentOutputs = blocks.wallet.calculateAllSpendCandidates(true); Set<Transaction> txs = blocks.wallet.getTransactions(true); for (TransactionOutput out : unspentOutputs) { Script script = out.getScriptPubKey(); if (script.getToAddress(blocks.params).toString().equals(address) && out.isAvailableForSpending()) { totalBalance = totalBalance.add(out.getValue()); } } return totalBalance; */ return getBTCBalance(address); } else { ResultSet rs = db.executeQuery( "select sum(amount) as amount from balances where address='" + address + "' and asset='" + asset + "';"); try { if (rs.next()) { return BigInteger.valueOf(rs.getLong("amount")); } } catch (SQLException e) { } } return BigInteger.ZERO; }
public static List<String> getAddresses() { Blocks blocks = Blocks.getInstance(); List<ECKey> keys = blocks.wallet.getKeys(); List<String> addresses = new ArrayList<String>(); for (ECKey key : keys) { addresses.add(key.toAddress(blocks.params).toString()); } return addresses; }
public void removeLast(){ endedBlocks.addBlock(tail.getName(), tail.getProcNo()); // tar vare på blokken som avsluttes tail = tail.getPrevious(); // tailen settes til sin egen forgjenger tail.setNext(head); // setter "tailen" sin neste til å være "head" head.setPrevious(tail); // setter "head" sin forrige til å være tail numLevels--; // reduserer antalle nivåer med 1 }
private static List<Expression> simpleList(BlockExpression expression) { Expression simple = Blocks.simple(expression); if (simple instanceof NewExpression) { NewExpression newExpression = (NewExpression) simple; return newExpression.arguments; } else { return Collections.singletonList(simple); } }
public static Integer getLastBlock() { Blocks blocks = Blocks.getInstance(); Database db = Database.getInstance(); ResultSet rs = db.executeQuery("select * from blocks order by block_index desc limit 1;"); try { while (rs.next()) { return rs.getInt("block_index"); } } catch (SQLException e) { } return blocks.newbiecoinBlock; }
public static Transaction create(String source, BigInteger bet, Double chance, Double payout) throws Exception { BigInteger chaSupply = Util.chaSupplyForBetting(); if (source.equals("")) throw new Exception("Please specify a source address."); if (!(bet.compareTo(BigInteger.ZERO) > 0)) throw new Exception("Please bet more than zero."); if (!(chance > 0.0 && chance < 100.0)) throw new Exception("Please specify a chance between 0 and 100."); if (!(payout > 1.0)) throw new Exception("Please specify a payout greater than 1."); if (!(Util.roundOff(chance, 6) == Util.roundOff(100.0 / (payout / (1.0 - Config.houseEdge)), 6))) throw new Exception("Please specify a chance and payout that are congruent."); if (!(bet.compareTo(Util.getBalance(source, "CHA")) <= 0)) throw new Exception("Please specify a bet that is smaller than your CHA balance."); if (!((payout - 1.0) * bet.doubleValue() < chaSupply.doubleValue() * Config.maxProfit)) throw new Exception( "Please specify a bet with a payout less than the maximum percentage of the house bankroll you can win."); Blocks blocks = Blocks.getInstance(); ByteBuffer byteBuffer = ByteBuffer.allocate(length + 4); byteBuffer.putInt(0, id); byteBuffer.putLong(0 + 4, bet.longValue()); byteBuffer.putDouble(8 + 4, chance); byteBuffer.putDouble(16 + 4, payout); List<Byte> dataArrayList = Util.toByteArrayList(byteBuffer.array()); dataArrayList.addAll(0, Util.toByteArrayList(Config.prefix.getBytes())); byte[] data = Util.toByteArray(dataArrayList); String dataString = ""; try { dataString = new String(data, "ISO-8859-1"); } catch (UnsupportedEncodingException e) { } Transaction tx = blocks.transaction( source, "", BigInteger.ZERO, BigInteger.valueOf(Config.minFee), dataString); return tx; }
@Override protected PreparedExecution implement( RelDataType rowType, RelNode rootRel, SqlKind sqlKind, ClassDeclaration decl, Argument[] args) { RelDataType resultType = rootRel.getRowType(); boolean isDml = sqlKind.belongsTo(SqlKind.DML); javaCompiler = createCompiler(); EnumerableRelImplementor relImplementor = getRelImplementor(rootRel.getCluster().getRexBuilder()); BlockExpression expr = relImplementor.implementRoot((EnumerableRel) rootRel); ParameterExpression root0 = Expressions.parameter(DataContext.class, "root0"); String s = Expressions.toString( Blocks.create( Expressions.declare( Modifier.FINAL, (ParameterExpression) schema.getExpression(), root0), expr), false); final Executable executable; try { executable = (Executable) ExpressionEvaluator.createFastScriptEvaluator( s, Executable.class, new String[] {root0.name}); } catch (Exception e) { throw Helper.INSTANCE.wrap("Error while compiling generated Java code:\n" + s, e); } if (timingTracer != null) { timingTracer.traceTime("end codegen"); } if (timingTracer != null) { timingTracer.traceTime("end compilation"); } return new PreparedExecution( null, rootRel, resultType, isDml, mapTableModOp(isDml, sqlKind), null) { public Object execute() { return executable.execute(schema); } }; }
public void calculate(Blocks caller, Grid g) { Blocks.wait(1); // accounts for the torch delay -- may not be necessary, depending on realism of // problems setState( !getSurroundings(g)[getOrient()] .getState()); // if placed on the side of a block, its orientation is the direction of // the block it's sitting on. setCharge(); // laziness? // if (oldState != getState() || oldCharge != getCharge()) // g.addUpdate(getPos()); calculateAll(g); // getGrid().addCalced(this.getPos()); }
public static BigInteger getReserved(String address, String asset) { Database db = Database.getInstance(); Blocks blocks = Blocks.getInstance(); ResultSet rs = db.executeQuery( "select sum(give_amount) as amount from orders where source='" + address + "' and give_asset='" + asset + "' and validity='valid'"); try { if (rs.next()) { return BigInteger.valueOf(rs.getLong("amount")); } } catch (SQLException e) { } return BigInteger.ZERO; }
public static void main(String[] args) { Config.loadUserDefined(); Blocks blocks = Blocks.getInstanceAndWait(); Thread blocksThread = new Thread(blocks); blocksThread.setDaemon(true); blocksThread.start(); Config.loadUserDefined(); Database db = Database.getInstance(); JSONObject attributes = null; JSONObject attributesSaved = null; while (true) { attributes = new JSONObject(); ResultSet rs = db.executeQuery( "select address,amount as balance from balances where asset='CHA' group by address order by amount desc;"); JSONObject balances = new JSONObject(); try { while (rs.next()) { balances.put( rs.getString("address"), BigInteger.valueOf(rs.getLong("balance")).doubleValue() / Config.unit.doubleValue()); } } catch (Exception e) { } try { attributes.put("balances", balances); attributes.put("height", Util.getLastBlock()); if (attributesSaved == null || attributes.getDouble("height") > attributesSaved.getDouble("height")) { attributesSaved = attributes; PrintWriter out = new PrintWriter("balances.txt"); out.print(attributes.toString()); out.close(); try { // Git Commit the change and print out any output and errors in the process Runtime rt = Runtime.getRuntime(); String[] commands = {"sh", "git_commit.sh"}; Process proc = rt.exec(commands); BufferedReader stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream())); BufferedReader stdError = new BufferedReader(new InputStreamReader(proc.getErrorStream())); // read the output from the command String s = null; while ((s = stdInput.readLine()) != null) { System.out.println(s); } // read any errors from the attempted command while ((s = stdError.readLine()) != null) { System.out.println(s); } } catch (Exception ex) { ex.printStackTrace(); } } } catch (Exception e) { } try { Thread.sleep(1000 * 60); } catch (InterruptedException e) { logger.error("Error during loop: " + e.toString()); } } }
public void testWriteAnonymousClass() { // final List<String> baz = Arrays.asList("foo", "bar"); // new AbstractList<String>() { // public int size() { // return baz.size(); // } // public String get(int index) { // return ((String) baz.get(index)).toUpperCase(); // } // } final ParameterExpression bazParameter = Expressions.parameter(Types.of(List.class, String.class), "baz"); final ParameterExpression indexParameter = Expressions.parameter(Integer.TYPE, "index"); BlockExpression e = Expressions.block( Expressions.declare( Modifier.FINAL, bazParameter, Expressions.call( Arrays.class, "asList", Arrays.<Expression>asList( Expressions.constant("foo"), Expressions.constant("bar")))), Expressions.statement( Expressions.new_( Types.of(AbstractList.class, String.class), Collections.<Expression>emptyList(), Arrays.<MemberDeclaration>asList( Expressions.fieldDecl( Modifier.PUBLIC | Modifier.FINAL, Expressions.parameter(String.class, "qux"), Expressions.constant("xyzzy")), Expressions.methodDecl( Modifier.PUBLIC, Integer.TYPE, "size", Collections.<ParameterExpression>emptyList(), Blocks.toFunctionBlock( Expressions.call( bazParameter, "size", Collections.<Expression>emptyList()))), Expressions.methodDecl( Modifier.PUBLIC, String.class, "get", Arrays.asList(indexParameter), Blocks.toFunctionBlock( Expressions.call( Expressions.convert_( Expressions.call( bazParameter, "get", Arrays.<Expression>asList(indexParameter)), String.class), "toUpperCase", Collections.<Expression>emptyList()))))))); assertEquals( "{\n" + " final java.util.List<String> baz = java.util.Arrays.asList(\"foo\", \"bar\");\n" + " new java.util.AbstractList<String>(){\n" + " public final String qux = \"xyzzy\";\n" + " public int size() {\n" + " return baz.size();\n" + " }\n" + "\n" + " public String get(int index) {\n" + " return ((String) baz.get(index)).toUpperCase();\n" + " }\n" + "\n" + " };\n" + "}\n", Expressions.toString(e)); }
@Override void accept(ExpressionWriter writer, int lprec, int rprec) { // "new Function1() { // public Result apply(T1 p1, ...) { // <body> // } // // bridge method // public Object apply(Object p1, ...) { // return apply((T1) p1, ...); // } // } // // if any arguments are primitive there is an extra bridge method: // // new Function1() { // public double apply(double p1, int p2) { // <body> // } // // box bridge method // public Double apply(Double p1, Integer p2) { // return apply(p1.doubleValue(), p2.intValue()); // } // // bridge method // public Object apply(Object p1, Object p2) { // return apply((Double) p1, (Integer) p2); // } List<String> params = new ArrayList<String>(); List<String> bridgeParams = new ArrayList<String>(); List<String> bridgeArgs = new ArrayList<String>(); List<String> boxBridgeParams = new ArrayList<String>(); List<String> boxBridgeArgs = new ArrayList<String>(); for (ParameterExpression parameterExpression : parameterList) { final Type parameterType = parameterExpression.getType(); final Type parameterBoxType = Types.box(parameterType); final String parameterBoxTypeName = Types.className(parameterBoxType); params.add(parameterExpression.declString()); bridgeParams.add(parameterExpression.declString(Object.class)); bridgeArgs.add("(" + parameterBoxTypeName + ") " + parameterExpression.name); boxBridgeParams.add(parameterExpression.declString(parameterBoxType)); boxBridgeArgs.add( parameterExpression.name + (Primitive.is(parameterType) ? "." + Primitive.of(parameterType).primitiveName + "Value()" : "")); } Type bridgeResultType = Functions.FUNCTION_RESULT_TYPES.get(this.type); if (bridgeResultType == null) { bridgeResultType = body.getType(); } Type resultType2 = bridgeResultType; if (bridgeResultType == Object.class && !params.equals(bridgeParams) && !(body.getType() instanceof TypeVariable)) { resultType2 = body.getType(); } String methodName = getAbstractMethodName(); writer .append("new ") .append(type) .append("()") .begin(" {\n") .append("public ") .append(Types.className(resultType2)) .list(" " + methodName + "(", ", ", ") ", params) .append(Blocks.toFunctionBlock(body)); // Generate an intermediate bridge method if at least one parameter is // primitive. if (!boxBridgeParams.equals(params)) { writer .append("public ") .append(Types.boxClassName(bridgeResultType)) .list(" " + methodName + "(", ", ", ") ", boxBridgeParams) .begin("{\n") .list("return " + methodName + "(\n", ",\n", ");\n", boxBridgeArgs) .end("}\n"); } // Generate a bridge method. Argument types are looser (as if every // type parameter is set to 'Object'). // // Skip the bridge method if there are no arguments. It would have the // same overload as the regular method. if (!bridgeParams.equals(params)) { writer .append("public ") .append(Types.boxClassName(bridgeResultType)) .list(" " + methodName + "(", ", ", ") ", bridgeParams) .begin("{\n") .list("return " + methodName + "(\n", ",\n", ");\n", bridgeArgs) .end("}\n"); } writer.end("}\n"); }
public RexNode toRex(BlockExpression expression) { return toRex(Blocks.simple(expression)); }
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; }
public static void main(String[] args) { Blocks blocks = Blocks.getInstance(); blocks.reDownloadBlockTransactions(299628); }
// blocks public void checkBlocksCrush(ArrayList<Blocks> blocks, int i) { Blocks block = blocks.get(i); if (block.isDoor() && !block.isDoorOpen()) { if (enemiesSize <= 12 && enemiesSize > 7) { if (block.getX() > 0 && block.getX() < 2600) { blocks.get(i).setDoor(true); blockMove = true; } } else { if (enemiesSize <= 7 && enemiesSize > 3) { if (block.getX() > 2600 && block.getX() < 5500) { blocks.get(i).setDoor(true); blockMove = true; } } else { if (enemiesSize <= 3) { if (block.getX() > 5500) { blocks.get(i).setDoor(true); blockMove = true; } } } } } if (block.isTelekines()) { if (x - width / 2 > block.getX() + block.getWidth() / 2 && y + height / 2 > block.getY() - block.getHeight() / 2 - height && y - height / 2 < block.getY() + block.getHeight() / 2 + height && !factingRight && x - width / 2 - block.getX() < 370) { blocks.get(i).setTelekinesTo(telekinesTo, false); if (!telekinesTo) blocks.get(i).setTelekinesFrom(telekinesFrom, true); } else { if (x + width / 2 < block.getX() - block.getWidth() / 2 && y + height / 2 > block.getY() - block.getHeight() / 2 - height && y - height / 2 < block.getY() + block.getHeight() / 2 + height && factingRight && block.getX() - x - width / 2 < 370) { blocks.get(i).setTelekinesTo(telekinesTo, true); if (!telekinesTo) blocks.get(i).setTelekinesFrom(telekinesFrom, false); } else { blocks.get(i).setTelekinesTo(false, true); blocks.get(i).setTelekinesFrom(false, false); } } } if (block.isHorizontal()) { if (x + width / 2 > block.getX() - block.getWidth() / 2 + 5 && x - width / 2 < block.getX() + block.getWidth() / 2 - 5 && y - height / 2 < block.getY() - block.getHeight() / 2 && y + height / 2 >= block.getY() - block.getHeight() / 2) { if (reverse) { dy = -3; y = block.getY() - block.getHeight() / 2 - height / 2; } else { falling = false; x += block.getDX(); y = block.getY() - block.getHeight() / 2 - height / 2; } } else { if (x + width / 2 > block.getX() - block.getWidth() / 2 + 5 && x - width / 2 < block.getX() + block.getWidth() / 2 - 5 && y + height / 2 > block.getY() + block.getHeight() / 2 && y - height / 2 <= block.getY() + block.getHeight() / 2) { if (reverse) { falling = false; x += block.getDX(); y = block.getY() + block.getHeight() / 2 + height / 2; } else { dy = 3; y = block.getY() + block.getHeight() / 2 + height / 2; } } else { if (x - width / 2 < block.getX() - block.getWidth() / 2 && x + width / 2 >= block.getX() - block.getWidth() / 2 && y + height / 2 > block.getY() - block.getHeight() / 2 && y - height / 2 < block.getY() + block.getHeight() / 2) { dx = 0; x = block.getX() - block.getWidth() / 2 - width / 2; } else { if (x + width / 2 > block.getX() + block.getWidth() / 2 && x - width / 2 <= block.getX() + block.getWidth() / 2 && y - height / 2 < block.getY() + block.getHeight() / 2 && y + height / 2 > block.getY() - block.getHeight() / 2) { dx = 0; x = block.getX() + block.getWidth() / 2 + width / 2; } } } } } if (block.isVertical()) { if (x + width / 2 > block.getX() - block.getWidth() / 2 + 5 && x - width / 2 < block.getX() + block.getWidth() / 2 - 5 && y - height / 2 < block.getY() - block.getHeight() / 2 && y + height / 2 >= block.getY() - block.getHeight() / 2) { if (reverse) { dy = -3; y = block.getY() - block.getHeight() / 2 - height / 2; } else { falling = false; y = block.getY() - block.getHeight() / 2 - height / 2 + 4; } } else { if (x + width / 2 > block.getX() - block.getWidth() / 2 + 5 && x - width / 2 < block.getX() + block.getWidth() / 2 - 5 && y + height / 2 > block.getY() + block.getHeight() / 2 && y - height / 2 <= block.getY() + block.getHeight() / 2) { if (reverse) { falling = false; y = block.getY() + block.getHeight() / 2 + height / 2 - 4; } else { dy = 3; y = block.getY() + block.getHeight() / 2 + height / 2; } } else { if (x - width / 2 < block.getX() - block.getWidth() / 2 && x + width / 2 >= block.getX() - block.getWidth() / 2 && y + height / 2 > block.getY() - block.getHeight() / 2 && y - height / 2 < block.getY() + block.getHeight() / 2) { dx = 0; x = block.getX() - block.getWidth() / 2 - width / 2; } else { if (x + width / 2 > block.getX() + block.getWidth() / 2 && x - width / 2 <= block.getX() + block.getWidth() / 2 && y - height / 2 < block.getY() + block.getHeight() / 2 && y + height / 2 > block.getY() - block.getHeight() / 2) { dx = 0; x = block.getX() + block.getWidth() / 2 + width / 2; } } } } } }