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


Java Block.getHeader方法代码示例

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


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

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

示例2: isValid

import org.ethereum.core.Block; //导入方法依赖的package包/类
@Override
public boolean isValid(Block block, Block parent) {
    if(block == null || parent == null) {
        logger.warn("BlockParentGasLimitRule - block or parent are null");
        return false;
    }

    BlockHeader header = block.getHeader();
    BigInteger headerGasLimit = new BigInteger(1, header.getGasLimit());
    BigInteger parentGasLimit = new BigInteger(1, parent.getGasLimit());

    if (headerGasLimit.compareTo(parentGasLimit.multiply(BigInteger.valueOf(gasLimitBoundDivisor - 1L)).divide(BigInteger.valueOf(gasLimitBoundDivisor))) < 0 ||
        headerGasLimit.compareTo(parentGasLimit.multiply(BigInteger.valueOf(gasLimitBoundDivisor + 1L)).divide(BigInteger.valueOf(gasLimitBoundDivisor))) > 0) {
        logger.warn(String.format("#%d: gas limit exceeds parentBlock.getGasLimit() (+-) GAS_LIMIT_BOUND_DIVISOR", header.getNumber()));
        return false;
    }
    return true;
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:19,代码来源:BlockParentGasLimitRule.java

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

示例4: isValid

import org.ethereum.core.Block; //导入方法依赖的package包/类
@Override
public boolean isValid(Block block, Block parent) {
    if(block == null || parent == null) {
        logger.warn("BlockParentNumberRule - block or parent are null");
        return false;
    }
    BlockHeader header = block.getHeader();
    BlockHeader parentHeader = parent.getHeader();
    if (header.getNumber() != (parentHeader.getNumber() + 1)) {
        logger.warn(String.format("#%d: block number is not parentBlock number + 1", header.getNumber()));
        return false;
    }
    return true;
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:15,代码来源:BlockParentNumberRule.java

示例5: isValid

import org.ethereum.core.Block; //导入方法依赖的package包/类
@Override
public boolean isValid(Block block) {
    BlockHeader header = block.getHeader();
    long gasUsed = header.getGasUsed();
    long gasLimit = new BigInteger(1, header.getGasLimit()).longValue();

    if(gasUsed < 0 || gasUsed > gasLimit) {
        logger.warn("Block gas used is less than 0 or more than the gas limit of the block");
        panicProcessor.panic("invalidGasValue", "Block gas used is less than 0 or more than the gas limit of the block");
        return false;
    }

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

示例6: setAndGetSiblings

import org.ethereum.core.Block; //导入方法依赖的package包/类
@Test
public void setAndGetSiblings() {
    RskAddress accountAddress = randomAddress();
    Repository repository = new RepositoryImpl(ConfigHelper.CONFIG);

    RemascStorageProvider provider = new RemascStorageProvider(repository, accountAddress);

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

    Sibling sibling1 = new Sibling(genesis.getHeader(), genesis.getCoinbase(), 1);
    Sibling sibling2 = new Sibling(block.getHeader(), block.getCoinbase(), 2);

    List<Sibling> siblings = new ArrayList<>();
    siblings.add(sibling1);
    siblings.add(sibling2);

    provider.getSiblings().put(Long.valueOf(1), siblings);

    SortedMap<Long, List<Sibling>> map = provider.getSiblings();

    Assert.assertNotNull(map);
    Assert.assertFalse(map.isEmpty());
    Assert.assertTrue(map.containsKey(Long.valueOf(1)));

    Assert.assertEquals(2, map.get(Long.valueOf(1)).size());
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:28,代码来源:RemascStorageProviderTest.java

示例7: setSaveRetrieveAndGetManySiblings

import org.ethereum.core.Block; //导入方法依赖的package包/类
@Test
public void setSaveRetrieveAndGetManySiblings() throws IOException {
    RskAddress accountAddress = randomAddress();
    Repository repository = new RepositoryImplForTesting();

    RemascStorageProvider provider = new RemascStorageProvider(repository, accountAddress);

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

    Sibling sibling1 = new Sibling(genesis.getHeader(), genesis.getCoinbase(), 1);
    Sibling sibling2 = new Sibling(block1.getHeader(), block1.getCoinbase(), 2);
    Sibling sibling3 = new Sibling(block2.getHeader(), block2.getCoinbase(), 3);
    Sibling sibling4 = new Sibling(block3.getHeader(), block3.getCoinbase(), 4);
    Sibling sibling5 = new Sibling(block4.getHeader(), block4.getCoinbase(), 5);
    Sibling sibling6 = new Sibling(block5.getHeader(), block5.getCoinbase(), 6);

    List<Sibling> siblings0 = new ArrayList<>();
    List<Sibling> siblings1 = new ArrayList<>();
    List<Sibling> siblings2 = new ArrayList<>();

    siblings0.add(sibling1);
    siblings0.add(sibling2);

    siblings1.add(sibling3);
    siblings1.add(sibling4);

    siblings2.add(sibling5);
    siblings2.add(sibling6);

    provider.getSiblings().put(Long.valueOf(0), siblings0);
    provider.getSiblings().put(Long.valueOf(1), siblings1);
    provider.getSiblings().put(Long.valueOf(2), siblings2);

    provider.save();

    RemascStorageProvider newProvider = new RemascStorageProvider(repository, accountAddress);

    SortedMap<Long, List<Sibling>> map = newProvider.getSiblings();

    Assert.assertNotNull(map);
    Assert.assertFalse(map.isEmpty());

    Assert.assertTrue(map.containsKey(Long.valueOf(0)));
    Assert.assertTrue(map.containsKey(Long.valueOf(1)));
    Assert.assertTrue(map.containsKey(Long.valueOf(2)));

    Assert.assertEquals(2, map.get(Long.valueOf(0)).size());
    Assert.assertEquals(2, map.get(Long.valueOf(1)).size());
    Assert.assertEquals(2, map.get(Long.valueOf(2)).size());

    List<Sibling> list0 = map.get(Long.valueOf(0));
    List<Sibling> list1 = map.get(Long.valueOf(1));
    List<Sibling> list2 = map.get(Long.valueOf(2));

    Assert.assertEquals(1, list0.get(0).getIncludedHeight());
    Assert.assertArrayEquals(genesis.getHeader().getHash(), list0.get(0).getHash());
    Assert.assertEquals(2, list0.get(1).getIncludedHeight());
    Assert.assertArrayEquals(block1.getHeader().getHash(), list0.get(1).getHash());

    Assert.assertEquals(3, list1.get(0).getIncludedHeight());
    Assert.assertArrayEquals(block2.getHeader().getHash(), list1.get(0).getHash());
    Assert.assertEquals(4, list1.get(1).getIncludedHeight());
    Assert.assertArrayEquals(block3.getHeader().getHash(), list1.get(1).getHash());

    Assert.assertEquals(5, list2.get(0).getIncludedHeight());
    Assert.assertArrayEquals(block4.getHeader().getHash(), list2.get(0).getHash());
    Assert.assertEquals(6, list2.get(1).getIncludedHeight());
    Assert.assertArrayEquals(block5.getHeader().getHash(), list2.get(1).getHash());
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:75,代码来源:RemascStorageProviderTest.java

示例8: siblingSerializeWithGenesis

import org.ethereum.core.Block; //导入方法依赖的package包/类
@Test
public void siblingSerializeWithGenesis() {
    Block genesis = BlockGenerator.getInstance().getGenesisBlock();

    Sibling sibling = new Sibling(genesis.getHeader(), genesis.getCoinbase(), 1);

    byte[] bytes = sibling.getEncoded();

    Assert.assertNotNull(bytes);

    Sibling result = Sibling.create(bytes);

    Assert.assertNotNull(result);

    Assert.assertArrayEquals(sibling.getHash(), result.getHash());
    Assert.assertArrayEquals(sibling.getIncludedBlockCoinbase(), result.getIncludedBlockCoinbase());
    Assert.assertArrayEquals(sibling.getEncoded(), result.getEncoded());

    Assert.assertEquals(sibling.getIncludedHeight(), result.getIncludedHeight());
    Assert.assertEquals(sibling.getPaidFees(), result.getPaidFees());
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:22,代码来源:SiblingTest.java

示例9: siblingSerializeWithBlock

import org.ethereum.core.Block; //导入方法依赖的package包/类
@Test
public void siblingSerializeWithBlock() {
    Block genesis = BlockGenerator.getInstance().getGenesisBlock();
    Block block = BlockGenerator.getInstance().createChildBlock(genesis);

    Sibling sibling = new Sibling(block.getHeader(), block.getCoinbase(), 0);

    byte[] bytes = sibling.getEncoded();

    Assert.assertNotNull(bytes);

    Sibling result = Sibling.create(bytes);

    Assert.assertNotNull(result);

    Assert.assertArrayEquals(sibling.getHash(), result.getHash());
    Assert.assertArrayEquals(sibling.getIncludedBlockCoinbase(), result.getIncludedBlockCoinbase());
    Assert.assertArrayEquals(sibling.getEncoded(), result.getEncoded());

    Assert.assertEquals(sibling.getIncludedHeight(), result.getIncludedHeight());
    Assert.assertEquals(sibling.getPaidFees(), result.getPaidFees());
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:23,代码来源:SiblingTest.java

示例10: serializeAndDeserializeWithSomeValues

import org.ethereum.core.Block; //导入方法依赖的package包/类
@Test
public void serializeAndDeserializeWithSomeValues() {
    Block genesis = BlockGenerator.getInstance().getGenesisBlock();
    Block block1 = BlockGenerator.getInstance().createChildBlock(genesis);
    Block block2 = BlockGenerator.getInstance().createChildBlock(block1);
    Block block3 = BlockGenerator.getInstance().createChildBlock(block2);
    Block block4 = BlockGenerator.getInstance().createChildBlock(block3);
    Block block5 = BlockGenerator.getInstance().createChildBlock(block4);

    Sibling sibling1 = new Sibling(genesis.getHeader(), genesis.getCoinbase(), 1);
    Sibling sibling2 = new Sibling(block1.getHeader(), block1.getCoinbase(), 2);
    Sibling sibling3 = new Sibling(block2.getHeader(), block2.getCoinbase(), 3);
    Sibling sibling4 = new Sibling(block3.getHeader(), block3.getCoinbase(), 4);
    Sibling sibling5 = new Sibling(block4.getHeader(), block4.getCoinbase(), 5);
    Sibling sibling6 = new Sibling(block5.getHeader(), block5.getCoinbase(), 6);

    List<Sibling> siblings0 = new ArrayList<>();
    List<Sibling> siblings1 = new ArrayList<>();
    List<Sibling> siblings2 = new ArrayList<>();

    siblings0.add(sibling1);
    siblings0.add(sibling2);

    siblings1.add(sibling3);
    siblings1.add(sibling4);

    siblings2.add(sibling5);
    siblings2.add(sibling6);

    SortedMap<Long, List<Sibling>> siblings = new TreeMap<>();

    siblings.put(Long.valueOf(0), siblings0);
    siblings.put(Long.valueOf(1), siblings1);
    siblings.put(Long.valueOf(2), siblings2);

    RemascState state = new RemascState(BigInteger.ONE, BigInteger.TEN, siblings, true);

    byte[] bytes = state.getEncoded();

    RemascState result = RemascState.create(bytes);

    Assert.assertNotNull(result);
    Assert.assertEquals(BigInteger.ONE, result.getRewardBalance());
    Assert.assertEquals(BigInteger.TEN, result.getBurnedBalance());
    Assert.assertNotNull(result.getSiblings());
    Assert.assertFalse(result.getSiblings().isEmpty());
    Assert.assertTrue(result.getBrokenSelectionRule());
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:49,代码来源:RemascStateTest.java

示例11: getBlockHeader

import org.ethereum.core.Block; //导入方法依赖的package包/类
@Test
public void getBlockHeader() {
    Block block = new BlockGenerator().getBlock(1);
    BlockHeadersMessage message = new BlockHeadersMessage(block.getHeader());
    Assert.assertSame(block.getHeader(), message.getBlockHeaders().get(0));
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:7,代码来源:BlockHeadersMessageTest.java

示例12: setSaveRetrieveAndGetSiblings

import org.ethereum.core.Block; //导入方法依赖的package包/类
@Test
public void setSaveRetrieveAndGetSiblings() throws IOException {
    RskAddress accountAddress = randomAddress();
    Repository repository = new RepositoryImplForTesting();

    RemascStorageProvider provider = new RemascStorageProvider(repository, accountAddress);

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

    Sibling sibling1 = new Sibling(genesis.getHeader(), genesis.getCoinbase(), 1);
    Sibling sibling2 = new Sibling(block.getHeader(), block.getCoinbase(), 2);

    List<Sibling> siblings = new ArrayList<>();
    siblings.add(sibling1);
    siblings.add(sibling2);

    provider.getSiblings().put(Long.valueOf(1), siblings);

    provider.save();

    RemascStorageProvider newProvider = new RemascStorageProvider(repository, accountAddress);

    SortedMap<Long, List<Sibling>> map = newProvider.getSiblings();

    Assert.assertNotNull(map);
    Assert.assertFalse(map.isEmpty());
    Assert.assertTrue(map.containsKey(Long.valueOf(1)));

    Assert.assertEquals(2, map.get(Long.valueOf(1)).size());
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:32,代码来源:RemascStorageProviderTest.java


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