mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-03-10 17:26:28 +01:00
DeterministicKeyChain, DeterministicHierarchy: add putKeys(), and use it
This commit is contained in:
parent
8bcfec0ed2
commit
1f0c1a3bb7
2 changed files with 15 additions and 4 deletions
|
@ -69,6 +69,14 @@ public class DeterministicHierarchy {
|
||||||
keys.put(path, key);
|
keys.put(path, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inserts a list of keys into the hierarchy
|
||||||
|
* @param keys A list of keys to put in the hierarchy
|
||||||
|
*/
|
||||||
|
public final void putKeys(List<DeterministicKey> keys) {
|
||||||
|
keys.forEach(this::putKey);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a key for the given path, optionally creating it.
|
* Returns a key for the given path, optionally creating it.
|
||||||
*
|
*
|
||||||
|
|
|
@ -505,8 +505,7 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
|
||||||
// It's safe to do this because when a network thread tries to calculate a Bloom filter, we'll go ahead
|
// It's safe to do this because when a network thread tries to calculate a Bloom filter, we'll go ahead
|
||||||
// and calculate the full lookahead zone there, so network requests will always use the right amount.
|
// and calculate the full lookahead zone there, so network requests will always use the right amount.
|
||||||
List<DeterministicKey> lookahead = maybeLookAhead(parentKey, index, 0, 0);
|
List<DeterministicKey> lookahead = maybeLookAhead(parentKey, index, 0, 0);
|
||||||
basicKeyChain.importKeys(lookahead);
|
putKeys(lookahead);
|
||||||
lookahead.forEach(hierarchy::putKey);
|
|
||||||
List<DeterministicKey> keys = new ArrayList<>(numberOfKeys);
|
List<DeterministicKey> keys = new ArrayList<>(numberOfKeys);
|
||||||
for (int i = 0; i < numberOfKeys; i++) {
|
for (int i = 0; i < numberOfKeys; i++) {
|
||||||
HDPath path = parentKey.getPath().extend(new ChildNumber(index - numberOfKeys + i, false));
|
HDPath path = parentKey.getPath().extend(new ChildNumber(index - numberOfKeys + i, false));
|
||||||
|
@ -530,6 +529,11 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
|
||||||
basicKeyChain.importKey(key);
|
basicKeyChain.importKey(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void putKeys(List<DeterministicKey> keys) {
|
||||||
|
hierarchy.putKeys(keys);
|
||||||
|
basicKeyChain.importKeys(keys);
|
||||||
|
}
|
||||||
|
|
||||||
private void checkForBitFlip(DeterministicKey k) {
|
private void checkForBitFlip(DeterministicKey k) {
|
||||||
DeterministicKey parent = checkNotNull(k.getParent());
|
DeterministicKey parent = checkNotNull(k.getParent());
|
||||||
byte[] rederived = HDKeyDerivation.deriveChildKeyBytesFromPublic(parent, k.getChildNumber(), HDKeyDerivation.PublicDeriveMode.WITH_INVERSION).keyBytes;
|
byte[] rederived = HDKeyDerivation.deriveChildKeyBytesFromPublic(parent, k.getChildNumber(), HDKeyDerivation.PublicDeriveMode.WITH_INVERSION).keyBytes;
|
||||||
|
@ -1184,8 +1188,7 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
|
||||||
// Batch add all keys at once so there's only one event listener invocation, as this will be listened to
|
// Batch add all keys at once so there's only one event listener invocation, as this will be listened to
|
||||||
// by the wallet and used to rebuild/broadcast the Bloom filter. That's expensive so we don't want to do
|
// by the wallet and used to rebuild/broadcast the Bloom filter. That's expensive so we don't want to do
|
||||||
// it more often than necessary.
|
// it more often than necessary.
|
||||||
basicKeyChain.importKeys(keys);
|
putKeys(keys);
|
||||||
keys.forEach(hierarchy::putKey);
|
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
|
|
Loading…
Add table
Reference in a new issue