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


Java BlockStore.getBlockByHash方法代碼示例

本文整理匯總了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;
}
 
開發者ID:rsksmart,項目名稱:rskj,代碼行數:18,代碼來源:FamilyUtils.java

示例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;
}
 
開發者ID:rsksmart,項目名稱:rskj,代碼行數:20,代碼來源:FamilyUtils.java

示例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;
}
 
開發者ID:rsksmart,項目名稱:rskj,代碼行數:30,代碼來源:BlockFork.java

示例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;
}
 
開發者ID:rsksmart,項目名稱:rskj,代碼行數:15,代碼來源:FamilyUtils.java

示例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;
}
 
開發者ID:rsksmart,項目名稱:rskj,代碼行數:43,代碼來源:FamilyUtils.java


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