本文整理汇总了Java中org.bitcoinj.core.StoredBlock.getHeight方法的典型用法代码示例。如果您正苦于以下问题:Java StoredBlock.getHeight方法的具体用法?Java StoredBlock.getHeight怎么用?Java StoredBlock.getHeight使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bitcoinj.core.StoredBlock
的用法示例。
在下文中一共展示了StoredBlock.getHeight方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: 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();
}
示例3: 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;
}
示例4: equals
import org.bitcoinj.core.StoredBlock; //导入方法依赖的package包/类
public boolean equals (StoredBlock storedBlock){
if (storedBlock == null )
return false;
return storedBlock.getHeight() == this.height &&
storedBlock.getHeader().getHashAsString().equals(this.hash) &&
storedBlock.getHeader().getMerkleRoot().toString().equals(this.merkleroot) &&
storedBlock.getHeader().getNonce() == this.nonce &&
storedBlock.getHeader().getTimeSeconds() == this.time &&
//storedBlock.getHeader().getTransactions().size() == this.tx.size() &&
storedBlock.getHeader().getVersion() == this.version;
}
示例5: 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);
}
}
示例6: setVerifiedChainHead
import org.bitcoinj.core.StoredBlock; //导入方法依赖的package包/类
@Override
public void setVerifiedChainHead(StoredBlock chainHead) throws BlockStoreException {
if (instrument)
beginMethod("setVerifiedChainHead");
Sha256Hash hash = chainHead.getHeader().getHash();
this.verifiedChainHeadHash = hash;
this.verifiedChainHeadBlock = chainHead;
batchPut(getKey(KeyType.VERIFIED_CHAIN_HEAD_SETTING), hash.getBytes());
if (this.chainHeadBlock.getHeight() < chainHead.getHeight())
setChainHead(chainHead);
removeUndoableBlocksWhereHeightIsLessThan(chainHead.getHeight() - fullStoreDepth);
if (instrument)
endMethod("setVerifiedChainHead");
}
示例7: getBlockchainState
import org.bitcoinj.core.StoredBlock; //导入方法依赖的package包/类
@Override
public BlockchainState getBlockchainState() {
final StoredBlock chainHead = blockChain.getChainHead();
final Date bestChainDate = chainHead.getHeader().getTime();
final int bestChainHeight = chainHead.getHeight();
final boolean replaying = chainHead.getHeight() < config.getBestChainHeightEver();
return new BlockchainState(bestChainDate, bestChainHeight, replaying, impediments);
}
示例8: truncate
import org.bitcoinj.core.StoredBlock; //导入方法依赖的package包/类
public void truncate(StoredBlock checkpoint) {
int index = checkpoint.getHeight();
lock.lock();
try {
Block block = get(index);
if (block == null)
channel.write(ByteBuffer.wrap(checkpoint.getHeader().cloneAsHeader().bitcoinSerialize()), index * HEADER_SIZE);
channel.truncate((index + 1) * HEADER_SIZE);
} catch (IOException e) {
propagate(e);
} finally {
lock.unlock();
}
}
示例9: getBlockchainState
import org.bitcoinj.core.StoredBlock; //导入方法依赖的package包/类
@Override
public BlockchainState getBlockchainState()
{
final StoredBlock chainHead = blockChain.getChainHead();
final Date bestChainDate = chainHead.getHeader().getTime();
final int bestChainHeight = chainHead.getHeight();
final boolean replaying = chainHead.getHeight() < config.getBestChainHeightEver();
return new BlockchainState(bestChainDate, bestChainHeight, replaying, impediments);
}
示例10: putBlockChain
import org.bitcoinj.core.StoredBlock; //导入方法依赖的package包/类
protected synchronized void putBlockChain(StoredBlock block) throws Exception {
// TODO: use BIP 113 timestamps
if ( (new Date().getTime() / 1000 ) - block.getHeader().getTimeSeconds() > 366 * 24 * 60 * 60) {
log.debug("NameDB halting walkbalk due to timestamp expiration, height " + block.getHeight());
return;
}
if (block.getHeight() > getChainHead() + 1) {
putBlockChain(block.getPrev(store));
}
putBlock(block);
}
示例11: allowDigishieldMinDifficultyForBlock
import org.bitcoinj.core.StoredBlock; //导入方法依赖的package包/类
/** Dogecoin: Normally minimum difficulty blocks can only occur in between
* retarget blocks. However, once we introduce Digishield every block is
* a retarget, so we need to handle minimum difficulty on all blocks.
*/
private boolean allowDigishieldMinDifficultyForBlock(final StoredBlock pindexLast, final Block pblock) {
// check if the chain allows minimum difficulty blocks
if (!this.allowMinDifficultyBlocks())
return false;
// check if the chain allows minimum difficulty blocks on recalc blocks
if (pindexLast.getHeight() < 157500)
return false;
// Allow for a minimum block time if the elapsed time > 2*nTargetSpacing
return (pblock.getTimeSeconds() > pindexLast.getHeader().getTimeSeconds() + this.getTargetSpacing(pindexLast.getHeight() + 1) * 2);
}
示例12: 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);
}
}
}
示例13: isBlockInMainChain
import org.bitcoinj.core.StoredBlock; //导入方法依赖的package包/类
public boolean isBlockInMainChain(Sha256Hash hash)
{
try
{
StoredBlock sb = store.get(hash);
int h = sb.getHeight();
return (hash.equals(getBlockHashAtHeight(h)));
}
catch(org.bitcoinj.store.BlockStoreException e)
{
throw new RuntimeException(e);
}
}
示例14: checkDifficultyTransitions
import org.bitcoinj.core.StoredBlock; //导入方法依赖的package包/类
@Override
public void checkDifficultyTransitions(final StoredBlock storedPrev, final Block nextBlock,
final BlockStore blockStore) throws VerificationException, BlockStoreException {
final Block prev = storedPrev.getHeader();
// Is this supposed to be a difficulty transition point?
if (!isDifficultyTransitionPoint(storedPrev.getHeight())) {
// No ... so check the difficulty didn't actually change.
if (nextBlock.getDifficultyTarget() != prev.getDifficultyTarget())
throw new VerificationException("Unexpected change in difficulty at height " + storedPrev.getHeight() +
": " + Long.toHexString(nextBlock.getDifficultyTarget()) + " vs " +
Long.toHexString(prev.getDifficultyTarget()));
return;
}
// We need to find a block far back in the chain. It's OK that this is expensive because it only occurs every
// two weeks after the initial block chain download.
final Stopwatch watch = Stopwatch.createStarted();
Sha256Hash hash = prev.getHash();
StoredBlock cursor = null;
final int interval = this.getInterval();
for (int i = 0; i < interval; i++) {
cursor = blockStore.get(hash);
if (cursor == null) {
// This should never happen. If it does, it means we are following an incorrect or busted chain.
throw new VerificationException(
"Difficulty transition point but we did not find a way back to the last transition point. Not found: " + hash);
}
hash = cursor.getHeader().getPrevBlockHash();
}
checkState(cursor != null && isDifficultyTransitionPoint(cursor.getHeight() - 1),
"Didn't arrive at a transition point.");
watch.stop();
if (watch.elapsed(TimeUnit.MILLISECONDS) > 50)
log.info("Difficulty transition traversal took {}", watch);
Block blockIntervalAgo = cursor.getHeader();
int timespan = (int) (prev.getTimeSeconds() - blockIntervalAgo.getTimeSeconds());
// Limit the adjustment step.
final int targetTimespan = this.getTargetTimespan();
if (timespan < targetTimespan / 4)
timespan = targetTimespan / 4;
if (timespan > targetTimespan * 4)
timespan = targetTimespan * 4;
BigInteger newTarget = Utils.decodeCompactBits(prev.getDifficultyTarget());
newTarget = newTarget.multiply(BigInteger.valueOf(timespan));
newTarget = newTarget.divide(BigInteger.valueOf(targetTimespan));
if (newTarget.compareTo(this.getMaxTarget()) > 0) {
log.info("Difficulty hit proof of work limit: {}", newTarget.toString(16));
newTarget = this.getMaxTarget();
}
int accuracyBytes = (int) (nextBlock.getDifficultyTarget() >>> 24) - 3;
long receivedTargetCompact = nextBlock.getDifficultyTarget();
// The calculated difficulty is to a higher precision than received, so reduce here.
BigInteger mask = BigInteger.valueOf(0xFFFFFFL).shiftLeft(accuracyBytes * 8);
newTarget = newTarget.and(mask);
long newTargetCompact = Utils.encodeCompactBits(newTarget);
if (newTargetCompact != receivedTargetCompact)
throw new VerificationException("Network provided difficulty bits do not match what was calculated: " +
Long.toHexString(newTargetCompact) + " vs " + Long.toHexString(receivedTargetCompact));
}
示例15: onBindViewHolder
import org.bitcoinj.core.StoredBlock; //导入方法依赖的package包/类
@Override
public void onBindViewHolder(final BlockViewHolder holder, final int position) {
final StoredBlock storedBlock = getItem(position);
final Block header = storedBlock.getHeader();
holder.miningRewardAdjustmentView
.setVisibility(isMiningRewardHalvingPoint(storedBlock) ? View.VISIBLE : View.GONE);
holder.miningDifficultyAdjustmentView
.setVisibility(isDifficultyTransitionPoint(storedBlock) ? View.VISIBLE : View.GONE);
final int height = storedBlock.getHeight();
holder.heightView.setText(Integer.toString(height));
final long timeMs = header.getTimeSeconds() * DateUtils.SECOND_IN_MILLIS;
if (timeMs < System.currentTimeMillis() - DateUtils.MINUTE_IN_MILLIS)
holder.timeView.setText(DateUtils.getRelativeDateTimeString(context, timeMs, DateUtils.MINUTE_IN_MILLIS,
DateUtils.WEEK_IN_MILLIS, 0));
else
holder.timeView.setText(R.string.block_row_now);
holder.hashView.setText(WalletUtils.formatHash(null, header.getHashAsString(), 8, 0, ' '));
final int transactionChildCount = holder.transactionsViewGroup.getChildCount() - ROW_BASE_CHILD_COUNT;
int iTransactionView = 0;
if (transactions != null) {
for (final Transaction tx : transactions) {
if (tx.getAppearsInHashes().containsKey(header.getHash())) {
final View view;
if (iTransactionView < transactionChildCount) {
view = holder.transactionsViewGroup.getChildAt(ROW_INSERT_INDEX + iTransactionView);
} else {
view = inflater.inflate(R.layout.block_row_transaction, null);
holder.transactionsViewGroup.addView(view, ROW_INSERT_INDEX + iTransactionView);
}
bindView(view, tx);
iTransactionView++;
}
}
}
final int leftoverTransactionViews = transactionChildCount - iTransactionView;
if (leftoverTransactionViews > 0)
holder.transactionsViewGroup.removeViews(ROW_INSERT_INDEX + iTransactionView, leftoverTransactionViews);
if (onClickListener != null) {
holder.menuView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
onClickListener.onBlockMenuClick(v, storedBlock);
}
});
}
}