mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-02-21 22:11:52 +01:00
Context: remove network parameters
This is the first step in the goal of making Context optional again, using it only for configuration of a test environment.
This commit is contained in:
parent
4098995a3c
commit
fb90c4458d
25 changed files with 57 additions and 195 deletions
|
@ -167,22 +167,10 @@ public abstract class AbstractBlockChain {
|
||||||
*/
|
*/
|
||||||
public AbstractBlockChain(NetworkParameters params, List<? extends Wallet> wallets,
|
public AbstractBlockChain(NetworkParameters params, List<? extends Wallet> wallets,
|
||||||
BlockStore blockStore) throws BlockStoreException {
|
BlockStore blockStore) throws BlockStoreException {
|
||||||
this(Context.getOrCreate(params), wallets, blockStore);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a BlockChain connected to the given list of listeners (wallets) and a store.
|
|
||||||
* @param context context for this network
|
|
||||||
* @param wallets list of listeners (wallets)
|
|
||||||
* @param blockStore where to store blocks
|
|
||||||
* @throws BlockStoreException if a failure occurs while storing a block
|
|
||||||
*/
|
|
||||||
public AbstractBlockChain(Context context, List<? extends Wallet> wallets,
|
|
||||||
BlockStore blockStore) throws BlockStoreException {
|
|
||||||
this.blockStore = blockStore;
|
this.blockStore = blockStore;
|
||||||
chainHead = blockStore.getChainHead();
|
chainHead = blockStore.getChainHead();
|
||||||
log.info("chain head is at height {}:\n{}", chainHead.getHeight(), chainHead.getHeader());
|
log.info("chain head is at height {}:\n{}", chainHead.getHeight(), chainHead.getHeader());
|
||||||
this.params = context.getParams();
|
this.params = params;
|
||||||
|
|
||||||
this.newBestBlockListeners = new CopyOnWriteArrayList<>();
|
this.newBestBlockListeners = new CopyOnWriteArrayList<>();
|
||||||
this.reorganizeListeners = new CopyOnWriteArrayList<>();
|
this.reorganizeListeners = new CopyOnWriteArrayList<>();
|
||||||
|
@ -191,7 +179,7 @@ public abstract class AbstractBlockChain {
|
||||||
for (ReorganizeListener l : wallets) addReorganizeListener(Threading.SAME_THREAD, l);
|
for (ReorganizeListener l : wallets) addReorganizeListener(Threading.SAME_THREAD, l);
|
||||||
for (TransactionReceivedInBlockListener l : wallets) addTransactionReceivedListener(Threading.SAME_THREAD, l);
|
for (TransactionReceivedInBlockListener l : wallets) addTransactionReceivedListener(Threading.SAME_THREAD, l);
|
||||||
|
|
||||||
this.versionTally = new VersionTally(context.getParams());
|
this.versionTally = new VersionTally(params);
|
||||||
this.versionTally.initialize(blockStore, chainHead);
|
this.versionTally.initialize(blockStore, chainHead);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,25 +51,15 @@ public class BlockChain extends AbstractBlockChain {
|
||||||
* {@link MemoryBlockStore} if you want to hold all headers in RAM and don't care about
|
* {@link MemoryBlockStore} if you want to hold all headers in RAM and don't care about
|
||||||
* disk serialization (this is rare).</p>
|
* disk serialization (this is rare).</p>
|
||||||
*/
|
*/
|
||||||
public BlockChain(Context context, Wallet wallet, BlockStore blockStore) throws BlockStoreException {
|
|
||||||
this(context, new ArrayList<Wallet>(), blockStore);
|
|
||||||
addWallet(wallet);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** See {@link #BlockChain(Context, Wallet, BlockStore)}} */
|
|
||||||
public BlockChain(NetworkParameters params, Wallet wallet, BlockStore blockStore) throws BlockStoreException {
|
public BlockChain(NetworkParameters params, Wallet wallet, BlockStore blockStore) throws BlockStoreException {
|
||||||
this(Context.getOrCreate(params), wallet, blockStore);
|
this(params, new ArrayList<Wallet>(), blockStore);
|
||||||
|
addWallet(wallet);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a BlockChain that has no wallet at all. This is helpful when you don't actually care about sending
|
* Constructs a BlockChain that has no wallet at all. This is helpful when you don't actually care about sending
|
||||||
* and receiving coins but rather, just want to explore the network data structures.
|
* and receiving coins but rather, just want to explore the network data structures.
|
||||||
*/
|
*/
|
||||||
public BlockChain(Context context, BlockStore blockStore) throws BlockStoreException {
|
|
||||||
this(context, new ArrayList<Wallet>(), blockStore);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** See {@link #BlockChain(Context, BlockStore)} */
|
|
||||||
public BlockChain(NetworkParameters params, BlockStore blockStore) throws BlockStoreException {
|
public BlockChain(NetworkParameters params, BlockStore blockStore) throws BlockStoreException {
|
||||||
this(params, new ArrayList<Wallet>(), blockStore);
|
this(params, new ArrayList<Wallet>(), blockStore);
|
||||||
}
|
}
|
||||||
|
@ -77,16 +67,11 @@ public class BlockChain extends AbstractBlockChain {
|
||||||
/**
|
/**
|
||||||
* Constructs a BlockChain connected to the given list of listeners and a store.
|
* Constructs a BlockChain connected to the given list of listeners and a store.
|
||||||
*/
|
*/
|
||||||
public BlockChain(Context params, List<? extends Wallet> wallets, BlockStore blockStore) throws BlockStoreException {
|
public BlockChain(NetworkParameters params, List<? extends Wallet> wallets, BlockStore blockStore) throws BlockStoreException {
|
||||||
super(params, wallets, blockStore);
|
super(params, wallets, blockStore);
|
||||||
this.blockStore = blockStore;
|
this.blockStore = blockStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** See {@link #BlockChain(Context, List, BlockStore)} */
|
|
||||||
public BlockChain(NetworkParameters params, List<? extends Wallet> wallets, BlockStore blockStore) throws BlockStoreException {
|
|
||||||
this(Context.getOrCreate(params), wallets, blockStore);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected StoredBlock addToBlockStore(StoredBlock storedPrev, Block blockHeader, TransactionOutputChanges txOutChanges)
|
protected StoredBlock addToBlockStore(StoredBlock storedPrev, Block blockHeader, TransactionOutputChanges txOutChanges)
|
||||||
throws BlockStoreException, VerificationException {
|
throws BlockStoreException, VerificationException {
|
||||||
|
|
|
@ -89,8 +89,8 @@ public class CheckpointManager {
|
||||||
public static final BaseEncoding BASE64 = BaseEncoding.base64().omitPadding();
|
public static final BaseEncoding BASE64 = BaseEncoding.base64().omitPadding();
|
||||||
|
|
||||||
/** Loads the default checkpoints bundled with bitcoinj */
|
/** Loads the default checkpoints bundled with bitcoinj */
|
||||||
public CheckpointManager(Context context) throws IOException {
|
public CheckpointManager(NetworkParameters params) throws IOException {
|
||||||
this(context.getParams(), null);
|
this(params, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Loads the checkpoints from the given stream */
|
/** Loads the checkpoints from the given stream */
|
||||||
|
|
|
@ -49,7 +49,6 @@ public class Context {
|
||||||
public static final int DEFAULT_EVENT_HORIZON = 100;
|
public static final int DEFAULT_EVENT_HORIZON = 100;
|
||||||
|
|
||||||
final private TxConfidenceTable confidenceTable;
|
final private TxConfidenceTable confidenceTable;
|
||||||
final private NetworkParameters params;
|
|
||||||
final private int eventHorizon;
|
final private int eventHorizon;
|
||||||
final private boolean ensureMinRequiredFee;
|
final private boolean ensureMinRequiredFee;
|
||||||
final private Coin feePerKb;
|
final private Coin feePerKb;
|
||||||
|
@ -57,25 +56,21 @@ public class Context {
|
||||||
/**
|
/**
|
||||||
* Creates a new context object. For now, this will be done for you by the framework. Eventually you will be
|
* Creates a new context object. For now, this will be done for you by the framework. Eventually you will be
|
||||||
* expected to do this yourself in the same manner as fetching a NetworkParameters object (at the start of your app).
|
* expected to do this yourself in the same manner as fetching a NetworkParameters object (at the start of your app).
|
||||||
*
|
|
||||||
* @param params The network parameters that will be associated with this context.
|
|
||||||
*/
|
*/
|
||||||
public Context(NetworkParameters params) {
|
public Context() {
|
||||||
this(params, DEFAULT_EVENT_HORIZON, Transaction.DEFAULT_TX_FEE, true);
|
this(DEFAULT_EVENT_HORIZON, Transaction.DEFAULT_TX_FEE, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new custom context object. This is mainly meant for unit tests for now.
|
* Creates a new custom context object. This is mainly meant for unit tests for now.
|
||||||
*
|
*
|
||||||
* @param params The network parameters that will be associated with this context.
|
|
||||||
* @param eventHorizon Number of blocks after which the library will delete data and be unable to always process reorgs. See {@link #getEventHorizon()}.
|
* @param eventHorizon Number of blocks after which the library will delete data and be unable to always process reorgs. See {@link #getEventHorizon()}.
|
||||||
* @param feePerKb The default fee per 1000 virtual bytes of transaction data to pay when completing transactions. For details, see {@link SendRequest#feePerKb}.
|
* @param feePerKb The default fee per 1000 virtual bytes of transaction data to pay when completing transactions. For details, see {@link SendRequest#feePerKb}.
|
||||||
* @param ensureMinRequiredFee Whether to ensure the minimum required fee by default when completing transactions. For details, see {@link SendRequest#ensureMinRequiredFee}.
|
* @param ensureMinRequiredFee Whether to ensure the minimum required fee by default when completing transactions. For details, see {@link SendRequest#ensureMinRequiredFee}.
|
||||||
*/
|
*/
|
||||||
public Context(NetworkParameters params, int eventHorizon, Coin feePerKb, boolean ensureMinRequiredFee) {
|
public Context(int eventHorizon, Coin feePerKb, boolean ensureMinRequiredFee) {
|
||||||
log.info("Creating bitcoinj {} context.", VersionMessage.BITCOINJ_VERSION);
|
log.info("Creating bitcoinj {} context.", VersionMessage.BITCOINJ_VERSION);
|
||||||
this.confidenceTable = new TxConfidenceTable();
|
this.confidenceTable = new TxConfidenceTable();
|
||||||
this.params = params;
|
|
||||||
this.eventHorizon = eventHorizon;
|
this.eventHorizon = eventHorizon;
|
||||||
this.ensureMinRequiredFee = ensureMinRequiredFee;
|
this.ensureMinRequiredFee = ensureMinRequiredFee;
|
||||||
this.feePerKb = feePerKb;
|
this.feePerKb = feePerKb;
|
||||||
|
@ -129,17 +124,15 @@ 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.
|
||||||
public static Context getOrCreate(NetworkParameters params) {
|
public static Context getOrCreate() {
|
||||||
Context context;
|
Context context;
|
||||||
try {
|
try {
|
||||||
context = get();
|
context = get();
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalStateException e) {
|
||||||
log.warn("Implicitly creating context. This is a migration step and this message will eventually go away.");
|
log.warn("Implicitly creating context. This is a migration step and this message will eventually go away.");
|
||||||
context = new Context(params);
|
context = new Context();
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
if (context.getParams() != params)
|
|
||||||
throw new IllegalStateException("Context does not match implicit network params: " + context.getParams() + " vs " + params);
|
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,15 +156,6 @@ public class Context {
|
||||||
return confidenceTable;
|
return confidenceTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the {@link 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 NetworkParameters getParams() {
|
|
||||||
return params;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The event horizon is the number of blocks after which various bits of the library consider a transaction to be
|
* 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. Re-orgs larger than the event horizon will not be correctly
|
* so confirmed that it's safe to delete data. Re-orgs larger than the event horizon will not be correctly
|
||||||
|
|
|
@ -66,57 +66,34 @@ public class FullPrunedBlockChain extends AbstractBlockChain {
|
||||||
// Whether or not to execute scriptPubKeys before accepting a transaction (i.e. check signatures).
|
// Whether or not to execute scriptPubKeys before accepting a transaction (i.e. check signatures).
|
||||||
private boolean runScripts = true;
|
private boolean runScripts = true;
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a block chain connected to the given wallet and store. To obtain a {@link Wallet} you can construct
|
|
||||||
* one from scratch, or you can deserialize a saved wallet from disk using
|
|
||||||
* {@link Wallet#loadFromFile(File, WalletExtension...)}
|
|
||||||
*/
|
|
||||||
public FullPrunedBlockChain(Context context, Wallet wallet, FullPrunedBlockStore blockStore) throws BlockStoreException {
|
|
||||||
this(context, new ArrayList<Wallet>(), blockStore);
|
|
||||||
addWallet(wallet);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a block chain connected to the given wallet and store. To obtain a {@link Wallet} you can construct
|
* Constructs a block chain connected to the given wallet and store. To obtain a {@link Wallet} you can construct
|
||||||
* one from scratch, or you can deserialize a saved wallet from disk using
|
* one from scratch, or you can deserialize a saved wallet from disk using
|
||||||
* {@link Wallet#loadFromFile(File, WalletExtension...)}
|
* {@link Wallet#loadFromFile(File, WalletExtension...)}
|
||||||
*/
|
*/
|
||||||
public FullPrunedBlockChain(NetworkParameters params, Wallet wallet, FullPrunedBlockStore blockStore) throws BlockStoreException {
|
public FullPrunedBlockChain(NetworkParameters params, Wallet wallet, FullPrunedBlockStore blockStore) throws BlockStoreException {
|
||||||
this(Context.getOrCreate(params), wallet, blockStore);
|
this(params, new ArrayList<Wallet>(), blockStore);
|
||||||
|
addWallet(wallet);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a block chain connected to the given store.
|
* Constructs a block chain connected to the given store.
|
||||||
*/
|
*/
|
||||||
public FullPrunedBlockChain(Context context, FullPrunedBlockStore blockStore) throws BlockStoreException {
|
|
||||||
this(context, new ArrayList<Wallet>(), blockStore);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* See {@link #FullPrunedBlockChain(Context, Wallet, FullPrunedBlockStore)}
|
|
||||||
*/
|
|
||||||
public FullPrunedBlockChain(NetworkParameters params, FullPrunedBlockStore blockStore) throws BlockStoreException {
|
public FullPrunedBlockChain(NetworkParameters params, FullPrunedBlockStore blockStore) throws BlockStoreException {
|
||||||
this(Context.getOrCreate(params), blockStore);
|
this(params, new ArrayList<Wallet>(), blockStore);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a block chain connected to the given list of wallets and a store.
|
* Constructs a block chain connected to the given list of wallets and a store.
|
||||||
*/
|
*/
|
||||||
public FullPrunedBlockChain(Context context, List<Wallet> listeners, FullPrunedBlockStore blockStore) throws BlockStoreException {
|
public FullPrunedBlockChain(NetworkParameters params, List<Wallet> listeners,
|
||||||
super(context, listeners, blockStore);
|
FullPrunedBlockStore blockStore) throws BlockStoreException {
|
||||||
|
super(params, listeners, blockStore);
|
||||||
this.blockStore = blockStore;
|
this.blockStore = blockStore;
|
||||||
// Ignore upgrading for now
|
// Ignore upgrading for now
|
||||||
this.chainHead = blockStore.getVerifiedChainHead();
|
this.chainHead = blockStore.getVerifiedChainHead();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* See {@link #FullPrunedBlockChain(Context, List, FullPrunedBlockStore)}
|
|
||||||
*/
|
|
||||||
public FullPrunedBlockChain(NetworkParameters params, List<Wallet> listeners,
|
|
||||||
FullPrunedBlockStore blockStore) throws BlockStoreException {
|
|
||||||
this(Context.getOrCreate(params), listeners, blockStore);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected StoredBlock addToBlockStore(StoredBlock storedPrev, Block header, TransactionOutputChanges txOutChanges)
|
protected StoredBlock addToBlockStore(StoredBlock storedPrev, Block header, TransactionOutputChanges txOutChanges)
|
||||||
throws BlockStoreException, VerificationException {
|
throws BlockStoreException, VerificationException {
|
||||||
|
|
|
@ -329,45 +329,30 @@ public class PeerGroup implements TransactionBroadcaster {
|
||||||
/** Whether bloom filter support is enabled when using a non FullPrunedBlockchain*/
|
/** Whether bloom filter support is enabled when using a non FullPrunedBlockchain*/
|
||||||
private volatile boolean vBloomFilteringEnabled = true;
|
private volatile boolean vBloomFilteringEnabled = true;
|
||||||
|
|
||||||
/** See {@link #PeerGroup(Context)} */
|
/**
|
||||||
|
* Creates a PeerGroup with the given network. No chain is provided so this node will report its chain height
|
||||||
|
* as zero to other peers. This constructor is useful if you just want to explore the network but aren't interested
|
||||||
|
* in downloading block data.
|
||||||
|
*/
|
||||||
public PeerGroup(NetworkParameters params) {
|
public PeerGroup(NetworkParameters params) {
|
||||||
this(params, null);
|
this(params, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a PeerGroup with the given context. No chain is provided so this node will report its chain height
|
* Creates a PeerGroup for the given network and chain. Blocks will be passed to the chain as they are broadcast
|
||||||
* as zero to other peers. This constructor is useful if you just want to explore the network but aren't interested
|
|
||||||
* in downloading block data.
|
|
||||||
*/
|
|
||||||
public PeerGroup(Context context) {
|
|
||||||
this(context, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** See {@link #PeerGroup(Context, AbstractBlockChain)} */
|
|
||||||
public PeerGroup(NetworkParameters params, @Nullable AbstractBlockChain chain) {
|
|
||||||
this(Context.getOrCreate(params), chain, new NioClientManager());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a PeerGroup for the given context and chain. Blocks will be passed to the chain as they are broadcast
|
|
||||||
* and downloaded. This is probably the constructor you want to use.
|
* and downloaded. This is probably the constructor you want to use.
|
||||||
*/
|
*/
|
||||||
public PeerGroup(Context context, @Nullable AbstractBlockChain chain) {
|
public PeerGroup(NetworkParameters params, @Nullable AbstractBlockChain chain) {
|
||||||
this(context, chain, new NioClientManager());
|
this(params, chain, new NioClientManager());
|
||||||
}
|
|
||||||
|
|
||||||
/** See {@link #PeerGroup(Context, AbstractBlockChain, ClientConnectionManager)} */
|
|
||||||
public PeerGroup(NetworkParameters params, @Nullable AbstractBlockChain chain, ClientConnectionManager connectionManager) {
|
|
||||||
this(Context.getOrCreate(params), chain, connectionManager);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new PeerGroup allowing you to specify the {@link ClientConnectionManager} which is used to create new
|
* Creates a new PeerGroup allowing you to specify the {@link ClientConnectionManager} which is used to create new
|
||||||
* connections and keep track of existing ones.
|
* connections and keep track of existing ones.
|
||||||
*/
|
*/
|
||||||
private PeerGroup(Context context, @Nullable AbstractBlockChain chain, ClientConnectionManager connectionManager) {
|
protected PeerGroup(NetworkParameters params, @Nullable AbstractBlockChain chain, ClientConnectionManager connectionManager) {
|
||||||
checkNotNull(context);
|
checkNotNull(params);
|
||||||
this.params = context.getParams();
|
this.params = params;
|
||||||
this.chain = chain;
|
this.chain = chain;
|
||||||
fastCatchupTimeSecs = params.getGenesisBlock().getTimeSeconds();
|
fastCatchupTimeSecs = params.getGenesisBlock().getTimeSeconds();
|
||||||
wallets = new CopyOnWriteArrayList<>();
|
wallets = new CopyOnWriteArrayList<>();
|
||||||
|
|
|
@ -110,8 +110,6 @@ public class WalletAppKit extends AbstractIdleService {
|
||||||
@Nullable protected DeterministicKey restoreFromKey;
|
@Nullable protected DeterministicKey restoreFromKey;
|
||||||
@Nullable protected PeerDiscovery discovery;
|
@Nullable protected PeerDiscovery discovery;
|
||||||
|
|
||||||
protected volatile Context context;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new WalletAppKit, with a newly created {@link Context}. Files will be stored in the given directory.
|
* Creates a new WalletAppKit, with a newly created {@link Context}. Files will be stored in the given directory.
|
||||||
* @deprecated Use {@link #WalletAppKit(BitcoinNetwork, ScriptType, KeyChainGroupStructure, File, String)}
|
* @deprecated Use {@link #WalletAppKit(BitcoinNetwork, ScriptType, KeyChainGroupStructure, File, String)}
|
||||||
|
@ -144,29 +142,12 @@ public class WalletAppKit extends AbstractIdleService {
|
||||||
KeyChainGroupStructure structure, File directory, String filePrefix) {
|
KeyChainGroupStructure structure, File directory, String filePrefix) {
|
||||||
this.network = checkNotNull(network);
|
this.network = checkNotNull(network);
|
||||||
this.params = NetworkParameters.of(this.network);
|
this.params = NetworkParameters.of(this.network);
|
||||||
this.context = new Context(params);
|
|
||||||
this.preferredOutputScriptType = checkNotNull(preferredOutputScriptType);
|
this.preferredOutputScriptType = checkNotNull(preferredOutputScriptType);
|
||||||
this.structure = checkNotNull(structure);
|
this.structure = checkNotNull(structure);
|
||||||
this.directory = checkNotNull(directory);
|
this.directory = checkNotNull(directory);
|
||||||
this.filePrefix = checkNotNull(filePrefix);
|
this.filePrefix = checkNotNull(filePrefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new WalletAppKit, with the given {@link Context}. Files will be stored in the given directory.
|
|
||||||
* @deprecated Use {@link #WalletAppKit(BitcoinNetwork, ScriptType, KeyChainGroupStructure, File, String)}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public WalletAppKit(Context context, ScriptType preferredOutputScriptType,
|
|
||||||
@Nullable KeyChainGroupStructure structure, File directory, String filePrefix) {
|
|
||||||
this.context = context;
|
|
||||||
this.params = checkNotNull(context.getParams());
|
|
||||||
this.network = params.network();
|
|
||||||
this.preferredOutputScriptType = checkNotNull(preferredOutputScriptType);
|
|
||||||
this.structure = structure != null ? structure : KeyChainGroupStructure.BIP32;
|
|
||||||
this.directory = checkNotNull(directory);
|
|
||||||
this.filePrefix = checkNotNull(filePrefix);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Will only connect to the given addresses. Cannot be called after startup. */
|
/** Will only connect to the given addresses. Cannot be called after startup. */
|
||||||
public WalletAppKit setPeerNodes(PeerAddress... addresses) {
|
public WalletAppKit setPeerNodes(PeerAddress... addresses) {
|
||||||
checkState(state() == State.NEW, "Cannot call after startup");
|
checkState(state() == State.NEW, "Cannot call after startup");
|
||||||
|
@ -331,7 +312,6 @@ 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());
|
||||||
|
@ -507,7 +487,6 @@ public class WalletAppKit extends AbstractIdleService {
|
||||||
protected void shutDown() throws Exception {
|
protected void shutDown() throws Exception {
|
||||||
// Runs in a separate thread.
|
// Runs in a separate thread.
|
||||||
try {
|
try {
|
||||||
Context.propagate(context);
|
|
||||||
vPeerGroup.stop();
|
vPeerGroup.stop();
|
||||||
vWallet.saveToFile(vWalletFile);
|
vWallet.saveToFile(vWalletFile);
|
||||||
vStore.close();
|
vStore.close();
|
||||||
|
|
|
@ -233,7 +233,6 @@ public class Wallet extends BaseTaggableObject
|
||||||
// A list of scripts watched by this wallet.
|
// A list of scripts watched by this wallet.
|
||||||
@GuardedBy("keyChainGroupLock") private final Set<Script> watchedScripts;
|
@GuardedBy("keyChainGroupLock") private final Set<Script> watchedScripts;
|
||||||
|
|
||||||
protected final Context context;
|
|
||||||
protected final NetworkParameters params;
|
protected final NetworkParameters params;
|
||||||
|
|
||||||
@Nullable private Sha256Hash lastBlockSeenHash;
|
@Nullable private Sha256Hash lastBlockSeenHash;
|
||||||
|
@ -307,7 +306,7 @@ public class Wallet extends BaseTaggableObject
|
||||||
* @return A new empty wallet
|
* @return A new empty wallet
|
||||||
*/
|
*/
|
||||||
public static Wallet createDeterministic(NetworkParameters params, ScriptType outputScriptType) {
|
public static Wallet createDeterministic(NetworkParameters params, ScriptType outputScriptType) {
|
||||||
return createDeterministic(Context.getOrCreate(params), outputScriptType, KeyChainGroupStructure.BIP32);
|
return createDeterministic(params, outputScriptType, KeyChainGroupStructure.BIP32);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -320,32 +319,7 @@ public class Wallet extends BaseTaggableObject
|
||||||
* @return A new empty wallet
|
* @return A new empty wallet
|
||||||
*/
|
*/
|
||||||
public static Wallet createDeterministic(NetworkParameters params, ScriptType outputScriptType, KeyChainGroupStructure keyChainGroupStructure) {
|
public static Wallet createDeterministic(NetworkParameters params, ScriptType outputScriptType, KeyChainGroupStructure keyChainGroupStructure) {
|
||||||
return createDeterministic(Context.getOrCreate(params), outputScriptType, keyChainGroupStructure);
|
return new Wallet(params, KeyChainGroup.builder(params, keyChainGroupStructure).fromRandom(outputScriptType).build());
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new, empty wallet with a randomly chosen seed and no transactions. Make sure to provide for sufficient
|
|
||||||
* backup! Any keys will be derived from the seed. If you want to restore a wallet from disk instead, see
|
|
||||||
* {@link #loadFromFile}.
|
|
||||||
* @param context bitcoinj context
|
|
||||||
* @param outputScriptType type of addresses (aka output scripts) to generate for receiving
|
|
||||||
* @return A new empty wallet
|
|
||||||
*/
|
|
||||||
public static Wallet createDeterministic(Context context, ScriptType outputScriptType) {
|
|
||||||
return createDeterministic(context, outputScriptType, KeyChainGroupStructure.BIP32);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new, empty wallet with a randomly chosen seed and no transactions. Make sure to provide for sufficient
|
|
||||||
* backup! Any keys will be derived from the seed. If you want to restore a wallet from disk instead, see
|
|
||||||
* {@link #loadFromFile}.
|
|
||||||
* @param context bitcoinj context
|
|
||||||
* @param outputScriptType type of addresses (aka output scripts) to generate for receiving
|
|
||||||
* @param keyChainGroupStructure structure (e.g. BIP32 or BIP43)
|
|
||||||
* @return A new empty wallet
|
|
||||||
*/
|
|
||||||
public static Wallet createDeterministic(Context context, ScriptType outputScriptType, KeyChainGroupStructure keyChainGroupStructure) {
|
|
||||||
return new Wallet(context, KeyChainGroup.builder(context.getParams(), keyChainGroupStructure).fromRandom(outputScriptType).build());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -470,12 +444,7 @@ public class Wallet extends BaseTaggableObject
|
||||||
* @param keyChainGroup keychain group to manage keychains
|
* @param keyChainGroup keychain group to manage keychains
|
||||||
*/
|
*/
|
||||||
public Wallet(NetworkParameters params, KeyChainGroup keyChainGroup) {
|
public Wallet(NetworkParameters params, KeyChainGroup keyChainGroup) {
|
||||||
this(Context.getOrCreate(params), keyChainGroup);
|
this.params = checkNotNull(params);
|
||||||
}
|
|
||||||
|
|
||||||
private Wallet(Context context, KeyChainGroup keyChainGroup) {
|
|
||||||
this.context = checkNotNull(context);
|
|
||||||
this.params = checkNotNull(context.getParams());
|
|
||||||
this.keyChainGroup = checkNotNull(keyChainGroup);
|
this.keyChainGroup = checkNotNull(keyChainGroup);
|
||||||
watchedScripts = new HashSet<>();
|
watchedScripts = new HashSet<>();
|
||||||
unspent = new HashMap<>();
|
unspent = new HashMap<>();
|
||||||
|
@ -1687,11 +1656,6 @@ public class Wallet extends BaseTaggableObject
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the API context that this wallet was created with. */
|
|
||||||
public Context getContext() {
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a wallet deserialized from the given file. Extensions previously saved with the wallet can be
|
* Returns a wallet deserialized from the given file. Extensions previously saved with the wallet can be
|
||||||
* deserialized by calling @{@link WalletExtension#deserializeWalletExtension(Wallet, byte[])}}
|
* deserialized by calling @{@link WalletExtension#deserializeWalletExtension(Wallet, byte[])}}
|
||||||
|
@ -2376,7 +2340,7 @@ public class Wallet extends BaseTaggableObject
|
||||||
// included once again. We could have a separate was-in-chain-and-now-isn't confidence type
|
// included once again. We could have a separate was-in-chain-and-now-isn't confidence type
|
||||||
// but this way is backwards compatible with existing software, and the new state probably
|
// but this way is backwards compatible with existing software, and the new state probably
|
||||||
// wouldn't mean anything different to just remembering peers anyway.
|
// wouldn't mean anything different to just remembering peers anyway.
|
||||||
if (confidence.incrementDepthInBlocks() > context.getEventHorizon())
|
if (confidence.incrementDepthInBlocks() > Context.getOrCreate().getEventHorizon())
|
||||||
confidence.clearBroadcastBy();
|
confidence.clearBroadcastBy();
|
||||||
confidenceChanged.put(tx, TransactionConfidence.Listener.ChangeReason.DEPTH);
|
confidenceChanged.put(tx, TransactionConfidence.Listener.ChangeReason.DEPTH);
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,7 +77,7 @@ public abstract class AbstractFullPrunedBlockChainTest {
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
BriefLogFormatter.init();
|
BriefLogFormatter.init();
|
||||||
Context.propagate(new Context(PARAMS, 100, Coin.ZERO, false));
|
Context.propagate(new Context(100, Coin.ZERO, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract FullPrunedBlockStore createStore(NetworkParameters params, int blockCount)
|
public abstract FullPrunedBlockStore createStore(NetworkParameters params, int blockCount)
|
||||||
|
@ -234,13 +234,12 @@ public abstract class AbstractFullPrunedBlockChainTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFirst100KBlocks() throws Exception {
|
public void testFirst100KBlocks() throws Exception {
|
||||||
Context context = new Context(MAINNET);
|
|
||||||
File blockFile = new File(getClass().getResource("first-100k-blocks.dat").getFile());
|
File blockFile = new File(getClass().getResource("first-100k-blocks.dat").getFile());
|
||||||
BlockFileLoader loader = new BlockFileLoader(MAINNET, Arrays.asList(blockFile));
|
BlockFileLoader loader = new BlockFileLoader(MAINNET, Arrays.asList(blockFile));
|
||||||
|
|
||||||
store = createStore(MAINNET, 10);
|
store = createStore(MAINNET, 10);
|
||||||
resetStore(store);
|
resetStore(store);
|
||||||
chain = new FullPrunedBlockChain(context, store);
|
chain = new FullPrunedBlockChain(MAINNET, store);
|
||||||
for (Block block : loader)
|
for (Block block : loader)
|
||||||
chain.add(block);
|
chain.add(block);
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -86,10 +86,10 @@ public class BlockChainTest {
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
BriefLogFormatter.initVerbose();
|
BriefLogFormatter.initVerbose();
|
||||||
Utils.setMockClock(); // Use mock clock
|
Utils.setMockClock(); // Use mock clock
|
||||||
Context.propagate(new Context(TESTNET, 100, Coin.ZERO, false));
|
Context.propagate(new Context(100, Coin.ZERO, false));
|
||||||
testNetChain = new BlockChain(TESTNET, Wallet.createDeterministic(TESTNET, ScriptType.P2PKH), new MemoryBlockStore(TESTNET));
|
testNetChain = new BlockChain(TESTNET, Wallet.createDeterministic(TESTNET, ScriptType.P2PKH), new MemoryBlockStore(TESTNET));
|
||||||
Context.propagate(new Context(UNITTEST, 100, Coin.ZERO, false));
|
Context.propagate(new Context(100, Coin.ZERO, false));
|
||||||
NetworkParameters params = Context.get().getParams();
|
NetworkParameters params = TESTNET;
|
||||||
wallet = new Wallet(params, KeyChainGroup.builder(params).fromRandom(ScriptType.P2PKH).build()) {
|
wallet = new Wallet(params, KeyChainGroup.builder(params).fromRandom(ScriptType.P2PKH).build()) {
|
||||||
@Override
|
@Override
|
||||||
public void receiveFromBlock(Transaction tx, StoredBlock block, BlockChain.NewBlockType blockType,
|
public void receiveFromBlock(Transaction tx, StoredBlock block, BlockChain.NewBlockType blockType,
|
||||||
|
@ -432,7 +432,7 @@ public class BlockChainTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void estimatedBlockTime() throws Exception {
|
public void estimatedBlockTime() throws Exception {
|
||||||
BlockChain prod = new BlockChain(new Context(MAINNET), new MemoryBlockStore(MAINNET));
|
BlockChain prod = new BlockChain(MAINNET, new MemoryBlockStore(MAINNET));
|
||||||
Date d = prod.estimateBlockTime(200000);
|
Date d = prod.estimateBlockTime(200000);
|
||||||
// The actual date of block 200,000 was 2012-09-22 10:47:00
|
// The actual date of block 200,000 was 2012-09-22 10:47:00
|
||||||
assertEquals(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.US).parse("2012-10-23T08:35:05.000-0700"), d);
|
assertEquals(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.US).parse("2012-10-23T08:35:05.000-0700"), d);
|
||||||
|
|
|
@ -225,8 +225,7 @@ public class BlockTest {
|
||||||
// Create a wallet contain the miner's key that receives a spend from a coinbase.
|
// Create a wallet contain the miner's key that receives a spend from a coinbase.
|
||||||
ECKey miningKey = DumpedPrivateKey.fromBase58(MAINNET, MINING_PRIVATE_KEY).getKey();
|
ECKey miningKey = DumpedPrivateKey.fromBase58(MAINNET, MINING_PRIVATE_KEY).getKey();
|
||||||
assertNotNull(miningKey);
|
assertNotNull(miningKey);
|
||||||
Context context = new Context(MAINNET);
|
Wallet wallet = Wallet.createDeterministic(MAINNET, ScriptType.P2PKH);
|
||||||
Wallet wallet = Wallet.createDeterministic(context, ScriptType.P2PKH);
|
|
||||||
wallet.importKey(miningKey);
|
wallet.importKey(miningKey);
|
||||||
|
|
||||||
// Initial balance should be zero by construction.
|
// Initial balance should be zero by construction.
|
||||||
|
|
|
@ -70,7 +70,7 @@ public class BloomFilterTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void walletTest() {
|
public void walletTest() {
|
||||||
Context.propagate(new Context(MAINNET));
|
Context.propagate(new Context());
|
||||||
|
|
||||||
DumpedPrivateKey privKey = DumpedPrivateKey.fromBase58(MAINNET, "5Kg1gnAjaLfKiwhhPpGS3QfRg2m6awQvaj98JCZBZQ5SuS2F15C");
|
DumpedPrivateKey privKey = DumpedPrivateKey.fromBase58(MAINNET, "5Kg1gnAjaLfKiwhhPpGS3QfRg2m6awQvaj98JCZBZQ5SuS2F15C");
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,7 @@ public class ChainSplitTest {
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
BriefLogFormatter.init();
|
BriefLogFormatter.init();
|
||||||
Utils.setMockClock(); // Use mock clock
|
Utils.setMockClock(); // Use mock clock
|
||||||
Context.propagate(new Context(UNITTEST, 100, Coin.ZERO, false));
|
Context.propagate(new Context(100, Coin.ZERO, false));
|
||||||
MemoryBlockStore blockStore = new MemoryBlockStore(UNITTEST);
|
MemoryBlockStore blockStore = new MemoryBlockStore(UNITTEST);
|
||||||
wallet = Wallet.createDeterministic(UNITTEST, ScriptType.P2PKH);
|
wallet = Wallet.createDeterministic(UNITTEST, ScriptType.P2PKH);
|
||||||
ECKey key1 = wallet.freshReceiveKey();
|
ECKey key1 = wallet.freshReceiveKey();
|
||||||
|
|
|
@ -90,8 +90,7 @@ public class ParseByteCacheTest {
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
Utils.setMockClock(); // Use mock clock
|
Utils.setMockClock(); // Use mock clock
|
||||||
Context context = new Context(UNITTEST);
|
Wallet wallet = Wallet.createDeterministic(UNITTEST, ScriptType.P2PKH);
|
||||||
Wallet wallet = Wallet.createDeterministic(context, ScriptType.P2PKH);
|
|
||||||
wallet.freshReceiveKey();
|
wallet.freshReceiveKey();
|
||||||
|
|
||||||
resetBlockStore();
|
resetBlockStore();
|
||||||
|
|
|
@ -37,7 +37,7 @@ public class TransactionInputTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStandardWalletDisconnect() throws Exception {
|
public void testStandardWalletDisconnect() throws Exception {
|
||||||
Wallet w = Wallet.createDeterministic(new Context(UNITTEST), ScriptType.P2PKH);
|
Wallet w = Wallet.createDeterministic(UNITTEST, ScriptType.P2PKH);
|
||||||
Address a = w.currentReceiveAddress();
|
Address a = w.currentReceiveAddress();
|
||||||
Transaction tx1 = FakeTxBuilder.createFakeTxWithoutChangeAddress(UNITTEST, Coin.COIN, a);
|
Transaction tx1 = FakeTxBuilder.createFakeTxWithoutChangeAddress(UNITTEST, Coin.COIN, a);
|
||||||
w.receivePending(tx1, null);
|
w.receivePending(tx1, null);
|
||||||
|
@ -60,7 +60,7 @@ public class TransactionInputTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUTXOWalletDisconnect() throws Exception {
|
public void testUTXOWalletDisconnect() throws Exception {
|
||||||
Wallet w = Wallet.createDeterministic(new Context(UNITTEST), ScriptType.P2PKH);
|
Wallet w = Wallet.createDeterministic(UNITTEST, ScriptType.P2PKH);
|
||||||
Address a = w.currentReceiveAddress();
|
Address a = w.currentReceiveAddress();
|
||||||
final UTXO utxo = new UTXO(Sha256Hash.of(new byte[] { 1, 2, 3 }), 1, Coin.COIN, 0, false,
|
final UTXO utxo = new UTXO(Sha256Hash.of(new byte[] { 1, 2, 3 }), 1, Coin.COIN, 0, false,
|
||||||
ScriptBuilder.createOutputScript(a));
|
ScriptBuilder.createOutputScript(a));
|
||||||
|
|
|
@ -45,7 +45,7 @@ public class TxConfidenceTableTest {
|
||||||
@Before
|
@Before
|
||||||
public void setup() throws Exception {
|
public void setup() throws Exception {
|
||||||
BriefLogFormatter.init();
|
BriefLogFormatter.init();
|
||||||
Context context = new Context(UNITTEST);
|
Context context = new Context();
|
||||||
Context.propagate(context);
|
Context.propagate(context);
|
||||||
table = context.getConfidenceTable();
|
table = context.getConfidenceTable();
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ import org.bitcoinj.core.Block;
|
||||||
import org.bitcoinj.core.BlockChain;
|
import org.bitcoinj.core.BlockChain;
|
||||||
import org.bitcoinj.core.BlockTest;
|
import org.bitcoinj.core.BlockTest;
|
||||||
import org.bitcoinj.base.Coin;
|
import org.bitcoinj.base.Coin;
|
||||||
|
import org.bitcoinj.core.Context;
|
||||||
import org.bitcoinj.core.ECKey;
|
import org.bitcoinj.core.ECKey;
|
||||||
import org.bitcoinj.core.LegacyAddress;
|
import org.bitcoinj.core.LegacyAddress;
|
||||||
import org.bitcoinj.core.NetworkParameters;
|
import org.bitcoinj.core.NetworkParameters;
|
||||||
|
@ -96,6 +97,7 @@ public class WalletProtobufSerializerTest {
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUpClass() {
|
public static void setUpClass() {
|
||||||
Utils.resetMocking();
|
Utils.resetMocking();
|
||||||
|
Context.propagate(new Context());
|
||||||
UNITTEST = UnitTestParams.get();
|
UNITTEST = UnitTestParams.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ public class TestWithWallet {
|
||||||
|
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
BriefLogFormatter.init();
|
BriefLogFormatter.init();
|
||||||
Context.propagate(new Context(UNITTEST, 100, Coin.ZERO, false));
|
Context.propagate(new Context(100, Coin.ZERO, false));
|
||||||
wallet = Wallet.createDeterministic(UNITTEST, ScriptType.P2PKH, KeyChainGroupStructure.BIP32);
|
wallet = Wallet.createDeterministic(UNITTEST, ScriptType.P2PKH, KeyChainGroupStructure.BIP32);
|
||||||
myKey = wallet.freshReceiveKey();
|
myKey = wallet.freshReceiveKey();
|
||||||
myAddress = wallet.freshReceiveAddress(ScriptType.P2PKH);
|
myAddress = wallet.freshReceiveAddress(ScriptType.P2PKH);
|
||||||
|
|
|
@ -20,7 +20,6 @@ package org.bitcoinj.wallet;
|
||||||
import org.bitcoinj.base.Coin;
|
import org.bitcoinj.base.Coin;
|
||||||
import org.bitcoinj.base.ScriptType;
|
import org.bitcoinj.base.ScriptType;
|
||||||
import org.bitcoinj.base.utils.ByteUtils;
|
import org.bitcoinj.base.utils.ByteUtils;
|
||||||
import org.bitcoinj.core.Context;
|
|
||||||
import org.bitcoinj.core.ECKey;
|
import org.bitcoinj.core.ECKey;
|
||||||
import org.bitcoinj.core.NetworkParameters;
|
import org.bitcoinj.core.NetworkParameters;
|
||||||
import org.bitcoinj.core.Transaction;
|
import org.bitcoinj.core.Transaction;
|
||||||
|
@ -58,7 +57,7 @@ public class DefaultRiskAnalysisTest {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
wallet = Wallet.createDeterministic(new Context(MAINNET), ScriptType.P2PKH);
|
wallet = Wallet.createDeterministic(MAINNET, ScriptType.P2PKH);
|
||||||
wallet.setLastBlockSeenHeight(1000);
|
wallet.setLastBlockSeenHeight(1000);
|
||||||
wallet.setLastBlockSeenTimeSecs(TIMESTAMP);
|
wallet.setLastBlockSeenTimeSecs(TIMESTAMP);
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,7 @@ public class FilteredBlockAndPartialMerkleTreeTest extends TestWithPeerGroup {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
Context.propagate(new Context(UNITTEST));
|
Context.propagate(new Context());
|
||||||
MemoryBlockStore store = new MemoryBlockStore(UNITTEST);
|
MemoryBlockStore store = new MemoryBlockStore(UNITTEST);
|
||||||
|
|
||||||
// Cheat and place the previous block (block 100000) at the head of the block store without supporting blocks
|
// Cheat and place the previous block (block 100000) at the head of the block store without supporting blocks
|
||||||
|
|
|
@ -102,7 +102,7 @@ public class TestWithNetworkConnections {
|
||||||
|
|
||||||
public void setUp(BlockStore blockStore) throws Exception {
|
public void setUp(BlockStore blockStore) throws Exception {
|
||||||
BriefLogFormatter.init();
|
BriefLogFormatter.init();
|
||||||
Context.propagate(new Context(UNITTEST, 100, Coin.ZERO, false));
|
Context.propagate(new Context(100, Coin.ZERO, false));
|
||||||
this.blockStore = blockStore;
|
this.blockStore = blockStore;
|
||||||
// Allow subclasses to override the wallet object with their own.
|
// Allow subclasses to override the wallet object with their own.
|
||||||
if (wallet == null) {
|
if (wallet == null) {
|
||||||
|
|
|
@ -81,7 +81,7 @@ public class WalletAccountPathTest {
|
||||||
|
|
||||||
// Create a wallet, save it to a file, then reload from a file
|
// Create a wallet, save it to a file, then reload from a file
|
||||||
private static Wallet createWallet(File walletFile, NetworkParameters params, KeyChainGroupStructure structure, ScriptType outputScriptType) throws IOException, UnreadableWalletException {
|
private static Wallet createWallet(File walletFile, NetworkParameters params, KeyChainGroupStructure structure, ScriptType outputScriptType) throws IOException, UnreadableWalletException {
|
||||||
Context.propagate(new Context(params));
|
Context.propagate(new Context());
|
||||||
DeterministicSeed seed = new DeterministicSeed(testWalletMnemonic, null, "", Instant.now().getEpochSecond());
|
DeterministicSeed seed = new DeterministicSeed(testWalletMnemonic, null, "", Instant.now().getEpochSecond());
|
||||||
Wallet wallet = Wallet.fromSeed(params, seed, outputScriptType, structure);
|
Wallet wallet = Wallet.fromSeed(params, seed, outputScriptType, structure);
|
||||||
wallet.saveToFile(walletFile);
|
wallet.saveToFile(walletFile);
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package org.bitcoinj.wallet;
|
package org.bitcoinj.wallet;
|
||||||
|
|
||||||
|
import org.bitcoinj.core.Context;
|
||||||
import org.bitcoinj.crypto.HDPath;
|
import org.bitcoinj.crypto.HDPath;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
@ -33,6 +34,7 @@ public class WalletLoadTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void basicWalletLoadTest() throws UnreadableWalletException {
|
void basicWalletLoadTest() throws UnreadableWalletException {
|
||||||
|
Context.propagate(new Context());
|
||||||
Wallet wallet = Wallet.loadFromFile(walletFile);
|
Wallet wallet = Wallet.loadFromFile(walletFile);
|
||||||
|
|
||||||
long creation = wallet.getKeyChainSeed().getCreationTimeSeconds();
|
long creation = wallet.getKeyChainSeed().getCreationTimeSeconds();
|
||||||
|
|
|
@ -75,7 +75,7 @@ public class BuildCheckpoints implements Callable<Integer> {
|
||||||
public Integer call() throws Exception {
|
public Integer call() throws Exception {
|
||||||
final String suffix;
|
final String suffix;
|
||||||
params = NetworkParameters.of(net);
|
params = NetworkParameters.of(net);
|
||||||
Context.propagate(new Context(params));
|
Context.propagate(new Context());
|
||||||
|
|
||||||
switch (net) {
|
switch (net) {
|
||||||
case MAINNET:
|
case MAINNET:
|
||||||
|
|
|
@ -374,7 +374,7 @@ public class WalletTool implements Callable<Integer> {
|
||||||
if (chainFile == null) {
|
if (chainFile == null) {
|
||||||
chainFile = new File(fileName);
|
chainFile = new File(fileName);
|
||||||
}
|
}
|
||||||
Context.propagate(new Context(params));
|
Context.propagate(new Context());
|
||||||
|
|
||||||
if (conditionStr != null) {
|
if (conditionStr != null) {
|
||||||
condition = new Condition(conditionStr);
|
condition = new Condition(conditionStr);
|
||||||
|
|
Loading…
Add table
Reference in a new issue