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


Java Blockchain类代码示例

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


Blockchain类属于org.ethereum.core包,在下文中一共展示了Blockchain类的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();
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:18,代码来源:EthModule.java

示例2: SyncProcessor

import org.ethereum.core.Blockchain; //导入依赖的package包/类
public SyncProcessor(RskSystemProperties config,
                     Blockchain blockchain,
                     BlockSyncService blockSyncService,
                     PeerScoringManager peerScoringManager,
                     SyncConfiguration syncConfiguration,
                     BlockHeaderValidationRule blockHeaderValidationRule,
                     DifficultyCalculator difficultyCalculator) {
    this.config = config;
    this.blockchain = blockchain;
    this.blockSyncService = blockSyncService;
    this.peerScoringManager = peerScoringManager;
    this.syncConfiguration = syncConfiguration;
    this.syncInformation = new SyncInformationImpl(blockHeaderValidationRule, difficultyCalculator);
    this.peerStatuses = new PeersInformation(syncConfiguration, syncInformation);
    this.pendingMessages = new PendingMessages();
    setSyncState(new DecidingSyncState(this.syncConfiguration, this, syncInformation, peerStatuses));
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:18,代码来源:SyncProcessor.java

示例3: tryToConnectWithFork

import org.ethereum.core.Blockchain; //导入依赖的package包/类
@Test
public void tryToConnectWithFork() {
    Blockchain blockchain = createBlockchain();

    Block block1 = BlockGenerator.getInstance().createChildBlock(blockchain.getBestBlock(),0,1);
    Block block1b = BlockGenerator.getInstance().createChildBlock(blockchain.getBestBlock(),0,2);
    Block block2 = BlockGenerator.getInstance().createChildBlock(block1,0,3);
    Block block2b = BlockGenerator.getInstance().createChildBlock(block1b, 0, 1);
    Block block3b = BlockGenerator.getInstance().createChildBlock(block2b,0,4);

    Assert.assertEquals(ImportResult.NO_PARENT, blockchain.tryToConnect(block2));
    Assert.assertEquals(ImportResult.IMPORTED_BEST, blockchain.tryToConnect(block1));
    Assert.assertEquals(ImportResult.IMPORTED_BEST, blockchain.tryToConnect(block2));
    Assert.assertEquals(ImportResult.IMPORTED_NOT_BEST, blockchain.tryToConnect(block1b));
    Assert.assertEquals(ImportResult.EXIST, blockchain.tryToConnect(block1));
    Assert.assertEquals(ImportResult.IMPORTED_NOT_BEST, blockchain.tryToConnect(block2b));
    Assert.assertEquals(ImportResult.IMPORTED_BEST, blockchain.tryToConnect(block3b));

    Assert.assertEquals(blockchain.getBestBlock(), block3b);
    Assert.assertEquals(3, block3b.getNumber());
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:22,代码来源:BlockchainTest.java

示例4: WorldManagerImpl

import org.ethereum.core.Blockchain; //导入依赖的package包/类
@Autowired
public WorldManagerImpl(RskSystemProperties config,
                        Blockchain blockchain,
                        BlockStore blockStore,
                        PendingState pendingState,
                        Repository repository,
                        NetworkStateExporter networkStateExporter,
                        HashRateCalculator hashRateCalculator,
                        ConfigCapabilities configCapabilities,
                        ChannelManager channelManager,
                        EthereumListener listener,
                        BlockProcessor nodeBlockProcessor) {
    this.blockchain = blockchain;
    this.blockStore = blockStore;
    this.pendingState = pendingState;
    this.repository = repository;
    this.hashRateCalculator = hashRateCalculator;
    this.configCapabilities = configCapabilities;
    this.listener = listener;
    this.nodeBlockProcessor = nodeBlockProcessor;

    BlockChainLoader loader = new BlockChainLoader(config, this.blockchain, this.blockStore, this.repository, this.listener);
    loader.loadBlockchain();
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:25,代码来源:WorldManagerImpl.java

示例5: tryToConnectWithCompetingChain

import org.ethereum.core.Blockchain; //导入依赖的package包/类
@Test
public void tryToConnectWithCompetingChain() {
    // Two competing blockchains of the same size (2)
    Blockchain blockchain = createBlockchain();

    Block block1 = BlockGenerator.getInstance().createChildBlock(blockchain.getBestBlock());
    Block block2 = BlockGenerator.getInstance().createChildBlock(block1, 0, 5);
    Block block1b = BlockGenerator.getInstance().createChildBlock(blockchain.getBestBlock());
    Block block2b = BlockGenerator.getInstance().createChildBlock(block1b,0,4);
    // genesis <- block1 <- block2
    // genesis <- block1b <- block2b

    Assert.assertEquals(ImportResult.NO_PARENT, blockchain.tryToConnect(block2));
    Assert.assertEquals(ImportResult.IMPORTED_BEST, blockchain.tryToConnect(block1));
    Assert.assertEquals(ImportResult.IMPORTED_BEST, blockchain.tryToConnect(block2));
    Assert.assertEquals(ImportResult.IMPORTED_NOT_BEST, blockchain.tryToConnect(block1b));
    Assert.assertEquals(ImportResult.EXIST, blockchain.tryToConnect(block1));
    Assert.assertEquals(ImportResult.EXIST, blockchain.tryToConnect(block1b));
    Assert.assertEquals(ImportResult.IMPORTED_NOT_BEST, blockchain.tryToConnect(block2b));

    Assert.assertEquals(blockchain.getBestBlock(), block2);
    Assert.assertEquals(2, block2.getNumber());
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:24,代码来源:BlockchainTest.java

示例6: refreshWorkRunOnce

import org.ethereum.core.Blockchain; //导入依赖的package包/类
@Test
public void refreshWorkRunOnce() {
    World world = new World();
    Blockchain blockchain = world.getBlockChain();

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

    MinerServerImpl minerServer = getMinerServer(blockchain);
    MinerClientImpl minerClient = getMinerClient(minerServer);

    MinerClientImpl.RefreshWork refreshWork = minerClient.createRefreshWork();

    Assert.assertNotNull(refreshWork);
    try {
        minerServer.buildBlockToMine(blockchain.getBestBlock(), false);
        refreshWork.run();
        Assert.assertTrue(minerClient.mineBlock());

        Assert.assertEquals(1, blockchain.getBestBlock().getNumber());
    } finally {
        refreshWork.cancel();
    }
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:24,代码来源:MinerManagerTest.java

示例7: 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

示例8: 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

示例9: addBlockTest

import org.ethereum.core.Blockchain; //导入依赖的package包/类
@Test
public void addBlockTest() {
    Blockchain blockchain = createBlockchain();


    Block lowDifficultyBlock = BlockGenerator.getInstance().createChildBlock(blockchain.getBestBlock(), 0, 1);
    Block highDifficultyBlock = BlockGenerator.getInstance().createChildBlock(lowDifficultyBlock, 0, 5);
    Block highDifficultyBlockWithMoreFees = BlockGenerator.getInstance().createChildBlock(lowDifficultyBlock, 10l, new ArrayList<>(), highDifficultyBlock.getDifficulty());

    //diff test
    assertFalse(SelectionRule.shouldWeAddThisBlock(lowDifficultyBlock.getDifficultyBI(),
            highDifficultyBlock.getDifficultyBI(), lowDifficultyBlock, highDifficultyBlock));
    assertTrue(SelectionRule.shouldWeAddThisBlock(highDifficultyBlock.getDifficultyBI(),
            lowDifficultyBlock.getDifficultyBI(), highDifficultyBlock, lowDifficultyBlock));
    // At same difficulty, more fees
    assertTrue(SelectionRule.shouldWeAddThisBlock(highDifficultyBlockWithMoreFees.getDifficultyBI(),
            highDifficultyBlock.getDifficultyBI(), highDifficultyBlockWithMoreFees, highDifficultyBlock));
    //Low hash is proved in smallerBlockHashTest
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:20,代码来源:SelectionRuleTest.java

示例10: sendBlockMessagesAndAddThemToBlockchain

import org.ethereum.core.Blockchain; //导入依赖的package包/类
@Test
public void sendBlockMessagesAndAddThemToBlockchain() {
    for (int i = 0; i < 50; 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());

        List<Block> extendedChain = BlockGenerator.getInstance().getBlockChain(blockchain.getBestBlock(), i);
        for (Block block : extendedChain) {
            blockSyncService.processBlock(null, block, false);
            Assert.assertEquals(block.getNumber(), blockchain.getBestBlock().getNumber());
            Assert.assertArrayEquals(block.getHash(), blockchain.getBestBlock().getHash());
        }
    }
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:18,代码来源:BlockSyncServiceTest.java

示例11: 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

示例12: processBlockSavingInStore

import org.ethereum.core.Blockchain; //导入依赖的package包/类
@Test
public void processBlockSavingInStore() throws UnknownHostException {
    final BlockStore store = new BlockStore();
    final MessageChannel sender = new SimpleMessageChannel();

    final Blockchain blockchain = BlockChainBuilder.ofSize(0);
    final Block parent = BlockGenerator.getInstance().createChildBlock(BlockGenerator.getInstance().getGenesisBlock());
    final Block orphan = BlockGenerator.getInstance().createChildBlock(parent);

    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(sender, orphan);
    Assert.assertTrue(processor.getNodeInformation().getNodesByBlock(orphan.getHash()).size() == 1);

    Assert.assertTrue(store.hasBlock(orphan));
    Assert.assertEquals(1, store.size());
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:21,代码来源:NodeBlockProcessorTest.java

示例13: 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

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

示例15: noSyncingWithEmptyBlockchainAndLowBestBlock

import org.ethereum.core.Blockchain; //导入依赖的package包/类
@Test @Ignore("Ignored when Process status deleted on block processor")
    public void noSyncingWithEmptyBlockchainAndLowBestBlock() {
        BlockStore store = new BlockStore();
        Block block = BlockGenerator.getInstance().createBlock(10, 0);
        Blockchain blockchain = BlockChainBuilder.ofSize(0);

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

        Assert.assertFalse(processor.hasBetterBlockToSync());

        Status status = new Status(block.getNumber(), block.getHash());
//        processor.processStatus(new SimpleNodeChannel(null, null), status);

        Assert.assertFalse(processor.hasBetterBlockToSync());
    }
 
开发者ID:rsksmart,项目名称:rskj,代码行数:19,代码来源:NodeBlockProcessorTest.java


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