Permalink
Browse files

Wallet-Tool: New action to modify the creation time of wallets.

This is useful for repairing wallets that accidently have been created "in the future".
  • Loading branch information...
1 parent 3966f42 commit 79d6716120efbafe4604c9d5a649eadb1944ae3a @schildbach schildbach committed Nov 8, 2015
@@ -48,7 +48,7 @@
@Nullable private final List<String> mnemonicCode; // only one of mnemonicCode/encryptedMnemonicCode will be set
@Nullable private final EncryptedData encryptedMnemonicCode;
@Nullable private EncryptedData encryptedSeed;
- private final long creationTimeSeconds;
+ private long creationTimeSeconds;
public DeterministicSeed(String mnemonicCode, byte[] seed, String passphrase, long creationTimeSeconds) throws UnreadableWalletException {
this(decodeMnemonicCode(mnemonicCode), seed, passphrase, creationTimeSeconds);
@@ -175,6 +175,10 @@ public long getCreationTimeSeconds() {
return creationTimeSeconds;
}
+ public void setCreationTimeSeconds(long creationTimeSeconds) {
+ this.creationTimeSeconds = creationTimeSeconds;
+ }
+
public DeterministicSeed encrypt(KeyCrypter keyCrypter, KeyParameter aesKey) {
checkState(encryptedMnemonicCode == null, "Trying to encrypt seed twice");
checkState(mnemonicCode != null, "Mnemonic missing so cannot encrypt");
@@ -177,6 +177,7 @@ public boolean matchBitcoins(Coin comparison) {
DECRYPT,
MARRY,
ROTATE,
+ SET_CREATION_TIME,
}
public enum WaitForEnum {
@@ -369,6 +370,7 @@ public static void main(String[] args) throws Exception {
case DECRYPT: decrypt(); break;
case MARRY: marry(); break;
case ROTATE: rotate(); break;
+ case SET_CREATION_TIME: setCreationTime(); break;
}
if (!wallet.isConsistent()) {
@@ -1084,4 +1086,18 @@ private static void dumpWallet() throws BlockStoreException {
setup();
System.out.println(wallet.toString(options.has("dump-privkeys"), true, true, chain));
}
+
+ private static void setCreationTime() {
+ DeterministicSeed seed = wallet.getActiveKeyChain().getSeed();
+ if (seed == null) {
+ System.err.println("Active chain does not have a seed.");
+ return;
+ }
+ long creationTime = getCreationTimeSeconds();
+ if (creationTime > 0)
+ System.out.println("Setting creation time to: " + Utils.dateTimeFormat(creationTime * 1000));
+ else
+ System.out.println("Clearing creation time.");
+ seed.setCreationTimeSeconds(creationTime);
+ }
}
@@ -56,6 +56,12 @@ Usage: wallet-tool --flags action-name
created before this date will be re-spent to a key (from an HD tree) that was created after it.
If --date is missing, the current time is assumed. If the time covers all keys, a new HD tree
will be created from a new random seed.
+ set-creation-time Modify the creation time of the active chain of this wallet. This is useful for repairing
+ wallets that accidently have been created "in the future". Currently, watching wallets are not
+ supported.
+ If --date is specified, that's the creation date.
+ If --unixtime is specified, that's the creation time and it overrides --date.
+ If you omit both options, the creation time is being cleared (set to 0).
>>> GENERAL OPTIONS
--debuglog Enables logging from the core library.

0 comments on commit 79d6716

Please sign in to comment.