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


Java Blockchain.getBlockStore方法代码示例

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


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

示例1: resetSnapshots

import org.ethereum.core.Blockchain; //导入方法依赖的package包/类
public boolean resetSnapshots(Blockchain blockchain) {
    this.snapshots = new ArrayList<>();

    PendingState pendingState = blockchain.getPendingState();

    long bestNumber = blockchain.getBestBlock().getNumber();

    BlockStore store = blockchain.getBlockStore();

    Block block = store.getChainBlockByNumber(0);
    BigInteger difficulty = blockchain.getBlockStore().getTotalDifficultyForHash(block.getHash());

    blockchain.setStatus(block, difficulty);

    // To clean pending state, first process the fork
    blockchain.getPendingState().processBest(block);
    // then, clear any reverted transaction
    pendingState.clearPendingState(pendingState.getAllPendingTransactions());
    pendingState.clearWire(pendingState.getWireTransactions());

    // Remove removed blocks from store
    for (long nb = blockchain.getBestBlock().getNumber() + 1; nb <= bestNumber; nb++) {
        blockchain.removeBlocksByNumber(nb);
    }

    return true;
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:28,代码来源:SnapshotManager.java

示例2: revertToSnapshot

import org.ethereum.core.Blockchain; //导入方法依赖的package包/类
public boolean revertToSnapshot(Blockchain blockchain, int snapshotId) {
    if (snapshotId <= 0 || snapshotId > this.snapshots.size()) {
        return false;
    }

    long newBestBlockNumber = this.snapshots.get(snapshotId - 1).longValue();

    List<Long> newSnapshots = this.snapshots.stream().limit(snapshotId).collect(Collectors.toList());

    this.snapshots = newSnapshots;

    PendingState pendingState = blockchain.getPendingState();

    long currentBestBlockNumber = blockchain.getBestBlock().getNumber();

    if (newBestBlockNumber >= currentBestBlockNumber) {
        return true;
    }

    BlockStore store = blockchain.getBlockStore();

    Block block = store.getChainBlockByNumber(newBestBlockNumber);
    BigInteger difficulty = blockchain.getBlockStore().getTotalDifficultyForHash(block.getHash());

    blockchain.setStatus(block, difficulty);

    // To clean pending state, first process the fork
    blockchain.getPendingState().processBest(block);
    // then, clear any reverted transaction
    pendingState.clearPendingState(pendingState.getAllPendingTransactions());
    pendingState.clearWire(pendingState.getWireTransactions());

    // Remove removed blocks from store
    for (long nb = blockchain.getBestBlock().getNumber() + 1; nb <= currentBestBlockNumber; nb++) {
        blockchain.removeBlocksByNumber(nb);
    }

    return true;
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:40,代码来源:SnapshotManager.java

示例3: getMinerServer

import org.ethereum.core.Blockchain; //导入方法依赖的package包/类
private static MinerServerImpl getMinerServer(Blockchain blockchain) {
    SimpleEthereum ethereum = new SimpleEthereum();
    SimpleWorldManager worldManager = new SimpleWorldManager();
    worldManager.setBlockchain(blockchain);
    ethereum.repository = (org.ethereum.facade.Repository)blockchain.getRepository();
    ethereum.worldManager = worldManager;
    DifficultyCalculator difficultyCalculator = new DifficultyCalculator(ConfigHelper.CONFIG);
    return new MinerServerImpl(ConfigHelper.CONFIG, ethereum, blockchain, blockchain.getBlockStore(), blockchain.getPendingState(),
            blockchain.getRepository(), ConfigUtils.getDefaultMiningConfig(),
            new BlockValidationRuleDummy(), worldManager.getNodeBlockProcessor(),
            difficultyCalculator, new GasLimitCalculator(ConfigHelper.CONFIG),
            new ProofOfWorkRule(ConfigHelper.CONFIG).setFallbackMiningEnabled(false));
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:14,代码来源:MinerManagerTest.java


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