本文整理汇总了Java中org.ethereum.core.Blockchain.getBestBlock方法的典型用法代码示例。如果您正苦于以下问题:Java Blockchain.getBestBlock方法的具体用法?Java Blockchain.getBestBlock怎么用?Java Blockchain.getBestBlock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.ethereum.core.Blockchain
的用法示例。
在下文中一共展示了Blockchain.getBestBlock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: bridgeState
import org.ethereum.core.Blockchain; //导入方法依赖的package包/类
public Map<String, Object> bridgeState(Blockchain blockchain) throws IOException, BlockStoreException {
Block block = blockchain.getBestBlock();
Repository repository = blockchain.getRepository().getSnapshotTo(block.getStateRoot()).startTracking();
BridgeSupport bridgeSupport = new BridgeSupport(
config,
repository,
null,
PrecompiledContracts.BRIDGE_ADDR,
block);
byte[] result = bridgeSupport.getStateForDebugging();
BridgeState state = BridgeState.create(config.getBlockchainConfig().getCommonConstants().getBridgeConstants(), result);
return state.stateToMap();
}
示例2: sendBlockMessageAndAddItToBlockchainWithCommonAncestors
import org.ethereum.core.Blockchain; //导入方法依赖的package包/类
@Test
public void sendBlockMessageAndAddItToBlockchainWithCommonAncestors() {
Blockchain blockchain = BlockChainBuilder.ofSize(10);
BlockStore store = new BlockStore();
BlockNodeInformation nodeInformation = new BlockNodeInformation();
BlockSyncService blockSyncService = new BlockSyncService(store, blockchain, nodeInformation, SyncConfiguration.IMMEDIATE_FOR_TESTING);
Block initialBestBlock = blockchain.getBestBlock();
Assert.assertEquals(10, initialBestBlock.getNumber());
Block branchingPoint = blockchain.getBlockByNumber(7);
BlockGenerator blockGenerator = new BlockGenerator();
List<Block> extendedChain = blockGenerator.getBlockChain(branchingPoint, 10, 1000000l);
// we have just surpassed the best branch
for (int i = 0; i < extendedChain.size(); i++) {
Block newBestBlock = extendedChain.get(i);
blockSyncService.processBlock(null, newBestBlock, false);
Assert.assertEquals(newBestBlock.getNumber(), blockchain.getBestBlock().getNumber());
Assert.assertArrayEquals(newBestBlock.getHash(), blockchain.getBestBlock().getHash());
}
}
示例3: processTenBlocksAddingToBlockchain
import org.ethereum.core.Blockchain; //导入方法依赖的package包/类
@Test
public void processTenBlocksAddingToBlockchain() {
Blockchain blockchain = BlockChainBuilder.ofSize(0);
BlockStore store = new BlockStore();
Block genesis = blockchain.getBestBlock();
List<Block> blocks = BlockGenerator.getInstance().getBlockChain(genesis, 10);
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
BlockSyncService blockSyncService = new BlockSyncService(store, blockchain, nodeInformation, syncConfiguration);
final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
processor.processBlock(null, genesis);
Assert.assertEquals(0, store.size());
for (Block b : blocks)
processor.processBlock(null, b);
Assert.assertEquals(10, blockchain.getBestBlock().getNumber());
Assert.assertEquals(0, store.size());
}
示例4: processTenBlocksGenesisAtLastAddingToBlockchain
import org.ethereum.core.Blockchain; //导入方法依赖的package包/类
@Test
public void processTenBlocksGenesisAtLastAddingToBlockchain() {
BlockStore store = new BlockStore();
Blockchain blockchain = BlockChainBuilder.ofSize(0);
Block genesis = blockchain.getBestBlock();
List<Block> blocks = BlockGenerator.getInstance().getBlockChain(genesis, 10);
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
BlockSyncService blockSyncService = new BlockSyncService(store, blockchain, nodeInformation, syncConfiguration);
final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
for (Block b : blocks)
processor.processBlock(null, b);
processor.processBlock(null, genesis);
Assert.assertEquals(10, blockchain.getBestBlock().getNumber());
Assert.assertEquals(0, store.size());
}
示例5: processTenBlocksInverseOrderAddingToBlockchain
import org.ethereum.core.Blockchain; //导入方法依赖的package包/类
@Test
public void processTenBlocksInverseOrderAddingToBlockchain() {
Blockchain blockchain = BlockChainBuilder.ofSize(0);
BlockStore store = new BlockStore();
Block genesis = blockchain.getBestBlock();
List<Block> blocks = BlockGenerator.getInstance().getBlockChain(genesis, 10);
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
BlockSyncService blockSyncService = new BlockSyncService(store, blockchain, nodeInformation, syncConfiguration);
final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
for (int k = 0; k < 10; k++)
processor.processBlock(null, blocks.get(9 - k));
processor.processBlock(null, genesis);
Assert.assertEquals(10, blockchain.getBestBlock().getNumber());
Assert.assertEquals(0, store.size());
}
示例6: processTenBlocksWithHoleAddingToBlockchain
import org.ethereum.core.Blockchain; //导入方法依赖的package包/类
@Test
public void processTenBlocksWithHoleAddingToBlockchain() {
Blockchain blockchain = BlockChainBuilder.ofSize(0);
BlockStore store = new BlockStore();
Block genesis = blockchain.getBestBlock();
List<Block> blocks = BlockGenerator.getInstance().getBlockChain(genesis, 10);
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
BlockSyncService blockSyncService = new BlockSyncService(store, blockchain, nodeInformation, syncConfiguration);
final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
for (int k = 0; k < 10; k++)
if (k != 5)
processor.processBlock(null, blocks.get(9 - k));
processor.processBlock(null, genesis);
processor.processBlock(null, blocks.get(4));
Assert.assertEquals(10, blockchain.getBestBlock().getNumber());
Assert.assertEquals(0, store.size());
}
示例7: processStatusHavingBestBlockAsBestBlockInBlockchain
import org.ethereum.core.Blockchain; //导入方法依赖的package包/类
@Test @Ignore("Ignored when Process status deleted on block processor")
public void processStatusHavingBestBlockAsBestBlockInBlockchain() throws UnknownHostException {
final BlockStore store = new BlockStore();
final Blockchain blockchain = BlockChainBuilder.ofSize(2);
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
BlockSyncService blockSyncService = new BlockSyncService(store, blockchain, nodeInformation, syncConfiguration);
final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
final SimpleMessageChannel sender = new SimpleMessageChannel();
final Block block = blockchain.getBestBlock();
final ByteArrayWrapper blockHash = new ByteArrayWrapper(block.getHash());
// final Status status = new Status(block.getNumber(), block.getHash());
// processor.processStatus(sender, status);
Assert.assertTrue(processor.getNodeInformation().getNodesByBlock(block.getHash()).size() == 1);
Assert.assertTrue(nodeInformation.getBlocksByNode(sender.getPeerNodeID()).contains(blockHash));
Assert.assertEquals(0, sender.getGetBlockMessages().size());
Assert.assertEquals(0, store.size());
}
示例8: EthHandler
import org.ethereum.core.Blockchain; //导入方法依赖的package包/类
protected EthHandler(Blockchain blockchain, SystemProperties config, CompositeEthereumListener ethereumListener, EthVersion version) {
this.ethereumListener = ethereumListener;
this.version = version;
maxHashesAsk = config.maxHashesAsk();
bestBlock = blockchain.getBestBlock();
ethereumListener.addListener(listener);
// when sync enabled we delay transactions processing until sync is complete
processTransactions = !config.isSyncEnabled();
}
示例9: sendBlockMessagesAndAddThemToBlockchainInReverseOrder
import org.ethereum.core.Blockchain; //导入方法依赖的package包/类
@Test
public void sendBlockMessagesAndAddThemToBlockchainInReverseOrder() {
for (int i = 1; i < 52; i += 5) {
Blockchain blockchain = BlockChainBuilder.ofSize(10 * i);
BlockStore store = new BlockStore();
BlockNodeInformation nodeInformation = new BlockNodeInformation();
BlockSyncService blockSyncService = new BlockSyncService(store, blockchain, nodeInformation, SyncConfiguration.IMMEDIATE_FOR_TESTING);
Assert.assertEquals(10 * i, blockchain.getBestBlock().getNumber());
Block initialBestBlock = blockchain.getBestBlock();
List<Block> extendedChain = BlockGenerator.getInstance().getBlockChain(blockchain.getBestBlock(), i);
Collections.reverse(extendedChain);
for (int j = 0; j < extendedChain.size() - 1; j++) {
Block block = extendedChain.get(j);
blockSyncService.processBlock(null, block, false);
// we don't have all the parents, so we wait to update the best chain
Assert.assertEquals(initialBestBlock.getNumber(), blockchain.getBestBlock().getNumber());
Assert.assertArrayEquals(initialBestBlock.getHash(), blockchain.getBestBlock().getHash());
}
// the chain is complete, we have a new best block
Block closingBlock = extendedChain.get(extendedChain.size() - 1);
Block newBestBlock = extendedChain.get(0);
blockSyncService.processBlock(null, closingBlock, false);
Assert.assertEquals(newBestBlock.getNumber(), blockchain.getBestBlock().getNumber());
Assert.assertArrayEquals(newBestBlock.getHash(), blockchain.getBestBlock().getHash());
}
}
示例10: processSkeletonRequestWithGenesisPlusBestBlockInSkeleton
import org.ethereum.core.Blockchain; //导入方法依赖的package包/类
@Test
public void processSkeletonRequestWithGenesisPlusBestBlockInSkeleton() throws UnknownHostException {
int skeletonStep = 192;
final Blockchain blockchain = BlockChainBuilder.ofSize(skeletonStep / 2);
final Block blockStart = blockchain.getBlockByNumber(5);
final Block blockEnd = blockchain.getBlockByNumber(skeletonStep / 2);
final BlockStore store = new BlockStore();
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
BlockSyncService blockSyncService = new BlockSyncService(store, blockchain, nodeInformation, syncConfiguration);
final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
final SimpleMessageChannel sender = new SimpleMessageChannel();
processor.processSkeletonRequest(sender, 100, 5);
Assert.assertFalse(sender.getMessages().isEmpty());
Assert.assertEquals(1, sender.getMessages().size());
final Message message = sender.getMessages().get(0);
Assert.assertEquals(MessageType.SKELETON_RESPONSE_MESSAGE, message.getMessageType());
final SkeletonResponseMessage bMessage = (SkeletonResponseMessage) message;
Assert.assertEquals(100, bMessage.getId());
Block genesis = blockchain.getBlockByNumber(0);
Block bestBlock = blockchain.getBestBlock();
BlockIdentifier[] expected = {
new BlockIdentifier(genesis.getHash(), genesis.getNumber()),
new BlockIdentifier(bestBlock.getHash(), bestBlock.getNumber()),
};
assertBlockIdentifiers(expected, bMessage.getBlockIdentifiers());
}
示例11: processSkeletonRequestWithThreeResults
import org.ethereum.core.Blockchain; //导入方法依赖的package包/类
@Test
public void processSkeletonRequestWithThreeResults() throws UnknownHostException {
int skeletonStep = 192;
final Blockchain blockchain = BlockChainBuilder.ofSize(300);
final BlockStore store = new BlockStore();
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
BlockSyncService blockSyncService = new BlockSyncService(store, blockchain, nodeInformation, syncConfiguration);
final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
final SimpleMessageChannel sender = new SimpleMessageChannel();
processor.processSkeletonRequest(sender, 100, 5);
Assert.assertFalse(sender.getMessages().isEmpty());
Assert.assertEquals(1, sender.getMessages().size());
final Message message = sender.getMessages().get(0);
Assert.assertEquals(MessageType.SKELETON_RESPONSE_MESSAGE, message.getMessageType());
final SkeletonResponseMessage bMessage = (SkeletonResponseMessage) message;
Assert.assertEquals(100, bMessage.getId());
Block b1 = blockchain.getBlockByNumber(0);
Block b2 = blockchain.getBlockByNumber(skeletonStep);
Block b3 = blockchain.getBestBlock();
BlockIdentifier[] expected = {
new BlockIdentifier(b1.getHash(), b1.getNumber()),
new BlockIdentifier(b2.getHash(), b2.getNumber()),
new BlockIdentifier(b3.getHash(), b3.getNumber()),
};
assertBlockIdentifiers(expected, bMessage.getBlockIdentifiers());
}
示例12: processSkeletonRequestNotIncludingGenesis
import org.ethereum.core.Blockchain; //导入方法依赖的package包/类
@Test
public void processSkeletonRequestNotIncludingGenesis() throws UnknownHostException {
int skeletonStep = 192;
final Blockchain blockchain = BlockChainBuilder.ofSize(400);
final BlockStore store = new BlockStore();
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
BlockSyncService blockSyncService = new BlockSyncService(store, blockchain, nodeInformation, syncConfiguration);
final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
final SimpleMessageChannel sender = new SimpleMessageChannel();
processor.processSkeletonRequest(sender, 100, skeletonStep + 5);
Assert.assertFalse(sender.getMessages().isEmpty());
Assert.assertEquals(1, sender.getMessages().size());
final Message message = sender.getMessages().get(0);
Assert.assertEquals(MessageType.SKELETON_RESPONSE_MESSAGE, message.getMessageType());
final SkeletonResponseMessage bMessage = (SkeletonResponseMessage) message;
Assert.assertEquals(100, bMessage.getId());
Block b1 = blockchain.getBlockByNumber(skeletonStep);
Block b2 = blockchain.getBlockByNumber(2 * skeletonStep);
Block b3 = blockchain.getBestBlock();
BlockIdentifier[] expected = {
new BlockIdentifier(b1.getHash(), b1.getNumber()),
new BlockIdentifier(b2.getHash(), b2.getNumber()),
new BlockIdentifier(b3.getHash(), b3.getNumber()),
};
assertBlockIdentifiers(expected, bMessage.getBlockIdentifiers());
}
示例13: blockchainTest
import org.ethereum.core.Blockchain; //导入方法依赖的package包/类
@Test
public void blockchainTest() {
Blockchain blockchain = createBlockchain();
Assert.assertNotNull(blockchain);
Block block = blockchain.getBestBlock();
Assert.assertNotNull(block);
Assert.assertEquals(0, block.getNumber());
}
示例14: SyncQueueImpl
import org.ethereum.core.Blockchain; //导入方法依赖的package包/类
public SyncQueueImpl(Blockchain bc) {
Block bestBlock = bc.getBestBlock();
long start = bestBlock.getNumber() - MAX_CHAIN_LEN;
start = start < 0 ? 0 : start;
List<Block> initBlocks = new ArrayList<>();
for (long i = start; i <= bestBlock.getNumber(); i++) {
initBlocks.add(bc.getBlockByNumber(i));
}
init(initBlocks);
}
示例15: mineBlockUsingTimeTravel
import org.ethereum.core.Blockchain; //导入方法依赖的package包/类
@Test
public void mineBlockUsingTimeTravel() {
World world = new World();
Blockchain blockchain = world.getBlockChain();
Assert.assertEquals(0, blockchain.getBestBlock().getNumber());
MinerManager manager = new MinerManager();
MinerServerImpl minerServer = getMinerServer(blockchain);
MinerClientImpl minerClient = getMinerClient(minerServer);
long currentTime = minerServer.getCurrentTimeInSeconds();
minerServer.increaseTime(10);
manager.mineBlock(blockchain, minerClient, minerServer);
Block block = blockchain.getBestBlock();
Assert.assertEquals(1, block.getNumber());
Assert.assertTrue(currentTime + 10 <= block.getTimestamp());
Assert.assertTrue(currentTime + 11 > block.getTimestamp());
}