/** See {@link org.bitcoinj.wallet.DeterministicKeyChain#setLookaheadSize(int)} for more info on this. */ public int getKeyChainGroupLookaheadSize() { keyChainGroupLock.lock(); try { return keyChainGroup.getLookaheadSize(); } finally { keyChainGroupLock.unlock(); } }
/** See {@link org.bitcoinj.wallet.DeterministicKeyChain#setLookaheadSize(int)} for more info on this. */ public int getKeyChainGroupLookaheadSize() { keyChainGroupLock.lock(); try { return keyChainGroup.getLookaheadSize(); } finally { keyChainGroupLock.unlock(); } }
/** See {@link org.bitcoinj.wallet.DeterministicKeyChain#setLookaheadSize(int)} for more info on this. */ public int getKeyChainGroupLookaheadSize() { keyChainGroupLock.lock(); try { return keyChainGroup.getLookaheadSize(); } finally { keyChainGroupLock.unlock(); } }
/** See {@link org.bitcoinj.wallet.DeterministicKeyChain#setLookaheadSize(int)} for more info on this. */ public int getKeyChainGroupLookaheadSize() { keyChainGroupLock.lock(); try { return keyChainGroup.getLookaheadSize(); } finally { keyChainGroupLock.unlock(); } }
@Test public void serializeWatching() throws Exception { group = new KeyChainGroup(PARAMS, watchingAccountKey); group.setLookaheadSize(LOOKAHEAD_SIZE); group.freshKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); group.freshKey(KeyChain.KeyPurpose.CHANGE); group.getBloomFilterElementCount(); // Force lookahead. List<Protos.Key> protoKeys1 = group.serializeToProtobuf(); assertEquals(3 + (group.getLookaheadSize() + group.getLookaheadThreshold() + 1) * 2, protoKeys1.size()); group = KeyChainGroup.fromProtobufUnencrypted(PARAMS, protoKeys1); assertEquals(3 + (group.getLookaheadSize() + group.getLookaheadThreshold() + 1) * 2, group.serializeToProtobuf().size()); }
@Test public void freshAddress() throws Exception { group = createMarriedKeyChainGroup(); Address a1 = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS); Address a2 = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS); assertTrue(a1.isP2SHAddress()); assertNotEquals(a1, a2); group.getBloomFilterElementCount(); assertEquals(((group.getLookaheadSize() + group.getLookaheadThreshold()) * 2) // * 2 because of internal/external + (2 - group.getLookaheadThreshold()) // keys issued + group.getActiveKeyChain().getAccountPath().size() + 3 /* master, account, int, ext */, group.numKeys()); Address a3 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS); assertEquals(a2, a3); }
@Test public void bloomFilterForMarriedChains() throws Exception { group = createMarriedKeyChainGroup(); int bufferSize = group.getLookaheadSize() + group.getLookaheadThreshold(); int expected = bufferSize * 2 /* chains */ * 2 /* elements */; assertEquals(expected, group.getBloomFilterElementCount()); Address address1 = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS); assertEquals(expected, group.getBloomFilterElementCount()); BloomFilter filter = group.getBloomFilter(expected + 2, 0.001, (long)(Math.random() * Long.MAX_VALUE)); assertTrue(filter.contains(address1.getHash160())); Address address2 = group.freshAddress(KeyChain.KeyPurpose.CHANGE); assertTrue(filter.contains(address2.getHash160())); // Check that the filter contains the lookahead buffer. for (int i = 0; i < bufferSize - 1 /* issued address */; i++) { Address address = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS); assertTrue("key " + i, filter.contains(address.getHash160())); } // We ran ahead of the lookahead buffer. assertFalse(filter.contains(group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS).getHash160())); }
@Test public void findRedeemScriptFromPubHash() throws Exception { group = createMarriedKeyChainGroup(); Address address = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS); assertTrue(group.findRedeemDataFromScriptHash(address.getHash160()) != null); group.getBloomFilterElementCount(); KeyChainGroup group2 = createMarriedKeyChainGroup(); group2.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS); group2.getBloomFilterElementCount(); // Force lookahead. // test address from lookahead zone and lookahead threshold zone for (int i = 0; i < group.getLookaheadSize() + group.getLookaheadThreshold(); i++) { address = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS); assertTrue(group2.findRedeemDataFromScriptHash(address.getHash160()) != null); } assertFalse(group2.findRedeemDataFromScriptHash(group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS).getHash160()) != null); }
@Test public void freshCurrentKeys() throws Exception { int numKeys = ((group.getLookaheadSize() + group.getLookaheadThreshold()) * 2) // * 2 because of internal/external + 1 // keys issued + group.getActiveKeyChain().getAccountPath().size() + 2 /* account key + int/ext parent keys */;