/** * Returns the earliest creation time of keys or watched scripts in this wallet, in seconds since the epoch, ie the min * of {@link org.bitcoinj.core.ECKey#getCreationTimeSeconds()}. This can return zero if at least one key does * not have that data (was created before key timestamping was implemented). <p> * * This method is most often used in conjunction with {@link PeerGroup#setFastCatchupTimeSecs(long)} in order to * optimize chain download for new users of wallet apps. Backwards compatibility notice: if you get zero from this * method, you can instead use the time of the first release of your software, as it's guaranteed no users will * have wallets pre-dating this time. <p> * * If there are no keys in the wallet, the current time is returned. */ @Override public long getEarliestKeyCreationTime() { keyChainGroupLock.lock(); try { long earliestTime = keyChainGroup.getEarliestKeyCreationTime(); for (Script script : watchedScripts) earliestTime = Math.min(script.getCreationTimeSeconds(), earliestTime); if (earliestTime == Long.MAX_VALUE) return Utils.currentTimeSeconds(); return earliestTime; } finally { keyChainGroupLock.unlock(); } }
/** * Returns the earliest creation time of keys or watched scripts in this wallet, in seconds since the epoch, ie the min * of {@link org.bitcoinj.core.ECKey#getCreationTimeSeconds()}. This can return zero if at least one key does * not have that data (was created before key timestamping was implemented). <p> * * This method is most often used in conjunction with {@link PeerGroup#setFastCatchupTimeSecs(long)} in order to * optimize chain download for new users of wallet apps. Backwards compatibility notice: if you get zero from this * method, you can instead use the time of the first release of your software, as it's guaranteed no users will * have wallets pre-dating this time. <p> * * If there are no keys in the wallet, the current time is returned. */ @Override public long getEarliestKeyCreationTime() { keyChainGroupLock.lock(); try { long earliestTime = keyChainGroup.getEarliestKeyCreationTime(); for (Script script : watchedScripts) earliestTime = Math.min(script.getCreationTimeSeconds(), earliestTime); if (earliestTime == Long.MAX_VALUE) return Utils.currentTimeSeconds(); return earliestTime; } finally { keyChainGroupLock.unlock(); } }
/** * Returns the earliest creation time of keys or watched scripts in this wallet, in seconds since the epoch, ie the min * of {@link org.bitcoinj.core.ECKey#getCreationTimeSeconds()}. This can return zero if at least one key does * not have that data (was created before key timestamping was implemented). <p> * * This method is most often used in conjunction with {@link PeerGroup#setFastCatchupTimeSecs(long)} in order to * optimize chain download for new users of wallet apps. Backwards compatibility notice: if you get zero from this * method, you can instead use the time of the first release of your software, as it's guaranteed no users will * have wallets pre-dating this time. <p> * * If there are no keys in the wallet, the current time is returned. */ @Override public long getEarliestKeyCreationTime() { keyChainGroupLock.lock(); try { long earliestTime = keyChainGroup.getEarliestKeyCreationTime(); for (Script script : watchedScripts) earliestTime = Math.min(script.getCreationTimeSeconds(), earliestTime); if (earliestTime == Long.MAX_VALUE) return Utils.currentTimeSeconds(); return earliestTime; } finally { keyChainGroupLock.unlock(); } }
/** * Returns the earliest creation time of keys or watched scripts in this wallet, in seconds since the epoch, ie the min * of {@link org.bitcoinj.core.ECKey#getCreationTimeSeconds()}. This can return zero if at least one key does * not have that data (was created before key timestamping was implemented). <p> * * This method is most often used in conjunction with {@link PeerGroup#setFastCatchupTimeSecs(long)} in order to * optimize chain download for new users of wallet apps. Backwards compatibility notice: if you get zero from this * method, you can instead use the time of the first release of your software, as it's guaranteed no users will * have wallets pre-dating this time. <p> * * If there are no keys in the wallet, the current time is returned. */ @Override public long getEarliestKeyCreationTime() { keyChainGroupLock.lock(); try { long earliestTime = keyChainGroup.getEarliestKeyCreationTime(); for (Script script : watchedScripts) earliestTime = Math.min(script.getCreationTimeSeconds(), earliestTime); if (earliestTime == Long.MAX_VALUE) return Utils.currentTimeSeconds(); return earliestTime; } finally { keyChainGroupLock.unlock(); } }
@Test public void earliestKeyTime() throws Exception { long now = Utils.currentTimeSeconds(); // mock long yesterday = now - 86400; assertEquals(now, group.getEarliestKeyCreationTime()); Utils.rollMockClock(10000); group.freshKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); Utils.rollMockClock(10000); group.freshKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); // Check that all keys are assumed to be created at the same instant the seed is. assertEquals(now, group.getEarliestKeyCreationTime()); ECKey key = new ECKey(); key.setCreationTimeSeconds(yesterday); group.importKeys(key); assertEquals(yesterday, group.getEarliestKeyCreationTime()); }
long now = Utils.currentTimeSeconds(); ECKey a = group.freshKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); assertEquals(now, group.getEarliestKeyCreationTime()); Utils.rollMockClock(-86400); long yesterday = Utils.currentTimeSeconds(); assertEquals(now, group.getEarliestKeyCreationTime()); group.importKeys(b); assertEquals(yesterday, group.getEarliestKeyCreationTime()); if (withImported) { assertTrue(checkNotNull(group.findKeyFromPubKey(b.getPubKey())).isEncrypted()); assertEquals(yesterday, group.getEarliestKeyCreationTime()); } else { assertEquals(now, group.getEarliestKeyCreationTime()); if (withImported) { assertFalse(checkNotNull(group.findKeyFromPubKey(b.getPubKey())).isEncrypted()); assertEquals(yesterday, group.getEarliestKeyCreationTime()); } else { assertEquals(now, group.getEarliestKeyCreationTime());