• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Block类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



Block类属于org.ethereum.core包,在下文中一共展示了Block类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: bridgeState

import org.ethereum.core.Block; //导入依赖的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: createSampleNewPendingStateWithAccounts

import org.ethereum.core.Block; //导入依赖的package包/类
private static PendingStateImpl createSampleNewPendingStateWithAccounts(int naccounts, BigInteger balance) {
    BlockChainImpl blockChain = createBlockchain();

    Block best = blockChain.getStatus().getBestBlock();
    Repository repository = blockChain.getRepository();

    Repository track = repository.startTracking();

    for (int k = 1; k <= naccounts; k++) {
        Account account = createAccount(k);
        track.createAccount(account.getAddress().getBytes());
        track.addBalance(account.getAddress().getBytes(), balance);
    }

    track.commit();

    best.setStateRoot(repository.getRoot());
    best.flushRLP();

    PendingStateImpl pendingState = new PendingStateImpl(ConfigHelper.CONFIG, blockChain, blockChain.getRepository(), blockChain.getBlockStore(), new ProgramInvokeFactoryImpl(), new BlockExecutorTest.SimpleEthereumListener(), 10, 100);
    blockChain.setPendingState(pendingState);

    return pendingState;
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:25,代码来源:PendingStateImplTest.java


示例3: isValid

import org.ethereum.core.Block; //导入依赖的package包/类
@Override
public boolean isValid(Block block, Block parent) {
    if(block == null || parent == null) {
        logger.warn("BlockDifficultyRule - block or parent are null");
        return false;
    }
    BlockHeader header = block.getHeader();
    BigInteger calcDifficulty = difficultyCalculator.calcDifficulty(header, parent.getHeader());
    BigInteger difficulty = header.getDifficultyBI();

    if (!isEqual(difficulty, calcDifficulty)) {
        logger.warn(String.format("#%d: difficulty != calcDifficulty", header.getNumber()));
        return false;
    }
    return true;
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:17,代码来源:BlockDifficultyRule.java


示例4: processTenBlocksAddingToBlockchain

import org.ethereum.core.Block; //导入依赖的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


示例5: getBlocksByNumber

import org.ethereum.core.Block; //导入依赖的package包/类
public synchronized List<Block> getBlocksByNumber(long number){

        List<Block> result = new ArrayList<>();

        if (number >= index.size()) {
            return result;
        }

        List<BlockInfo> blockInfos = index.get((int) number);

        if (blockInfos == null) {
            return result;
        }

        for (BlockInfo blockInfo : blockInfos){

            byte[] hash = blockInfo.getHash();
            Block block = blocks.get(hash);

            result.add(block);
        }
        return result;
    }
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:24,代码来源:IndexedBlockStore.java


示例6: isValid

import org.ethereum.core.Block; //导入依赖的package包/类
@Override
public boolean isValid(Block block) {
    List<Transaction> txs = block.getTransactionsList();
    if(block.getMinGasPriceAsInteger() == null) {
        logger.warn("Could not retrieve block min gas priceß");
        return false;
    }

    BigInteger blockMgp = block.getMinGasPriceAsInteger();
    if(CollectionUtils.isNotEmpty(block.getTransactionsList())) {
        for (Transaction tx : txs) {
            if (!(tx instanceof RemascTransaction) && tx.getGasPriceAsInteger().compareTo(blockMgp) < 0) {
                logger.warn("Tx gas price is under the Min gas Price of the block");
                panicProcessor.panic("invalidmingasprice", "Tx gas price is under the Min gas Price of the block");
                return false;
            }
        }
    }

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


示例7: prepareData

import org.ethereum.core.Block; //导入依赖的package包/类
@Ignore("long stress test")
@Test // loads blocks from file and store them into disk DB
public void prepareData() throws URISyntaxException, IOException {
    URL dataURL = ClassLoader.getSystemResource("blockstore/big_data.dmp");

    File file = new File(dataURL.toURI());

    BufferedReader reader = new BufferedReader(new FileReader(file));
    String blockRLP;
    while(null != (blockRLP = reader.readLine())) {
        Block block = new Block(
                Hex.decode(blockRLP)
        );
        blockSource.put(block.getHash(), block);

        if (block.getNumber() % 10000 == 0)
            logger.info(
                    "adding block.hash: [{}] block.number: [{}]",
                    block.getShortHash(),
                    block.getNumber()
            );
    }
    logger.info("total blocks loaded: {}", blockSource.size());
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:25,代码来源:BlockStressTest.java


示例8: blockInSomeBlockChain

import org.ethereum.core.Block; //导入依赖的package包/类
@Test
public void blockInSomeBlockChain() {
    BlockChainImpl blockChain = new BlockChainBuilder().build();

    Block genesis = BlockGenerator.getInstance().getGenesisBlock();
    genesis.setStateRoot(blockChain.getRepository().getRoot());
    genesis.flushRLP();

    Block block1 = new BlockBuilder().parent(genesis).build();
    Block block1b = new BlockBuilder().parent(genesis).build();
    Block block2 = new BlockBuilder().parent(block1).build();
    Block block3 = new BlockBuilder().parent(block2).build();
    blockChain.getBlockStore().saveBlock(block3, BigInteger.ONE, false);

    Assert.assertEquals(ImportResult.IMPORTED_BEST, blockChain.tryToConnect(genesis));
    blockChain.tryToConnect(block1);
    blockChain.tryToConnect(block1b);

    Assert.assertTrue(BlockUtils.blockInSomeBlockChain(genesis, blockChain));
    Assert.assertTrue(BlockUtils.blockInSomeBlockChain(block1, blockChain));
    Assert.assertTrue(BlockUtils.blockInSomeBlockChain(block1b, blockChain));
    Assert.assertFalse(BlockUtils.blockInSomeBlockChain(block2, blockChain));
    Assert.assertTrue(BlockUtils.blockInSomeBlockChain(block3, blockChain));
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:25,代码来源:BlockUtilsTest.java


示例9: processBlockBuildCommandWithUncles

import org.ethereum.core.Block; //导入依赖的package包/类
@Test
public void processBlockBuildCommandWithUncles() throws DslProcessorException {
    World world = new World();

    WorldDslProcessor processor = new WorldDslProcessor(world);

    DslParser parser = new DslParser("block_chain g00 b01\nblock_chain g00 u01\nblock_chain g00 u02\nblock_build b02\nparent b01\nuncles u01 u02\nbuild");

    processor.processCommands(parser);

    Block block = world.getBlockByName("b02");
    Assert.assertNotNull(block);
    Assert.assertEquals(2, block.getNumber());
    Assert.assertNotNull(block.getUncleList());
    Assert.assertFalse(block.getUncleList().isEmpty());
    Assert.assertEquals(2, block.getUncleList().size());

    Assert.assertArrayEquals(world.getBlockByName("u01").getHash(), block.getUncleList().get(0).getHash());
    Assert.assertArrayEquals(world.getBlockByName("u02").getHash(), block.getUncleList().get(1).getHash());
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:21,代码来源:WorldDslProcessorTest.java


示例10: processBlockSavingInStore

import org.ethereum.core.Block; //导入依赖的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


示例11: newBody

import org.ethereum.core.Block; //导入依赖的package包/类
@Override
public void newBody(BodyResponseMessage message, MessageChannel peer) {
    NodeID peerId = peer.getPeerNodeID();
    if (!isExpectedBody(message.getId(), peerId)) {
        handleUnexpectedBody(peerId);
        return;
    }

    // we already checked that this message was expected
    BlockHeader header = pendingBodyResponses.remove(message.getId()).header;
    Block block = Block.fromValidData(header, message.getTransactions(), message.getUncles());
    if (!blockUnclesHashValidationRule.isValid(block) || !blockTransactionsValidationRule.isValid(block)) {
        handleInvalidMessage(peerId, header);
        return;
    }

    // handle block
    if (syncInformation.processBlock(block).isInvalidBlock()){
        handleInvalidBlock(peerId, header);
        return;
    }
    // updates peer downloading information
    tryRequestNextBody(peerId);
    // check if this was the last block to download
    verifyDownloadIsFinished();
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:27,代码来源:DownloadingBodiesSyncState.java


示例12: getBestBlock

import org.ethereum.core.Block; //导入依赖的package包/类
public synchronized Block getBestBlock(){

        Long maxLevel = getMaxNumber();
        if (maxLevel < 0) return null;

        Block bestBlock = getChainBlockByNumber(maxLevel);
        if (bestBlock != null) return  bestBlock;

        // That scenario can happen
        // if there is a fork branch that is
        // higher than main branch but has
        // less TD than the main branch TD
        while (bestBlock == null){
            --maxLevel;
            bestBlock = getChainBlockByNumber(maxLevel);
        }

        return bestBlock;
    }
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:20,代码来源:IndexedBlockStore.java


示例13: removeBlockByNumber

import org.ethereum.core.Block; //导入依赖的package包/类
private void removeBlockByNumber(ByteArrayWrapper key, Long nkey) {
    Set<Block> bynumber = this.blocksbynumber.get(nkey);

    if (bynumber != null && !bynumber.isEmpty()) {
        Block toremove = null;

        for (Block blk : bynumber) {
            if (new ByteArrayWrapper(blk.getHash()).equals(key)) {
                toremove = blk;
                break;
            }
        }

        if (toremove != null) {
            bynumber.remove(toremove);
            if (bynumber.isEmpty()) {
                this.blocksbynumber.remove(nkey);
            }
        }
    }
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:22,代码来源:BlockStore.java


示例14: exportBlocks

import org.ethereum.core.Block; //导入依赖的package包/类
private List<Block> exportBlocks() {
    List<Block> ret = new ArrayList<>();
    for (long i = minNum; i <= maxNum; i++) {
        Map<ByteArrayWrapper, HeaderElement> gen = headers.get(i);
        if (gen == null) break;

        boolean hasAny = false;
        for (HeaderElement element : gen.values()) {
            HeaderElement parent = element.getParent();
            if (element.block != null && (i == minNum || parent != null && parent.exported)) {
                if (!element.exported) {
                    exportNewBlock(element.block);
                    ret.add(element.block);
                    element.exported = true;
                }
                hasAny = true;
            }
        }
        if (!hasAny) break;
    }
    trimExported();
    return ret;
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:24,代码来源:SyncQueueImpl.java


示例15: blockTimeEqualsParentTime

import org.ethereum.core.Block; //导入依赖的package包/类
@Test
public void blockTimeEqualsParentTime() {
    int validPeriod = 540;
    BlockTimeStampValidationRule validationRule = new BlockTimeStampValidationRule(validPeriod);

    Block block = Mockito.mock(Block.class);
    Block parent = Mockito.mock(Block.class);

    Mockito.when(block.getTimestamp())
            .thenReturn(System.currentTimeMillis() / 1000);

    Mockito.when(parent.getTimestamp())
            .thenReturn(System.currentTimeMillis() / 1000);

    Assert.assertFalse(validationRule.isValid(block, parent));
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:17,代码来源:BlockTimeStampValidationRuleTest.java


示例16: executeTransaction

import org.ethereum.core.Block; //导入依赖的package包/类
public static TransactionExecutor executeTransaction(RskSystemProperties config,
                                                     Repository track,
                                                     BlockStore blockStore,
                                                     ReceiptStore receiptStore,
                                                     ProgramInvokeFactory programInvokeFactory,
                                                     Block executionBlock,
                                                     byte[] coinbase,
                                                     byte[] gasPrice,
                                                     byte[] gasLimit,
                                                     byte[] toAddress,
                                                     byte[] value,
                                                     byte[] data,
                                                     byte[] fromAddress) {
    Repository repository = track.getSnapshotTo(executionBlock.getStateRoot()).startTracking();

    byte[] nonce = repository.getNonce(fromAddress).toByteArray();
    UnsignedTransaction tx = new UnsignedTransaction(nonce, gasPrice, gasLimit, toAddress, value, data, fromAddress);

    ReversibleTransactionExecutor executor = new ReversibleTransactionExecutor(config, tx, coinbase, repository, blockStore, receiptStore, programInvokeFactory, executionBlock);
    return executor.executeTransaction();
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:22,代码来源:ReversibleTransactionExecutor.java


示例17: getHeaderElement

import org.ethereum.core.Block; //导入依赖的package包/类
private BlockHeaderElement getHeaderElement(byte[] hash) {
    BlockHeaderElement element = null;
    if (hash != null) {
        ByteArrayWrapper key = new ByteArrayWrapper(hash);
        element = this.headerCache.get(key);
        if (element == null) {
            Block block = this.blockStore.getBlockByHash(hash);
            if (block != null) {
                element = new BlockHeaderElement(block.getHeader(), this.blockStore.getBlockByHash(hash).getCumulativeDifficulty());
                this.headerCache.put(key, element);
            }
        }
    }
    return element;
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:16,代码来源:HashRateCalculator.java


示例18: processBlockProcessCommand

import org.ethereum.core.Block; //导入依赖的package包/类
private void processBlockProcessCommand(DslCommand cmd) {
    NodeBlockProcessor blockProcessor = world.getBlockProcessor();
    int nblocks = cmd.getArity();

    for (int k = 0; k < nblocks; k++) {
        String name = cmd.getArgument(k);
        Block block = world.getBlockByName(name);
        blockProcessor.processBlock(null, block);
    }
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:11,代码来源:WorldDslProcessor.java


示例19: noParentBlock

import org.ethereum.core.Block; //导入依赖的package包/类
@Test
public void noParentBlock() {
    Block block = Mockito.mock(Block.class);

    Mockito.when(block.getParentHash()).thenReturn(PARENT_HASH);
    Mockito.when(block.getMinGasPriceAsInteger()).thenReturn(BLOCK_MGP);

    PrevMinGasPriceRule pmgpv = new PrevMinGasPriceRule();

    Assert.assertFalse(pmgpv.isValid(block, null));
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:12,代码来源:PrevMinGasPriceValidatorTest.java


示例20: writeBlock

import org.ethereum.core.Block; //导入依赖的package包/类
public void writeBlock(Block block) {
    try {
        writer.write(formatter.format(new Date()));
        writer.write(",");
        writer.write(String.valueOf(block.getNumber()));
        writer.write(",");
        writer.write(Hex.toHexString(block.getEncoded()));
        writer.newLine();
        writer.flush();
    }
    catch (IOException ex) {
        logger.error("Exception writing block: ", ex);
    }
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:15,代码来源:FileBlockRecorder.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java RootFactory类代码示例发布时间:2022-05-23
下一篇:
Java HInvalidRequestException类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap