Context: add some more TODOs.

WalletAppKit: propagate context.
This commit is contained in:
Mike Hearn 2015-03-03 09:38:44 -08:00
parent d03b68a109
commit e3f70c6d4f
2 changed files with 13 additions and 2 deletions

View File

@ -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.
/**
* <p>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()}.</p>
@ -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();

View File

@ -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());