本文整理了Java中org.bitcoinj.core.BlockChain.getChainHead()
方法的一些代码示例,展示了BlockChain.getChainHead()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BlockChain.getChainHead()
方法的具体详情如下:
包路径:org.bitcoinj.core.BlockChain
类名称:BlockChain
方法名:getChainHead
暂无
代码示例来源:origin: ConsensusJ/consensusj
@Override
public Integer getblockcount() {
if(!kit.isRunning()) {
return null;
}
return kit.chain().getChainHead().getHeight();
}
代码示例来源:origin: blockchain/thunder
@Override
public Transaction getTransaction (Sha256Hash hash) {
try {
Transaction transaction = blockExplorer.getBitcoinJTransaction(hash.toString());
double height = blockExplorer.getTransaction(hash.toString()).getBlockHeight();
if (height > 0) {
transaction.getConfidence().setDepthInBlocks((int) (blockChain.getChainHead().getHeight() - height));
}
return transaction;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: greenaddress/GreenBits
@Test
public void unconnectedBlocks() throws Exception {
Block b1 = PARAMS.getGenesisBlock().createNextBlock(coinbaseTo);
Block b2 = b1.createNextBlock(coinbaseTo);
Block b3 = b2.createNextBlock(coinbaseTo);
// Connected.
assertTrue(chain.add(b1));
// Unconnected but stored. The head of the chain is still b1.
assertFalse(chain.add(b3));
assertEquals(chain.getChainHead().getHeader(), b1.cloneAsHeader());
// Add in the middle block.
assertTrue(chain.add(b2));
assertEquals(chain.getChainHead().getHeader(), b3.cloneAsHeader());
}
代码示例来源:origin: greenaddress/GreenBits
@Test
public void duplicates() throws Exception {
// Adding a block twice should not have any effect, in particular it should not send the block to the wallet.
Block b1 = PARAMS.getGenesisBlock().createNextBlock(coinbaseTo);
Block b2 = b1.createNextBlock(coinbaseTo);
Block b3 = b2.createNextBlock(coinbaseTo);
assertTrue(chain.add(b1));
assertEquals(b1, block[0].getHeader());
assertTrue(chain.add(b2));
assertEquals(b2, block[0].getHeader());
assertTrue(chain.add(b3));
assertEquals(b3, block[0].getHeader());
assertEquals(b3, chain.getChainHead().getHeader());
assertTrue(chain.add(b2));
assertEquals(b3, chain.getChainHead().getHeader());
// Wallet was NOT called with the new block because the duplicate add was spotted.
assertEquals(b3, block[0].getHeader());
}
代码示例来源:origin: greenaddress/GreenBits
@Test
public void rollbackBlockStore() throws Exception {
// This test simulates an issue on Android, that causes the VM to crash while receiving a block, so that the
// block store is persisted but the wallet is not.
Block b1 = PARAMS.getGenesisBlock().createNextBlock(coinbaseTo);
Block b2 = b1.createNextBlock(coinbaseTo);
// Add block 1, no frills.
assertTrue(chain.add(b1));
assertEquals(b1.cloneAsHeader(), chain.getChainHead().getHeader());
assertEquals(1, chain.getBestChainHeight());
assertEquals(1, wallet.getLastBlockSeenHeight());
// Add block 2 while wallet is disconnected, to simulate crash.
chain.removeWallet(wallet);
assertTrue(chain.add(b2));
assertEquals(b2.cloneAsHeader(), chain.getChainHead().getHeader());
assertEquals(2, chain.getBestChainHeight());
assertEquals(1, wallet.getLastBlockSeenHeight());
// Add wallet back. This will detect the height mismatch and repair the damage done.
chain.addWallet(wallet);
assertEquals(b1.cloneAsHeader(), chain.getChainHead().getHeader());
assertEquals(1, chain.getBestChainHeight());
assertEquals(1, wallet.getLastBlockSeenHeight());
// Now add block 2 correctly.
assertTrue(chain.add(b2));
assertEquals(b2.cloneAsHeader(), chain.getChainHead().getHeader());
assertEquals(2, chain.getBestChainHeight());
assertEquals(2, wallet.getLastBlockSeenHeight());
}
}
代码示例来源:origin: greenaddress/GreenBits
assertEquals(exhaustionPoint.getPrevBlockHash(), blockChain.getChainHead().getHeader().getHash());
assertEquals(blocks.get(blocks.size() - 1).getHash(), blockChain.getChainHead().getHeader().getHash());
内容来源于网络,如有侵权,请联系作者删除!