本文整理汇总了Java中org.ethereum.db.BlockStore.getBlockByHash方法的典型用法代码示例。如果您正苦于以下问题:Java BlockStore.getBlockByHash方法的具体用法?Java BlockStore.getBlockByHash怎么用?Java BlockStore.getBlockByHash使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.ethereum.db.BlockStore
的用法示例。
在下文中一共展示了BlockStore.getBlockByHash方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAncestors
import org.ethereum.db.BlockStore; //导入方法依赖的package包/类
public static Set<ByteArrayWrapper> getAncestors(BlockStore blockStore, long blockNumber, byte[] parentHash, int limitNum) {
Set<ByteArrayWrapper> ret = new HashSet<>();
if (blockStore == null) {
return ret;
}
int limit = (int) max(0, blockNumber - limitNum);
Block it = blockStore.getBlockByHash(parentHash);
while(it != null && it.getNumber() >= limit) {
ret.add(new ByteArrayWrapper(it.getHash()));
it = blockStore.getBlockByHash(it.getParentHash());
}
return ret;
}
示例2: getUsedUncles
import org.ethereum.db.BlockStore; //导入方法依赖的package包/类
public static Set<ByteArrayWrapper> getUsedUncles(BlockStore blockStore, long blockNumber, byte[] parentHash, int limitNum) {
Set<ByteArrayWrapper> ret = new HashSet<>();
if (blockStore == null) {
return ret;
}
long minNumber = max(0, blockNumber - limitNum);
Block it = blockStore.getBlockByHash(parentHash);
while(it != null && it.getNumber() >= minNumber) {
for (BlockHeader uncle : it.getUncleList()) {
ret.add(new ByteArrayWrapper(uncle.getHash()));
}
it = blockStore.getBlockByHash(it.getParentHash());
}
return ret;
}
示例3: calculate
import org.ethereum.db.BlockStore; //导入方法依赖的package包/类
public void calculate(Block fromBlock, Block toBlock, BlockStore store) {
Block oldBlock = fromBlock;
Block newBlock = toBlock;
if (oldBlock.isParentOf(newBlock)) {
commonAncestor = oldBlock;
newBlocks.add(newBlock);
return;
}
while (newBlock.getNumber() > oldBlock.getNumber()) {
newBlocks.add(0, newBlock);
newBlock = store.getBlockByHash(newBlock.getParentHash());
}
while (oldBlock.getNumber() > newBlock.getNumber()) {
oldBlocks.add(0, oldBlock);
oldBlock = store.getBlockByHash(oldBlock.getParentHash());
}
while (!Arrays.equals(oldBlock.getHash(), newBlock.getHash())) {
newBlocks.add(0, newBlock);
newBlock = store.getBlockByHash(newBlock.getParentHash());
oldBlocks.add(0, oldBlock);
oldBlock = store.getBlockByHash(oldBlock.getParentHash());
}
commonAncestor = oldBlock;
}
示例4: getUnclesHeaders
import org.ethereum.db.BlockStore; //导入方法依赖的package包/类
public static List<BlockHeader> getUnclesHeaders(@Nonnull BlockStore store, long blockNumber, byte[] parentHash, int levels) {
List<BlockHeader> uncles = new ArrayList<>();
Set<ByteArrayWrapper> unclesHeaders = getUncles(store, blockNumber, parentHash, levels);
for (ByteArrayWrapper uncleHash : unclesHeaders) {
Block uncle = store.getBlockByHash(uncleHash.getData());
if (uncle != null) {
uncles.add(uncle.getHeader());
}
}
return uncles;
}
示例5: getFamily
import org.ethereum.db.BlockStore; //导入方法依赖的package包/类
public static Set<ByteArrayWrapper> getFamily(BlockStore store, long blockNumber, byte[] parentHash, int levels) {
long minNumber = max(0, blockNumber - levels);
Set<ByteArrayWrapper> family = new HashSet<>();
List<Block> ancestors = new ArrayList<>();
Block parent = store.getBlockByHash(parentHash);
while (parent != null && parent.getNumber() >= minNumber) {
ancestors.add(0, parent);
parent = store.getBlockByHash(parent.getParentHash());
}
for (Block b : ancestors) {
family.add(new ByteArrayWrapper(b.getHash()));
}
for (int k = 1; k < ancestors.size(); k++) {
Block ancestorParent = ancestors.get(k - 1);
Block ancestor = ancestors.get(k);
List<Block> uncles = store.getChainBlocksByNumber(ancestor.getNumber());
for (Block uncle : uncles) {
// TODO quick fix, the block storage should be reviewed
if (uncle == null) {
continue;
}
if (!Arrays.equals(ancestorParent.getHash(), uncle.getParentHash())) {
continue;
}
if (Arrays.equals(ancestor.getHash(), uncle.getHash())) {
continue;
}
family.add(new ByteArrayWrapper(uncle.getHash()));
}
}
return family;
}