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


Java Blockchain.getBlockByNumber方法代码示例

本文整理汇总了Java中org.ethereum.core.Blockchain.getBlockByNumber方法的典型用法代码示例。如果您正苦于以下问题:Java Blockchain.getBlockByNumber方法的具体用法?Java Blockchain.getBlockByNumber怎么用?Java Blockchain.getBlockByNumber使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.ethereum.core.Blockchain的用法示例。


在下文中一共展示了Blockchain.getBlockByNumber方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

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

示例2: processBlockAddingToBlockchain

import org.ethereum.core.Blockchain; //导入方法依赖的package包/类
@Test
public void processBlockAddingToBlockchain() {
    Blockchain blockchain = BlockChainBuilder.ofSize(10);

    Assert.assertEquals(10, blockchain.getBestBlock().getNumber());

    BlockStore store = new BlockStore();
    Block genesis = blockchain.getBlockByNumber(0);
    store.saveBlock(genesis);
    Block block = BlockGenerator.getInstance().createChildBlock(blockchain.getBlockByNumber(10));

    Assert.assertEquals(11, block.getNumber());
    Assert.assertArrayEquals(blockchain.getBestBlockHash(), block.getParentHash());

    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, block);

    Assert.assertFalse(store.hasBlock(block));
    Assert.assertEquals(11, blockchain.getBestBlock().getNumber());
    Assert.assertArrayEquals(block.getHash(), blockchain.getBestBlockHash());
    Assert.assertEquals(1, store.size());
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:27,代码来源:NodeBlockProcessorTest.java

示例3: processStatusHavingBestBlockInBlockchainStore

import org.ethereum.core.Blockchain; //导入方法依赖的package包/类
@Test @Ignore("Ignored when Process status deleted on block processor")
    public void processStatusHavingBestBlockInBlockchainStore() 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.getBlockByNumber(1);
        final ByteArrayWrapper blockHash = new ByteArrayWrapper(block.getHash());

        store.saveBlock(block);
//        final Status status = new Status(block.getNumber(), block.getHash());

        Assert.assertTrue(nodeInformation.getBlocksByNode(sender.getPeerNodeID()).isEmpty());

//        processor.processStatus(sender, status);
        Assert.assertTrue(nodeInformation.getBlocksByNode(sender.getPeerNodeID()).contains(blockHash));

        Assert.assertEquals(0, sender.getGetBlockMessages().size());
    }
 
开发者ID:rsksmart,项目名称:rskj,代码行数:25,代码来源:NodeBlockProcessorTest.java

示例4: processGetBlockHeaderMessageUsingBlockInBlockchain

import org.ethereum.core.Blockchain; //导入方法依赖的package包/类
@Test
public void processGetBlockHeaderMessageUsingBlockInBlockchain() throws UnknownHostException {
    final Blockchain blockchain = BlockChainBuilder.ofSize(10);
    final Block block = blockchain.getBlockByNumber(5);
    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.processBlockHeadersRequest(sender, 1, block.getHash(), 1);

    Assert.assertFalse(sender.getMessages().isEmpty());
    Assert.assertEquals(1, sender.getMessages().size());

    final Message message = sender.getMessages().get(0);

    Assert.assertEquals(MessageType.BLOCK_HEADERS_RESPONSE_MESSAGE, message.getMessageType());

    final BlockHeadersResponseMessage bMessage = (BlockHeadersResponseMessage) message;

    Assert.assertArrayEquals(block.getHeader().getHash(), bMessage.getBlockHeaders().get(0).getHash());
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:27,代码来源:NodeBlockProcessorTest.java

示例5: processBodyRequestMessageUsingBlockInBlockchain

import org.ethereum.core.Blockchain; //导入方法依赖的package包/类
@Test
public void processBodyRequestMessageUsingBlockInBlockchain() throws UnknownHostException {
    final Blockchain blockchain = BlockChainBuilder.ofSize(10);
    final Block block = blockchain.getBlockByNumber(3);
    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.processBodyRequest(sender, 100, block.getHash());

    Assert.assertFalse(sender.getMessages().isEmpty());
    Assert.assertEquals(1, sender.getMessages().size());

    final Message message = sender.getMessages().get(0);

    Assert.assertEquals(MessageType.BODY_RESPONSE_MESSAGE, message.getMessageType());

    final BodyResponseMessage bMessage = (BodyResponseMessage) message;

    Assert.assertEquals(100, bMessage.getId());
    Assert.assertEquals(block.getTransactionsList(), bMessage.getTransactions());
    Assert.assertEquals(block.getUncleList(), bMessage.getUncles());
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:28,代码来源:NodeBlockProcessorTest.java

示例6: processBlockHashRequestMessageUsingBlockInBlockchain

import org.ethereum.core.Blockchain; //导入方法依赖的package包/类
@Test
public void processBlockHashRequestMessageUsingBlockInBlockchain() throws UnknownHostException {
    final Blockchain blockchain = BlockChainBuilder.ofSize(10);
    final Block block = blockchain.getBlockByNumber(5);
    final ByteArrayWrapper blockHash = new ByteArrayWrapper(block.getHash());
    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();

    Assert.assertTrue(nodeInformation.getBlocksByNode(sender.getPeerNodeID()).isEmpty());

    processor.processBlockRequest(sender, 100, block.getHash());

    Assert.assertTrue(nodeInformation.getBlocksByNode(sender.getPeerNodeID()).contains(blockHash));

    Assert.assertFalse(sender.getMessages().isEmpty());
    Assert.assertEquals(1, sender.getMessages().size());

    final Message message = sender.getMessages().get(0);

    Assert.assertEquals(MessageType.BLOCK_RESPONSE_MESSAGE, message.getMessageType());

    final BlockResponseMessage bMessage = (BlockResponseMessage) message;

    Assert.assertEquals(100, bMessage.getId());
    Assert.assertArrayEquals(block.getHash(), bMessage.getBlock().getHash());
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:33,代码来源:NodeBlockProcessorTest.java

示例7: processBlockHeadersRequestMessageUsingBlockInBlockchain

import org.ethereum.core.Blockchain; //导入方法依赖的package包/类
@Test
public void processBlockHeadersRequestMessageUsingBlockInBlockchain() throws UnknownHostException {
    final Blockchain blockchain = BlockChainBuilder.ofSize(100);
    final Block block = blockchain.getBlockByNumber(60);
    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.processBlockHeadersRequest(sender, 100, block.getHash(), 20);

    Assert.assertFalse(sender.getMessages().isEmpty());
    Assert.assertEquals(1, sender.getMessages().size());

    final Message message = sender.getMessages().get(0);

    Assert.assertEquals(MessageType.BLOCK_HEADERS_RESPONSE_MESSAGE, message.getMessageType());

    final BlockHeadersResponseMessage response = (BlockHeadersResponseMessage) message;

    Assert.assertEquals(100, response.getId());
    Assert.assertNotNull(response.getBlockHeaders());
    Assert.assertEquals(20, response.getBlockHeaders().size());

    for (int k = 0; k < 20; k++)
        Assert.assertArrayEquals(blockchain.getBlockByNumber(60 - k).getHash(), response.getBlockHeaders().get(k).getHash());
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:32,代码来源:NodeBlockProcessorTest.java

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

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

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

示例11: processGetBlockMessageUsingBlockInBlockchain

import org.ethereum.core.Blockchain; //导入方法依赖的package包/类
@Test
public void processGetBlockMessageUsingBlockInBlockchain() throws UnknownHostException {
    final Blockchain blockchain = BlockChainBuilder.ofSize(10);
    final Block block = blockchain.getBlockByNumber(5);
    final ByteArrayWrapper blockHash = new ByteArrayWrapper(block.getHash());
    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();

    Assert.assertTrue(nodeInformation.getBlocksByNode(sender.getPeerNodeID()).isEmpty());

    processor.processGetBlock(sender, block.getHash());

    Assert.assertTrue(nodeInformation.getBlocksByNode(sender.getPeerNodeID()).contains(blockHash));

    Assert.assertFalse(sender.getMessages().isEmpty());
    Assert.assertEquals(1, sender.getMessages().size());

    final Message message = sender.getMessages().get(0);

    Assert.assertEquals(MessageType.BLOCK_MESSAGE, message.getMessageType());

    final BlockMessage bMessage = (BlockMessage) message;

    Assert.assertArrayEquals(block.getHash(), bMessage.getBlock().getHash());
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:32,代码来源:NodeBlockProcessorTest.java


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