@Override public void onBlocksDownloaded(Peer peer, Block block, @Nullable FilteredBlock filteredBlock, int blocksLeft) { //Log.d("BlocksDownloaded",block.getHashAsString()); Integer height=blockChain.getChainHead().getHeight(); synchronized (blocks) { blocks.put(block, height); if (blocks.keySet().size() >= 30) { blocks.remove(blocks.keySet().toArray()[blocks.keySet().size() - 1]); } } if(System.currentTimeMillis()-lastTimestamp>1000) { refreshUI(); lastTimestamp = System.currentTimeMillis(); } }
@Override public void onBindViewHolder(ViewHolder holder, int position) { // - get element from your dataset at this position // - replace the contents of the view with that element synchronized (mDataset) { final Block block = (Block) (mDataset.keySet().toArray()[position]); Integer height = (Integer) (mDataset.values().toArray())[position]; SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy/MM/dd HH:mm"); String formatted = dateFormat.format(block.getTime()); holder.mTvTitle.setText(formatted); holder.mTvBlockHash.setText(block.getHashAsString()); holder.mTvHeight.setText(String.valueOf(height)); holder.mTvTransactions.setText(String.valueOf(block.getTransactions().size())); holder.key = block.getHashAsString().toString(); } }
public SQLiteBlockStore(NetworkParameters params, Context context) throws BlockStoreException { this.params = params; blocksDataSource = new BlocksDataSource(context); blocksDataSource.open(); if (blocksDataSource.count()==0){ createNewBlockStore(params); } else{ try { DBBlock block = blocksDataSource.getLast(); Block b = new Block(params, block.getHeader()); StoredBlock s = build(b); this.chainHead = s.getHeader().getHash(); } catch (Exception e) { throw new BlockStoreException("Invalid BlockStore chainHead"); } } blocksDataSource.close(); }
@Override public synchronized StoredBlock get(Sha256Hash hash) throws BlockStoreException { if(hash==null) throw new BlockStoreException("Invalid hash"); blocksDataSource.open(); DBBlock block = null; try { block = blocksDataSource.getHash(hash.toString()); } catch (Exception e) { blocksDataSource.close(); return null; } Block b = new Block(params, block.getHeader()); StoredBlock s = build(b); blocksDataSource.close(); return s; }
public void onBlocksDownloaded(Peer peer, Block block, @Nullable FilteredBlock filteredBlock, int blocksLeft) { if(!this.caughtUp) { if(blocksLeft == 0) { this.caughtUp = true; this.doneDownload(); this.future.set(Long.valueOf(peer.getBestHeight())); } if(blocksLeft >= 0 && this.originalBlocksLeft > 0) { double pct = 100.0D - 100.0D * ((double)blocksLeft / (double)this.originalBlocksLeft); if((int)pct != this.lastPercent) { this.lastBlockDate = new Date(block.getTimeSeconds() * 1000L); this.progress(pct, blocksLeft, this.lastBlockDate); this.lastPercent = (int)pct; } } } }
@Override public void onBlocksDownloaded(Peer arg0, Block arg1, @Nullable FilteredBlock arg2, int arg3) { System.out.println("received block"); boolean receivedBcastAnnouncmnt = false; Map<Sha256Hash, Transaction> assocTxs = arg2.getAssociatedTransactions(); for(Transaction tx : assocTxs.values()) { System.out.println("from within mixpartner discovery " + tx); if(tx.getOutputs().size() > 1 && BroadcastAnnouncement.isBroadcastAnnouncementScript(tx.getOutput(1).getScriptBytes())) //&& !wallet.isTransactionRelevant(tx)) { //tx.getInput(0).getScriptSig().getChunks().get(0) { if(!this.broadcasts.contains(tx) && wallet.getTransaction(tx.getHash()) == null) { this.broadcasts.add(tx); receivedBcastAnnouncmnt = true; } } } if(receivedBcastAnnouncmnt) { for(BroadcastAnnouncementChangeEventListener l : listeners) { l.onBroadcastAnnouncementChanged(); } } }
private static Block createGenesis(NetworkParameters n) { Block genesisBlock = new Block(n, Block.BLOCK_VERSION_GENESIS); Transaction t = new Transaction(n); try { // A script containing the difficulty bits and the following message: // // "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks" byte[] bytes = Utils.HEX.decode ("04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73"); t.addInput(new TransactionInput(n, t, bytes)); ByteArrayOutputStream scriptPubKeyBytes = new ByteArrayOutputStream(); Script.writeBytes(scriptPubKeyBytes, Utils.HEX.decode ("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f")); scriptPubKeyBytes.write(ScriptOpCodes.OP_CHECKSIG); t.addOutput(new TransactionOutput(n, t, FIFTY_COINS, scriptPubKeyBytes.toByteArray())); } catch (Exception e) { // Cannot happen. throw new RuntimeException(e); } genesisBlock.addTransaction(t); return genesisBlock; }
/** * The flags indicating which script validation tests should be applied to * the given transaction. Enables support for alternative blockchains which enable * tests based on different criteria. * * @param block block the transaction belongs to. * @param transaction to determine flags for. * @param height height of the block, if known, null otherwise. Returned * tests should be a safe subset if block height is unknown. */ public EnumSet<Script.VerifyFlag> getTransactionVerificationFlags(final Block block, final Transaction transaction, final VersionTally tally, final Integer height) { final EnumSet<Script.VerifyFlag> verifyFlags = EnumSet.noneOf(Script.VerifyFlag.class); if (block.getTimeSeconds() >= NetworkParameters.BIP16_ENFORCE_TIME) verifyFlags.add(Script.VerifyFlag.P2SH); // Start enforcing CHECKLOCKTIMEVERIFY, (BIP65) for block.nVersion=4 // blocks, when 75% of the network has upgraded: if (block.getVersion() >= Block.BLOCK_VERSION_BIP65 && tally.getCountAtOrAbove(Block.BLOCK_VERSION_BIP65) > this.getMajorityEnforceBlockUpgrade()) { verifyFlags.add(Script.VerifyFlag.CHECKLOCKTIMEVERIFY); } return verifyFlags; }
@Override public void onBlocksDownloaded(Peer peer, Block block, @Nullable FilteredBlock filteredBlock, int blocksLeft) { if (caughtUp) return; if (blocksLeft == 0) { caughtUp = true; doneDownload(); future.set(peer.getBestHeight()); } if (blocksLeft < 0 || originalBlocksLeft <= 0) return; double pct = 100.0 - (100.0 * (blocksLeft / (double) originalBlocksLeft)); if ((int) pct != lastPercent) { progress(pct, blocksLeft, new Date(block.getTimeSeconds() * 1000)); lastPercent = (int) pct; } }
public void reDownloadBlockTransactions(Integer blockHeight) { Database db = Database.getInstance(); ResultSet rs = db.executeQuery("select * from blocks where block_index='"+blockHeight.toString()+"';"); try { if (rs.next()) { Block block = peerGroup.getDownloadPeer().getBlock(new Sha256Hash(rs.getString("block_hash"))).get(); db.executeUpdate("delete from transactions where block_index='"+blockHeight.toString()+"';"); Integer txSnInBlock=0; for (Transaction tx : block.getTransactions()) { importPPkTransaction(tx,txSnInBlock, block, blockHeight); txSnInBlock++; } } } catch (Exception e) { } }
public void importBlock(Block block, Integer blockHeight) { statusMessage = "Importing block "+blockHeight; logger.info(statusMessage); Database db = Database.getInstance(); ResultSet rs = db.executeQuery("select * from blocks where block_hash='"+block.getHashAsString()+"';"); try { if (!rs.next()) { db.executeUpdate("INSERT INTO blocks(block_index,block_hash,block_time,block_nonce) VALUES('"+blockHeight.toString()+"','"+block.getHashAsString()+"','"+block.getTimeSeconds()+"','"+block.getNonce()+"')"); } Integer txSnInBlock=0; for (Transaction tx : block.getTransactions()) { importPPkTransaction(tx,txSnInBlock, block, blockHeight); txSnInBlock++; } } catch (SQLException e) { } }
/** * Get the block at height index. * * Returns null if we didn't see the block yet, or if we started at a checkpoint after the block. */ public Block get(long index) { lock.lock(); try { if (channel.size() < (index+1) * HEADER_SIZE) return null; ByteBuffer b = ByteBuffer.allocate((int)HEADER_SIZE); int n = channel.read(b, index * HEADER_SIZE); if (n == 0) return null; if (n != HEADER_SIZE) throw new RuntimeException("partial read from store file"); if (Arrays.equals(b.array(), EMPTY)) return null; return new Block(params, b.array()); } catch (IOException e) { throw propagate(e); } finally { lock.unlock(); } }
public boolean add(Block block) { checkState(block.getTransactions() == null); lock.lock(); try { if (!block.getPrevBlockHash().equals(top().getHash())) { log.error("block.prev = {}, but expecting {}@{}", block.getPrevBlockHash(), top().getHash(), getHeight()); return false; } channel.write(ByteBuffer.wrap(block.bitcoinSerialize()), channel.size()); return true; } catch (Exception e) { throw propagate(e); } finally { lock.unlock(); } }
public UnitTestParams() { super(); id = ID_UNITTESTNET; packetMagic = 0x0b110907; addressHeader = CoinDefinition.testnetAddressHeader; p2shHeader = CoinDefinition.testnetp2shHeader; acceptableAddressCodes = new int[] { addressHeader, p2shHeader }; maxTarget = new BigInteger("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16); genesisBlock.setTime(System.currentTimeMillis() / 1000); genesisBlock.setDifficultyTarget(Block.EASIEST_DIFFICULTY_TARGET); //genesisBlock.solve(); port = CoinDefinition.TestPort; interval = 10; dumpedPrivateKeyHeader = 128 + CoinDefinition.testnetAddressHeader; targetTimespan = 200000000; // 6 years. Just a very big number. spendableCoinbaseDepth = 5; subsidyDecreaseBlockCount = 100; dnsSeeds = null; }
private static AltcoinBlock createGenesis(NetworkParameters params) { AltcoinBlock genesisBlock = new AltcoinBlock(params, Block.BLOCK_VERSION_GENESIS); Transaction t = new Transaction(params); try { byte[] bytes = Utils.HEX.decode ("04ffff001d0104084e696e746f6e646f"); t.addInput(new TransactionInput(params, t, bytes)); ByteArrayOutputStream scriptPubKeyBytes = new ByteArrayOutputStream(); Script.writeBytes(scriptPubKeyBytes, Utils.HEX.decode ("040184710fa689ad5023690c80f3a49c8f13f8d45b8c857fbcbc8bc4a8e4d3eb4b10f4d4604fa08dce601aaf0f470216fe1b51850b4acf21b179c45070ac7b03a9")); scriptPubKeyBytes.write(ScriptOpCodes.OP_CHECKSIG); t.addOutput(new TransactionOutput(params, t, COIN.multiply(88), scriptPubKeyBytes.toByteArray())); } catch (Exception e) { // Cannot happen. throw new RuntimeException(e); } genesisBlock.addTransaction(t); return genesisBlock; }
private static AltcoinBlock createGenesis(NetworkParameters params) { AltcoinBlock genesisBlock = new AltcoinBlock(params, Block.BLOCK_VERSION_GENESIS); Transaction t = new Transaction(params); try { byte[] bytes = Hex.decode ("04ffff001d0104404e592054696d65732030352f4f63742f32303131205374657665204a6f62732c204170706c65e280997320566973696f6e6172792c2044696573206174203536"); t.addInput(new TransactionInput(params, t, bytes)); ByteArrayOutputStream scriptPubKeyBytes = new ByteArrayOutputStream(); Script.writeBytes(scriptPubKeyBytes, Hex.decode ("040184710fa689ad5023690c80f3a49c8f13f8d45b8c857fbcbc8bc4a8e4d3eb4b10f4d4604fa08dce601aaf0f470216fe1b51850b4acf21b179c45070ac7b03a9")); scriptPubKeyBytes.write(ScriptOpCodes.OP_CHECKSIG); t.addOutput(new TransactionOutput(params, t, COIN.multiply(50), scriptPubKeyBytes.toByteArray())); } catch (Exception e) { // Cannot happen. throw new RuntimeException(e); } genesisBlock.addTransaction(t); genesisBlock.setTime(1317798646L); genesisBlock.setDifficultyTarget(0x1e0ffff0L); genesisBlock.setNonce(385270584); return genesisBlock; }
/** * Extract from Litecoin source code, definition of regtest params. * https://github.com/litecoin-project/litecoin/blob/edc66b374ea68107c721062152dd95e6aa037d53/src/chainparams.cpp */ @Override public Block getGenesisBlock() { synchronized (LitecoinRegTestParams.class) { if (genesis == null) { genesis = super.getGenesisBlock(); genesis.setNonce(0); genesis.setDifficultyTarget(0x207fffffL); genesis.setTime(1296688602L); checkState(genesis.getVersion() == 1); checkState(genesis.getMerkleRoot().toString().equals("97ddfbbae6be97fd6cdf3e7ca13232a3afff2353e29badfab7f73011edd4ced9")); checkState(genesis.getHashAsString().toLowerCase().equals("530827f38f93b43ed12af0b3ad25a288dc02ed74d6d7857862df51fc56c416f9")); genesis.verifyHeader(); } return genesis; } }
private static AltcoinBlock createGenesis(NetworkParameters params) { AltcoinBlock genesisBlock = new AltcoinBlock(params, Block.BLOCK_VERSION_GENESIS); Transaction t = new Transaction(params); try { byte[] bytes = Hex.decode ("04ffff001d0104404e592054696d65732030352f4f63742f32303131205374657665204a6f62732c204170706c65e280997320566973696f6e6172792c2044696573206174203536"); t.addInput(new TransactionInput(params, t, bytes)); ByteArrayOutputStream scriptPubKeyBytes = new ByteArrayOutputStream(); Script.writeBytes(scriptPubKeyBytes, Hex.decode ("040184710fa689ad5023690c80f3a49c8f13f8d45b8c857fbcbc8bc4a8e4d3eb4b10f4d4604fa08dce601aaf0f470216fe1b51850b4acf21b179c45070ac7b03a9")); scriptPubKeyBytes.write(ScriptOpCodes.OP_CHECKSIG); t.addOutput(new TransactionOutput(params, t, COIN.multiply(50), scriptPubKeyBytes.toByteArray())); } catch (Exception e) { // Cannot happen. throw new RuntimeException(e); } genesisBlock.addTransaction(t); genesisBlock.setTime(1317972665L); genesisBlock.setDifficultyTarget(0x1e0ffff0L); genesisBlock.setNonce(2084524493); return genesisBlock; }
private static AltcoinBlock createGenesis(NetworkParameters params) { AltcoinBlock genesisBlock = new AltcoinBlock(params, Block.BLOCK_VERSION_GENESIS); Transaction t = new Transaction(params); try { // "... choose what comes next. Lives of your own, or a return to chains. -- V" byte[] bytes = Utils.HEX.decode ("04ff7f001c020a024b2e2e2e2063686f6f7365207768617420636f6d6573206e6578742e20204c69766573206f6620796f7572206f776e2c206f7220612072657475726e20746f20636861696e732e202d2d2056"); t.addInput(new TransactionInput(params, t, bytes)); ByteArrayOutputStream scriptPubKeyBytes = new ByteArrayOutputStream(); Script.writeBytes(scriptPubKeyBytes, Utils.HEX.decode ("04b620369050cd899ffbbc4e8ee51e8c4534a855bb463439d63d235d4779685d8b6f4870a238cf365ac94fa13ef9a2a22cd99d0d5ee86dcabcafce36c7acf43ce5")); scriptPubKeyBytes.write(ScriptOpCodes.OP_CHECKSIG); t.addOutput(new TransactionOutput(params, t, COIN.multiply(50), scriptPubKeyBytes.toByteArray())); } catch (Exception e) { // Cannot happen. throw new RuntimeException(e); } genesisBlock.addTransaction(t); return genesisBlock; }
public UnitTestParams() { super(); id = ID_UNITTESTNET; packetMagic = 0x0b110907; addressHeader = 111; p2shHeader = 196; acceptableAddressCodes = new int[] { addressHeader, p2shHeader }; maxTarget = new BigInteger("00ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16); genesisBlock.setTime(System.currentTimeMillis() / 1000); genesisBlock.setDifficultyTarget(Block.EASIEST_DIFFICULTY_TARGET); genesisBlock.solve(); port = 18333; interval = 10; dumpedPrivateKeyHeader = 239; targetTimespan = 200000000; // 6 years. Just a very big number. spendableCoinbaseDepth = 5; subsidyDecreaseBlockCount = 100; dnsSeeds = null; }
private CoinbleskTestParams() { super(); id = ID_UNITTESTNET; packetMagic = 0x0b110907; addressHeader = 111; p2shHeader = 196; acceptableAddressCodes = new int[]{addressHeader, p2shHeader}; maxTarget = new BigInteger("00ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16); genesisBlock.setTime(System.currentTimeMillis() / 1000); genesisBlock.setDifficultyTarget(Block.EASIEST_DIFFICULTY_TARGET); genesisBlock.solve(); port = 18333; interval = 500000; // changed to something bigger to avoid difficulty transition errors dumpedPrivateKeyHeader = 239; targetTimespan = 200000000; // 6 years. Just a very big number. spendableCoinbaseDepth = 5; subsidyDecreaseBlockCount = 100; dnsSeeds = null; addrSeeds = null; bip32HeaderPub = 0x043587CF; bip32HeaderPriv = 0x04358394; majorityEnforceBlockUpgrade = 3; majorityRejectBlockOutdated = 4; majorityWindow = 7; }
public UnitTestParams() { super(); id = ID_UNITTESTNET; packetMagic = 0x0b110907; addressHeader = 111; p2shHeader = 196; acceptableAddressCodes = new int[] { addressHeader, p2shHeader }; maxTarget = new BigInteger("00ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16); genesisBlock.setTime(System.currentTimeMillis() / 1000); genesisBlock.setDifficultyTarget(Block.EASIEST_DIFFICULTY_TARGET); genesisBlock.solve(); port = 18333; interval = 10; dumpedPrivateKeyHeader = 239; targetTimespan = 200000000; // 6 years. Just a very big number. spendableCoinbaseDepth = 5; subsidyDecreaseBlockCount = 100; dnsSeeds = null; bip32HeaderPub = 0x043587CF; bip32HeaderPriv = 0x04358394; }
public BlockSummary(int height, Block blk, TXUtil tx_util, Map<Sha256Hash, TransactionSummary> tx_cache) { this.height = height; this.block_hash = blk.getHash(); tx_map = new HashMap<>(); for(Transaction tx : blk.getTransactions()) { TransactionSummary tx_sum = new TransactionSummary(tx, tx_util, tx_cache); tx_map.put(tx.getHash(), tx_sum); synchronized(tx_cache) { tx_cache.put(tx.getHash(), tx_sum); } } }
@Override public void addBlockThings(int height, Block b) { //System.out.println("Adding block " + height + " " + b.getHash()); //Make my own copy, which is needed for working in a single block (from importer) HashMap<Sha256Hash, TransactionSummary> import_block_cache = new HashMap<Sha256Hash, TransactionSummary>(); BlockSummary block_summary = new BlockSummary(height, b, tx_util, import_block_cache); // Put everything in the shared cache for other threads, which hit it in getTransactionSummary below synchronized(import_tx_summary_cache) { import_tx_summary_cache.putAll(import_block_cache); } getBlockSummaryMap().put(b.getHash(), block_summary); long t1=System.nanoTime(); cake.addAddresses(height, block_summary.getAllAddresses()); TimeRecord.record(t1, "cake_add_addresses"); }
public void populateBlockData(StoredBlock blk, JSONObject block_data) throws org.json.JSONException { Block header = blk.getHeader(); block_data.put("nonce", header.getNonce()); block_data.put("prev_block_hash", header.getPrevBlockHash().toString()); block_data.put("timestamp", header.getTimeSeconds()); block_data.put("merkle_root", header.getMerkleRoot().toString()); block_data.put("block_height", blk.getHeight()); block_data.put("version",header.getVersion()); block_data.put("bits", header.getDifficultyTarget()); //block_data.put("utxo_root", jelly.getUtxoTrieMgr().getRootHash(header.getHash())); }
private void downloadBlock(int height) throws Exception { Sha256Hash hash = null; try { hash = jelly.getBitcoinRPC().getBlockHash(height); if (downloaded.contains(hash)) return; SerializedBlock block = jelly.getBitcoinRPC().getBlock(hash); Block b = block.getBlock(jelly.getNetworkParameters()); jelly.getBlockStore().put(b); jelly.getImporter().saveBlock(b); downloaded.add(hash); } catch(Exception e) { jelly.getEventLog().alarm(String.format("Error in download of block %d (%s) - %s", height, hash, e.toString())); throw e; } }
public void saveBlock(Block b) { try { Sha256Hash hash = b.getHash(); needed_prev_blocks.offer(b.getPrevBlockHash()); int h = block_store.getHeight(hash); synchronized(in_progress) { if (!in_progress.containsKey(hash)) { in_progress.put(hash, new Semaphore(0)); } } jelly.getEventLog().log("Enqueing block: " + hash + " - " + h); block_queue.put(b); } catch(java.lang.InterruptedException e) { throw new RuntimeException(e); } }
@Test public void bigMerkleFirst() throws Exception { Sha256Hash block_hash = new Sha256Hash("000000000000000083d9b2fcc1d14e53c97604648e4610091ba5f9eb4d1b930b"); Block blk = jelly.getDB().getBlock(block_hash).getBlock(jelly.getNetworkParameters()); JSONObject result = Util.getMerkleTreeForTransaction(blk.getTransactions(), new Sha256Hash("5672d9a9055237c3801ad03af38b75216e23f2f977fe1b38616046d87b6c4c5e")); JSONArray merk = result.getJSONArray("merkle"); Assert.assertEquals(0, result.getInt("pos")); Assert.assertEquals(10, merk.length()); Assert.assertEquals("e958da99798f1edb0455334d1eba8cb924d0192ff5eebd759ae932492e7eb616",merk.getString(5)); Assert.assertEquals("34325213ee37ae23a5266de8f812de5f13cda4deceb81601783811f858ae201b",merk.getString(9)); System.out.println(result); }
@Test public void bigMerkleLast() throws Exception { Sha256Hash block_hash = new Sha256Hash("000000000000000083d9b2fcc1d14e53c97604648e4610091ba5f9eb4d1b930b"); Block blk = jelly.getDB().getBlock(block_hash).getBlock(jelly.getNetworkParameters()); JSONObject result = Util.getMerkleTreeForTransaction(blk.getTransactions(), new Sha256Hash("32bb3d77f14a69e9998af9e6d60a2b4fa9c2bb0022f271928d01bfe7e4720b69")); JSONArray merk = result.getJSONArray("merkle"); Assert.assertEquals(978, result.getInt("pos")); Assert.assertEquals(10, merk.length()); Assert.assertEquals("6c915f47db641cefdcd379230ad52cb428780a01fe7ce59e25b28607e67d428e",merk.getString(9)); System.out.println(result); }
public synchronized void createNewBlockStore(NetworkParameters params) throws BlockStoreException { // Set up the genesis block. When we start out fresh, it is by definition the top of the chain. Block genesis = params.getGenesisBlock().cloneAsHeader(); StoredBlock storedGenesis = new StoredBlock(genesis, genesis.getWork(), 0); this.chainHead = storedGenesis.getHeader().getHash(); this.put(storedGenesis); }
/** * * @param peer * @param block * @param filteredBlock * @param blocksLeft */ @Override public void onBlocksDownloaded(Peer peer, Block block, @Nullable FilteredBlock filteredBlock, int blocksLeft) { super.onBlocksDownloaded(peer, block, filteredBlock, blocksLeft); // to avoid overhead on notification, only 100th blocks or the last ones if (blocksLeft % 100 == 0 || blocksLeft < 10) { for (CoinActionCallback<CurrencyCoin> callback : _callbacks) { callback.onBlocksDownloaded(_bitcoinManager.getCurrencyCoin(), this.lastPercent, blocksLeft, this.lastBlockDate); } } }
/** * * @param peer * @param block * @param filteredBlock * @param blocksLeft */ @Override public void onBlocksDownloaded(Peer peer, Block block, @Nullable FilteredBlock filteredBlock, int blocksLeft) { super.onBlocksDownloaded(peer, block, filteredBlock, blocksLeft); // to avoid overhead on notification, only 100th blocks or the last ones if (blocksLeft % 100 == 0 || blocksLeft < 10) { for (CoinActionCallback<CurrencyCoin> callback : _callbacks) { callback.onBlocksDownloaded(_bitcoin, this.lastPercent, blocksLeft, this.lastBlockDate); } } }
public void searchBlockForPartner(Block block) throws NullPointerException { if(this.head == null) { throw new NullPointerException("Block must not be null"); } List<Transaction> listTxs = block.getTransactions(); for(Transaction tx : listTxs) { System.out.println("test transaction " + tx.getHashAsString()); if(isTransactionBroadcastAnnouncement(tx)) { broadcasts.add(tx); System.out.println("found a broadcast announcement!"); System.out.println(tx); } } }