Skip to content

Commit

Permalink
Wallet-Tool: New action to modify the creation time of wallets.
Browse files Browse the repository at this point in the history
This is useful for repairing wallets that accidently have been created "in the future".
  • Loading branch information
schildbach committed Nov 27, 2015
1 parent 3966f42 commit 79d6716
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down
16 changes: 16 additions & 0 deletions tools/src/main/java/org/bitcoinj/tools/WalletTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ public enum ActionEnum {
DECRYPT,
MARRY,
ROTATE,
SET_CREATION_TIME,
}

public enum WaitForEnum {
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 79d6716

Please sign in to comment.