本文整理汇总了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;
}
示例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));
}
示例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;
}
示例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;
}
示例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;
}
示例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));
}
示例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())));
}
示例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())));
}