mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-13 10:45:51 +00:00
Context: add some more TODOs.
WalletAppKit: propagate context.
This commit is contained in:
parent
d03b68a109
commit
e3f70c6d4f
@ -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: 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: 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: 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.
|
// 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
|
* <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>
|
* 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.
|
// 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;
|
Context context;
|
||||||
try {
|
try {
|
||||||
context = get();
|
context = get();
|
||||||
|
@ -84,8 +84,15 @@ public class WalletAppKit extends AbstractIdleService {
|
|||||||
@Nullable protected DeterministicSeed restoreFromSeed;
|
@Nullable protected DeterministicSeed restoreFromSeed;
|
||||||
@Nullable protected PeerDiscovery discovery;
|
@Nullable protected PeerDiscovery discovery;
|
||||||
|
|
||||||
|
protected volatile Context context;
|
||||||
|
|
||||||
public WalletAppKit(NetworkParameters params, File directory, String filePrefix) {
|
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.directory = checkNotNull(directory);
|
||||||
this.filePrefix = checkNotNull(filePrefix);
|
this.filePrefix = checkNotNull(filePrefix);
|
||||||
if (!Utils.isAndroidRuntime()) {
|
if (!Utils.isAndroidRuntime()) {
|
||||||
@ -241,6 +248,7 @@ public class WalletAppKit extends AbstractIdleService {
|
|||||||
@Override
|
@Override
|
||||||
protected void startUp() throws Exception {
|
protected void startUp() throws Exception {
|
||||||
// Runs in a separate thread.
|
// Runs in a separate thread.
|
||||||
|
Context.propagate(context);
|
||||||
if (!directory.exists()) {
|
if (!directory.exists()) {
|
||||||
if (!directory.mkdirs()) {
|
if (!directory.mkdirs()) {
|
||||||
throw new IOException("Could not create directory " + directory.getAbsolutePath());
|
throw new IOException("Could not create directory " + directory.getAbsolutePath());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user