/** * <p>Gets a bloom filter that contains all of the public keys from this wallet, and which will provide the given * false-positive rate if it has size elements. Keep in mind that you will get 2 elements in the bloom filter for * each key in the wallet, for the public key and the hash of the public key (address form).</p> * * <p>This is used to generate a BloomFilter which can be {@link BloomFilter#merge(BloomFilter)}d with another. * It could also be used if you have a specific target for the filter's size.</p> * * <p>See the docs for {@link BloomFilter#BloomFilter(int, double, long, org.bitcoinj.core.BloomFilter.BloomUpdate)} for a brief explanation of anonymity when using bloom * filters.</p> */ @Override @GuardedBy("keyChainGroupLock") public BloomFilter getBloomFilter(int size, double falsePositiveRate, long nTweak) { beginBloomFilterCalculation(); try { BloomFilter filter = keyChainGroup.getBloomFilter(size, falsePositiveRate, nTweak); for (Script script : watchedScripts) { for (ScriptChunk chunk : script.getChunks()) { // Only add long (at least 64 bit) data to the bloom filter. // If any long constants become popular in scripts, we will need logic // here to exclude them. if (!chunk.isOpCode() && chunk.data.length >= MINIMUM_BLOOM_DATA_LENGTH) { filter.insert(chunk.data); } } } for (TransactionOutPoint point : bloomOutPoints) filter.insert(point.unsafeBitcoinSerialize()); return filter; } finally { endBloomFilterCalculation(); } }
/** * <p>Gets a bloom filter that contains all of the public keys from this wallet, and which will provide the given * false-positive rate if it has size elements. Keep in mind that you will get 2 elements in the bloom filter for * each key in the wallet, for the public key and the hash of the public key (address form).</p> * * <p>This is used to generate a BloomFilter which can be {@link BloomFilter#merge(BloomFilter)}d with another. * It could also be used if you have a specific target for the filter's size.</p> * * <p>See the docs for {@link BloomFilter(int, double)} for a brief explanation of anonymity when using bloom * filters.</p> */ @Override @GuardedBy("keyChainGroupLock") public BloomFilter getBloomFilter(int size, double falsePositiveRate, long nTweak) { beginBloomFilterCalculation(); try { BloomFilter filter = keyChainGroup.getBloomFilter(size, falsePositiveRate, nTweak); for (Script script : watchedScripts) { for (ScriptChunk chunk : script.getChunks()) { // Only add long (at least 64 bit) data to the bloom filter. // If any long constants become popular in scripts, we will need logic // here to exclude them. if (!chunk.isOpCode() && chunk.data.length >= MINIMUM_BLOOM_DATA_LENGTH) { filter.insert(chunk.data); } } } for (TransactionOutPoint point : bloomOutPoints) filter.insert(point.unsafeBitcoinSerialize()); return filter; } finally { endBloomFilterCalculation(); } }
/** * Gets a bloom filter that contains all of the public keys from this wallet, and which will provide the given * false-positive rate. See the docs for {@link BloomFilter} for a brief explanation of anonymity when using filters. */ public BloomFilter getBloomFilter(double falsePositiveRate) { beginBloomFilterCalculation(); try { return getBloomFilter(getBloomFilterElementCount(), falsePositiveRate, (long) (Math.random() * Long.MAX_VALUE)); } finally { endBloomFilterCalculation(); } }
@Override public BloomFilter getFilter(int size, double falsePositiveRate, long tweak) { lock.lock(); try { checkArgument(size >= numBloomFilterEntries()); maybeLookAhead(); return basicKeyChain.getFilter(size, falsePositiveRate, tweak); } finally { lock.unlock(); } }
@Override public BloomFilter getFilter(int size, double falsePositiveRate, long tweak) { lock.lock(); try { BloomFilter filter = new BloomFilter(size, falsePositiveRate, tweak); for (ECKey key : hashToKeys.values()) filter.insert(key); return filter; } finally { lock.unlock(); } }
@Test public void bloom() throws Exception { ECKey key1 = new ECKey(); ECKey key2 = new ECKey(); chain.importKeys(key1, key2); assertEquals(2, chain.numKeys()); assertEquals(4, chain.numBloomFilterEntries()); BloomFilter filter = chain.getFilter(4, 0.001, 100); assertTrue(filter.contains(key1.getPubKey())); assertTrue(filter.contains(key1.getPubKeyHash())); assertTrue(filter.contains(key2.getPubKey())); assertTrue(filter.contains(key2.getPubKeyHash())); ECKey key3 = new ECKey(); assertFalse(filter.contains(key3.getPubKey())); }
@Override public BloomFilter getFilter(int size, double falsePositiveRate, long tweak) { lock.lock(); try { checkArgument(size >= numBloomFilterEntries(), "Bloom filter too small"); maybeLookAhead(); return simpleKeyChain.getFilter(size, falsePositiveRate, tweak); } finally { lock.unlock(); } }
@Test public void testBloomFilter() { final List<Integer> integers = Arrays.asList(10, 100, 1000, 2000, 5000, 10000); for (Integer i : integers) { final BloomFilter res = new BloomFilter(i, 1.0E-5, System.currentTimeMillis()); System.out.println("" + res ); } }
public BloomFilter getLastFilter() { return lastFilter; }
@Override public BloomFilter getFilter(int size, double falsePositiveRate, long tweak) { throw new RuntimeException("Not implemented"); }
/** * <p>Gets a bloom filter that contains all of the public keys from this chain, and which will provide the given * false-positive rate if it has size elements. Keep in mind that you will get 2 elements in the bloom filter for * each key in the key chain, for the public key and the hash of the public key (address form). For this reason * size should be <i>at least</i> 2x the result of {@link #numKeys()}.</p> * * <p>This is used to generate a {@link BloomFilter} which can be {@link BloomFilter#merge(BloomFilter)}d with * another. It could also be used if you have a specific target for the filter's size.</p> * * <p>See the docs for {@link org.bitcoinj.core.BloomFilter#BloomFilter(int, double, long)} for a brief * explanation of anonymity when using bloom filters, and for the meaning of these parameters.</p> */ BloomFilter getFilter(int size, double falsePositiveRate, long tweak);
/** * <p>Gets a bloom filter that contains all of the public keys from this chain, and which will provide the given * false-positive rate if it has size elements. Keep in mind that you will get 2 elements in the bloom filter for * each key in the key chain, for the public key and the hash of the public key (address form). For this reason * size should be <i>at least</i> 2x the result of {@link #numKeys()}.</p> * * <p>This is used to generate a {@link BloomFilter} which can be {@link BloomFilter#merge(BloomFilter)}d with * another. It could also be used if you have a specific target for the filter's size.</p> * * <p>See the docs for {@link org.bitcoinj.core.BloomFilter#BloomFilter(int, double, long)} for a brief * explanation of anonymity when using bloom filters, and for the meaning of these parameters.</p> */ public BloomFilter getFilter(int size, double falsePositiveRate, long tweak);