本文整理汇总了Java中com.google.bitcoin.store.SPVBlockStore类的典型用法代码示例。如果您正苦于以下问题:Java SPVBlockStore类的具体用法?Java SPVBlockStore怎么用?Java SPVBlockStore使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SPVBlockStore类属于com.google.bitcoin.store包,在下文中一共展示了SPVBlockStore类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setChainHeadClearCachesAndTruncateBlockStore
import com.google.bitcoin.store.SPVBlockStore; //导入依赖的package包/类
/**
* Set the chainhead, clear any cached blocks and truncate the blockchain .
* (Used for blockchain replay).
* @param chainHead
* @throws BlockStoreException
*/
public void setChainHeadClearCachesAndTruncateBlockStore(StoredBlock chainHead, String blockStoreFilename) throws BlockStoreException {
if (blockStore instanceof SPVBlockStore) {
// Delete the blockstore and recreate it.
((SPVBlockStore) blockStore).close();
File blockStoreFile = new File(blockStoreFilename);
blockStoreFile.delete();
} else {
blockStore.setChainHead(chainHead);
super.setChainHead(chainHead);
}
}
示例2: store
import com.google.bitcoin.store.SPVBlockStore; //导入依赖的package包/类
public SPVBlockStore store() {
checkState(state() == State.STARTING || state() == State.RUNNING, "Cannot call until startup is complete");
return vStore;
}
示例3: startUp
import com.google.bitcoin.store.SPVBlockStore; //导入依赖的package包/类
@SuppressLint("NewApi")
@Override
protected void startUp() throws Exception {
// Runs in a separate thread.
if (!directory.exists()) {
if (!directory.mkdir()) {
throw new IOException("Could not create named directory.");
}
}
FileInputStream walletStream = null;
try {
File chainFile = new File(directory, filePrefix + ".spvchain");
boolean chainFileExists = chainFile.exists();
vWalletFile = new File(directory, filePrefix + ".wallet");
boolean shouldReplayWallet = vWalletFile.exists() && !chainFileExists;
vStore = new SPVBlockStore(params, chainFile);
if (!chainFileExists && checkpoints != null) {
mLogger.info(String.format("checkpoint at time %d", scanTime));
CheckpointManager.checkpoint(params, checkpoints, vStore, scanTime);
}
vChain = new BlockChain(params, vStore);
vPeerGroup = new PeerGroup(params, vChain);
if (this.userAgent != null)
vPeerGroup.setUserAgent(userAgent, version);
if (vWalletFile.exists()) {
walletStream = new FileInputStream(vWalletFile);
vWallet = new Wallet(params);
addWalletExtensions(); // All extensions must be present before we deserialize
new WalletProtobufSerializer().readWallet(WalletProtobufSerializer.parseToProto(walletStream), vWallet);
if (shouldReplayWallet)
vWallet.clearTransactions(0);
} else {
if (keyCrypter == null)
vWallet = new Wallet(params);
else
vWallet = new Wallet(params, keyCrypter);
// vWallet.addKey(new ECKey());
addWalletExtensions();
}
if (useAutoSave) vWallet.autosaveToFile(vWalletFile, 1, TimeUnit.SECONDS, null);
// Set up peer addresses or discovery first, so if wallet extensions try to broadcast a transaction
// before we're actually connected the broadcast waits for an appropriate number of connections.
if (peerAddresses != null) {
for (PeerAddress addr : peerAddresses) vPeerGroup.addAddress(addr);
peerAddresses = null;
} else {
vPeerGroup.addPeerDiscovery(new DnsDiscovery(params));
}
vChain.addWallet(vWallet);
vPeerGroup.addWallet(vWallet);
onSetupCompleted();
if (blockingStartup) {
vPeerGroup.startAndWait();
// Make sure we shut down cleanly.
installShutdownHook();
MyDownloadListener listener = (this.downloadListener != null) ? this.downloadListener : new MyDownloadListener();
vPeerGroup.startBlockChainDownload(listener);
listener.await();
} else {
Futures.addCallback(vPeerGroup.start(), new FutureCallback<State>() {
@Override
public void onSuccess(State result) {
final PeerEventListener l = downloadListener == null ? new MyDownloadListener() : downloadListener;
vPeerGroup.startBlockChainDownload(l);
}
@Override
public void onFailure(Throwable t) {
throw new RuntimeException(t);
}
});
}
} catch (BlockStoreException e) {
throw new IOException(e);
} finally {
if (walletStream != null) walletStream.close();
}
}
示例4: store
import com.google.bitcoin.store.SPVBlockStore; //导入依赖的package包/类
public SPVBlockStore store() {
checkState(state() == State.RUNNING, "Cannot call until startup is complete");
return vStore;
}
示例5: init
import com.google.bitcoin.store.SPVBlockStore; //导入依赖的package包/类
public synchronized void init(String n) throws Exception {
nodeName = n;
params = TestNet3Params.get();
walletFile = new File(nodeName + ".wallet");
try {
wallet = Wallet.loadFromFile(walletFile);
System.out.println("Opened wallet " + walletFile.getAbsolutePath());
} catch (UnreadableWalletException e) {
wallet = new Wallet(params);
wallet.addKey(new ECKey());
System.out.println("Created new wallet "
+ walletFile.getAbsolutePath());
}
wallet.autosaveToFile(walletFile, 1, TimeUnit.SECONDS, null);
// System.out.println("Reading block store from disk");
File file = new File(nodeName + ".spvchain");
boolean chainExistedAlready = file.exists();
blockStore = new SPVBlockStore(params, file);
if (!chainExistedAlready) {
File checkpointsFile = new File("checkpoints");
if (checkpointsFile.exists()) {
ECKey key = wallet.getKeys().iterator().next();
FileInputStream stream = new FileInputStream(checkpointsFile);
CheckpointManager.checkpoint(params, stream, blockStore,
key.getCreationTimeSeconds());
}
}
chain = new BlockChain(params, wallet, blockStore);
// make sure that we shut down cleanly!
final WalletMgr walletMgr = this;
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
walletMgr.shutdown();
}
});
txCommands = new TxCommands(this);
}