KeyChainGroup: Introduce concept of multiple active keychains.

The newest/last active keychain is the default. Almost all of this class only works on the default active keychain.
All other active keychains are meant as fallback for if a sender doesn't understand a certain new script type.
New P2WPKH KeyChainGroups are created with a P2PKH fallback chain. This will likely go away in future as P2WPKH
and Bech32 are becoming the norm.
This commit is contained in:
Andreas Schildbach
2019-02-08 16:13:33 +01:00
parent 16b53836b8
commit 3c73f5e8a1
5 changed files with 152 additions and 22 deletions

View File

@@ -33,6 +33,7 @@ import org.bitcoinj.store.*;
import org.bitcoinj.uri.BitcoinURI;
import org.bitcoinj.uri.BitcoinURIParseException;
import org.bitcoinj.utils.BriefLogFormatter;
import org.bitcoinj.wallet.DeterministicKeyChain;
import org.bitcoinj.wallet.DeterministicSeed;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;
@@ -1514,17 +1515,18 @@ public class WalletTool {
}
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();
for (DeterministicKeyChain chain : wallet.getActiveKeyChains()) {
DeterministicSeed seed = chain.getSeed();
if (seed == null)
System.out.println("Active chain does not have a seed: " + chain);
else
seed.setCreationTimeSeconds(creationTime);
}
if (creationTime > 0)
System.out.println("Setting creation time to: " + Utils.dateTimeFormat(creationTime * 1000));
else
System.out.println("Clearing creation time.");
seed.setCreationTimeSeconds(creationTime);
}
static synchronized void onChange(final CountDownLatch latch) {

View File

@@ -61,7 +61,7 @@ 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
set-creation-time Modify the creation time of the active chains 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.