core: remove deprecated methods that take instants or duration as long and TimeUnit

This commit is contained in:
Andreas Schildbach 2024-09-02 13:23:37 +02:00
parent bc7883ef8f
commit 3daf1692ad
21 changed files with 0 additions and 267 deletions

View File

@ -230,24 +230,6 @@ public class Block extends BaseMessage {
null;
}
/**
* Construct a block initialized with all the given fields.
* @param version This should usually be set to 1 or 2, depending on if the height is in the coinbase input.
* @param prevBlockHash Reference to previous block in the chain or {@link Sha256Hash#ZERO_HASH} if genesis.
* @param merkleRoot The root of the merkle tree formed by the transactions.
* @param time UNIX time seconds when the block was mined.
* @param difficultyTarget Number which this block hashes lower than.
* @param nonce Arbitrary number to make the block hash lower than the target.
* @param transactions List of transactions including the coinbase, or {@code null} for header-only blocks
* @deprecated use {@link #Block(long, Sha256Hash, Sha256Hash, Instant, long, long, List)}
*/
@Deprecated
public Block(long version, Sha256Hash prevBlockHash, Sha256Hash merkleRoot, long time,
long difficultyTarget, long nonce, @Nullable List<Transaction> transactions) {
this(version, prevBlockHash, merkleRoot, Instant.ofEpochSecond(time), difficultyTarget, nonce,
transactions);
}
public static Block createGenesis(Instant time, long difficultyTarget) {
return new Block(BLOCK_VERSION_GENESIS, time, difficultyTarget, genesisTransactions());
}

View File

@ -166,12 +166,6 @@ public class CheckpointManager {
}
}
/** @deprecated use {@link #getCheckpointBefore(Instant)} */
@Deprecated
public StoredBlock getCheckpointBefore(long timeSecs) {
return getCheckpointBefore(Instant.ofEpochSecond(timeSecs));
}
/** Returns the number of checkpoints that were loaded. */
public int numCheckpoints() {
return checkpoints.size();
@ -207,11 +201,4 @@ public class CheckpointManager {
store.put(checkpoint);
store.setChainHead(checkpoint);
}
/** @deprecated use {@link #checkpoint(NetworkParameters, InputStream, BlockStore, Instant)} */
@Deprecated
public static void checkpoint(NetworkParameters params, InputStream checkpoints, BlockStore store, long timeSecs)
throws IOException, BlockStoreException {
checkpoint(params, checkpoints, store, Instant.ofEpochSecond(timeSecs));
}
}

View File

@ -1354,15 +1354,6 @@ public class Peer extends PeerSocketHandler {
}
}
/** @deprecated use {@link #setDownloadParameters(boolean)} or {@link #setFastDownloadParameters(boolean, Instant)} */
@Deprecated
public void setDownloadParameters(long fastCatchupTimeSecs, boolean useFilteredBlocks) {
if (fastCatchupTimeSecs > 0)
setFastDownloadParameters(useFilteredBlocks, Instant.ofEpochSecond(fastCatchupTimeSecs));
else
setDownloadParameters(useFilteredBlocks);
}
/**
* Links the given wallet to this peer. If you have multiple peers, you should use a {@link PeerGroup} to manage
* them and use the {@link PeerGroup#addWallet(Wallet)} method instead of registering the wallet with each peer

View File

@ -414,12 +414,6 @@ public class PeerAddress {
return time;
}
/** @deprecated use {@link #time()} */
@Deprecated
public long getTime() {
return time.getEpochSecond();
}
@Override
public String toString() {
if (hostname != null) {

View File

@ -33,13 +33,6 @@ public interface PeerFilterProvider {
*/
Instant earliestKeyCreationTime();
/** @deprecated use {@link #earliestKeyCreationTime()} */
@Deprecated
default long getEarliestKeyCreationTime() {
Instant earliestKeyCreationTime = earliestKeyCreationTime();
return earliestKeyCreationTime.equals(Instant.MAX) ? Long.MAX_VALUE : earliestKeyCreationTime.getEpochSecond();
}
/**
* Called on all registered filter providers before {@link #getBloomFilterElementCount()} and
* {@link #getBloomFilter(int, double, int)} are called. Once called, the provider should ensure that the items

View File

@ -511,15 +511,6 @@ public class PeerGroup implements TransactionBroadcaster {
this.vPeerDiscoveryTimeout = peerDiscoveryTimeout;
}
/**
* This is how many milliseconds we wait for peer discoveries to return their results.
* @deprecated use {@link #setPeerDiscoveryTimeout(Duration)}
*/
@Deprecated
public void setPeerDiscoveryTimeoutMillis(long peerDiscoveryTimeoutMillis) {
setPeerDiscoveryTimeout(Duration.ofMillis(peerDiscoveryTimeoutMillis));
}
/**
* Adjusts the desired number of connections that we will create to peers. Note that if there are already peers
* open and the new value is lower than the current number of peers, those connections will be terminated. Likewise
@ -1774,12 +1765,6 @@ public class PeerGroup implements TransactionBroadcaster {
}
}
/** @deprecated use {@link #setFastCatchupTime(Instant)} */
@Deprecated
public void setFastCatchupTimeSecs(long fastCatchupTimeSecs) {
setFastCatchupTime(Instant.ofEpochSecond(fastCatchupTimeSecs));
}
/**
* Returns the current fast catchup time. The contents of blocks before this time won't be downloaded as they
* cannot contain any interesting transactions. If you use {@link PeerGroup#addWallet(Wallet)} this just returns
@ -1795,12 +1780,6 @@ public class PeerGroup implements TransactionBroadcaster {
}
}
/** @deprecated use {@link #getFastCatchupTime()} */
@Deprecated
public long getFastCatchupTimeSecs() {
return getFastCatchupTime().getEpochSecond();
}
protected void handlePeerDeath(final Peer peer, @Nullable Throwable exception) {
// Peer deaths can occur during startup if a connect attempt after peer discovery aborts immediately.
if (!isRunning()) return;

View File

@ -44,11 +44,4 @@ public interface EncryptableItem {
/** Returns the time at which this encryptable item was first created/derived, or empty of unknown. */
Optional<Instant> getCreationTime();
/** @deprecated use {@link #getCreationTime()} */
@Deprecated
default long getCreationTimeSeconds() {
Optional<Instant> creationTime = getCreationTime();
return creationTime.isPresent() ? creationTime.get().getEpochSecond() : 0;
}
}

View File

@ -60,7 +60,6 @@ import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import static org.bitcoinj.base.internal.Preconditions.checkState;

View File

@ -73,12 +73,6 @@ public class BlockingClientManager extends AbstractIdleService implements Client
this.connectTimeout = connectTimeout;
}
/** @deprecated use {@link #setConnectTimeout(Duration)} */
@Deprecated
public void setConnectTimeoutMillis(int connectTimeoutMillis) {
setConnectTimeout(Duration.ofMillis(connectTimeoutMillis));
}
@Override
protected void startUp() throws Exception { }

View File

@ -23,7 +23,6 @@ import org.bitcoinj.core.VersionMessage;
import java.net.InetSocketAddress;
import java.time.Duration;
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
* A PeerDiscovery object is responsible for finding addresses of other nodes in the Bitcoin P2P network. Note that
@ -40,14 +39,6 @@ public interface PeerDiscovery {
*/
List<InetSocketAddress> getPeers(long services, Duration timeout) throws PeerDiscoveryException;
/**
* @deprecated use {@link #getPeers(long, Duration)}
*/
@Deprecated
default List<InetSocketAddress> getPeers(long services, long timeoutValue, TimeUnit timeoutUnit) throws PeerDiscoveryException {
return getPeers(services, Duration.ofMillis(timeoutUnit.toMillis(timeoutValue)));
}
/** Stops any discovery in progress when we want to shut down quickly. */
void shutdown();
}

View File

@ -42,7 +42,6 @@ import java.time.Duration;
import java.time.Instant;
import java.time.temporal.Temporal;
import java.time.temporal.TemporalUnit;
import java.util.concurrent.TimeUnit;
import static org.bitcoinj.base.internal.Preconditions.checkState;

View File

@ -382,12 +382,6 @@ public class Script {
return Optional.ofNullable(creationTime);
}
/** @deprecated use {@link #creationTime()} */
@Deprecated
public long getCreationTimeSeconds() {
return creationTime().orElse(Instant.EPOCH).getEpochSecond();
}
/**
* Returns the program opcodes as a string, for example "[1234] DUP HASH160", or "&lt;empty&gt;".
*/

View File

@ -277,13 +277,6 @@ public class FakeTxBuilder {
return createFakeBlock(blockStore, version, time, 0, transactions);
}
/** @deprecated use {@link #createFakeBlock(BlockStore, long, Instant, Transaction...)} */
@Deprecated
public static BlockPair createFakeBlock(BlockStore blockStore, long version,
long timeSecs, Transaction... transactions) {
return createFakeBlock(blockStore, version, Instant.ofEpochSecond(timeSecs), transactions);
}
/** Emulates receiving a valid block */
public static BlockPair createFakeBlock(BlockStore blockStore, StoredBlock previousStoredBlock, long version,
Instant time, int height, Transaction... transactions) {
@ -305,14 +298,6 @@ public class FakeTxBuilder {
}
}
/** @deprecated use {@link #createFakeBlock(BlockStore, StoredBlock, long, Instant, int, Transaction...)} */
@Deprecated
public static BlockPair createFakeBlock(BlockStore blockStore, StoredBlock previousStoredBlock, long version,
long timeSecs, int height, Transaction... transactions) {
return createFakeBlock(blockStore, previousStoredBlock, version, Instant.ofEpochSecond(timeSecs), height,
transactions);
}
public static BlockPair createFakeBlock(BlockStore blockStore, StoredBlock previousStoredBlock, int height, Transaction... transactions) {
return createFakeBlock(blockStore, previousStoredBlock, Block.BLOCK_VERSION_BIP66, TimeUtils.currentTime(), height, transactions);
}
@ -326,12 +311,6 @@ public class FakeTxBuilder {
}
}
/** @deprecated use {@link #createFakeBlock(BlockStore, long, Instant, int, Transaction...)} */
@Deprecated
public static BlockPair createFakeBlock(BlockStore blockStore, long version, long timeSecs, int height, Transaction... transactions) {
return createFakeBlock(blockStore, version, Instant.ofEpochSecond(timeSecs), height, transactions);
}
/** Emulates receiving a valid block that builds on top of the chain. */
public static BlockPair createFakeBlock(BlockStore blockStore, int height,
Transaction... transactions) {

View File

@ -95,15 +95,6 @@ public class ExponentialBackoff implements Comparable<ExponentialBackoff> {
return retryTime;
}
/**
* Get the next time to retry, in milliseconds since the epoch
* @deprecated use {@link #retryTime()}
**/
@Deprecated
public long getRetryTime() {
return retryTime.toEpochMilli();
}
@Override
public int compareTo(ExponentialBackoff other) {
// note that in this implementation compareTo() is not consistent with equals()

View File

@ -650,13 +650,6 @@ public class BasicKeyChain implements EncryptableKeyChain {
}
}
/** @deprecated use {@link #findOldestKeyAfter(Instant)} */
@Nullable
@Deprecated
public ECKey findOldestKeyAfter(long timeSecs) {
return findOldestKeyAfter(Instant.ofEpochSecond(timeSecs)).orElse(null);
}
/** Returns a list of all ECKeys created after the given time. */
public List<ECKey> findKeysBefore(Instant time) {
lock.lock();
@ -674,12 +667,6 @@ public class BasicKeyChain implements EncryptableKeyChain {
}
}
/** @deprecated use {@link #findKeysBefore(Instant)} */
@Deprecated
public List<ECKey> findKeysBefore(long timeSecs) {
return findKeysBefore(Instant.ofEpochSecond(timeSecs));
}
public String toString(boolean includePrivateKeys, @Nullable AesKey aesKey, Network network) {
final StringBuilder builder = new StringBuilder();
List<ECKey> keys = getKeys();

View File

@ -219,13 +219,6 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
return self();
}
/** @deprecated use {@link #entropy(byte[], Instant)} */
@Deprecated
public T entropy(byte[] entropy, long creationTimeSecs) {
checkArgument(creationTimeSecs > 0);
return entropy(entropy, Instant.ofEpochSecond(creationTimeSecs));
}
/**
* Creates a deterministic key chain starting from the given seed. All keys yielded by this chain will be the same
* if the starting seed is the same.

View File

@ -141,12 +141,6 @@ public class DeterministicSeed implements EncryptableItem {
this(decodeMnemonicCode(mnemonicString), seed, passphrase, creationTime);
}
/** @deprecated use {@link #ofMnemonic(String, String, Instant)} or {@link #ofMnemonic(String, String)} */
@Deprecated
public DeterministicSeed(String mnemonicString, byte[] seed, String passphrase, long creationTimeSecs) {
this(mnemonicString, seed, passphrase, creationTimeSecs > 0 ? Instant.ofEpochSecond(creationTimeSecs) : null);
}
/** Internal use only. */
private DeterministicSeed(byte[] seed, List<String> mnemonic, @Nullable Instant creationTime) {
this.seed = Objects.requireNonNull(seed);
@ -165,23 +159,11 @@ public class DeterministicSeed implements EncryptableItem {
this.creationTime = creationTime;
}
/** @deprecated will be removed in a future release */
@Deprecated
public DeterministicSeed(EncryptedData encryptedMnemonic, @Nullable EncryptedData encryptedSeed, long creationTimeSecs) {
this(encryptedMnemonic, encryptedSeed, creationTimeSecs > 0 ? Instant.ofEpochSecond(creationTimeSecs) : null);
}
/** Internal use only. */
private DeterministicSeed(List<String> mnemonicCode, @Nullable byte[] seed, String passphrase, @Nullable Instant creationTime) {
this((seed != null ? seed : MnemonicCode.toSeed(mnemonicCode, Objects.requireNonNull(passphrase))), mnemonicCode, creationTime);
}
/** @deprecated use {@link #ofMnemonic(List, String, Instant)} or {@link #ofMnemonic(List, String)} */
@Deprecated
public DeterministicSeed(List<String> mnemonicCode, @Nullable byte[] seed, String passphrase, long creationTimeSecs) {
this(mnemonicCode, seed, passphrase, creationTimeSecs > 0 ? Instant.ofEpochSecond(creationTimeSecs) : null);
}
/** @deprecated use {@link #ofRandom(SecureRandom, int, String)} */
@Deprecated
public DeterministicSeed(SecureRandom random, int bits, String passphrase) {
@ -200,12 +182,6 @@ public class DeterministicSeed implements EncryptableItem {
this.creationTime = creationTime;
}
/** @deprecated use {@link #ofEntropy(byte[], String, Instant)} or {@link #ofEntropy(byte[], String)} */
@Deprecated
public DeterministicSeed(byte[] entropy, String passphrase, long creationTimeSecs) {
this(entropy, passphrase, creationTimeSecs > 0 ? Instant.ofEpochSecond(creationTimeSecs) : null);
}
private static byte[] getEntropy(SecureRandom random, int bits) {
checkArgument(bits <= MAX_SEED_ENTROPY_BITS, () ->
"requested entropy size too large");
@ -291,17 +267,6 @@ public class DeterministicSeed implements EncryptableItem {
this.creationTime = null;
}
/** @deprecated use {@link #setCreationTime(Instant)} */
@Deprecated
public void setCreationTimeSeconds(long creationTimeSecs) {
if (creationTimeSecs > 0)
setCreationTime(Instant.ofEpochSecond(creationTimeSecs));
else if (creationTimeSecs == 0)
clearCreationTime();
else
throw new IllegalArgumentException("Cannot set creation time to negative value: " + creationTimeSecs);
}
public DeterministicSeed encrypt(KeyCrypter keyCrypter, AesKey aesKey) {
checkState(encryptedMnemonicCode == null, () ->
"trying to encrypt seed twice");

View File

@ -57,12 +57,6 @@ public class KeyTimeCoinSelector implements CoinSelector {
this.ignorePending = ignorePending;
}
/** @deprecated use {@link #KeyTimeCoinSelector(Wallet, Instant, boolean)} */
@Deprecated
public KeyTimeCoinSelector(Wallet wallet, long timeSecs, boolean ignorePending) {
this(wallet, Instant.ofEpochSecond(timeSecs), ignorePending);
}
@Override
public CoinSelection select(Coin target, List<TransactionOutput> candidates) {
try {

View File

@ -134,7 +134,6 @@ import java.util.TreeSet;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
@ -497,16 +496,6 @@ public class Wallet extends BaseTaggableObject
return fromWatchingKeyB58(params.network(), watchKeyB58);
}
/**
* @deprecated Use {@link #fromWatchingKeyB58(Network, String, Instant)} or {@link #fromWatchingKeyB58(Network, String)}
*/
@Deprecated
public static Wallet fromWatchingKeyB58(NetworkParameters params, String watchKeyB58, long creationTimeSeconds) {
return (creationTimeSeconds == 0)
? fromWatchingKeyB58(params.network(), watchKeyB58)
: fromWatchingKeyB58(params.network(), watchKeyB58, Instant.ofEpochSecond(creationTimeSeconds));
}
/**
* Creates a wallet that tracks payments to and from the HD key hierarchy rooted by the given spending key. This HAS
* to be an account key as returned by {@link DeterministicKeyChain#getWatchingKey()}. This wallet can also spend.
@ -570,16 +559,6 @@ public class Wallet extends BaseTaggableObject
return fromSpendingKeyB58(params.network(), spendingKeyB58);
}
/**
* @deprecated Use {@link #fromSpendingKeyB58(Network, String, Instant)} or {@link #fromSpendingKeyB58(Network, String)}
*/
@Deprecated
public static Wallet fromSpendingKeyB58(NetworkParameters params, String spendingKeyB58, long creationTimeSeconds) {
return (creationTimeSeconds == 0)
? fromSpendingKeyB58(params.network(), spendingKeyB58)
: fromSpendingKeyB58(params.network(), spendingKeyB58, Instant.ofEpochSecond(creationTimeSeconds));
}
/**
* Creates a spending wallet that tracks payments to and from a BIP32-style HD key hierarchy rooted by {@code masterKey} and
* {@code accountNumber}. The account path must be directly below the master key as in BIP-32.
@ -1189,14 +1168,6 @@ public class Wallet extends BaseTaggableObject
return addWatchedAddresses(Collections.singletonList(address), creationTime) == 1;
}
/** @deprecated use {@link #addWatchedAddress(Address, Instant)} or {@link #addWatchedAddress(Address)} */
@Deprecated
public boolean addWatchedAddress(final Address address, long creationTime) {
return creationTime > 0 ?
addWatchedAddress(address, Instant.ofEpochSecond(creationTime)) :
addWatchedAddress(address);
}
/**
* Adds the given addresses to the wallet to be watched. Outputs can be retrieved
* by {@link #getWatchedOutputs(boolean)}.
@ -1228,14 +1199,6 @@ public class Wallet extends BaseTaggableObject
return addWatchedScripts(scripts);
}
/** @deprecated use {@link #addWatchedAddresses(List, Instant)} or {@link #addWatchedAddresses(List)} */
@Deprecated
public int addWatchedAddresses(final List<Address> addresses, long creationTime) {
return creationTime > 0 ?
addWatchedAddresses(addresses, creationTime) :
addWatchedAddresses(addresses);
}
/**
* Adds the given output scripts to the wallet to be watched. Outputs can be retrieved by {@link #getWatchedOutputs(boolean)}.
* If a script is already being watched, the object is replaced with the one in the given list. As {@link Script}
@ -1859,12 +1822,6 @@ public class Wallet extends BaseTaggableObject
}
}
/** @deprecated use {@link #autosaveToFile(File, Duration, WalletFiles.Listener)} */
@Deprecated
public WalletFiles autosaveToFile(File f, long delayTime, TimeUnit timeUnit, @Nullable WalletFiles.Listener eventListener) {
return autosaveToFile(f, Duration.ofMillis(timeUnit.toMillis(delayTime)), eventListener);
}
/**
* <p>
* Disables auto-saving, after it had been enabled with
@ -3855,13 +3812,6 @@ public class Wallet extends BaseTaggableObject
}
}
/** @deprecated use {@link #setLastBlockSeenTime(Instant)} or {@link #clearLastBlockSeenTime()} */
@Deprecated
public void setLastBlockSeenTimeSecs(long timeSecs) {
checkArgument(timeSecs > 0);
setLastBlockSeenTime(Instant.ofEpochSecond(timeSecs));
}
/**
* Returns time extracted from the last best seen block header, or empty. This timestamp
* is <b>not</b> the local time at which the block was first observed by this application but rather what the block
@ -3878,12 +3828,6 @@ public class Wallet extends BaseTaggableObject
}
}
/** @deprecated use {@link #lastBlockSeenTime()} */
@Deprecated
public long getLastBlockSeenTimeSecs() {
return lastBlockSeenTime().map(Instant::getEpochSecond).orElse((long) 0);
}
/**
* Returns the height of the last seen best-chain block. Can be 0 if a wallet is brand new or -1 if the wallet
* is old and doesn't have that data.
@ -5667,15 +5611,6 @@ public class Wallet extends BaseTaggableObject
saveNow();
}
/** @deprecated use {@link #setKeyRotationTime(Instant)} */
@Deprecated
public void setKeyRotationTime(long timeSecs) {
if (timeSecs == 0)
setKeyRotationTime((Instant) null);
else
setKeyRotationTime(Instant.ofEpochSecond(timeSecs));
}
/**
* Returns the key rotation time, or empty if unconfigured. See {@link #setKeyRotationTime(Instant)} for a description
* of the field.

View File

@ -104,12 +104,6 @@ public class WalletFiles {
};
}
/** @deprecated use {@link #WalletFiles(Wallet, File, Duration)} */
@Deprecated
public WalletFiles(final Wallet wallet, File file, long delayTime, TimeUnit timeUnit) {
this(wallet, file, Duration.ofMillis(timeUnit.toMillis(delayTime)));
}
/** Get the {@link Wallet} this {@link WalletFiles} is managing. */
public Wallet getWallet() {
return wallet;

View File

@ -22,7 +22,6 @@ import org.junit.Test;
import java.net.InetSocketAddress;
import java.time.Duration;
import java.util.List;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;