Commit graph

3424 commits

Author SHA1 Message Date
Sean Gilligan
afe8086aec TransactionBroadcast: simplify lambda and extract chooseBroadastPeers()
* Simplifies the lambda in broadcast:
  ** shortens it by two lines of code
  ** makes `peers` effectively final
  ** doesn't mutate the list `peers` with `shuffle`
* chooseBroadastPeers() gets JavaDoc
* chooseBroadastPeers() is more testable
2022-07-28 22:33:14 +02:00
Sean Gilligan
3754fa8d99 TransactionBroadcast: convert EnoughAvailablePeers to lambda 2022-07-28 21:24:12 +02:00
Sean Gilligan
3786d70de6 CoinSelection: encapsulate fields
* Encapsulate `valueGathered` as `totalValue()`
* Encapsulate `gathered` as `outputs()`
* Deprecate public members
* Update clients to use accessors
2022-07-28 21:03:36 +02:00
Sean Gilligan
e52e4d0e72 CoinSelection: require a List of outputs, rather than a Collection
Rationale:

* The comment says that it is a "list"
* Immutable Lists are the collection that maps most easily/logically to and from Stream
* Lists are easier to enforce reproducibility (mainly for unit tests)
2022-07-28 20:59:32 +02:00
Sean Gilligan
c2b4472f5c WalletAppKit: give shutdownHook thread a name 2022-07-28 19:22:49 +02:00
Sean Gilligan
952751eee2 WalletAppKit: move shutdownHook into its own method 2022-07-28 19:18:01 +02:00
Sean Gilligan
368cdba42d Peer, TransactionBroadcast: use thenRunAsync() instead of addListener()
Use CompletableFuture.thenRunAsync() rather than rely on the converter
method ListenableCompletableFuture.addListener().
2022-07-28 13:22:38 +02:00
Sean Gilligan
bee8427761 WalletAppKit: simplify blocking startup
* Use `startAsync()` for the blocking case, too. Since we were already
  waiting on `downloadListner.await()`
* Make sure `installShutdownHook()` is called in both cases (bug fix)
* Add more comments
2022-07-28 01:07:07 +02:00
Sean Gilligan
ff674ea605 WalletAppKit: make sure downloadListener is never null
This simplifies the `if (blockingStartup)` and its `else` block. This change makes way
for further simplification.
2022-07-27 23:15:39 +02:00
Sean Gilligan
4bd79448ee WalletAppKit: remove unnecessary try/catch in startUp()
Remove the very long try/catch in startup that catches BlockStoreException
and rethrows it wrapped in an IOException.

The Guava service base class (`AbstractIdleService`) that we are extending
allows us to throw `Exception` so there is no reason to wrap the exception
and it can just be thrown directly.
2022-07-27 12:36:52 -07:00
Sean Gilligan
54cd676560 StreamUtils: new util class with .toUnmodifiableList(), and use it
This will also make it easier to find and upgrade these
methods when we upgrade to newer JDKs.
2022-07-27 19:49:32 +02:00
Sean Gilligan
225551593d Coin: improve JavaDoc
Also add explicit `throws ArithmeticException` on the
two BigDecimal conversion methods to match the `@throws`
in the JavaDoc.
2022-07-27 12:05:45 +02:00
Andreas Schildbach
e5558986d4 LinuxSecureRandom: don't automatically install RNG workaround any more
LinuxSecureRandom used to be installed on Android because very old Android versions had a bug
in the random number generator. We don't support those old versions any more, so the workaround
has become unnecessary. It is still possible to initialize it manually if desired.
2022-07-19 19:57:38 +02:00
Andreas Schildbach
abc81d6d6e Transaction: remove the Android performance hack from getValue()
Mobile devices have become very powerful over the years, so a specific optimization
like this should not be needed.
2022-07-19 18:46:10 +02:00
Andreas Schildbach
9763a40a46 CoinSelection: fix JavaDoc by removing type argument 2022-07-19 16:54:25 +02:00
Andreas Schildbach
26f343a607 DefaultCoinSelector: use checked add to sum up output values 2022-07-19 10:28:10 +02:00
Andreas Schildbach
f6cb6c15d1 CoinSelection: add a new constructor that doesn't require valueGathered
We'll add the output values up ourselves.

This also deprecates the old constructor.
2022-07-19 09:37:27 +02:00
Sean Gilligan
e7b8508491 BitcoinNetwork: build name lists and map at init time
* In constructor create a list of all names
* Build static map of names to BitcoinNetwork at class initialization time
2022-07-14 16:19:12 -07:00
Sean Gilligan
dae9e0fff6 BitcoinNetwork: simplify declaration of alternateNames 2022-07-14 23:06:10 +02:00
Andreas Schildbach
fb90c4458d 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.
2022-07-14 01:59:49 +02:00
Sean Gilligan
9f02cd2af3 WalletAppKit: add constructor with BitcoinNetwork, deprecate others
* WalletAppKit: add a constructor that takes a BitcoinNetwork
* WalletAppKit: deprecate constructors taking netParams or Context
* WalletAppKit: add an accessor for network()
* Update examples, tools, and wallettemplate to use the new constructor
2022-07-13 22:59:17 +02:00
Sean Gilligan
e98b5e68fc NetworkParameters: make network final
* Make the private member `network` final.
* Constructor requires a network
* Update super() calls in subclasses
2022-07-13 22:20:35 +02:00
Andreas Schildbach
50ccb6b8fc Network: rename MAIN to MAINNET and TEST to TESTNET
The old, shorter names can be used as an alternate name so they will still be accepted for user-facing input.
2022-07-13 22:04:31 +02:00
Sean Gilligan
567d88e13f Network: uriScheme moved from NetworkParameters 2022-07-13 20:19:26 +02:00
Andreas Schildbach
932a871f86 BitcoinNetwork: allow a number of common alternate network names in fromString()
Also adds tests.
2022-07-12 15:15:38 +02:00
Sean Gilligan
60bad143ff BitcoinNetwork: simplify/standardize static factories and use lowercase strings for input/output
Also adds tests.
2022-07-12 01:05:04 +02:00
Sean Gilligan
b375a96565 BitcoinNetwork: of()/find() get by name, ofId()/findById() by ID 2022-07-11 09:43:05 +02:00
Sean Gilligan
e78bb3438e NetworkParameters: deprecate getMonetaryFormat() 2022-07-08 08:21:58 -07:00
Sean Gilligan
80595e1a58 Network: hasMaxMoney(), maxMoney() moved from NetworkParameters
Deprecate methods in NetworkParameters/AbstractBitcoinNetParams.
2022-07-08 11:15:00 +02:00
Sean Gilligan
a4299dfb39 Network: add interface and implement in BitcoinNetwork enum 2022-07-06 17:26:00 +02:00
Sean Gilligan
089f9c45e4 Wallet.SendRequest: construct from TransactionBroadcast only
Simplify the constructor for Wallet.SendRequest to only take
a TransactionBroadcast object. The transaction was inside
the TransactionBroadcast object anyway, we just had to create
an accessor.

This paves the way for removing SendResult entirely and replacing
it with TransactionBroadcast.
2022-07-06 17:02:22 +02:00
Sean Gilligan
47eb2620cc o.b.c.net: TimeoutHandler interface replaces abstract base class
* Create TimeoutHandler interface
* Create standalone SocketTimeoutTask to implement it
* Deprecate and replace AbstractTimeoutHandler

This simplifies the inheritance of PeerSocketHandler and NioClient and
will enable future refactoring.
2022-07-06 15:39:53 +02:00
Sean Gilligan
458b777d51 PeerGroup: use standard ScheduledExecutorService instead of Listenable
Since we migrated to (Listenable)CompletableFuture in startAync/stopAsync
we no longer need it.
2022-07-06 15:27:27 +02:00
Sean Gilligan
043993645d TaggableObject, BaseTaggableObject: deprecate setting and getting tags on objects
The only known usage of this feature is in the JavaFX wallettemplate where
it is used to save the estimated elapsed time for deriving a key for purposes
of displaying a progress bar.
2022-07-06 15:18:26 +02:00
Sean Gilligan
b8729f2fbd Network: rename to BitcoinNetwork
This is done in preparation for introducing a `Network` interface as a parent,
coming in a future commit.
2022-06-27 12:11:25 +02:00
Sean Gilligan
3bb2af795f Address: deprecate getParameters() and find alternatives for its usages
* Add NetworkParameters.fromAddress() method to consolidate the use cases
  where an Address is used to get a NetworkParameters
* Deprecate NetworkParameters.fromAddress() to indicate code must be rewritten
* This also removes one dependency on NetworkParameters in Address and helps
  prepare for moving Address to `o.b.base`
2022-06-26 22:05:44 +02:00
Sean Gilligan
bfa6536942 org.bitcoinj.base: move Network to base 2022-06-26 20:05:09 +02:00
Sean Gilligan
26117bbda8 Address: add network() helper to allow migrating away from using NetworkParameters 2022-06-26 19:49:20 +02:00
Sean Gilligan
1d5e752917 Address: implement PrefixedChecksummedBytes inline, rather than extend it
In preparation for future refactoring of Address, we don't want Address
tied to a base class with dependencies on o.b.core or NetworkParameters.

We also want the option of making Address itself an interface in the future.

This results in some code duplication but there is no strong need for or
use of polymorphism in the subclasses of PrefixedChecksummedBytes.

Since equals() was copied from NetworkParameters into Address, create AddressTest
and copy the equals() test from PrefixedChecksummedBytesTest.
2022-06-26 19:36:29 +02:00
Andreas Schildbach
bd002594eb Context: remove useless Context instantiations from a few tests 2022-06-26 17:26:04 +02:00
Andreas Schildbach
76c8d71e44 Context: fix implicit context propagation by constructor
We used to do this a long time ago, but switched the codebase to explicit propagation.
Generally, constructors should not have any side-effects.
2022-06-26 17:09:15 +02:00
Sean Gilligan
ddfaa606af ScriptType: add ID string, deprecate numeric ID 2022-06-26 16:03:16 +02:00
Sean Gilligan
a40ca0ce26 NetworkParameters: deprecate/move fromID()
Deprecate static fromID() method that only knows about Bitcoin networks and
move to AbstractBitcoinNetParams.
2022-06-25 14:52:18 -07:00
Sean Gilligan
fc036c6fd0 NetworkParameters: fix JavaDoc error that breaks build
Removing the whole line because the suggested method doesn't exist yet.
2022-06-25 22:58:09 +02:00
Sean Gilligan
ce103ed2c3 NetworkParameters: move payment protocol related IDs and methods to PaymentProtocol
The old symbols are marked as deprecated.
2022-06-25 18:26:37 +02:00
Sean Gilligan
a0b0392093 NetworkParameters: depend on Network enum, rather the reverse
This change makes NetworkParameters use and depend upon Network instead
of the reverse. This will allow Network to be moved to `base`.

Define `UnitTestParams` as being on the `TEST` network. We must choose
a `Network` property for `UnitTestParams` and I have learned through trial-and-error
that `TEST` is the correct choice.
2022-06-24 12:30:40 +02:00
Andreas Schildbach
7db1521b6c ByteUtils: fix integer shift implicitly cast to long problem 2022-06-23 17:06:33 +02:00
Andreas Schildbach
8ab62e7149 ByteUtils: fix redundant type casts 2022-06-23 17:06:33 +02:00
Andreas Schildbach
91f22138e8 ByteUtils: fix long literal ends with lowercase l problems 2022-06-23 17:06:28 +02:00
Sean Gilligan
ef870fcbc8 PrefixedChecksummedBytes: remove unused transient keyword
Now that serialization support has been removed from PrefixedChecksummedBytes,
we no longer need the `transient` keyword.
2022-06-23 16:54:27 +02:00