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:
Andreas Schildbach 2022-06-24 02:26:54 +02:00
parent 4098995a3c
commit fb90c4458d
25 changed files with 57 additions and 195 deletions

View file

@ -167,22 +167,10 @@ public abstract class AbstractBlockChain {
*/
public AbstractBlockChain(NetworkParameters params, List<? extends Wallet> wallets,
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;
chainHead = blockStore.getChainHead();
log.info("chain head is at height {}:\n{}", chainHead.getHeight(), chainHead.getHeader());
this.params = context.getParams();
this.params = params;
this.newBestBlockListeners = new CopyOnWriteArrayList<>();
this.reorganizeListeners = new CopyOnWriteArrayList<>();
@ -191,7 +179,7 @@ public abstract class AbstractBlockChain {
for (ReorganizeListener l : wallets) addReorganizeListener(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);
}

View file

@ -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
* 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 {
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
* 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 {
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.
*/
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);
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
protected StoredBlock addToBlockStore(StoredBlock storedPrev, Block blockHeader, TransactionOutputChanges txOutChanges)
throws BlockStoreException, VerificationException {

View file

@ -89,8 +89,8 @@ public class CheckpointManager {
public static final BaseEncoding BASE64 = BaseEncoding.base64().omitPadding();
/** Loads the default checkpoints bundled with bitcoinj */
public CheckpointManager(Context context) throws IOException {
this(context.getParams(), null);
public CheckpointManager(NetworkParameters params) throws IOException {
this(params, null);
}
/** Loads the checkpoints from the given stream */

View file

@ -49,7 +49,6 @@ public class Context {
public static final int DEFAULT_EVENT_HORIZON = 100;
final private TxConfidenceTable confidenceTable;
final private NetworkParameters params;
final private int eventHorizon;
final private boolean ensureMinRequiredFee;
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
* 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) {
this(params, DEFAULT_EVENT_HORIZON, Transaction.DEFAULT_TX_FEE, true);
public Context() {
this(DEFAULT_EVENT_HORIZON, Transaction.DEFAULT_TX_FEE, true);
}
/**
* 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 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}.
*/
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);
this.confidenceTable = new TxConfidenceTable();
this.params = params;
this.eventHorizon = eventHorizon;
this.ensureMinRequiredFee = ensureMinRequiredFee;
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.
public static Context getOrCreate(NetworkParameters params) {
public static Context getOrCreate() {
Context context;
try {
context = get();
} catch (IllegalStateException e) {
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;
}
if (context.getParams() != params)
throw new IllegalStateException("Context does not match implicit network params: " + context.getParams() + " vs " + params);
return context;
}
@ -163,15 +156,6 @@ public class Context {
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
* so confirmed that it's safe to delete data. Re-orgs larger than the event horizon will not be correctly

View file

@ -66,57 +66,34 @@ public class FullPrunedBlockChain extends AbstractBlockChain {
// Whether or not to execute scriptPubKeys before accepting a transaction (i.e. check signatures).
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
* one from scratch, or you can deserialize a saved wallet from disk using
* {@link Wallet#loadFromFile(File, WalletExtension...)}
*/
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.
*/
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 {
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.
*/
public FullPrunedBlockChain(Context context, List<Wallet> listeners, FullPrunedBlockStore blockStore) throws BlockStoreException {
super(context, listeners, blockStore);
public FullPrunedBlockChain(NetworkParameters params, List<Wallet> listeners,
FullPrunedBlockStore blockStore) throws BlockStoreException {
super(params, listeners, blockStore);
this.blockStore = blockStore;
// Ignore upgrading for now
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
protected StoredBlock addToBlockStore(StoredBlock storedPrev, Block header, TransactionOutputChanges txOutChanges)
throws BlockStoreException, VerificationException {

View file

@ -329,45 +329,30 @@ public class PeerGroup implements TransactionBroadcaster {
/** Whether bloom filter support is enabled when using a non FullPrunedBlockchain*/
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) {
this(params, null);
}
/**
* Creates a PeerGroup with the given context. 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(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
* Creates a PeerGroup for the given network and chain. Blocks will be passed to the chain as they are broadcast
* and downloaded. This is probably the constructor you want to use.
*/
public PeerGroup(Context context, @Nullable AbstractBlockChain chain) {
this(context, chain, new NioClientManager());
}
/** See {@link #PeerGroup(Context, AbstractBlockChain, ClientConnectionManager)} */
public PeerGroup(NetworkParameters params, @Nullable AbstractBlockChain chain, ClientConnectionManager connectionManager) {
this(Context.getOrCreate(params), chain, connectionManager);
public PeerGroup(NetworkParameters params, @Nullable AbstractBlockChain chain) {
this(params, chain, new NioClientManager());
}
/**
* Creates a new PeerGroup allowing you to specify the {@link ClientConnectionManager} which is used to create new
* connections and keep track of existing ones.
*/
private PeerGroup(Context context, @Nullable AbstractBlockChain chain, ClientConnectionManager connectionManager) {
checkNotNull(context);
this.params = context.getParams();
protected PeerGroup(NetworkParameters params, @Nullable AbstractBlockChain chain, ClientConnectionManager connectionManager) {
checkNotNull(params);
this.params = params;
this.chain = chain;
fastCatchupTimeSecs = params.getGenesisBlock().getTimeSeconds();
wallets = new CopyOnWriteArrayList<>();

View file

@ -110,8 +110,6 @@ public class WalletAppKit extends AbstractIdleService {
@Nullable protected DeterministicKey restoreFromKey;
@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.
* @deprecated Use {@link #WalletAppKit(BitcoinNetwork, ScriptType, KeyChainGroupStructure, File, String)}
@ -144,29 +142,12 @@ public class WalletAppKit extends AbstractIdleService {
KeyChainGroupStructure structure, File directory, String filePrefix) {
this.network = checkNotNull(network);
this.params = NetworkParameters.of(this.network);
this.context = new Context(params);
this.preferredOutputScriptType = checkNotNull(preferredOutputScriptType);
this.structure = checkNotNull(structure);
this.directory = checkNotNull(directory);
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. */
public WalletAppKit setPeerNodes(PeerAddress... addresses) {
checkState(state() == State.NEW, "Cannot call after startup");
@ -331,7 +312,6 @@ 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());
@ -507,7 +487,6 @@ public class WalletAppKit extends AbstractIdleService {
protected void shutDown() throws Exception {
// Runs in a separate thread.
try {
Context.propagate(context);
vPeerGroup.stop();
vWallet.saveToFile(vWalletFile);
vStore.close();

View file

@ -233,7 +233,6 @@ public class Wallet extends BaseTaggableObject
// A list of scripts watched by this wallet.
@GuardedBy("keyChainGroupLock") private final Set<Script> watchedScripts;
protected final Context context;
protected final NetworkParameters params;
@Nullable private Sha256Hash lastBlockSeenHash;
@ -307,7 +306,7 @@ public class Wallet extends BaseTaggableObject
* @return A new empty wallet
*/
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
*/
public static Wallet createDeterministic(NetworkParameters params, ScriptType outputScriptType, KeyChainGroupStructure keyChainGroupStructure) {
return createDeterministic(Context.getOrCreate(params), outputScriptType, keyChainGroupStructure);
}
/**
* 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());
return new Wallet(params, KeyChainGroup.builder(params, keyChainGroupStructure).fromRandom(outputScriptType).build());
}
/**
@ -470,12 +444,7 @@ public class Wallet extends BaseTaggableObject
* @param keyChainGroup keychain group to manage keychains
*/
public Wallet(NetworkParameters params, KeyChainGroup keyChainGroup) {
this(Context.getOrCreate(params), keyChainGroup);
}
private Wallet(Context context, KeyChainGroup keyChainGroup) {
this.context = checkNotNull(context);
this.params = checkNotNull(context.getParams());
this.params = checkNotNull(params);
this.keyChainGroup = checkNotNull(keyChainGroup);
watchedScripts = new HashSet<>();
unspent = new HashMap<>();
@ -1687,11 +1656,6 @@ public class Wallet extends BaseTaggableObject
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
* 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
// but this way is backwards compatible with existing software, and the new state probably
// wouldn't mean anything different to just remembering peers anyway.
if (confidence.incrementDepthInBlocks() > context.getEventHorizon())
if (confidence.incrementDepthInBlocks() > Context.getOrCreate().getEventHorizon())
confidence.clearBroadcastBy();
confidenceChanged.put(tx, TransactionConfidence.Listener.ChangeReason.DEPTH);
}

View file

@ -77,7 +77,7 @@ public abstract class AbstractFullPrunedBlockChainTest {
@Before
public void setUp() {
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)
@ -234,13 +234,12 @@ public abstract class AbstractFullPrunedBlockChainTest {
@Test
public void testFirst100KBlocks() throws Exception {
Context context = new Context(MAINNET);
File blockFile = new File(getClass().getResource("first-100k-blocks.dat").getFile());
BlockFileLoader loader = new BlockFileLoader(MAINNET, Arrays.asList(blockFile));
store = createStore(MAINNET, 10);
resetStore(store);
chain = new FullPrunedBlockChain(context, store);
chain = new FullPrunedBlockChain(MAINNET, store);
for (Block block : loader)
chain.add(block);
try {

View file

@ -86,10 +86,10 @@ public class BlockChainTest {
public void setUp() throws Exception {
BriefLogFormatter.initVerbose();
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));
Context.propagate(new Context(UNITTEST, 100, Coin.ZERO, false));
NetworkParameters params = Context.get().getParams();
Context.propagate(new Context(100, Coin.ZERO, false));
NetworkParameters params = TESTNET;
wallet = new Wallet(params, KeyChainGroup.builder(params).fromRandom(ScriptType.P2PKH).build()) {
@Override
public void receiveFromBlock(Transaction tx, StoredBlock block, BlockChain.NewBlockType blockType,
@ -432,7 +432,7 @@ public class BlockChainTest {
@Test
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);
// 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);

View file

@ -225,8 +225,7 @@ public class BlockTest {
// Create a wallet contain the miner's key that receives a spend from a coinbase.
ECKey miningKey = DumpedPrivateKey.fromBase58(MAINNET, MINING_PRIVATE_KEY).getKey();
assertNotNull(miningKey);
Context context = new Context(MAINNET);
Wallet wallet = Wallet.createDeterministic(context, ScriptType.P2PKH);
Wallet wallet = Wallet.createDeterministic(MAINNET, ScriptType.P2PKH);
wallet.importKey(miningKey);
// Initial balance should be zero by construction.

View file

@ -70,7 +70,7 @@ public class BloomFilterTest {
@Test
public void walletTest() {
Context.propagate(new Context(MAINNET));
Context.propagate(new Context());
DumpedPrivateKey privKey = DumpedPrivateKey.fromBase58(MAINNET, "5Kg1gnAjaLfKiwhhPpGS3QfRg2m6awQvaj98JCZBZQ5SuS2F15C");

View file

@ -65,7 +65,7 @@ public class ChainSplitTest {
public void setUp() throws Exception {
BriefLogFormatter.init();
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);
wallet = Wallet.createDeterministic(UNITTEST, ScriptType.P2PKH);
ECKey key1 = wallet.freshReceiveKey();

View file

@ -90,8 +90,7 @@ public class ParseByteCacheTest {
@Before
public void setUp() throws Exception {
Utils.setMockClock(); // Use mock clock
Context context = new Context(UNITTEST);
Wallet wallet = Wallet.createDeterministic(context, ScriptType.P2PKH);
Wallet wallet = Wallet.createDeterministic(UNITTEST, ScriptType.P2PKH);
wallet.freshReceiveKey();
resetBlockStore();

View file

@ -37,7 +37,7 @@ public class TransactionInputTest {
@Test
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();
Transaction tx1 = FakeTxBuilder.createFakeTxWithoutChangeAddress(UNITTEST, Coin.COIN, a);
w.receivePending(tx1, null);
@ -60,7 +60,7 @@ public class TransactionInputTest {
@Test
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();
final UTXO utxo = new UTXO(Sha256Hash.of(new byte[] { 1, 2, 3 }), 1, Coin.COIN, 0, false,
ScriptBuilder.createOutputScript(a));

View file

@ -45,7 +45,7 @@ public class TxConfidenceTableTest {
@Before
public void setup() throws Exception {
BriefLogFormatter.init();
Context context = new Context(UNITTEST);
Context context = new Context();
Context.propagate(context);
table = context.getConfidenceTable();

View file

@ -26,6 +26,7 @@ import org.bitcoinj.core.Block;
import org.bitcoinj.core.BlockChain;
import org.bitcoinj.core.BlockTest;
import org.bitcoinj.base.Coin;
import org.bitcoinj.core.Context;
import org.bitcoinj.core.ECKey;
import org.bitcoinj.core.LegacyAddress;
import org.bitcoinj.core.NetworkParameters;
@ -96,6 +97,7 @@ public class WalletProtobufSerializerTest {
@BeforeClass
public static void setUpClass() {
Utils.resetMocking();
Context.propagate(new Context());
UNITTEST = UnitTestParams.get();
}

View file

@ -69,7 +69,7 @@ public class TestWithWallet {
public void setUp() throws Exception {
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);
myKey = wallet.freshReceiveKey();
myAddress = wallet.freshReceiveAddress(ScriptType.P2PKH);

View file

@ -20,7 +20,6 @@ package org.bitcoinj.wallet;
import org.bitcoinj.base.Coin;
import org.bitcoinj.base.ScriptType;
import org.bitcoinj.base.utils.ByteUtils;
import org.bitcoinj.core.Context;
import org.bitcoinj.core.ECKey;
import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.core.Transaction;
@ -58,7 +57,7 @@ public class DefaultRiskAnalysisTest {
@Before
public void setup() {
wallet = Wallet.createDeterministic(new Context(MAINNET), ScriptType.P2PKH);
wallet = Wallet.createDeterministic(MAINNET, ScriptType.P2PKH);
wallet.setLastBlockSeenHeight(1000);
wallet.setLastBlockSeenTimeSecs(TIMESTAMP);
}

View file

@ -66,7 +66,7 @@ public class FilteredBlockAndPartialMerkleTreeTest extends TestWithPeerGroup {
@Before
public void setUp() throws Exception {
Context.propagate(new Context(UNITTEST));
Context.propagate(new Context());
MemoryBlockStore store = new MemoryBlockStore(UNITTEST);
// Cheat and place the previous block (block 100000) at the head of the block store without supporting blocks

View file

@ -102,7 +102,7 @@ public class TestWithNetworkConnections {
public void setUp(BlockStore blockStore) throws Exception {
BriefLogFormatter.init();
Context.propagate(new Context(UNITTEST, 100, Coin.ZERO, false));
Context.propagate(new Context(100, Coin.ZERO, false));
this.blockStore = blockStore;
// Allow subclasses to override the wallet object with their own.
if (wallet == null) {

View file

@ -81,7 +81,7 @@ public class WalletAccountPathTest {
// 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 {
Context.propagate(new Context(params));
Context.propagate(new Context());
DeterministicSeed seed = new DeterministicSeed(testWalletMnemonic, null, "", Instant.now().getEpochSecond());
Wallet wallet = Wallet.fromSeed(params, seed, outputScriptType, structure);
wallet.saveToFile(walletFile);

View file

@ -16,6 +16,7 @@
package org.bitcoinj.wallet;
import org.bitcoinj.core.Context;
import org.bitcoinj.crypto.HDPath;
import org.junit.jupiter.api.Test;
@ -33,6 +34,7 @@ public class WalletLoadTest {
@Test
void basicWalletLoadTest() throws UnreadableWalletException {
Context.propagate(new Context());
Wallet wallet = Wallet.loadFromFile(walletFile);
long creation = wallet.getKeyChainSeed().getCreationTimeSeconds();

View file

@ -75,7 +75,7 @@ public class BuildCheckpoints implements Callable<Integer> {
public Integer call() throws Exception {
final String suffix;
params = NetworkParameters.of(net);
Context.propagate(new Context(params));
Context.propagate(new Context());
switch (net) {
case MAINNET:

View file

@ -374,7 +374,7 @@ public class WalletTool implements Callable<Integer> {
if (chainFile == null) {
chainFile = new File(fileName);
}
Context.propagate(new Context(params));
Context.propagate(new Context());
if (conditionStr != null) {
condition = new Condition(conditionStr);