mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-02-23 14:40:40 +01:00
SPVBlockStore: make method initNewStore()
take genesisBlock
This makes the method independent of `NetworkParameters`.
This commit is contained in:
parent
f62259b780
commit
8fe1d84a59
1 changed files with 4 additions and 5 deletions
|
@ -159,7 +159,7 @@ public class SPVBlockStore implements BlockStore {
|
||||||
if (!new String(header, StandardCharsets.US_ASCII).equals(HEADER_MAGIC))
|
if (!new String(header, StandardCharsets.US_ASCII).equals(HEADER_MAGIC))
|
||||||
throw new BlockStoreException("Header bytes do not equal " + HEADER_MAGIC);
|
throw new BlockStoreException("Header bytes do not equal " + HEADER_MAGIC);
|
||||||
} else {
|
} else {
|
||||||
initNewStore(params);
|
initNewStore(params.getGenesisBlock());
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
try {
|
try {
|
||||||
|
@ -171,7 +171,7 @@ public class SPVBlockStore implements BlockStore {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initNewStore(NetworkParameters params) throws Exception {
|
private void initNewStore(Block genesisBlock) throws Exception {
|
||||||
byte[] header;
|
byte[] header;
|
||||||
header = HEADER_MAGIC.getBytes(StandardCharsets.US_ASCII);
|
header = HEADER_MAGIC.getBytes(StandardCharsets.US_ASCII);
|
||||||
buffer.put(header);
|
buffer.put(header);
|
||||||
|
@ -182,8 +182,7 @@ public class SPVBlockStore implements BlockStore {
|
||||||
} finally {
|
} finally {
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
Block genesis = params.getGenesisBlock().cloneAsHeader();
|
StoredBlock storedGenesis = new StoredBlock(genesisBlock.cloneAsHeader(), genesisBlock.getWork(), 0);
|
||||||
StoredBlock storedGenesis = new StoredBlock(genesis, genesis.getWork(), 0);
|
|
||||||
put(storedGenesis);
|
put(storedGenesis);
|
||||||
setChainHead(storedGenesis);
|
setChainHead(storedGenesis);
|
||||||
}
|
}
|
||||||
|
@ -350,7 +349,7 @@ public class SPVBlockStore implements BlockStore {
|
||||||
}
|
}
|
||||||
// Initialize store again
|
// Initialize store again
|
||||||
((Buffer) buffer).position(0);
|
((Buffer) buffer).position(0);
|
||||||
initNewStore(params);
|
initNewStore(params.getGenesisBlock());
|
||||||
} finally { lock.unlock(); }
|
} finally { lock.unlock(); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue