本文整理汇总了Java中com.google.bitcoin.core.StoredBlock类的典型用法代码示例。如果您正苦于以下问题:Java StoredBlock类的具体用法?Java StoredBlock怎么用?Java StoredBlock使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StoredBlock类属于com.google.bitcoin.core包,在下文中一共展示了StoredBlock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getLastBlockForAlgo
import com.google.bitcoin.core.StoredBlock; //导入依赖的package包/类
public static StoredBlock getLastBlockForAlgo(StoredBlock block, int algo, BlockStore blockStore)
{
for(;;)
{
if(block == null || block.getHeader().getPrevBlockHash().equals(Sha256Hash.ZERO_HASH))
return null;
if(block.getHeader().getAlgo() == algo)
return block;
try {
block = block.getPrev(blockStore);
}
catch(BlockStoreException x)
{
return null;
}
}
}
示例2: getRecentBlocks
import com.google.bitcoin.core.StoredBlock; //导入依赖的package包/类
@Override
public List<StoredBlock> getRecentBlocks(final int maxBlocks)
{
final List<StoredBlock> blocks = new ArrayList<StoredBlock>(maxBlocks);
try
{
StoredBlock block = blockChain.getChainHead();
while (block != null)
{
blocks.add(block);
if (blocks.size() >= maxBlocks)
break;
block = block.getPrev(blockStore);
}
}
catch (final BlockStoreException x)
{
// swallow
}
return blocks;
}
示例3: maybeRotateKeys
import com.google.bitcoin.core.StoredBlock; //导入依赖的package包/类
private void maybeRotateKeys()
{
final Wallet wallet = application.getWallet();
wallet.setKeyRotationEnabled(false);
final StoredBlock chainHead = blockChain.getChainHead();
new Thread()
{
@Override
public void run()
{
final boolean replaying = chainHead.getHeight() < bestChainHeightEver; // checking again
wallet.setKeyRotationEnabled(!replaying);
}
}.start();
}
示例4: JelectrumDBCloudData
import com.google.bitcoin.core.StoredBlock; //导入依赖的package包/类
public JelectrumDBCloudData(Config conf)
throws Exception
{
super(conf);
conf.require("google_api_keyfile");
conf.require("google_api_account");
conf.require("google_project");
ds = DatastoreFactory.get().create(getDatastoreOptions().build());
openStorage();
String file_base = conf.get("db_direct_path");
tx_map = new DatastoreMap<Sha256Hash, SerializedTransaction>(ds,bigstore,"tx_map");
address_to_tx_map = new DatastoreMap<String, HashSet<Sha256Hash> >(ds,bigstore,"address_to_tx_map");
//block_store_map = new DatastoreMap<Sha256Hash, StoredBlock>(ds,bigstore,"block_store_map");
block_store_map = new DirectFileMap<Sha256Hash, StoredBlock>(file_base,"block_store_map",4);
special_block_store_map = new DatastoreMap<String, StoredBlock>(ds,bigstore,"special_block_store_map");
block_map = new DatastoreMap<Sha256Hash, SerializedBlock>(ds,bigstore,"block_map");
tx_to_block_map = new DatastoreMap<Sha256Hash, HashSet<Sha256Hash> >(ds,bigstore,"tx_to_block_map");
}
示例5: basics
import com.google.bitcoin.core.StoredBlock; //导入依赖的package包/类
@Test
public void basics() throws Exception {
NetworkParameters params = UnitTestParams.get();
File f = File.createTempFile("spvblockstore", null);
f.delete();
f.deleteOnExit();
SPVBlockStore store = new SPVBlockStore(params, f);
Address to = new ECKey().toAddress(params);
// Check the first block in a new store is the genesis block.
StoredBlock genesis = store.getChainHead();
assertEquals(params.getGenesisBlock(), genesis.getHeader());
assertEquals(0, genesis.getHeight());
// Build a new block.
StoredBlock b1 = genesis.build(genesis.getHeader().createNextBlock(to).cloneAsHeader());
store.put(b1);
store.setChainHead(b1);
store.close();
// Check we can get it back out again if we rebuild the store object.
store = new SPVBlockStore(params, f);
StoredBlock b2 = store.get(b1.getHeader().getHash());
assertEquals(b1, b2);
// Check the chain head was stored correctly also.
StoredBlock chainHead = store.getChainHead();
assertEquals(b1, chainHead);
}
示例6: basics
import com.google.bitcoin.core.StoredBlock; //导入依赖的package包/类
@Test
public void basics() throws Exception {
NetworkParameters params = UnitTestParams.get();
File f = File.createTempFile("spvblockstore", null);
f.delete();
f.deleteOnExit();
SPVBlockStore store = new SPVBlockStore(params, f);
Address to = new ECKey().toAddress(params);
// Check the first block in a new store is the genesis block.
StoredBlock genesis = store.getChainHead();
assertEquals(params.getGenesisBlock(), genesis.getHeader());
assertEquals(0, genesis.getHeight());
// Build a new block.
StoredBlock b1 = genesis.build(genesis.getHeader().createNextBlock(to).cloneAsHeader(), store);
store.put(b1);
store.setChainHead(b1);
store.close();
// Check we can get it back out again if we rebuild the store object.
store = new SPVBlockStore(params, f);
StoredBlock b2 = store.get(b1.getHeader().getHash());
assertEquals(b1, b2);
// Check the chain head was stored correctly also.
StoredBlock chainHead = store.getChainHead();
assertEquals(b1, chainHead);
}
示例7: getBlock
import com.google.bitcoin.core.StoredBlock; //导入依赖的package包/类
private StoredBlock getBlock(BlockStore store, Long height)
{
try
{
StoredBlock current = store.getChainHead();
if(height > current.getHeight() || height < 0)
{
return null;
}
while(current.getHeight() > height)
{
StoredBlock previous = store.get(current.getHeader().getPrevBlockHash());
current = previous;
}
// for(int i = current.getHeight(); i > height; i -= 1)
// {
// StoredBlock previous = store.get(current.getHeader().getPrevBlockHash());
// current = previous;
// }
return current;
}
catch (BlockStoreException e)
{
e.printStackTrace();
return null;
}
}
示例8: sendBroadcastBlockchainState
import com.google.bitcoin.core.StoredBlock; //导入依赖的package包/类
private void sendBroadcastBlockchainState(final int download)
{
final StoredBlock chainHead = blockChain.getChainHead();
final Intent broadcast = new Intent(ACTION_BLOCKCHAIN_STATE);
broadcast.setPackage(getPackageName());
broadcast.putExtra(ACTION_BLOCKCHAIN_STATE_BEST_CHAIN_DATE, chainHead.getHeader().getTime());
broadcast.putExtra(ACTION_BLOCKCHAIN_STATE_BEST_CHAIN_HEIGHT, chainHead.getHeight());
broadcast.putExtra(ACTION_BLOCKCHAIN_STATE_REPLAYING, chainHead.getHeight() < bestChainHeightEver);
broadcast.putExtra(ACTION_BLOCKCHAIN_STATE_DOWNLOAD, download);
sendStickyBroadcast(broadcast);
}
示例9: replace
import com.google.bitcoin.core.StoredBlock; //导入依赖的package包/类
public void replace(@Nonnull final Collection<StoredBlock> blocks)
{
this.blocks.clear();
this.blocks.addAll(blocks);
notifyDataSetChanged();
}
示例10: onLoadFinished
import com.google.bitcoin.core.StoredBlock; //导入依赖的package包/类
@Override
public void onLoadFinished(final Loader<List<StoredBlock>> loader, final List<StoredBlock> blocks)
{
adapter.replace(blocks);
final Loader<Set<Transaction>> transactionLoader = loaderManager.getLoader(ID_TRANSACTION_LOADER);
if (transactionLoader != null && transactionLoader.isStarted())
transactionLoader.forceLoad();
}
示例11: getCheckpointBeforeOrAtHeight
import com.google.bitcoin.core.StoredBlock; //导入依赖的package包/类
/**
* Returns a {@link StoredBlock} representing the last checkpoint before the given block height, for example, normally
* you would want to know the checkpoint before the last block the wallet had seen.
*/
public StoredBlock getCheckpointBeforeOrAtHeight(int height) {
Map.Entry<Long, StoredBlock> highestCheckpointBeforeHeight = null;
for (Map.Entry<Long, StoredBlock> loop : checkpoints.entrySet()) {
if (loop.getValue().getHeight() < height) {
// This checkpoint is before the specified height.
if (highestCheckpointBeforeHeight == null) {
highestCheckpointBeforeHeight = loop;
} else {
if (highestCheckpointBeforeHeight.getValue().getHeight() < loop.getValue().getHeight()) {
// This entry is later.
highestCheckpointBeforeHeight = loop;
}
}
}
}
if (highestCheckpointBeforeHeight == null) {
try {
return new StoredBlock(params.getGenesisBlock(), params.getGenesisBlock().getWork(), 0);
} catch (VerificationException e) {
e.printStackTrace();
}
}
return highestCheckpointBeforeHeight.getValue();
}
示例12: getNetworkHashRate
import com.google.bitcoin.core.StoredBlock; //导入依赖的package包/类
public static double getNetworkHashRate(StoredBlock currentBlock, BlockStore blockStore)
{
double totalHash = 0.0;
long totalTime = 0;
long lastTime = currentBlock.getHeader().getTimeSeconds();
double lastDiff = ConvertBitsToDouble(currentBlock.getHeader().getDifficultyTarget());
StoredBlock block = currentBlock;
for (int i = 0; i < 10; ++i)
{
try {
block = block.getPrev(blockStore);
block = getLastBlockForAlgo(block, currentBlock.getHeader().getAlgo(), blockStore);
if(block == null)
return 0.0;
}
catch(BlockStoreException x)
{
return 0.0;
}
totalHash += lastDiff * (lastTime - block.getHeader().getTimeSeconds());
totalTime += lastTime - block.getHeader().getTimeSeconds();
lastTime = block.getHeader().getTimeSeconds();
lastDiff = ConvertBitsToDouble(block.getHeader().getDifficultyTarget());
}
return ((totalHash * java.lang.Math.pow(2.0, 32)) / totalTime)/(totalTime/10);
}
示例13: open
import com.google.bitcoin.core.StoredBlock; //导入依赖的package包/类
public synchronized void open()
{
try
{
//tx_map = new BandingMap<Sha256Hash, SerializedTransaction>(new SqlMap<Sha256Hash, SerializedTransaction>("tx_map", 64),100);
tx_map = new SqlMap<Sha256Hash, SerializedTransaction>("tx_map", 64);
block_store_map = new CacheMap<Sha256Hash, StoredBlock>(25000,new SqlMap<Sha256Hash, StoredBlock>("block_store_map",64));
special_block_store_map = new SqlMap<String, StoredBlock>("special_block_store_map",128);
block_map = new CacheMap<Sha256Hash, SerializedBlock>(240,new SqlMap<Sha256Hash, SerializedBlock>("block_map",64));
block_rescan_map = new SqlMap<Sha256Hash, String>("block_rescan_map",64);
special_object_map = new SqlMap<String, Object>("special_object_map",128);
header_chunk_map = new CacheMap<Integer, String>(200, new SqlMap<Integer, String>("header_chunk_map",32));
utxo_trie_map = new CacheMap<String, UtxoTrieNode>(10000, new SqlMap<String, UtxoTrieNode>("utxo_trie_map",56*2));
//address_to_tx_map = new BandingMapSet<String, Sha256Hash>(new SqlMapSet<String>("address_to_tx_map",35),10);
//tx_to_block_map = new BandingMapSet<Sha256Hash, Sha256Hash>(new SqlMapSet<Sha256Hash>("tx_to_block_map",64),10);
//txout_spent_by_map = new BandingMapSet<String, Sha256Hash>(new SqlMapSet<String>("txout_spent_by_map",128),10);
address_to_tx_map = new SqlMapSet<String>("address_to_tx_map",35);
tx_to_block_map = new SqlMapSet<Sha256Hash>("tx_to_block_map",64);
}
catch(Exception e)
{
throw new RuntimeException(e);
}
}
示例14: getSpecialBlockStoreMap
import com.google.bitcoin.core.StoredBlock; //导入依赖的package包/类
public synchronized Map<String, StoredBlock> getSpecialBlockStoreMap()
{
return special_block_store_map;
}
示例15: getBlockStoreMap
import com.google.bitcoin.core.StoredBlock; //导入依赖的package包/类
public Map<Sha256Hash, StoredBlock> getBlockStoreMap()
{
return block_store_map;
}