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".
This commit is contained in:
Andreas Schildbach 2015-11-08 12:19:46 +01:00
parent 3966f424a0
commit 79d6716120
3 changed files with 27 additions and 1 deletions

View File

@ -48,7 +48,7 @@ public class DeterministicSeed implements EncryptableItem {
@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 class DeterministicSeed implements EncryptableItem {
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");

View File

@ -177,6 +177,7 @@ public class WalletTool {
DECRYPT,
MARRY,
ROTATE,
SET_CREATION_TIME,
}
public enum WaitForEnum {
@ -369,6 +370,7 @@ public class WalletTool {
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 @@ public class WalletTool {
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);
}
}

View File

@ -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.