Transaction: migrate estimateLockTime() method to java.time API

This commit is contained in:
Andreas Schildbach 2023-03-13 18:36:59 +01:00
parent f7fffc6af2
commit 65afcf076d
2 changed files with 12 additions and 6 deletions

View File

@ -1851,14 +1851,20 @@ public class Transaction extends ChildMessage {
}
/**
* Returns either the lock time as a date, if it was specified in seconds, or an estimate based on the time in
* Returns either the lock time, if it was specified in seconds, or an estimate based on the time in
* the current head block if it was specified as a block time.
*/
public Instant estimateLockTimeInstant(AbstractBlockChain chain) {
long lockTime = getLockTime();
return lockTime < LOCKTIME_THRESHOLD ?
chain.estimateBlockTimeInstant(Math.toIntExact(lockTime)) :
Instant.ofEpochSecond(lockTime);
}
/** @deprecated use {@link #estimateLockTimeInstant(AbstractBlockChain)} */
@Deprecated
public Date estimateLockTime(AbstractBlockChain chain) {
if (lockTime < LOCKTIME_THRESHOLD)
return Date.from(chain.estimateBlockTimeInstant((int) getLockTime()));
else
return new Date(getLockTime()*1000);
return Date.from(estimateLockTimeInstant(chain));
}
/**

View File

@ -158,7 +158,7 @@ public class TransactionTest {
replay(mockBlockChain);
assertEquals(tx.estimateLockTime(mockBlockChain).toInstant(), now);
assertEquals(tx.estimateLockTimeInstant(mockBlockChain), now);
}
@Test