From e3f70c6d4f7aee475fe278d6b2b8070f28600db5 Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Tue, 3 Mar 2015 09:38:44 -0800 Subject: [PATCH] Context: add some more TODOs. WalletAppKit: propagate context. --- core/src/main/java/org/bitcoinj/core/Context.java | 5 ++++- core/src/main/java/org/bitcoinj/kits/WalletAppKit.java | 10 +++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/bitcoinj/core/Context.java b/core/src/main/java/org/bitcoinj/core/Context.java index cb5f5b1ea..92d91781b 100644 --- a/core/src/main/java/org/bitcoinj/core/Context.java +++ b/core/src/main/java/org/bitcoinj/core/Context.java @@ -8,8 +8,11 @@ import static com.google.common.base.Preconditions.checkState; // TODO: Finish adding Context c'tors to all the different objects so we can start deprecating the versions that take NetworkParameters. // TODO: Add a working directory notion to Context and make various subsystems that want to use files default to that directory (eg. Orchid, block stores, wallet, etc). // TODO: Auto-register the block chain object here, and then use it in the (newly deprecated) TransactionConfidence.getDepthInBlocks() method: the new version should take an AbstractBlockChain specifically. +// TODO: Move Threading.USER_THREAD to here and leave behind just a source code stub. Allow different instantiations of the library to use different user threads. +// TODO: Keep a URI to where library internal data files can be found, to abstract over the lack of JAR files on Android. // TODO: Stash anything else that resembles global library configuration in here and use it to clean up the rest of the API without breaking people. + /** *

The Context object holds various objects and pieces of configuration that are scoped to a specific instantiation of * bitcoinj for a specific network. You can get an instance of this class through calling {@link #get()}.

@@ -86,7 +89,7 @@ public class Context { } // A temporary internal shim designed to help us migrate internally in a way that doesn't wreck source compatibility. - static Context getOrCreate(NetworkParameters params) { + public static Context getOrCreate(NetworkParameters params) { Context context; try { context = get(); diff --git a/core/src/main/java/org/bitcoinj/kits/WalletAppKit.java b/core/src/main/java/org/bitcoinj/kits/WalletAppKit.java index ccf82aeea..2fc47601f 100644 --- a/core/src/main/java/org/bitcoinj/kits/WalletAppKit.java +++ b/core/src/main/java/org/bitcoinj/kits/WalletAppKit.java @@ -84,8 +84,15 @@ public class WalletAppKit extends AbstractIdleService { @Nullable protected DeterministicSeed restoreFromSeed; @Nullable protected PeerDiscovery discovery; + protected volatile Context context; + public WalletAppKit(NetworkParameters params, File directory, String filePrefix) { - this.params = checkNotNull(params); + this(Context.getOrCreate(params), directory, filePrefix); + } + + public WalletAppKit(Context context, File directory, String filePrefix) { + this.context = context; + this.params = checkNotNull(context.getParams()); this.directory = checkNotNull(directory); this.filePrefix = checkNotNull(filePrefix); if (!Utils.isAndroidRuntime()) { @@ -241,6 +248,7 @@ public class WalletAppKit extends AbstractIdleService { @Override protected void startUp() throws Exception { // Runs in a separate thread. + Context.propagate(context); if (!directory.exists()) { if (!directory.mkdirs()) { throw new IOException("Could not create directory " + directory.getAbsolutePath());