org.bitcoinj.net.discovery.DnsDiscovery Java Examples
The following examples show how to use
org.bitcoinj.net.discovery.DnsDiscovery.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WatchMempool.java From green_android with GNU General Public License v3.0 | 6 votes |
public static void main(String[] args) throws InterruptedException { BriefLogFormatter.init(); PeerGroup peerGroup = new PeerGroup(PARAMS); peerGroup.setMaxConnections(32); peerGroup.addPeerDiscovery(new DnsDiscovery(PARAMS)); peerGroup.addOnTransactionBroadcastListener(new OnTransactionBroadcastListener() { @Override public void onTransaction(Peer peer, Transaction tx) { Result result = DefaultRiskAnalysis.FACTORY.create(null, tx, NO_DEPS).analyze(); incrementCounter(TOTAL_KEY); log.info("tx {} result {}", tx.getHash(), result); incrementCounter(result.name()); if (result == Result.NON_STANDARD) incrementCounter(Result.NON_STANDARD + "-" + DefaultRiskAnalysis.isStandard(tx)); } }); peerGroup.start(); while (true) { Thread.sleep(STATISTICS_FREQUENCY_MS); printCounters(); } }
Example #2
Source File: WatchMempool.java From GreenBits with GNU General Public License v3.0 | 6 votes |
public static void main(String[] args) throws InterruptedException { BriefLogFormatter.init(); PeerGroup peerGroup = new PeerGroup(PARAMS); peerGroup.setMaxConnections(32); peerGroup.addPeerDiscovery(new DnsDiscovery(PARAMS)); peerGroup.addOnTransactionBroadcastListener(new OnTransactionBroadcastListener() { @Override public void onTransaction(Peer peer, Transaction tx) { Result result = DefaultRiskAnalysis.FACTORY.create(null, tx, NO_DEPS).analyze(); incrementCounter(TOTAL_KEY); log.info("tx {} result {}", tx.getHash(), result); incrementCounter(result.name()); if (result == Result.NON_STANDARD) incrementCounter(Result.NON_STANDARD + "-" + DefaultRiskAnalysis.isStandard(tx)); } }); peerGroup.start(); while (true) { Thread.sleep(STATISTICS_FREQUENCY_MS); printCounters(); } }
Example #3
Source File: PrintPeers.java From green_android with GNU General Public License v3.0 | 5 votes |
private static void printDNS() throws PeerDiscoveryException { long start = System.currentTimeMillis(); DnsDiscovery dns = new DnsDiscovery(MainNetParams.get()); dnsPeers = dns.getPeers(0, 10, TimeUnit.SECONDS); printPeers(dnsPeers); printElapsed(start); }
Example #4
Source File: PrintPeers.java From GreenBits with GNU General Public License v3.0 | 5 votes |
private static void printDNS() throws PeerDiscoveryException { long start = System.currentTimeMillis(); DnsDiscovery dns = new DnsDiscovery(MainNetParams.get()); dnsPeers = dns.getPeers(0, 10, TimeUnit.SECONDS); printPeers(dnsPeers); printElapsed(start); }
Example #5
Source File: RestoreFromSeed.java From green_android with GNU General Public License v3.0 | 4 votes |
public static void main(String[] args) throws Exception { NetworkParameters params = TestNet3Params.get(); // Bitcoinj supports hierarchical deterministic wallets (or "HD Wallets"): https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki // HD wallets allow you to restore your wallet simply from a root seed. This seed can be represented using a short mnemonic sentence as described in BIP 39: https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki // Here we restore our wallet from a seed with no passphrase. Also have a look at the BackupToMnemonicSeed.java example that shows how to backup a wallet by creating a mnemonic sentence. String seedCode = "yard impulse luxury drive today throw farm pepper survey wreck glass federal"; String passphrase = ""; Long creationtime = 1409478661L; DeterministicSeed seed = new DeterministicSeed(seedCode, null, passphrase, creationtime); // The wallet class provides a easy fromSeed() function that loads a new wallet from a given seed. Wallet wallet = Wallet.fromSeed(params, seed); // Because we are importing an existing wallet which might already have transactions we must re-download the blockchain to make the wallet picks up these transactions // You can find some information about this in the guides: https://bitcoinj.github.io/working-with-the-wallet#setup // To do this we clear the transactions of the wallet and delete a possible existing blockchain file before we download the blockchain again further down. System.out.println(wallet.toString()); wallet.clearTransactions(0); File chainFile = new File("restore-from-seed.spvchain"); if (chainFile.exists()) { chainFile.delete(); } // Setting up the BlochChain, the BlocksStore and connecting to the network. SPVBlockStore chainStore = new SPVBlockStore(params, chainFile); BlockChain chain = new BlockChain(params, chainStore); PeerGroup peers = new PeerGroup(params, chain); peers.addPeerDiscovery(new DnsDiscovery(params)); // Now we need to hook the wallet up to the blockchain and the peers. This registers event listeners that notify our wallet about new transactions. chain.addWallet(wallet); peers.addWallet(wallet); DownloadProgressTracker bListener = new DownloadProgressTracker() { @Override public void doneDownload() { System.out.println("blockchain downloaded"); } }; // Now we re-download the blockchain. This replays the chain into the wallet. Once this is completed our wallet should know of all its transactions and print the correct balance. peers.start(); peers.startBlockChainDownload(bListener); bListener.await(); // Print a debug message with the details about the wallet. The correct balance should now be displayed. System.out.println(wallet.toString()); // shutting down again peers.stop(); }
Example #6
Source File: RestoreFromSeed.java From GreenBits with GNU General Public License v3.0 | 4 votes |
public static void main(String[] args) throws Exception { NetworkParameters params = TestNet3Params.get(); // Bitcoinj supports hierarchical deterministic wallets (or "HD Wallets"): https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki // HD wallets allow you to restore your wallet simply from a root seed. This seed can be represented using a short mnemonic sentence as described in BIP 39: https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki // Here we restore our wallet from a seed with no passphrase. Also have a look at the BackupToMnemonicSeed.java example that shows how to backup a wallet by creating a mnemonic sentence. String seedCode = "yard impulse luxury drive today throw farm pepper survey wreck glass federal"; String passphrase = ""; Long creationtime = 1409478661L; DeterministicSeed seed = new DeterministicSeed(seedCode, null, passphrase, creationtime); // The wallet class provides a easy fromSeed() function that loads a new wallet from a given seed. Wallet wallet = Wallet.fromSeed(params, seed); // Because we are importing an existing wallet which might already have transactions we must re-download the blockchain to make the wallet picks up these transactions // You can find some information about this in the guides: https://bitcoinj.github.io/working-with-the-wallet#setup // To do this we clear the transactions of the wallet and delete a possible existing blockchain file before we download the blockchain again further down. System.out.println(wallet.toString()); wallet.clearTransactions(0); File chainFile = new File("restore-from-seed.spvchain"); if (chainFile.exists()) { chainFile.delete(); } // Setting up the BlochChain, the BlocksStore and connecting to the network. SPVBlockStore chainStore = new SPVBlockStore(params, chainFile); BlockChain chain = new BlockChain(params, chainStore); PeerGroup peers = new PeerGroup(params, chain); peers.addPeerDiscovery(new DnsDiscovery(params)); // Now we need to hook the wallet up to the blockchain and the peers. This registers event listeners that notify our wallet about new transactions. chain.addWallet(wallet); peers.addWallet(wallet); DownloadProgressTracker bListener = new DownloadProgressTracker() { @Override public void doneDownload() { System.out.println("blockchain downloaded"); } }; // Now we re-download the blockchain. This replays the chain into the wallet. Once this is completed our wallet should know of all its transactions and print the correct balance. peers.start(); peers.startBlockChainDownload(bListener); bListener.await(); // Print a debug message with the details about the wallet. The correct balance should now be displayed. System.out.println(wallet.toString()); // shutting down again peers.stop(); }