Java Code Examples for org.bitcoinj.core.StoredBlock#deserializeCompact()

The following examples show how to use org.bitcoinj.core.StoredBlock#deserializeCompact() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LevelDBFullPrunedBlockStore.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
public StoredBlock get(Sha256Hash hash, boolean wasUndoableOnly) throws BlockStoreException {

        // Optimize for chain head
        if (chainHeadHash != null && chainHeadHash.equals(hash))
            return chainHeadBlock;
        if (verifiedChainHeadHash != null && verifiedChainHeadHash.equals(hash))
            return verifiedChainHeadBlock;

        if (instrument)
            beginMethod("get");// ignore optimised case as not interesting for
        // tuning.
        boolean undoableResult;

        byte[] result = batchGet(getKey(KeyType.HEADERS_ALL, hash));
        if (result == null) {
            if (instrument)
                endMethod("get");
            return null;
        }
        undoableResult = (result[96] == 1 ? true : false);
        if (wasUndoableOnly && !undoableResult) {
            if (instrument)
                endMethod("get");
            return null;
        }
        // TODO Should I chop the last byte off? Seems to work with it left
        // there...
        StoredBlock stored = StoredBlock.deserializeCompact(params, ByteBuffer.wrap(result));
        stored.getHeader().verifyHeader();

        if (instrument)
            endMethod("get");
        return stored;
    }
 
Example 2
Source File: LevelDBFullPrunedBlockStore.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
public StoredBlock get(Sha256Hash hash, boolean wasUndoableOnly) throws BlockStoreException {

        // Optimize for chain head
        if (chainHeadHash != null && chainHeadHash.equals(hash))
            return chainHeadBlock;
        if (verifiedChainHeadHash != null && verifiedChainHeadHash.equals(hash))
            return verifiedChainHeadBlock;

        if (instrument)
            beginMethod("get");// ignore optimised case as not interesting for
                               // tuning.
        boolean undoableResult;

        byte[] result = batchGet(getKey(KeyType.HEADERS_ALL, hash));
        if (result == null) {
            if (instrument)
                endMethod("get");
            return null;
        }
        undoableResult = (result[96] == 1 ? true : false);
        if (wasUndoableOnly && !undoableResult) {
            if (instrument)
                endMethod("get");
            return null;
        }
        // TODO Should I chop the last byte off? Seems to work with it left
        // there...
        StoredBlock stored = StoredBlock.deserializeCompact(params, ByteBuffer.wrap(result));
        stored.getHeader().verifyHeader();

        if (instrument)
            endMethod("get");
        return stored;
    }
 
Example 3
Source File: LevelDBFullPrunedBlockStore.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
public StoredBlock get(Sha256Hash hash, boolean wasUndoableOnly) throws BlockStoreException {

        // Optimize for chain head
        if (chainHeadHash != null && chainHeadHash.equals(hash))
            return chainHeadBlock;
        if (verifiedChainHeadHash != null && verifiedChainHeadHash.equals(hash))
            return verifiedChainHeadBlock;

        if (instrument)
            beginMethod("get");// ignore optimised case as not interesting for
                               // tuning.
        boolean undoableResult;

        byte[] result = batchGet(getKey(KeyType.HEADERS_ALL, hash));
        if (result == null) {
            if (instrument)
                endMethod("get");
            return null;
        }
        undoableResult = (result[96] == 1 ? true : false);
        if (wasUndoableOnly && !undoableResult) {
            if (instrument)
                endMethod("get");
            return null;
        }
        // TODO Should I chop the last byte off? Seems to work with it left
        // there...
        StoredBlock stored = StoredBlock.deserializeCompact(params, ByteBuffer.wrap(result));
        stored.getHeader().verifyHeader();

        if (instrument)
            endMethod("get");
        return stored;
    }