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


Java Block.flushRLP方法代码示例

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


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

示例1: createNodeBlockProcessor

import org.ethereum.core.Block; //导入方法依赖的package包/类
private static NodeBlockProcessor createNodeBlockProcessor() {
    Blockchain blockChain = new BlockChainBuilder().build();

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

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

    BlockStore store = new BlockStore();
    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);

    return processor;
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:18,代码来源:NodeBlockProcessorUnclesTest.java

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

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

示例4: ofSize

import org.ethereum.core.Block; //导入方法依赖的package包/类
public static Blockchain ofSize(int size, boolean mining, List<Account> accounts, List<BigInteger> balances, boolean withoutCleaner) {
    BlockChainBuilder builder = new BlockChainBuilder();
    BlockChainImpl blockChain = builder.build(withoutCleaner);

    Block genesis = BlockGenerator.getInstance().getGenesisBlock();

    if (accounts != null)
        for (int k = 0; k < accounts.size(); k++) {
            Account account = accounts.get(k);
            BigInteger balance = balances.get(k);
            blockChain.getRepository().createAccount(account.getAddress().getBytes());
            blockChain.getRepository().addBalance(account.getAddress().getBytes(), balance);
        }

    genesis.setStateRoot(blockChain.getRepository().getRoot());
    genesis.flushRLP();

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

    if (size > 0) {
        List<Block> blocks = mining ? BlockGenerator.getInstance().getMinedBlockChain(genesis, size) : BlockGenerator.getInstance().getBlockChain(genesis, size);

        for (Block block: blocks)
            Assert.assertEquals(ImportResult.IMPORTED_BEST, blockChain.tryToConnect(block));
    }

    return blockChain;
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:29,代码来源:BlockChainBuilder.java

示例5: build

import org.ethereum.core.Block; //导入方法依赖的package包/类
public Account build() {
    byte[] privateKeyBytes = HashUtil.sha3(name.getBytes());
    ECKey key = ECKey.fromPrivate(privateKeyBytes);
    Account account = new Account(key);

    if (blockChain != null) {
        Block best = blockChain.getStatus().getBestBlock();
        BigInteger td = blockChain.getStatus().getTotalDifficulty();
        Repository repository = blockChain.getRepository();

        Repository track = repository.startTracking();

        track.createAccount(account.getAddress().getBytes());

        if (this.balance != null)
            track.addBalance(account.getAddress().getBytes(), this.balance);

        if (this.code != null)
            track.saveCode(account.getAddress().getBytes(), this.code);

        track.commit();

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

        blockChain.getBlockStore().saveBlock(best, td, true);
    }

    return account;
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:31,代码来源:AccountBuilder.java

示例6: test_RLPEncoding

import org.ethereum.core.Block; //导入方法依赖的package包/类
@Test
public void test_RLPEncoding() {
    // mined block
    Block b = BlockMiner.mineBlock(new BlockGenerator().getBlock(1));
    byte[] lastField = b.getBitcoinMergedMiningCoinbaseTransaction(); // last field
    b.flushRLP();// force re-encode
    byte[] encoded = b.getEncoded();
    Block b2 = new Block(encoded);
    byte[] lastField2 = b2.getBitcoinMergedMiningCoinbaseTransaction(); // last field
    b2.flushRLP();// force re-encode
    byte[] encoded2 = b2.getEncoded();
    Assert.assertTrue(Arrays.equals(encoded,encoded2));
    Assert.assertTrue(Arrays.equals(lastField,lastField2));
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:15,代码来源:ProofOfWorkRuleTest.java

示例7: unknowAncestorsHashes

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

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

    Block block1 = new BlockBuilder().difficulty(2l).parent(genesis).build();
    Block block1b = new BlockBuilder().difficulty(1l).parent(genesis).build();
    Block block2 = new BlockBuilder().parent(block1).build();
    Block block3 = new BlockBuilder().parent(block2).build();

    store.saveBlock(block3);

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

    Set<ByteArrayWrapper> hashes = BlockUtils.unknownAncestorsHashes(genesis.getHash(), blockChain, store);

    Assert.assertNotNull(hashes);
    Assert.assertTrue(hashes.isEmpty());

    hashes = BlockUtils.unknownAncestorsHashes(block1.getHash(), blockChain, store);

    Assert.assertNotNull(hashes);
    Assert.assertTrue(hashes.isEmpty());

    hashes = BlockUtils.unknownAncestorsHashes(block1b.getHash(), blockChain, store);

    Assert.assertNotNull(hashes);
    Assert.assertTrue(hashes.isEmpty());

    hashes = BlockUtils.unknownAncestorsHashes(block2.getHash(), blockChain, store);

    Assert.assertNotNull(hashes);
    Assert.assertFalse(hashes.isEmpty());
    Assert.assertEquals(1, hashes.size());
    Assert.assertTrue(hashes.contains(new ByteArrayWrapper(block2.getHash())));

    hashes = BlockUtils.unknownAncestorsHashes(block3.getHash(), blockChain, store);

    Assert.assertNotNull(hashes);
    Assert.assertFalse(hashes.isEmpty());
    Assert.assertEquals(1, hashes.size());
    Assert.assertTrue(hashes.contains(new ByteArrayWrapper(block2.getHash())));
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:50,代码来源:BlockUtilsTest.java

示例8: unknowAncestorsHashesUsingUncles

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

    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 uncle1 = new BlockBuilder().parent(block1).build();
    Block uncle2 = new BlockBuilder().parent(block1).build();
    List<BlockHeader> uncles = new ArrayList<>();
    uncles.add(uncle1.getHeader());
    uncles.add(uncle2.getHeader());
    Block block3 = new BlockBuilder().parent(block2).uncles(uncles).build();

    store.saveBlock(block3);

    blockChain.tryToConnect(genesis);
    blockChain.tryToConnect(block1);
    blockChain.tryToConnect(block1b);

    Set<ByteArrayWrapper> hashes = BlockUtils.unknownAncestorsHashes(genesis.getHash(), blockChain, store);

    Assert.assertNotNull(hashes);
    Assert.assertTrue(hashes.isEmpty());

    hashes = BlockUtils.unknownAncestorsHashes(block1.getHash(), blockChain, store);

    Assert.assertNotNull(hashes);
    Assert.assertTrue(hashes.isEmpty());

    hashes = BlockUtils.unknownAncestorsHashes(block1b.getHash(), blockChain, store);

    Assert.assertNotNull(hashes);

    Assert.assertTrue(hashes.isEmpty());

    hashes = BlockUtils.unknownAncestorsHashes(block2.getHash(), blockChain, store);

    Assert.assertNotNull(hashes);
    Assert.assertFalse(hashes.isEmpty());
    Assert.assertEquals(1, hashes.size());
    Assert.assertTrue(hashes.contains(new ByteArrayWrapper(block2.getHash())));

    hashes = BlockUtils.unknownAncestorsHashes(block3.getHash(), blockChain, store);

    Assert.assertNotNull(hashes);
    Assert.assertFalse(hashes.isEmpty());
    Assert.assertEquals(3, hashes.size());
    Assert.assertTrue(hashes.contains(new ByteArrayWrapper(block2.getHash())));
    Assert.assertTrue(hashes.contains(new ByteArrayWrapper(uncle1.getHash())));
    Assert.assertTrue(hashes.contains(new ByteArrayWrapper(uncle2.getHash())));
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:58,代码来源:BlockUtilsTest.java


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