当前位置: 首页>>代码示例>>Java>>正文


Java Blockchain.tryToConnect方法代码示例

本文整理汇总了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);
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:19,代码来源:TwoAsyncNodeTest.java

示例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);
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:19,代码来源:TwoAsyncNodeTest.java

示例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);
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:19,代码来源:TwoNodeTest.java

示例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);
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:10,代码来源:BlockchainTest.java

示例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());
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:14,代码来源:BlockchainTest.java

示例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());
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:15,代码来源:BlockchainTest.java

示例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");
    }
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:35,代码来源:ShortSyncTest.java

示例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");
    }
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:35,代码来源:ShortSyncTest.java

示例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);
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:7,代码来源:Web3ImplSnapshotTest.java

示例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");
    }
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:46,代码来源:ShortSyncTest.java


注:本文中的org.ethereum.core.Blockchain.tryToConnect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。