本文整理汇总了Java中org.bitcoinj.core.StoredBlock.getPrev方法的典型用法代码示例。如果您正苦于以下问题:Java StoredBlock.getPrev方法的具体用法?Java StoredBlock.getPrev怎么用?Java StoredBlock.getPrev使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bitcoinj.core.StoredBlock
的用法示例。
在下文中一共展示了StoredBlock.getPrev方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: currentBitcoinBIP113Time
import org.bitcoinj.core.StoredBlock; //导入方法依赖的package包/类
public static long currentBitcoinBIP113Time(BlockChain bc) {
StoredBlock headBlock = bc.getChainHead();
StoredBlock iteratingBlock = headBlock;
long[] blockTimeStamps = new long[11];
for(int i=0; i < 11; i++) {
blockTimeStamps[i] = iteratingBlock.getHeader().getTimeSeconds();
try {
iteratingBlock = iteratingBlock.getPrev(bc.getBlockStore());
} catch (BlockStoreException e) {
e.printStackTrace();
}
}
Arrays.sort(blockTimeStamps);
System.out.println("current bitcoinbip113time yielded " + new Date(blockTimeStamps[5]*1000));
return blockTimeStamps[5];
}
示例2: initialize
import org.bitcoinj.core.StoredBlock; //导入方法依赖的package包/类
/**
* Initialize the version tally from the block store. Note this does not
* search backwards past the start of the block store, so if starting from
* a checkpoint this may not fill the window.
*
* @param blockStore block store to load blocks from.
* @param chainHead current chain tip.
*/
public void initialize(final BlockStore blockStore, final StoredBlock chainHead)
throws BlockStoreException {
StoredBlock versionBlock = chainHead;
final Stack<Long> versions = new Stack<>();
// We don't know how many blocks back we can go, so load what we can first
versions.push(versionBlock.getHeader().getVersion());
for (int headOffset = 0; headOffset < versionWindow.length; headOffset++) {
versionBlock = versionBlock.getPrev(blockStore);
if (null == versionBlock) {
break;
}
versions.push(versionBlock.getHeader().getVersion());
}
// Replay the versions into the tally
while (!versions.isEmpty()) {
add(versions.pop());
}
}
示例3: getRecentBlocks
import org.bitcoinj.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;
}
示例4: initialize
import org.bitcoinj.core.StoredBlock; //导入方法依赖的package包/类
/**
* Initialize the version tally from the block store. Note this does not
* search backwards past the start of the block store, so if starting from
* a checkpoint this may not fill the window.
*
* @param blockStore block store to load blocks from.
* @param chainHead current chain tip.
*/
public void initialize(final BlockStore blockStore, final StoredBlock chainHead)
throws BlockStoreException {
StoredBlock versionBlock = chainHead;
final Stack<Long> versions = new Stack<Long>();
// We don't know how many blocks back we can go, so load what we can first
versions.push(versionBlock.getHeader().getVersion());
for (int headOffset = 0; headOffset < versionWindow.length; headOffset++) {
versionBlock = versionBlock.getPrev(blockStore);
if (null == versionBlock) {
break;
}
versions.push(versionBlock.getHeader().getVersion());
}
// Replay the versions into the tally
while (!versions.isEmpty()) {
add(versions.pop());
}
}
示例5: getRecentBlocks
import org.bitcoinj.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;
}
示例6: initBlockHashCache
import org.bitcoinj.core.StoredBlock; //导入方法依赖的package包/类
protected void initBlockHashCache() throws BlockStoreException {
blockHashCache = new ConcurrentHashMap<Integer, Sha256Hash>(72000);
StoredBlock blockPointer = chain.getChainHead();
int headHeight = blockPointer.getHeight();
int reorgSafety = 120;
int newestHeight = headHeight - reorgSafety;
int oldestHeight = headHeight - 36000 - reorgSafety; // 36000 = name expiration
while (blockPointer.getHeight() >= oldestHeight) {
if (blockPointer.getHeight() <= newestHeight) {
blockHashCache.put(new Integer(blockPointer.getHeight()), blockPointer.getHeader().getHash());
}
blockPointer = blockPointer.getPrev(store);
}
}
示例7: getBlockHash
import org.bitcoinj.core.StoredBlock; //导入方法依赖的package包/类
public Sha256Hash getBlockHash(int height) throws BlockStoreException {
Sha256Hash maybeResult = blockHashCache.get(new Integer(height));
if (maybeResult != null) {
return maybeResult;
}
// If we got this far, the block height is uncached.
// This could be because the block is immature,
// or it could be because the cache is only initialized on initial startup.
StoredBlock blockPointer = chain.getChainHead();
while (blockPointer.getHeight() != height) {
blockPointer = blockPointer.getPrev(store);
}
return blockPointer.getHeader().getHash();
}
示例8: getLastBlockForAlgo
import org.bitcoinj.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;
}
}
}
示例9: getChainHead
import org.bitcoinj.core.StoredBlock; //导入方法依赖的package包/类
public StoredBlock getChainHead()
throws org.bitcoinj.store.BlockStoreException
{
StoredBlock head_blk = file_db.getSpecialBlockStoreMap().get("head");
StoredBlock curr = head_blk;
int stepback=0;
if (file_db.getBlockSavedMap()==null) throw new RuntimeException("BlockMap is null");
while((!file_db.getBlockSavedMap().containsKey(curr.getHeader().getHash())) && (curr.getHeight()>=1))
{
int step_size=10;
if (curr.getHeight() < 1000) step_size=1;
for(int i=0; i<step_size; i++)
{
stepback++;
curr = curr.getPrev(this);
}
}
setChainHead(curr);
jelly.getEventLog().alarm("Current Head: " + curr.getHeader().getHash().toString() + " - " + curr.getHeight() + " stepback " + stepback);
return curr;
}
示例10: updateTable
import org.bitcoinj.core.StoredBlock; //导入方法依赖的package包/类
/** Updates table for blocks
* @throws BlockStoreException Occurs when requested Block is not available. */
public void updateTable() throws BlockStoreException {
DefaultTableModel model = (DefaultTableModel) table.getModel();
model.setRowCount(0);
StoredBlock working = kit.getChainHead();
StoredBlock previous = working.getPrev(kit.getBlockStore());
for (int i = 0; i < 200; i++) {
kit.getBlockStoreVersion(working);
Object[] row = { Integer.toString(working.getHeight()), working.getHeader().getHashAsString(),
kit.getBlockStoreTime(working).trim(), kit.getBlockStoreVersion(working).trim() };
working = previous;
previous = working.getPrev(kit.getBlockStore());
model.addRow(row);
}
}
示例11: getBlockHashByHeight
import org.bitcoinj.core.StoredBlock; //导入方法依赖的package包/类
private Sha256Hash getBlockHashByHeight(BlockChain bc, int appearedInChainheight2) {
int bestchainheight = bc.getBestChainHeight();
StoredBlock block = bc.getChainHead();
assert(block != null);
for(int i=0; i < bestchainheight-appearedInChainheight2; i++) {
try {
System.out.println("iteration: " + i);
assert(block != null);
block = block.getPrev(bc.getBlockStore());
} catch (BlockStoreException e) {
e.printStackTrace();
}
}
return block.getHeader().getHash();
}
示例12: checkDifficultyTransitions
import org.bitcoinj.core.StoredBlock; //导入方法依赖的package包/类
@Override
public void checkDifficultyTransitions(final StoredBlock storedPrev, final Block nextBlock,
final BlockStore blockStore) throws VerificationException, BlockStoreException {
if (!isDifficultyTransitionPoint(storedPrev.getHeight()) && nextBlock.getTime().after(testnetDiffDate)) {
Block prev = storedPrev.getHeader();
// After 15th February 2012 the rules on the testnet change to avoid people running up the difficulty
// and then leaving, making it too hard to mine a block. On non-difficulty transition points, easy
// blocks are allowed if there has been a span of 20 minutes without one.
final long timeDelta = nextBlock.getTimeSeconds() - prev.getTimeSeconds();
// There is an integer underflow bug in bitcoin-qt that means mindiff blocks are accepted when time
// goes backwards.
if (timeDelta >= 0 && timeDelta <= NetworkParameters.TARGET_SPACING * 2) {
// Walk backwards until we find a block that doesn't have the easiest proof of work, then check
// that difficulty is equal to that one.
StoredBlock cursor = storedPrev;
while (!cursor.getHeader().equals(getGenesisBlock()) &&
cursor.getHeight() % getInterval() != 0 &&
cursor.getHeader().getDifficultyTargetAsInteger().equals(getMaxTarget()))
cursor = cursor.getPrev(blockStore);
BigInteger cursorTarget = cursor.getHeader().getDifficultyTargetAsInteger();
BigInteger newTarget = nextBlock.getDifficultyTargetAsInteger();
if (!cursorTarget.equals(newTarget))
throw new VerificationException("Testnet block transition that is not allowed: " +
Long.toHexString(cursor.getHeader().getDifficultyTarget()) + " vs " +
Long.toHexString(nextBlock.getDifficultyTarget()));
}
} else {
super.checkDifficultyTransitions(storedPrev, nextBlock, blockStore);
}
}
示例13: getSafeBlock
import org.bitcoinj.core.StoredBlock; //导入方法依赖的package包/类
protected StoredBlock getSafeBlock(StoredBlock block) throws BlockStoreException {
StoredBlock result = block;
int safetyCount;
for (safetyCount = 0; safetyCount < 12; safetyCount++) {
result = result.getPrev(store);
}
return result;
}
示例14: getNetworkHashRate
import org.bitcoinj.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 * Math.pow(2.0, 32)) / totalTime)/(totalTime/10);
}
示例15: undumbSelf
import org.bitcoinj.core.StoredBlock; //导入方法依赖的package包/类
public void undumbSelf(NetworkParameters params, BlockStore block_store)
throws org.bitcoinj.store.BlockStoreException
{
Sha256Hash genesis_hash = params.getGenesisBlock().getHash();
StoredBlock cur = block_store.get(head);
synchronized(update_lock)
{
while(true)
{
int height = cur.getHeight();
if (!height_map.containsKey(height))
{
System.out.println("Height map missing: " + height);
height_map.put(height, cur.getHeader().getHash());
}
if (main_chain.contains(cur.getHeader().getHash()))
{
System.out.println("Main chain missing: " + height);
main_chain.add(cur.getHeader().getHash());
}
if (cur.getHeader().getHash().equals(genesis_hash)) return;
cur = cur.getPrev(block_store);
}
}
}