Script: rename getCreationTime() method from creationTime()

This effectively reverts commit b309308076.
This commit is contained in:
Andreas Schildbach 2024-05-05 17:02:12 +02:00
parent 2199c7a577
commit 781d64550b
15 changed files with 40 additions and 40 deletions

View file

@ -306,7 +306,7 @@ public class DeterministicKey extends ECKey {
EncryptedData encryptedPrivateKey = keyCrypter.encrypt(privKeyBytes, aesKey);
DeterministicKey key = new DeterministicKey(childNumberPath, chainCode, keyCrypter, pub, encryptedPrivateKey, newParent);
if (newParent == null) {
Optional<Instant> creationTime = this.creationTime();
Optional<Instant> creationTime = this.getCreationTime();
if (creationTime.isPresent())
key.setCreationTime(creationTime.get());
else
@ -386,7 +386,7 @@ public class DeterministicKey extends ECKey {
if (!Arrays.equals(key.getPubKey(), getPubKey()))
throw new KeyCrypterException.PublicPrivateMismatch("Provided AES key is wrong");
if (parent == null) {
Optional<Instant> creationTime = this.creationTime();
Optional<Instant> creationTime = this.getCreationTime();
if (creationTime.isPresent())
key.setCreationTime(creationTime.get());
else
@ -704,14 +704,14 @@ public class DeterministicKey extends ECKey {
/**
* The creation time of a deterministic key is equal to that of its parent, unless this key is the root of a tree
* in which case the time is stored alongside the key as per normal, see {@link ECKey#creationTime()}.
* in which case the time is stored alongside the key as per normal, see {@link ECKey#getCreationTime()}.
*/
@Override
public Optional<Instant> creationTime() {
public Optional<Instant> getCreationTime() {
if (parent != null)
return parent.creationTime();
return parent.getCreationTime();
else
return super.creationTime();
return super.getCreationTime();
}
/**
@ -775,7 +775,7 @@ public class DeterministicKey extends ECKey {
helper.add("pub", ByteUtils.formatHex(pub.getEncoded()));
helper.add("chainCode", ByteUtils.formatHex(chainCode));
helper.add("path", getPathAsString());
Optional<Instant> creationTime = this.creationTime();
Optional<Instant> creationTime = this.getCreationTime();
if (!creationTime.isPresent())
helper.add("creationTimeSeconds", "unknown");
else if (parent != null)

View file

@ -117,7 +117,7 @@ public class ECKey implements EncryptableItem {
private static final Comparator<byte[]> LEXICOGRAPHICAL_COMPARATOR = ByteUtils.arrayUnsignedComparator();
/** Sorts oldest keys first, newest last. */
public static final Comparator<ECKey> AGE_COMPARATOR = Comparator.comparing(ecKey -> ecKey.creationTime().orElse(Instant.EPOCH));
public static final Comparator<ECKey> AGE_COMPARATOR = Comparator.comparing(ecKey -> ecKey.getCreationTime().orElse(Instant.EPOCH));
/** Compares by extracting pub key as a {@code byte[]} and using a lexicographic comparator */
public static final Comparator<ECKey> PUBKEY_COMPARATOR = Comparator.comparing(ECKey::getPubKey, LEXICOGRAPHICAL_COMPARATOR);
@ -1088,7 +1088,7 @@ public class ECKey implements EncryptableItem {
* that data.
*/
@Override
public Optional<Instant> creationTime() {
public Optional<Instant> getCreationTime() {
return Optional.ofNullable(creationTime);
}

View file

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

View file

@ -409,13 +409,13 @@ public class WalletAppKit extends AbstractIdleService implements Closeable {
// Initialize the chain file with a checkpoint to speed up first-run sync.
Instant time;
if (restoreFromSeed != null) {
time = restoreFromSeed.creationTime().orElse(Instant.EPOCH);
time = restoreFromSeed.getCreationTime().orElse(Instant.EPOCH);
if (chainFileExists) {
log.info("Clearing the chain file in preparation for restore.");
vStore.clear();
}
} else if (restoreFromKey != null) {
time = restoreFromKey.creationTime().orElse(Instant.EPOCH);
time = restoreFromKey.getCreationTime().orElse(Instant.EPOCH);
if (chainFileExists) {
log.info("Clearing the chain file in preparation for restore.");
vStore.clear();

View file

@ -297,7 +297,7 @@ public class BasicKeyChain implements EncryptableKeyChain {
lock.lock();
try {
return hashToKeys.values().stream()
.map(key -> key.creationTime().orElse(Instant.EPOCH))
.map(key -> key.getCreationTime().orElse(Instant.EPOCH))
.min(Instant::compareTo)
.orElse(Instant.MAX);
} finally {
@ -350,7 +350,7 @@ public class BasicKeyChain implements EncryptableKeyChain {
/*package*/ static Protos.Key.Builder serializeEncryptableItem(EncryptableItem item) {
Protos.Key.Builder proto = Protos.Key.newBuilder();
item.creationTime().ifPresent(creationTime -> proto.setCreationTimestamp(creationTime.toEpochMilli()));
item.getCreationTime().ifPresent(creationTime -> proto.setCreationTimestamp(creationTime.toEpochMilli()));
if (item.isEncrypted() && item.getEncryptedData() != null) {
// The encrypted data can be missing for an "encrypted" key in the case of a deterministic wallet for
// which the leaf keys chain to an encrypted parent and rederive their private keys on the fly. In that
@ -638,9 +638,9 @@ public class BasicKeyChain implements EncryptableKeyChain {
try {
ECKey oldest = null;
for (ECKey key : hashToKeys.values()) {
Instant keyTime = key.creationTime().orElse(Instant.EPOCH);
Instant keyTime = key.getCreationTime().orElse(Instant.EPOCH);
if (keyTime.isAfter(time)) {
if (oldest == null || oldest.creationTime().orElse(Instant.EPOCH).isAfter(keyTime))
if (oldest == null || oldest.getCreationTime().orElse(Instant.EPOCH).isAfter(keyTime))
oldest = key;
}
}
@ -663,7 +663,7 @@ public class BasicKeyChain implements EncryptableKeyChain {
try {
List<ECKey> results = new LinkedList<>();
for (ECKey key : hashToKeys.values()) {
Instant keyTime = key.creationTime().orElse(Instant.EPOCH);
Instant keyTime = key.getCreationTime().orElse(Instant.EPOCH);
if (keyTime.isBefore(time)) {
results.add(key);
}

View file

@ -392,7 +392,7 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
basicKeyChain = new BasicKeyChain(crypter);
if (!seed.isEncrypted()) {
rootKey = HDKeyDerivation.createMasterPrivateKey(Objects.requireNonNull(seed.getSeedBytes()));
Optional<Instant> creationTime = seed.creationTime();
Optional<Instant> creationTime = seed.getCreationTime();
if (creationTime.isPresent())
rootKey.setCreationTime(creationTime.get());
else
@ -722,8 +722,8 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
@Override
public Instant earliestKeyCreationTime() {
return (seed != null ?
seed.creationTime() :
getWatchingKey().creationTime()
seed.getCreationTime() :
getWatchingKey().getCreationTime()
).orElse(Instant.EPOCH);
}
@ -1444,7 +1444,7 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
builder.append("Seed is encrypted\n");
}
builder.append("Seed birthday: ");
Optional<Instant> seedCreationTime = seed.creationTime();
Optional<Instant> seedCreationTime = seed.getCreationTime();
if (seedCreationTime.isPresent())
builder.append(seedCreationTime.get().getEpochSecond()).append(" [")
.append(TimeUtils.dateTimeFormat(seedCreationTime.get())).append("]");
@ -1453,7 +1453,7 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
builder.append("\n");
} else {
builder.append("Key birthday: ");
Optional<Instant> watchingKeyCreationTime = watchingKey.creationTime();
Optional<Instant> watchingKeyCreationTime = watchingKey.getCreationTime();
if (watchingKeyCreationTime.isPresent())
builder.append(watchingKeyCreationTime.get().getEpochSecond()).append(" [")
.append(TimeUtils.dateTimeFormat(watchingKeyCreationTime.get())).append("]");

View file

@ -271,7 +271,7 @@ public class DeterministicSeed implements EncryptableItem {
}
@Override
public Optional<Instant> creationTime() {
public Optional<Instant> getCreationTime() {
return Optional.ofNullable(creationTime);
}

View file

@ -79,7 +79,7 @@ public class KeyTimeCoinSelector implements CoinSelector {
private boolean isKeyBeforeCutoff(TransactionOutput output) {
Optional<ECKey> optKey = findKey(output);
// It's older than the cutoff time so select.
return optKey.isPresent() && optKey.get().creationTime().orElse(Instant.EPOCH).isBefore(time);
return optKey.isPresent() && optKey.get().getCreationTime().orElse(Instant.EPOCH).isBefore(time);
}
/**

View file

@ -598,7 +598,7 @@ public class Wallet extends BaseTaggableObject
ScriptType outputScriptType, ChildNumber accountNumber) {
DeterministicKey accountKey = HDKeyDerivation.deriveChildKey(masterKey, accountNumber);
accountKey = accountKey.dropParent(); // Drop the parent private key, so it won't be used or saved.
Optional<Instant> creationTime = masterKey.creationTime();
Optional<Instant> creationTime = masterKey.getCreationTime();
if (creationTime.isPresent())
accountKey.setCreationTime(creationTime.get());
else
@ -3782,7 +3782,7 @@ public class Wallet extends BaseTaggableObject
/**
* Returns the earliest creation time of keys or watched scripts in this wallet, ie the min
* of {@link ECKey#creationTime()}. This can return {@link Instant#EPOCH} if at least one key does
* of {@link ECKey#getCreationTime()}. This can return {@link Instant#EPOCH} if at least one key does
* not have that data (e.g. is an imported key with unknown timestamp). <p>
*
* This method is most often used in conjunction with {@link PeerGroup#setFastCatchupTime(Instant)} in order to
@ -5714,7 +5714,7 @@ public class Wallet extends BaseTaggableObject
/** Returns whether the keys creation time is before the key rotation time, if one was set. */
public boolean isKeyRotating(ECKey key) {
Instant keyRotationTime = vKeyRotationTime;
return keyRotationTime != null && key.creationTime().orElse(Instant.EPOCH).isBefore(keyRotationTime);
return keyRotationTime != null && key.getCreationTime().orElse(Instant.EPOCH).isBefore(keyRotationTime);
}
/**

View file

@ -384,12 +384,12 @@ public class ECKeyTest {
public void testUnencryptedCreate() {
TimeUtils.setMockClock();
ECKey key = new ECKey();
Optional<Instant> time = key.creationTime();
Optional<Instant> time = key.getCreationTime();
assertTrue(time.isPresent());
assertFalse(key.isEncrypted());
byte[] originalPrivateKeyBytes = key.getPrivKeyBytes();
ECKey encryptedKey = key.encrypt(keyCrypter, keyCrypter.deriveKey(PASSWORD1));
assertEquals(time, encryptedKey.creationTime());
assertEquals(time, encryptedKey.getCreationTime());
assertTrue(encryptedKey.isEncrypted());
assertNull(encryptedKey.getSecretBytes());
key = encryptedKey.decrypt(keyCrypter.deriveKey(PASSWORD1));

View file

@ -124,7 +124,7 @@ public class WalletProtobufSerializerTest {
ECKey foundKey = wallet1.findKeyFromPubKeyHash(myKey.getPubKeyHash(), null);
assertArrayEquals(myKey.getPubKey(), foundKey.getPubKey());
assertArrayEquals(myKey.getPrivKeyBytes(), foundKey.getPrivKeyBytes());
assertEquals(myKey.creationTime(), foundKey.creationTime());
assertEquals(myKey.getCreationTime(), foundKey.getCreationTime());
assertEquals(mScriptCreationTime.truncatedTo(ChronoUnit.MILLIS),
wallet1.getWatchedScripts().get(0).creationTime().get());
assertEquals(1, wallet1.getWatchedScripts().size());
@ -342,7 +342,7 @@ public class WalletProtobufSerializerTest {
ECKey foundKey = wallet1.findKeyFromPubKeyHash(myKey.getPubKeyHash(), null);
assertArrayEquals(myKey.getPubKey(), foundKey.getPubKey());
assertArrayEquals(myKey.getPrivKeyBytes(), foundKey.getPrivKeyBytes());
assertEquals(myKey.creationTime(), foundKey.creationTime());
assertEquals(myKey.getCreationTime(), foundKey.getCreationTime());
}
@Test
@ -353,9 +353,9 @@ public class WalletProtobufSerializerTest {
Wallet wallet2 = roundTrip(wallet);
Wallet wallet3 = roundTrip(wallet2);
assertEquals(xpub, wallet.getWatchingKey().serializePubB58(TESTNET.network()));
assertEquals(creationTime, wallet.getWatchingKey().creationTime().get());
assertEquals(creationTime, wallet2.getWatchingKey().creationTime().get());
assertEquals(creationTime, wallet3.getWatchingKey().creationTime().get());
assertEquals(creationTime, wallet.getWatchingKey().getCreationTime().get());
assertEquals(creationTime, wallet2.getWatchingKey().getCreationTime().get());
assertEquals(creationTime, wallet3.getWatchingKey().getCreationTime().get());
assertEquals(creationTime, wallet.earliestKeyCreationTime());
assertEquals(creationTime, wallet2.earliestKeyCreationTime());
assertEquals(creationTime, wallet3.earliestKeyCreationTime());

View file

@ -657,7 +657,7 @@ public class DeterministicKeyChainTest {
//Simulate Wallet.fromMasterKey(params, coinLevelKey, 0)
DeterministicKey accountKey = HDKeyDerivation.deriveChildKey(coinLevelKey, new ChildNumber(0, true));
accountKey = accountKey.dropParent();
accountKey.setCreationTime(watchingKey.creationTime().get());
accountKey.setCreationTime(watchingKey.getCreationTime().get());
KeyChainGroup group = KeyChainGroup.builder(network).addChain(DeterministicKeyChain.builder().spend(accountKey)
.outputScriptType(bip44chain.getOutputScriptType()).build()).build();
DeterministicKeyChain fromMasterKeyChain = group.getActiveKeyChain();

View file

@ -39,7 +39,7 @@ public class BackupToMnemonicSeed {
DeterministicSeed seed = wallet.getKeyChainSeed();
System.out.println("seed: " + seed.toString());
System.out.println("creation time: " + seed.creationTime().get().getEpochSecond());
System.out.println("creation time: " + seed.getCreationTime().get().getEpochSecond());
System.out.println("mnemonicCode: " + InternalUtils.SPACE_JOINER.join(seed.getMnemonicCode()));
}
}

View file

@ -38,7 +38,7 @@ public class WalletLoadTest {
Context.propagate(new Context());
Wallet wallet = Wallet.loadFromFile(walletFile);
Instant creation = wallet.getKeyChainSeed().creationTime().get();
Instant creation = wallet.getKeyChainSeed().getCreationTime().get();
assertEquals(testWalletCreation, creation, "unexpected creation timestamp");
String mnemonic = wallet.getKeyChainSeed().getMnemonicString();

View file

@ -88,7 +88,7 @@ public class WalletSettingsController implements OverlayController<WalletSetting
}
// Set the date picker to show the birthday of this wallet.
Instant creationTime = seed.creationTime().get();
Instant creationTime = seed.getCreationTime().get();
LocalDate origDate = creationTime.atZone(ZoneId.systemDefault()).toLocalDate();
datePicker.setValue(origDate);