當前位置: 首頁>>代碼示例>>Java>>正文


Java BlockStore.saveBlock方法代碼示例

本文整理匯總了Java中org.ethereum.db.BlockStore.saveBlock方法的典型用法代碼示例。如果您正苦於以下問題:Java BlockStore.saveBlock方法的具體用法?Java BlockStore.saveBlock怎麽用?Java BlockStore.saveBlock使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.ethereum.db.BlockStore的用法示例。


在下文中一共展示了BlockStore.saveBlock方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: rejectBlockWithSiblingUncle

import org.ethereum.db.BlockStore; //導入方法依賴的package包/類
@Test
public void rejectBlockWithSiblingUncle() {
    Block genesis = BlockGenerator.getInstance().getGenesisBlock();

    Block block1 = BlockGenerator.getInstance().createChildBlock(genesis);
    Block uncle = BlockGenerator.getInstance().createChildBlock(block1);
    List<BlockHeader> uncles = new ArrayList<>();
    uncles.add(uncle.getHeader());

    Block block = BlockGenerator.getInstance().createChildBlock(block1, null, uncles, 1, null);

    BlockChainImpl blockChain = BlockChainImplTest.createBlockChain();
    BlockStore store = blockChain.getBlockStore();

    store.saveBlock(genesis, BigInteger.valueOf(1), true);
    store.saveBlock(block1, BigInteger.valueOf(2), true);

    BlockUnclesValidationRule rule = new BlockUnclesValidationRule(ConfigHelper.CONFIG, store, 10, 10, new BlockCompositeRule(), new BlockParentCompositeRule());

    Assert.assertFalse(rule.isValid(block));
}
 
開發者ID:rsksmart,項目名稱:rskj,代碼行數:22,代碼來源:BlockUnclesValidationRuleTest.java

示例2: rejectBlockWithUncleHavingHigherNumber

import org.ethereum.db.BlockStore; //導入方法依賴的package包/類
@Test
public void rejectBlockWithUncleHavingHigherNumber() {
    Block genesis = BlockGenerator.getInstance().getGenesisBlock();

    Block block1 = BlockGenerator.getInstance().createChildBlock(genesis);
    Block uncle1 = BlockGenerator.getInstance().createChildBlock(block1);
    Block uncle2 = BlockGenerator.getInstance().createChildBlock(uncle1);
    List<BlockHeader> uncles = new ArrayList<>();
    uncles.add(uncle2.getHeader());

    Block block = BlockGenerator.getInstance().createChildBlock(block1, null, uncles, 1, null);

    BlockChainImpl blockChain = BlockChainImplTest.createBlockChain();
    BlockStore store = blockChain.getBlockStore();

    store.saveBlock(genesis, BigInteger.valueOf(1), true);
    store.saveBlock(block1, BigInteger.valueOf(2), true);

    BlockUnclesValidationRule rule = new BlockUnclesValidationRule(ConfigHelper.CONFIG, store, 10, 10, new BlockCompositeRule(), new BlockParentCompositeRule());

    Assert.assertFalse(rule.isValid(block));
}
 
開發者ID:rsksmart,項目名稱:rskj,代碼行數:23,代碼來源:BlockUnclesValidationRuleTest.java

示例3: calculateParentChild

import org.ethereum.db.BlockStore; //導入方法依賴的package包/類
@Test
public void calculateParentChild() {
    BlockStore store = createBlockStore();
    Block genesis = BlockGenerator.getInstance().getGenesisBlock();
    Block block = BlockGenerator.getInstance().createChildBlock(genesis);

    store.saveBlock(genesis, BigInteger.ONE, true);
    store.saveBlock(block, BigInteger.ONE, true);

    BlockFork fork = new BlockFork();

    fork.calculate(genesis, block, store);

    Assert.assertSame(genesis, fork.getCommonAncestor());
    Assert.assertTrue(fork.getOldBlocks().isEmpty());
    Assert.assertFalse(fork.getNewBlocks().isEmpty());
    Assert.assertEquals(1, fork.getNewBlocks().size());
    Assert.assertSame(block, fork.getNewBlocks().get(0));
}
 
開發者ID:rsksmart,項目名稱:rskj,代碼行數:20,代碼來源:BlockForkTest.java

示例4: getFamilyGetParent

import org.ethereum.db.BlockStore; //導入方法依賴的package包/類
@Test
public void getFamilyGetParent() {
    BlockStore store = createBlockStore();

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

    store.saveBlock(genesis, BigInteger.ONE, true);
    store.saveBlock(block1, BigInteger.ONE, true);

    Set<ByteArrayWrapper> family = FamilyUtils.getFamily(store, block1, 6);

    Assert.assertNotNull(family);
    Assert.assertFalse(family.isEmpty());
    Assert.assertEquals(1, family.size());

    Assert.assertTrue(family.contains(new ByteArrayWrapper(genesis.getHash())));
}
 
開發者ID:rsksmart,項目名稱:rskj,代碼行數:19,代碼來源:FamilyUtilsTest.java

示例5: getFamilyGetAncestorsUpToLevel

import org.ethereum.db.BlockStore; //導入方法依賴的package包/類
@Test
public void getFamilyGetAncestorsUpToLevel() {
    BlockStore store = createBlockStore();

    Block genesis = BlockGenerator.getInstance().getGenesisBlock();
    Block block1 = BlockGenerator.getInstance().createChildBlock(genesis);
    Block block2 = BlockGenerator.getInstance().createChildBlock(block1);
    Block block3 = BlockGenerator.getInstance().createChildBlock(block2);

    store.saveBlock(genesis, BigInteger.ONE, true);
    store.saveBlock(block1, BigInteger.ONE, true);
    store.saveBlock(block2, BigInteger.ONE, true);
    store.saveBlock(block3, BigInteger.ONE, true);

    Set<ByteArrayWrapper> family = FamilyUtils.getFamily(store, block3, 2);

    Assert.assertNotNull(family);
    Assert.assertFalse(family.isEmpty());
    Assert.assertEquals(2, family.size());

    Assert.assertFalse(family.contains(new ByteArrayWrapper(genesis.getHash())));
    Assert.assertFalse(family.contains(new ByteArrayWrapper(block3.getHash())));
    Assert.assertTrue(family.contains(new ByteArrayWrapper(block1.getHash())));
    Assert.assertTrue(family.contains(new ByteArrayWrapper(block2.getHash())));
}
 
開發者ID:rsksmart,項目名稱:rskj,代碼行數:26,代碼來源:FamilyUtilsTest.java

示例6: calculateForkLengthTwo

import org.ethereum.db.BlockStore; //導入方法依賴的package包/類
@Test
public void calculateForkLengthTwo() {
    BlockStore store = createBlockStore();
    Block genesis = BlockGenerator.getInstance().getGenesisBlock();
    Block parent = BlockGenerator.getInstance().createChildBlock(genesis);

    store.saveBlock(genesis, BigInteger.ONE, true);
    store.saveBlock(parent, BigInteger.ONE, true);

    List<Block> oldBranch = makeChain(parent, 2, store);
    List<Block> newBranch = makeChain(parent, 2, store);

    BlockFork fork = new BlockFork();

    fork.calculate(oldBranch.get(1), newBranch.get(1) , store);

    Assert.assertArrayEquals(parent.getHash(), fork.getCommonAncestor().getHash());

    Assert.assertFalse(fork.getOldBlocks().isEmpty());
    Assert.assertEquals(2, fork.getOldBlocks().size());
    Assert.assertArrayEquals(oldBranch.get(0).getHash(), fork.getOldBlocks().get(0).getHash());
    Assert.assertArrayEquals(oldBranch.get(1).getHash(), fork.getOldBlocks().get(1).getHash());

    Assert.assertFalse(fork.getNewBlocks().isEmpty());
    Assert.assertEquals(2, fork.getNewBlocks().size());
    Assert.assertArrayEquals(newBranch.get(0).getHash(), fork.getNewBlocks().get(0).getHash());
    Assert.assertArrayEquals(newBranch.get(1).getHash(), fork.getNewBlocks().get(1).getHash());
}
 
開發者ID:rsksmart,項目名稱:rskj,代碼行數:29,代碼來源:BlockForkTest.java

示例7: calculateForkLengthTwoOldThreeNew

import org.ethereum.db.BlockStore; //導入方法依賴的package包/類
@Test
public void calculateForkLengthTwoOldThreeNew() {
    BlockStore store = createBlockStore();
    Block genesis = BlockGenerator.getInstance().getGenesisBlock();
    Block parent = BlockGenerator.getInstance().createChildBlock(genesis);

    store.saveBlock(genesis, BigInteger.ONE, true);
    store.saveBlock(parent, BigInteger.ONE, true);

    List<Block> oldBranch = makeChain(parent, 2, store);
    List<Block> newBranch = makeChain(parent, 3, store);

    BlockFork fork = new BlockFork();

    fork.calculate(oldBranch.get(1), newBranch.get(2) , store);

    Assert.assertArrayEquals(parent.getHash(), fork.getCommonAncestor().getHash());

    Assert.assertFalse(fork.getOldBlocks().isEmpty());
    Assert.assertEquals(2, fork.getOldBlocks().size());
    Assert.assertArrayEquals(oldBranch.get(0).getHash(), fork.getOldBlocks().get(0).getHash());
    Assert.assertArrayEquals(oldBranch.get(1).getHash(), fork.getOldBlocks().get(1).getHash());

    Assert.assertFalse(fork.getNewBlocks().isEmpty());
    Assert.assertEquals(3, fork.getNewBlocks().size());
    Assert.assertArrayEquals(newBranch.get(0).getHash(), fork.getNewBlocks().get(0).getHash());
    Assert.assertArrayEquals(newBranch.get(1).getHash(), fork.getNewBlocks().get(1).getHash());
    Assert.assertArrayEquals(newBranch.get(2).getHash(), fork.getNewBlocks().get(2).getHash());
}
 
開發者ID:rsksmart,項目名稱:rskj,代碼行數:30,代碼來源:BlockForkTest.java

示例8: calculateForkLengthThreeOldTwoNew

import org.ethereum.db.BlockStore; //導入方法依賴的package包/類
@Test
public void calculateForkLengthThreeOldTwoNew() {
    BlockStore store = createBlockStore();
    Block genesis = BlockGenerator.getInstance().getGenesisBlock();
    Block parent = BlockGenerator.getInstance().createChildBlock(genesis);

    store.saveBlock(genesis, BigInteger.ONE, true);
    store.saveBlock(parent, BigInteger.ONE, true);

    List<Block> oldBranch = makeChain(parent, 3, store);
    List<Block> newBranch = makeChain(parent, 2, store);

    BlockFork fork = new BlockFork();

    fork.calculate(oldBranch.get(2), newBranch.get(1) , store);

    Assert.assertArrayEquals(parent.getHash(), fork.getCommonAncestor().getHash());

    Assert.assertFalse(fork.getOldBlocks().isEmpty());
    Assert.assertEquals(3, fork.getOldBlocks().size());
    Assert.assertArrayEquals(oldBranch.get(0).getHash(), fork.getOldBlocks().get(0).getHash());
    Assert.assertArrayEquals(oldBranch.get(1).getHash(), fork.getOldBlocks().get(1).getHash());
    Assert.assertArrayEquals(oldBranch.get(2).getHash(), fork.getOldBlocks().get(2).getHash());

    Assert.assertFalse(fork.getNewBlocks().isEmpty());
    Assert.assertEquals(2, fork.getNewBlocks().size());
    Assert.assertArrayEquals(newBranch.get(0).getHash(), fork.getNewBlocks().get(0).getHash());
    Assert.assertArrayEquals(newBranch.get(1).getHash(), fork.getNewBlocks().get(1).getHash());
}
 
開發者ID:rsksmart,項目名稱:rskj,代碼行數:30,代碼來源:BlockForkTest.java

示例9: makeChain

import org.ethereum.db.BlockStore; //導入方法依賴的package包/類
private static List<Block> makeChain(Block parent, int length, BlockStore store) {
    List<Block> blocks = new ArrayList<>();

    for (int k = 0; k < length; k++) {
        Block block = BlockGenerator.getInstance().createChildBlock(parent);
        blocks.add(block);
        store.saveBlock(block, BigInteger.ONE, false);
        parent = block;
    }

    return blocks;
}
 
開發者ID:rsksmart,項目名稱:rskj,代碼行數:13,代碼來源:BlockForkTest.java

示例10: getFamilyGetAncestorsWithUncles

import org.ethereum.db.BlockStore; //導入方法依賴的package包/類
@Test
public void getFamilyGetAncestorsWithUncles() {
    BlockStore store = createBlockStore();

    Block genesis = BlockGenerator.getInstance().getGenesisBlock();
    Block block1 = BlockGenerator.getInstance().createChildBlock(genesis);
    Block uncle11 = BlockGenerator.getInstance().createChildBlock(genesis);
    Block uncle12 = BlockGenerator.getInstance().createChildBlock(genesis);
    Block block2 = BlockGenerator.getInstance().createChildBlock(block1);
    Block uncle21 = BlockGenerator.getInstance().createChildBlock(block1);
    Block uncle22 = BlockGenerator.getInstance().createChildBlock(block1);
    Block block3 = BlockGenerator.getInstance().createChildBlock(block2);
    Block uncle31 = BlockGenerator.getInstance().createChildBlock(block2);
    Block uncle32 = BlockGenerator.getInstance().createChildBlock(block2);

    store.saveBlock(genesis, BigInteger.ONE, true);
    store.saveBlock(block1, BigInteger.ONE, true);
    store.saveBlock(uncle11, BigInteger.ONE, false);
    store.saveBlock(uncle12, BigInteger.ONE, false);
    store.saveBlock(block2, BigInteger.ONE, true);
    store.saveBlock(uncle21, BigInteger.ONE, false);
    store.saveBlock(uncle22, BigInteger.ONE, false);
    store.saveBlock(block3, BigInteger.ONE, true);
    store.saveBlock(uncle31, BigInteger.ONE, false);
    store.saveBlock(uncle32, BigInteger.ONE, false);

    Set<ByteArrayWrapper> family = FamilyUtils.getFamily(store, block3, 2);

    Assert.assertNotNull(family);
    Assert.assertFalse(family.isEmpty());
    Assert.assertEquals(4, family.size());

    Assert.assertFalse(family.contains(new ByteArrayWrapper(genesis.getHash())));
    Assert.assertTrue(family.contains(new ByteArrayWrapper(block1.getHash())));
    Assert.assertFalse(family.contains(new ByteArrayWrapper(uncle11.getHash())));
    Assert.assertFalse(family.contains(new ByteArrayWrapper(uncle12.getHash())));
    Assert.assertTrue(family.contains(new ByteArrayWrapper(block2.getHash())));
    Assert.assertTrue(family.contains(new ByteArrayWrapper(uncle21.getHash())));
    Assert.assertTrue(family.contains(new ByteArrayWrapper(uncle22.getHash())));
    Assert.assertFalse(family.contains(new ByteArrayWrapper(block3.getHash())));
    Assert.assertFalse(family.contains(new ByteArrayWrapper(uncle31.getHash())));
    Assert.assertFalse(family.contains(new ByteArrayWrapper(uncle32.getHash())));

    family = FamilyUtils.getFamily(store, block3, 3);

    Assert.assertNotNull(family);
    Assert.assertFalse(family.isEmpty());
    Assert.assertEquals(7, family.size());

    Assert.assertTrue(family.contains(new ByteArrayWrapper(genesis.getHash())));
    Assert.assertTrue(family.contains(new ByteArrayWrapper(block1.getHash())));
    Assert.assertTrue(family.contains(new ByteArrayWrapper(uncle11.getHash())));
    Assert.assertTrue(family.contains(new ByteArrayWrapper(uncle12.getHash())));
    Assert.assertTrue(family.contains(new ByteArrayWrapper(block2.getHash())));
    Assert.assertTrue(family.contains(new ByteArrayWrapper(uncle21.getHash())));
    Assert.assertTrue(family.contains(new ByteArrayWrapper(uncle22.getHash())));
    Assert.assertFalse(family.contains(new ByteArrayWrapper(block3.getHash())));
    Assert.assertFalse(family.contains(new ByteArrayWrapper(uncle31.getHash())));
    Assert.assertFalse(family.contains(new ByteArrayWrapper(uncle32.getHash())));
}
 
開發者ID:rsksmart,項目名稱:rskj,代碼行數:61,代碼來源:FamilyUtilsTest.java

示例11: getUnclesHeaders

import org.ethereum.db.BlockStore; //導入方法依賴的package包/類
@Test
public void getUnclesHeaders() {
    BlockStore store = createBlockStore();

    Block genesis = BlockGenerator.getInstance().getGenesisBlock();
    Block block1 = BlockGenerator.getInstance().createChildBlock(genesis);
    Block uncle11 = BlockGenerator.getInstance().createChildBlock(genesis);
    Block uncle111 = BlockGenerator.getInstance().createChildBlock(uncle11);
    Block uncle12 = BlockGenerator.getInstance().createChildBlock(genesis);
    Block uncle121 = BlockGenerator.getInstance().createChildBlock(uncle12);
    Block block2 = BlockGenerator.getInstance().createChildBlock(block1);
    Block uncle21 = BlockGenerator.getInstance().createChildBlock(block1);
    Block uncle22 = BlockGenerator.getInstance().createChildBlock(block1);
    Block block3 = BlockGenerator.getInstance().createChildBlock(block2);
    Block uncle31 = BlockGenerator.getInstance().createChildBlock(block2);
    Block uncle32 = BlockGenerator.getInstance().createChildBlock(block2);

    store.saveBlock(genesis, BigInteger.ONE, true);
    store.saveBlock(block1, BigInteger.ONE, true);
    store.saveBlock(uncle11, BigInteger.ONE, false);
    store.saveBlock(uncle12, BigInteger.ONE, false);
    store.saveBlock(uncle111, BigInteger.ONE, false);
    store.saveBlock(uncle121, BigInteger.ONE, false);
    store.saveBlock(block2, BigInteger.ONE, true);
    store.saveBlock(uncle21, BigInteger.ONE, false);
    store.saveBlock(uncle22, BigInteger.ONE, false);
    store.saveBlock(block3, BigInteger.ONE, true);
    store.saveBlock(uncle31, BigInteger.ONE, false);
    store.saveBlock(uncle32, BigInteger.ONE, false);

    List<BlockHeader> list = FamilyUtils.getUnclesHeaders(store, block3, 3);

    Assert.assertNotNull(list);
    Assert.assertFalse(list.isEmpty());
    Assert.assertEquals(4, list.size());

    Assert.assertTrue(containsHash(uncle11.getHash(), list));
    Assert.assertTrue(containsHash(uncle12.getHash(), list));
    Assert.assertTrue(containsHash(uncle21.getHash(), list));
    Assert.assertTrue(containsHash(uncle22.getHash(), list));
}
 
開發者ID:rsksmart,項目名稱:rskj,代碼行數:42,代碼來源:FamilyUtilsTest.java

示例12: getUncles

import org.ethereum.db.BlockStore; //導入方法依賴的package包/類
@Test
public void getUncles() {
    BlockStore store = createBlockStore();

    Block genesis = BlockGenerator.getInstance().getGenesisBlock();
    Block block1 = BlockGenerator.getInstance().createChildBlock(genesis);
    Block uncle11 = BlockGenerator.getInstance().createChildBlock(genesis);
    Block uncle12 = BlockGenerator.getInstance().createChildBlock(genesis);
    Block block2 = BlockGenerator.getInstance().createChildBlock(block1);
    Block uncle21 = BlockGenerator.getInstance().createChildBlock(block1);
    Block uncle22 = BlockGenerator.getInstance().createChildBlock(block1);
    Block block3 = BlockGenerator.getInstance().createChildBlock(block2);
    Block uncle31 = BlockGenerator.getInstance().createChildBlock(block2);
    Block uncle32 = BlockGenerator.getInstance().createChildBlock(block2);

    store.saveBlock(genesis, BigInteger.ONE, true);
    store.saveBlock(block1, BigInteger.ONE, true);
    store.saveBlock(uncle11, BigInteger.ONE, false);
    store.saveBlock(uncle12, BigInteger.ONE, false);
    store.saveBlock(block2, BigInteger.ONE, true);
    store.saveBlock(uncle21, BigInteger.ONE, false);
    store.saveBlock(uncle22, BigInteger.ONE, false);
    store.saveBlock(block3, BigInteger.ONE, true);
    store.saveBlock(uncle31, BigInteger.ONE, false);
    store.saveBlock(uncle32, BigInteger.ONE, false);

    Set<ByteArrayWrapper> family = FamilyUtils.getUncles(store, block3, 3);

    Assert.assertNotNull(family);
    Assert.assertFalse(family.isEmpty());
    Assert.assertEquals(4, family.size());

    Assert.assertFalse(family.contains(new ByteArrayWrapper(genesis.getHash())));
    Assert.assertFalse(family.contains(new ByteArrayWrapper(block1.getHash())));
    Assert.assertTrue(family.contains(new ByteArrayWrapper(uncle11.getHash())));
    Assert.assertTrue(family.contains(new ByteArrayWrapper(uncle12.getHash())));
    Assert.assertFalse(family.contains(new ByteArrayWrapper(block2.getHash())));
    Assert.assertTrue(family.contains(new ByteArrayWrapper(uncle21.getHash())));
    Assert.assertTrue(family.contains(new ByteArrayWrapper(uncle22.getHash())));
    Assert.assertFalse(family.contains(new ByteArrayWrapper(block3.getHash())));
    Assert.assertFalse(family.contains(new ByteArrayWrapper(uncle31.getHash())));
    Assert.assertFalse(family.contains(new ByteArrayWrapper(uncle32.getHash())));
}
 
開發者ID:rsksmart,項目名稱:rskj,代碼行數:44,代碼來源:FamilyUtilsTest.java

示例13: getEmptyFamilyForGenesis

import org.ethereum.db.BlockStore; //導入方法依賴的package包/類
@Test
public void getEmptyFamilyForGenesis() {
    BlockStore store = createBlockStore();

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

    store.saveBlock(genesis, BigInteger.ONE, true);

    Set<ByteArrayWrapper> family = FamilyUtils.getFamily(store, genesis, 6);

    Assert.assertNotNull(family);
    Assert.assertTrue(family.isEmpty());
}
 
開發者ID:rsksmart,項目名稱:rskj,代碼行數:14,代碼來源:FamilyUtilsTest.java


注:本文中的org.ethereum.db.BlockStore.saveBlock方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。