本文整理汇总了Java中org.bitcoinj.net.discovery.DnsDiscovery类的典型用法代码示例。如果您正苦于以下问题:Java DnsDiscovery类的具体用法?Java DnsDiscovery怎么用?Java DnsDiscovery使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DnsDiscovery类属于org.bitcoinj.net.discovery包,在下文中一共展示了DnsDiscovery类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: resume
import org.bitcoinj.net.discovery.DnsDiscovery; //导入依赖的package包/类
public static void resume() {
if (isInitialize == false)
return;
if (isPaused == false)
return;
isPaused = false;
Log.d("BITCOINJ", "Create PeerGroup");
peerGroup = new PeerGroup(netParams, blockChain);
peerGroup.setUserAgent("PeerMonitor", "1.0");
peerGroup.setMaxConnections(8);
peerGroup.addPeerDiscovery(new DnsDiscovery(netParams));
Log.d("BITCOINJ", "Start Asynchronous PeerGroup");
peerGroup.start();
Log.d("BITCOINJ", "Download Started");
myDownload = new MyDownload();
peerGroup.startBlockChainDownload(myDownload);
}
开发者ID:lvaccaro,项目名称:BitcoinBlockExplorer,代码行数:22,代码来源:Bitcoin.java
示例2: main
import org.bitcoinj.net.discovery.DnsDiscovery; //导入依赖的package包/类
public static void main(String[] args) {
BriefLogFormatter.init();
NetworkParameters params = MainNetParams.get();
PeerGroup peerGroup = new PeerGroup(params);
peerGroup.addPeerDiscovery(new DnsDiscovery(params));
peerGroup.addEventListener(new AbstractPeerEventListener() {
@Override
public void onTransaction(Peer peer, Transaction tx) {
try {
if (tx.getOutputs().size() != 1) return;
if (!tx.getOutput(0).getScriptPubKey().isSentToRawPubKey()) return;
log.info("Saw raw pay to pubkey {}", tx);
} catch (ScriptException e) {
e.printStackTrace();
}
}
});
peerGroup.startAsync();
}
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:20,代码来源:WatchMempool.java
示例3: main
import org.bitcoinj.net.discovery.DnsDiscovery; //导入依赖的package包/类
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();
}
}
开发者ID:HashEngineering,项目名称:dashj,代码行数:24,代码来源:WatchMempool.java
示例4: initWallet
import org.bitcoinj.net.discovery.DnsDiscovery; //导入依赖的package包/类
/**
*
*/
private void initWallet(final NetworkParameters netParams) {
//File dataDir = getDir("consensus_folder", Context.MODE_PRIVATE);
// _bitcoinJContext = new org.bitcoinj.core.Context(netParams);
// Start up a basic app using a class that automates some boilerplate. Ensure we always have at least one key.
_walletKit = new WalletAppKit(Constants.NETWORK_PARAMETERS,
_bitcoin.getDataDir(),
ServiceConsts.SERVICE_APP_NAME + "-" + netParams.getPaymentProtocolId()) {
/**
*
*/
@Override
protected void onSetupCompleted() {
System.out.println("Setting up wallet : " + wallet().toString());
// This is called in a background thread after startAndWait is called, as setting up various objects
// can do disk and network IO that may cause UI jank/stuttering in wallet apps if it were to be done
// on the main thread.
if (wallet().getKeyChainGroupSize() < 1)
wallet().importKey(new ECKey());
peerGroup().setFastCatchupTimeSecs(wallet().getEarliestKeyCreationTime());
peerGroup().addPeerDiscovery(new DnsDiscovery(netParams));
// wallet.removeCoinsReceivedEventListener(_bitcoinManger);
// wallet.addCoinsReceivedEventListener(_bitcoinManger);
_bitcoin.setWalletManager(_walletKit);
}
};
}
开发者ID:ehanoc,项目名称:xwallet,代码行数:37,代码来源:BitcoinSetupAction.java
示例5: initKit
import org.bitcoinj.net.discovery.DnsDiscovery; //导入依赖的package包/类
private WalletAppKit initKit(@Nullable DeterministicSeed seed) {
//initialize files and stuff here, add our address to the watched ones
WalletAppKit kit = new WalletAppKit(params, new File("./spv"), fileprefix);
kit.setAutoSave(true);
kit.useTor();
kit.setDiscovery(new DnsDiscovery(params));
// fresh restore if seed provided
if (seed != null) {
kit.restoreWalletFromSeed(seed);
}
// startUp WalletAppKit
kit.startAndWait();
return kit;
}
开发者ID:DanielKrawisz,项目名称:Shufflepuff,代码行数:15,代码来源:BitcoinCrypto.java
示例6: printDNS
import org.bitcoinj.net.discovery.DnsDiscovery; //导入依赖的package包/类
private static void printDNS() throws PeerDiscoveryException {
long start = System.currentTimeMillis();
DnsDiscovery dns = new DnsDiscovery(MainNetParams.get());
dnsPeers = dns.getPeers(10, TimeUnit.SECONDS);
printPeers(dnsPeers);
printElapsed(start);
}
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:8,代码来源:PrintPeers.java
示例7: start
import org.bitcoinj.net.discovery.DnsDiscovery; //导入依赖的package包/类
/**
* Starts a bitcoin network peer and begins to listen
*
* @throws BlockStoreException
*/
public void start() throws BlockStoreException {
BlockChain blockChain = new BlockChain(NET_PARAMS, new MemoryBlockStore(NET_PARAMS));
PeerGroup peerGroup = new PeerGroup(NET_PARAMS, blockChain);
peerGroup.addPeerDiscovery(new DnsDiscovery(NET_PARAMS));
peerGroup.addEventListener(peerEventListener);
peerGroup.startAsync();
}
开发者ID:lifeofreilly,项目名称:ostendo,代码行数:15,代码来源:PeerListener.java
示例8: BitcoinNetworkProvider
import org.bitcoinj.net.discovery.DnsDiscovery; //导入依赖的package包/类
public BitcoinNetworkProvider(String DB_HOST, String DB_NAME, String DB_USER, String DB_PASSWD,
String spvBlockStorePath, NetworkParameters params, long fastCatchup, String coldWalletAddr) throws Exception {
fas = new FollowedAddressStore(DB_HOST, DB_NAME, DB_USER, DB_PASSWD);
s = new SPVBlockStore(params, new File(spvBlockStorePath));
bc = new BlockChain(params, s);
this.params = params;
this.coldWalletAddr = coldWalletAddr;
vPeerGroup = new PeerGroup(params, bc);
vPeerGroup.setUserAgent("Satoshi", "0.9.3");
vPeerGroup.addPeerDiscovery( new DnsDiscovery(params) );
vPeerGroup.setMaxConnections(16);
if(fastCatchup != 0) {
log.info("Starting BitcoinNetworkProvider with {} fastCatchupParam", fastCatchup);
vPeerGroup.setFastCatchupTimeSecs(fastCatchup);
}
// Importing addresses from DB
w = new Wallet(params);
ArrayList<String> addresses = fas.getAddresses();
for(String addr : addresses){
ECKey key = ECKeyUtils.getECKey(addr);
if(key != null)
w.importKey(key);
}
vPeerGroup.addWallet(w);
eventListener = new BitcoinNetworkEventListener(vPeerGroup, bc, s, w, params, this.coldWalletAddr);
bc.addListener(eventListener, Threading.THREAD_POOL);
}
开发者ID:canselcik,项目名称:BitcoinPaymentGateway,代码行数:32,代码来源:BitcoinNetworkProvider.java
示例9: printDNS
import org.bitcoinj.net.discovery.DnsDiscovery; //导入依赖的package包/类
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);
}
开发者ID:HashEngineering,项目名称:dashj,代码行数:8,代码来源:PrintPeers.java
示例10: syncBlockChain
import org.bitcoinj.net.discovery.DnsDiscovery; //导入依赖的package包/类
/**
* Synchronize a list of {@code Wallet} against the BlockChain.
*
* @param params the NetworkParameters to use
* @param wallets the list of Wallet
* @param chainFile the chain file to use
* @param listener the listener to inform for status changes
*/
public static void syncBlockChain(UniquidNodeConfiguration configuration, final List<Wallet> wallets, final File chainFile,
final DownloadProgressTracker listener, final NativePeerEventListener peerListener) {
try {
NetworkParameters params = configuration.getNetworkParameters();
BlockStore chainStore = new SPVBlockStore(params, chainFile);
for (Wallet wallet : wallets) {
if ((wallet.getLastBlockSeenHeight() < 1) &&
(openStream(params) != null)) {
try {
CheckpointManager.checkpoint(params, openStream(params), chainStore,
configuration.getCreationTime());
StoredBlock head = chainStore.getChainHead();
LOGGER.info("Skipped to checkpoint " + head.getHeight() + " at "
+ Utils.dateTimeFormat(head.getHeader().getTimeSeconds() * 1000));
} catch (Throwable t) {
LOGGER.warn("Problem using checkpoints", t);
}
break;
}
}
BlockChain chain = new BlockChain(params, wallets, chainStore);
final PeerGroup peerGroup = new PeerGroup(params, chain);
peerGroup.setUserAgent("UNIQUID", "0.1");
peerGroup.setMaxPeersToDiscoverCount(3);
peerGroup.setMaxConnections(2);
if (params.getDnsSeeds() != null &&
params.getDnsSeeds().length > 0) {
peerGroup.addPeerDiscovery(new DnsDiscovery(params));
} else if (params.getAddrSeeds() != null &&
params.getAddrSeeds().length > 0) {
peerGroup.addPeerDiscovery(new SeedPeers(params.getAddrSeeds(), params));
} else {
throw new Exception("Problem with Peers discovery!");
}
LOGGER.info("BLOCKCHAIN Preparing to download blockchain...");
peerGroup.addConnectedEventListener(peerListener);
peerGroup.addDisconnectedEventListener(peerListener);
peerGroup.addDiscoveredEventListener(peerListener);
peerGroup.start();
peerGroup.startBlockChainDownload(listener);
listener.await();
peerGroup.stop();
chainStore.close();
LOGGER.info("BLOCKCHAIN downloaded.");
} catch (Exception ex) {
LOGGER.error("Exception catched ", ex);
}
}
开发者ID:uniquid,项目名称:uidcore-java,代码行数:78,代码来源:NodeUtils.java
示例11: startWalletSystem
import org.bitcoinj.net.discovery.DnsDiscovery; //导入依赖的package包/类
public void startWalletSystem() {
peerGroup.start();
peerGroup.addPeerDiscovery(new DnsDiscovery(params));
}
开发者ID:IUNO-TDM,项目名称:CouponGenerator,代码行数:5,代码来源:CouponWallet.java
示例12: main
import org.bitcoinj.net.discovery.DnsDiscovery; //导入依赖的package包/类
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);
DownloadListener bListener = new DownloadListener() {
@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.startAsync();
peers.awaitRunning();
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.stopAsync();
peers.awaitTerminated();
}
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:59,代码来源:RestoreFromSeed.java
示例13: main
import org.bitcoinj.net.discovery.DnsDiscovery; //导入依赖的package包/类
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();
}
开发者ID:HashEngineering,项目名称:dashj,代码行数:56,代码来源:RestoreFromSeed.java
示例14: main
import org.bitcoinj.net.discovery.DnsDiscovery; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
BriefLogFormatter.init();
// Parse command line arguments
OptionParser parser = new OptionParser();
OptionSet opts = null;
List<String> nonOpts = null;
try {
parser.accepts("localhost", "Connect to the localhost node");
parser.accepts("help", "Displays program options");
opts = parser.parse(args);
if (opts.has("help")) {
System.out.println("usage: org.bitcoinj.examples.FetchBlock [--localhost] <blockHash>");
parser.printHelpOn(System.out);
return;
}
nonOpts = opts.nonOptionArguments();
if (nonOpts.size() != 1) {
throw new IllegalArgumentException("Incorrect number of block hash, please provide only one block hash.");
}
} catch (OptionException | IllegalArgumentException e) {
System.err.println(e.getMessage());
System.err.println("usage: org.bitcoinj.examples.FetchBlock [--localhost] <blockHash>");
parser.printHelpOn(System.err);
return;
}
// Connect to testnet and find a peer
System.out.println("Connecting to node");
final NetworkParameters params = TestNet3Params.get();
BlockStore blockStore = new MemoryBlockStore(params);
BlockChain chain = new BlockChain(params, blockStore);
PeerGroup peerGroup = new PeerGroup(params, chain);
if (!opts.has("localhost")) {
peerGroup.addPeerDiscovery(new DnsDiscovery(params));
} else {
PeerAddress addr = new PeerAddress(params, InetAddress.getLocalHost());
peerGroup.addAddress(addr);
}
peerGroup.start();
peerGroup.waitForPeers(1).get();
Peer peer = peerGroup.getConnectedPeers().get(0);
// Retrieve a block through a peer
Sha256Hash blockHash = Sha256Hash.wrap(nonOpts.get(0));
Future<Block> future = peer.getBlock(blockHash);
System.out.println("Waiting for node to send us the requested block: " + blockHash);
Block block = future.get();
System.out.println(block);
peerGroup.stopAsync();
}
开发者ID:bitcoinj,项目名称:bitcoinj,代码行数:51,代码来源:FetchBlock.java
示例15: main
import org.bitcoinj.net.discovery.DnsDiscovery; //导入依赖的package包/类
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 peerGroup = new PeerGroup(params, chain);
peerGroup.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);
peerGroup.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.
peerGroup.start();
peerGroup.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
peerGroup.stop();
}
开发者ID:bitcoinj,项目名称:bitcoinj,代码行数:56,代码来源:RestoreFromSeed.java
注:本文中的org.bitcoinj.net.discovery.DnsDiscovery类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论