本文整理汇总了Java中org.ethereum.core.Blockchain.tryToConnect方法的典型用法代码示例。如果您正苦于以下问题:Java Blockchain.tryToConnect方法的具体用法?Java Blockchain.tryToConnect怎么用?Java Blockchain.tryToConnect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.ethereum.core.Blockchain
的用法示例。
在下文中一共展示了Blockchain.tryToConnect方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createNode
import org.ethereum.core.Blockchain; //导入方法依赖的package包/类
private static SimpleAsyncNode createNode(int size) {
final World world = new World();
final BlockStore store = new BlockStore();
final Blockchain blockchain = world.getBlockChain();
List<Block> blocks = BlockGenerator.getInstance().getBlockChain(blockchain.getBestBlock(), size);
for (Block b: blocks)
blockchain.tryToConnect(b);
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
BlockSyncService blockSyncService = new BlockSyncService(store, blockchain, nodeInformation, syncConfiguration);
NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
NodeMessageHandler handler = new NodeMessageHandler(ConfigHelper.CONFIG, processor, null, null, null, null, null, new DummyBlockValidationRule());
return new SimpleAsyncNode(handler);
}
示例2: createNodeWithUncles
import org.ethereum.core.Blockchain; //导入方法依赖的package包/类
private static SimpleAsyncNode createNodeWithUncles(int size) {
final World world = new World();
final BlockStore store = new BlockStore();
final Blockchain blockchain = world.getBlockChain();
List<Block> blocks = BlockGenerator.getInstance().getBlockChain(blockchain.getBestBlock(), size, 0, true);
for (Block b: blocks)
blockchain.tryToConnect(b);
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
BlockSyncService blockSyncService = new BlockSyncService(store, blockchain, nodeInformation, syncConfiguration);
NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
NodeMessageHandler handler = new NodeMessageHandler(ConfigHelper.CONFIG, processor, null, null, null, null, null, new DummyBlockValidationRule());
return new SimpleAsyncNode(handler);
}
示例3: createNode
import org.ethereum.core.Blockchain; //导入方法依赖的package包/类
private static SimpleNode createNode(int size) {
final World world = new World();
final BlockStore store = new BlockStore();
final Blockchain blockchain = world.getBlockChain();
List<Block> blocks = BlockGenerator.getInstance().getBlockChain(blockchain.getBestBlock(), size);
for (Block b: blocks)
blockchain.tryToConnect(b);
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
BlockSyncService blockSyncService = new BlockSyncService(store, blockchain, nodeInformation, syncConfiguration);
NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
NodeMessageHandler handler = new NodeMessageHandler(ConfigHelper.CONFIG, processor, null, null, null, null, null, new DummyBlockValidationRule());
return new SimpleNode(handler);
}
示例4: addFirstBlock
import org.ethereum.core.Blockchain; //导入方法依赖的package包/类
@Test
public void addFirstBlock() {
Blockchain blockchain = createBlockchain();
Block block = BlockGenerator.getInstance().createChildBlock(blockchain.getBestBlock());
blockchain.tryToConnect(block);
Assert.assertEquals(blockchain.getBestBlock(), block);
}
示例5: addTwoBlocks
import org.ethereum.core.Blockchain; //导入方法依赖的package包/类
@Test
public void addTwoBlocks() {
Blockchain blockchain = createBlockchain();
Block block1 = BlockGenerator.getInstance().createChildBlock(blockchain.getBestBlock());
Block block2 = BlockGenerator.getInstance().createChildBlock(block1);
blockchain.tryToConnect(block1);
blockchain.tryToConnect(block2);
Assert.assertEquals(blockchain.getBestBlock(), block2);
Assert.assertEquals(2, block2.getNumber());
}
示例6: checkItDoesntAddAnInvalidBlock
import org.ethereum.core.Blockchain; //导入方法依赖的package包/类
@Test
public void checkItDoesntAddAnInvalidBlock() {
Blockchain blockchain = createBlockchain();
Block block1 = BlockGenerator.getInstance().createChildBlock(blockchain.getBestBlock());
ImportResult importResult1 = blockchain.tryToConnect(block1);
assertTrue(importResult1.isSuccessful());
Block block2 = BlockGenerator.getInstance().createChildBlock(blockchain.getBestBlock());
Block block2b = BlockGenerator.getInstance().createBlock(10, 5);
Block block3 = Block.fromValidData(block2.getHeader(), block2b.getTransactionsList(), block2b.getUncleList());
ImportResult importResult2 = blockchain.tryToConnect(block3);
Assert.assertFalse(importResult2.isSuccessful());
}
示例7: test1
import org.ethereum.core.Blockchain; //导入方法依赖的package包/类
@Test
public void test1() throws InterruptedException {
setupPeers();
// A == B == genesis
Blockchain blockchainA = (Blockchain) ethereumA.getBlockchain();
for (Block b : mainB1B10) {
blockchainA.tryToConnect(b);
}
// A == b10, B == genesis
final CountDownLatch semaphore = new CountDownLatch(1);
ethereumB.addListener(new EthereumListenerAdapter() {
@Override
public void onBlock(Block block, List<TransactionReceipt> receipts) {
if (block.isEqual(b10)) {
semaphore.countDown();
}
}
});
ethA.sendNewBlock(b10);
semaphore.await(10, SECONDS);
// check if B == b10
if(semaphore.getCount() > 0) {
fail("PeerB bestBlock is incorrect");
}
}
示例8: test2
import org.ethereum.core.Blockchain; //导入方法依赖的package包/类
@Test
public void test2() throws InterruptedException {
setupPeers();
// A == B == genesis
Blockchain blockchainA = (Blockchain) ethereumA.getBlockchain();
for (Block b : forkB1B5B8_) {
blockchainA.tryToConnect(b);
}
// A == b8', B == genesis
final CountDownLatch semaphore = new CountDownLatch(1);
ethereumB.addListener(new EthereumListenerAdapter() {
@Override
public void onBlock(Block block, List<TransactionReceipt> receipts) {
if (block.isEqual(b8_)) {
semaphore.countDown();
}
}
});
ethA.sendNewBlock(b8_);
semaphore.await(10, SECONDS);
// check if B == b8'
if(semaphore.getCount() > 0) {
fail("PeerB bestBlock is incorrect");
}
}
示例9: addBlocks
import org.ethereum.core.Blockchain; //导入方法依赖的package包/类
private static void addBlocks(Blockchain blockchain, int size) {
List<Block> blocks = BlockGenerator.getInstance().getBlockChain(blockchain.getBestBlock(), size);
for (Block block : blocks)
blockchain.tryToConnect(block);
}
示例10: test12
import org.ethereum.core.Blockchain; //导入方法依赖的package包/类
@Test
public void test12() throws InterruptedException {
SysPropConfigA.eth62 = new Eth62() {
@Override
protected void processGetBlockBodies(GetBlockBodiesMessage msg) {
List<byte[]> bodies = Arrays.asList(
mainB1B10.get(0).getEncodedBody()
);
BlockBodiesMessage response = new BlockBodiesMessage(bodies);
sendMessage(response);
}
};
setupPeers();
Blockchain blockchainA = (Blockchain) ethereumA.getBlockchain();
for (Block b : mainB1B10) {
blockchainA.tryToConnect(b);
}
// A == b10, B == genesis
final CountDownLatch semaphoreDisconnect = new CountDownLatch(1);
ethereumA.addListener(new EthereumListenerAdapter() {
@Override
public void onRecvMessage(Channel channel, Message message) {
if (message instanceof DisconnectMessage) {
semaphoreDisconnect.countDown();
}
}
});
ethA.sendNewBlock(b10);
semaphoreDisconnect.await(10, SECONDS);
// check if peer was dropped
if(semaphoreDisconnect.getCount() > 0) {
fail("PeerA is not dropped");
}
}