本文整理汇总了Java中org.ethereum.core.Block.getGasLimit方法的典型用法代码示例。如果您正苦于以下问题:Java Block.getGasLimit方法的具体用法?Java Block.getGasLimit怎么用?Java Block.getGasLimit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.ethereum.core.Block
的用法示例。
在下文中一共展示了Block.getGasLimit方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: testBadBlockEncoding1
import org.ethereum.core.Block; //导入方法依赖的package包/类
@Test(expected = ArithmeticException.class)
public void testBadBlockEncoding1() {
List<Transaction> txs = new ArrayList<>();
Transaction tx = new Transaction(
BigInteger.ZERO.toByteArray(),
BigInteger.ONE.toByteArray(),
BigInteger.valueOf(21000).toByteArray(),
new ECKey().getAddress(),
BigInteger.valueOf(1000).toByteArray(),
null);
txs.add(tx);
byte[] bigBadByteArray = new byte[10000];
Arrays.fill(bigBadByteArray , (byte) -1);
FreeBlock fblock = new FreeBlock(
PegTestUtils.createHash3().getBytes(), // parent hash
EMPTY_LIST_HASH, // uncle hash
PegTestUtils.createHash3().getBytes(), // coinbase
new Bloom().getData(), // logs bloom
BigInteger.ONE.toByteArray(), // difficulty
bigBadByteArray ,
bigBadByteArray , // gasLimit
bigBadByteArray ,// gasUsed
bigBadByteArray , //timestamp
new byte[0], // extraData
new byte[0], // mixHash
new byte[]{0}, // provisory nonce
HashUtil.EMPTY_TRIE_HASH, // receipts root
BlockChainImpl.calcTxTrie(txs), // transaction root
HashUtil.EMPTY_TRIE_HASH, //EMPTY_TRIE_HASH, // state root
txs, // transaction list
null, // uncle list
BigInteger.TEN.toByteArray(),
new byte[0]
);
// Now decode, and re-encode
Block parsedBlock = new Block(fblock.getEncoded());
// must throw java.lang.ArithmeticException
parsedBlock.getGasLimit(); // forced parse
}