public class Context
extends java.lang.Object
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 get()
.
Context is new in 0.13 and the library is currently in a transitional period: you should create a Context that wraps your chosen network parameters before using the rest of the library. However if you don't, things will still work as a Context will be created for you and stashed in thread local storage. The context is then propagated between library created threads as needed. This automagical propagation and creation is a temporary mechanism: one day it will be removed to avoid confusing edge cases that could occur if the developer does not fully understand it e.g. in the case where multiple instances of the library are in use simultaneously.
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_EVENT_HORIZON |
Constructor and Description |
---|
Context(NetworkParameters params)
Creates a new context object.
|
Context(NetworkParameters params,
int eventHorizon,
Coin feePerKb,
boolean ensureMinRequiredFee)
Creates a new custom context object.
|
Modifier and Type | Method and Description |
---|---|
static void |
enableStrictMode()
Require that new threads use
propagate(Context) or ContextPropagatingThreadFactory ,
rather than using a heuristic for the desired context. |
static Context |
get()
Returns the current context that is associated with the calling thread.
|
TxConfidenceTable |
getConfidenceTable()
Returns the
TxConfidenceTable created by this context. |
int |
getEventHorizon()
The event horizon is the number of blocks after which various bits of the library consider a transaction to be
so confirmed that it's safe to delete data.
|
Coin |
getFeePerKb()
The default fee per 1000 virtual bytes of transaction data to pay when completing transactions.
|
static Context |
getOrCreate(NetworkParameters params) |
NetworkParameters |
getParams()
Returns the
NetworkParameters specified when this context was (auto) created. |
boolean |
isEnsureMinRequiredFee()
Whether to ensure the minimum required fee by default when completing transactions.
|
static void |
propagate(Context context)
Sets the given context as the current thread context.
|
public static final int DEFAULT_EVENT_HORIZON
public Context(NetworkParameters params)
params
- The network parameters that will be associated with this context.public Context(NetworkParameters params, int eventHorizon, Coin feePerKb, boolean ensureMinRequiredFee)
params
- The network parameters that will be associated with this context.eventHorizon
- Number of blocks after which the library will delete data and be unable to always process reorgs. See getEventHorizon()
.feePerKb
- The default fee per 1000 virtual bytes of transaction data to pay when completing transactions. For details, see SendRequest.feePerKb
.ensureMinRequiredFee
- Whether to ensure the minimum required fee by default when completing transactions. For details, see SendRequest.ensureMinRequiredFee
.public static Context get()
java.lang.IllegalStateException
- if no context exists at all or if we are in strict mode and there is no context.public static void enableStrictMode()
propagate(Context)
or ContextPropagatingThreadFactory
,
rather than using a heuristic for the desired context.public static Context getOrCreate(NetworkParameters params)
public static void propagate(Context context)
ContextPropagatingThreadFactory
.public TxConfidenceTable getConfidenceTable()
TxConfidenceTable
created by this context. The pool tracks advertised
and downloaded transactions so their confidence can be measured as a proportion of how many peers announced it.
With an un-tampered with internet connection, the more peers announce a transaction the more confidence you can
have that it's really valid.public NetworkParameters getParams()
NetworkParameters
specified when this context was (auto) created. The
network parameters defines various hard coded constants for a specific instance of a Bitcoin network, such as
main net, testnet, etc.public int getEventHorizon()
public Coin getFeePerKb()
SendRequest.feePerKb
.public boolean isEnsureMinRequiredFee()
SendRequest.ensureMinRequiredFee
.