* Make the static field `estimatedKeyDerivationTime` private
* Refactor the calculation to a private, side-effect free function
* Replace `estimatedKeyDerivationTimeMsec()` with `initEstimatedKeyDerivationTime()`
** Don’t return a value that wasn’t unused anyway
** Make better use of CompletableFuture API
* Platform.runLater wasn’t needed because no JavaFX functions are called
* Make all public fields private and wrap with accessors
* Make `WalletAppKit` (was confusingly named `bitcoin`) field a member not a static
* Rename `bitcoin` to `walletAppKit`
* Extract abstract class `WalletApplication` from `WalletTemplate`
* `WalletTemplate` implements `loadController()` with resource names
* `MainController`: Add `scene` member and `scene()` method
* Introduce `AppDelegate` class for delegating JavaFX `Application`
* Move almost all of `Main` to `WalletTemplate`
Rationale:
* The “template” JavaFX Application main class (`Main`) is now about 30 lines of code
* `Main` class allows easy switching between TestNet and MainNet (in fact it could become a command-line argument) and other configuration changes (e.g. `preferredOutputScriptType`)
* Prepares the way for the next steps of refactoring
* OverlayController: rename init method, add rootController to params
* OverlayableStackPaneController: update to use updated initOverlay() method,
also pass this.getClass() into GuiUtils.getResource()
* GuiUtils.getResource(): replace reference to MainController.class with clazz parameter
* Main: Reduce visibility to “package” of 3 static globals
* MainController: Reduce visibility of `instance` static to “package”, initialize
addressControl by calling 2 initialization methods
* 4 other controllers: Update for OverlayController changes
* ClickableBitcoinAddress: OverlayController changes, eliminate use of Main.APP_NAME
Rationale:
* Decrease coupling
* Eliminate cross-package use of `Main` and `MainController` static globals
* Prepare for further refactoring — moving wallettemplate.controls package
to org.bitcoinj.walletfx.controls
Problem: A transaction received from the network is added to all wallets
that find it relevant. If two wallets find the same transaction relevant
the same Transaction instance is added to both wallets.
Spending the outputs from this transaction can cause consistiency
issues, in particular if the outputs are spent in the same transaction,
as shown in WalletTest.oneTxTwoWallets. There are probably more issues
with having the same Transaction instance handled by two different
wallets.
Fix: Clone the transaction before adding it to the wallet.
AccessControlException is deprecated for removal in JDK 17.
its parent classes are:
`AccessControlException` <- `SecurityException` <- `RuntimeException`
It can be replaced with its parent `SecurityException` which is not deprecated and will behave almost identically in this one place where it is used.
* Extract abstract class OverlayableStackPaneController from MainController
* Rename OverlayWindowController to OverlayController (Window was misleading)
Rationale:
1. Overlay functionality is independent of MainContoller’s wallet functions
2. Increases reusability of classes in module
3. Prepares for further refactoring
Rationale:
1. Stronger typing makes code more readable and refactorable
2. Eliminates “automatic” reflection in MainController
3. Makes overlayUI field in implementing classes private
4. Is a step towards further refactoring and reusability
Move OverlayUI and other related functionality from Main (Application) class
to MainController.
Motivation:
1. This simplifies the Main class
2. The code more logically belongs in the controller
3. The code being in the controller increases reusability
4. Is a first step towards additional refactoring made possible
because MainController can subclass an abstract class and Main
can’t because it must subclass Application
I did this for two reasons:
1. So users will know why the buttons are there and that they work
2. A convenient way to test the informational alert function.
Replace a few calls to:
Utils.setMockClock(Utils.setCurrentTimeSeconds())
with
Utils.setMockClock()
The behavior of the first is slightly different
and possibly pathological, and I believe that in
all three cases in this PR, it is the later behavior
that is intended.
This refactoring breaks the cyclic dependency of NetworkParameters constructors
on the constructors in Block and will allow us to migrate the code
now in the getGenesisBlock() methods into (atomic) factories/constructors
in `Block` allowing us to create block objects that are unmodifiable/immutable.
* Add Block.STANDARD_MAX_DIFFICULTY_TARGET and use in subclasses
* Always define maxTarget in terms of a nBits constant and use
Utils.decodeCompactBits()
* Define constants for GENESIS_TIME and GENESIS_NONCE
The tests are currently using a custom value for maxTarget
that can’t be generated via CompactBits format.
This commit changes the string constant to match what would be
generated by using Utils.decodeCompactBits(EASIEST_DIFFICULTY_TARGET).
1. Define Sha256 constants for expected hashes
2. Compare hashes in binary form
3. Move hash comparison to immediately follow Block creation
4. Add error message to the check state call
It said “half of all possible hash solutions” which
led me to believe that decodeCompactBits() would
extend 1’s all the way out to the least significant
bit.
Reorganize the initialization of the constants in each NetworkParameters
subclass so we can easily do diffs of `MainNetParms` vs `TestNet3Params`
and easily see how they are the same and how they are different.
I also reorganized the import statements so they “diff” better as well.
Other than those changes the only code I actually changed is
using the constant `PAYMENT_PROTOCOL_ID_UNIT_TESTS` instead of “unittest”
in getPaymentProcolId in UnitTestParams.
This will help us with the next step which is to create symbolic constants
for some of the parameters for the genesis blocks.
Its a factory method for creating Blocks, so it really belongs
there. Moving it there will also help us move further along
our path to reduced mutability in the Block class.