mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2024-11-19 09:50:32 +01:00
StoredBlock: make deserializeCompact()
use serializer
...not `params`.
This commit is contained in:
parent
98d4df5fe5
commit
820b671dbc
@ -145,7 +145,7 @@ public class CheckpointManager {
|
||||
for (int i = 0; i < numCheckpoints; i++) {
|
||||
if (dis.read(buffer.array(), 0, size) < size)
|
||||
throw new IOException("Incomplete read whilst loading checkpoints.");
|
||||
StoredBlock block = StoredBlock.deserializeCompact(params, buffer);
|
||||
StoredBlock block = StoredBlock.deserializeCompact(params.getDefaultSerializer(), buffer);
|
||||
((Buffer) buffer).position(0);
|
||||
checkpoints.put(block.getHeader().time(), block);
|
||||
}
|
||||
@ -183,7 +183,7 @@ public class CheckpointManager {
|
||||
((Buffer) buffer).position(0);
|
||||
buffer.put(bytes);
|
||||
((Buffer) buffer).position(0);
|
||||
StoredBlock block = StoredBlock.deserializeCompact(params, buffer);
|
||||
StoredBlock block = StoredBlock.deserializeCompact(params.getDefaultSerializer(), buffer);
|
||||
checkpoints.put(block.getHeader().time(), block);
|
||||
}
|
||||
HashCode hash = hasher.hash();
|
||||
|
@ -141,14 +141,14 @@ public class StoredBlock {
|
||||
}
|
||||
|
||||
/** De-serializes the stored block from a custom packed format. Used by {@link CheckpointManager}. */
|
||||
public static StoredBlock deserializeCompact(NetworkParameters params, ByteBuffer buffer) throws ProtocolException {
|
||||
public static StoredBlock deserializeCompact(MessageSerializer serializer, ByteBuffer buffer) throws ProtocolException {
|
||||
byte[] chainWorkBytes = new byte[StoredBlock.CHAIN_WORK_BYTES];
|
||||
buffer.get(chainWorkBytes);
|
||||
BigInteger chainWork = ByteUtils.bytesToBigInteger(chainWorkBytes);
|
||||
int height = buffer.getInt(); // +4 bytes
|
||||
byte[] header = new byte[Block.HEADER_SIZE + 1]; // Extra byte for the 00 transactions length.
|
||||
buffer.get(header, 0, Block.HEADER_SIZE);
|
||||
return new StoredBlock(params.getDefaultSerializer().makeBlock(ByteBuffer.wrap(header)), chainWork, height);
|
||||
return new StoredBlock(serializer.makeBlock(ByteBuffer.wrap(header)), chainWork, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -246,7 +246,7 @@ public class SPVBlockStore implements BlockStore {
|
||||
buffer.get(scratch);
|
||||
if (Arrays.equals(scratch, targetHashBytes)) {
|
||||
// Found the target.
|
||||
StoredBlock storedBlock = StoredBlock.deserializeCompact(params, buffer);
|
||||
StoredBlock storedBlock = StoredBlock.deserializeCompact(params.getDefaultSerializer(), buffer);
|
||||
blockCache.put(hash, storedBlock);
|
||||
return storedBlock;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user