Commit Graph

340 Commits

Author SHA1 Message Date
Sean Gilligan
884072c9e3 WalletAppKit: make Closeable 2023-03-26 19:40:28 +02:00
Sean Gilligan
84c8a2887a ForwardingService: make Closable not AutoCloseable
`Closeable` implements `AutoCloseable` but narrows the exception thrown
from `Exception` to `IOException`. ForwardingService.close() currently
doesn't throw any exceptions.
2023-03-26 19:37:08 +02:00
Sean Gilligan
f58d07a623 ForwardingService: start() returns receiving address 2023-03-26 18:10:09 +02:00
Andreas Schildbach
04c72ce003 Peer: migrate pingIntervals field to java.time API 2023-03-19 20:15:00 +01:00
Andreas Schildbach
b309308076 EncryptableItem: rename creationTime() method from getCreationTime() 2023-03-18 11:23:05 +01:00
Andreas Schildbach
9ec245c259 Objects: migrate entire codebase to requireNonNull() from Guava Precondition.checkNotNull()
This has the added benefit of exception messages being evaluated on demand.
2023-03-16 20:12:28 +01:00
Andreas Schildbach
54754e14e9 EncryptableItem, ECKey, DeterministicKey, DeterministicSeed: migrate creationTime field to java.time API 2023-03-10 09:28:27 +01:00
Sean Gilligan
3023947df8 ByteUtils: move to o.b.base.internal
We don't consider ByteUtils to be part of our external API.
2023-03-10 01:28:23 +01:00
Andreas Schildbach
92ee36848c DeterministicSeed: introduce static constructors meant for external consumers
* native constructors that were meant to be called by consumers now have static equivalents
* all native constructors are discouraged from being used by a JavaDoc comment
* one constructor that wasn't meant to be used by consumers is switched to private access
* tests and tools that resemble consumers are updated to use the new API

Note: although most native constructors are now deprecated, we're not using
annotations because we're still calling them.
2023-03-10 00:53:35 +01:00
Andreas Schildbach
913f5ac8c6 PeerDiscovery: migrate getPeers() to java.time API 2023-03-03 00:10:35 +01:00
Sean Gilligan
916989a7cd ByteUtils: replace HEX (Guava BaseEncoding) with with own implementation
* Deprecate ByteUtils.HEX
* Migrate usages to new ByteUtils.formatHex() and ByteUtils.parseHex()
* Direct use of Guava BaseEncoding in tests that use some specific
  features of BaseEncoding that aren't provided by new methods.
2023-03-02 15:16:06 +01:00
Sean Gilligan
03782a4697 InternalUtils: move to o.b.base.internal package 2023-02-24 11:47:59 +01:00
Sean Gilligan
0d3c9780b0 SignatureDecodeException: move to o.b.crypto package 2023-02-24 11:21:11 +01:00
Sean Gilligan
1b0ac02eed ECKey, DumpedPrivateKey, EncodedPrivateKey: move to o.b.crypto package
Also move associated tests and test resources.
2023-02-24 10:49:35 +01:00
Sean Gilligan
74821e3517 DefaultAddressParser: move from o.b.core to base 2023-02-24 09:45:59 +01:00
Sean Gilligan
804e8cafec examples: always use BitcoinNetwork enum to specify network
* Replace all usages of *Net*Params.get() with BitcoinNetwork.* enum
* Where NetworkParameters is needed get it with NetworkParameters.of(network)

This change does the following:

* Makes it clear that BitcoinNetwork.* is the preferred method of specifying/declaring
  the active network.
* Prepares the way for examples to get the network string as a command-line arg
* Continues the general migration from NetworkParameters to Network
2023-02-21 18:54:37 +01:00
Sean Gilligan
0acfcb10ec PeerGroup: migrate constructors argument from NetworkParameters to Network
* Add 3 new constructors which take Network
* Deprecate (2 of 3) constructors that take NetworkParameters
* Mark 3-arg NetworkParameters constructor as @VisibleForTesting
2023-02-17 20:21:48 +01:00
Sean Gilligan
d354bc13ce Address, LegacyAddress, SegwitAddress, AddressParser: move to o.b.base
* Move related tests too
* Update imports in referencing classes
2023-02-16 22:50:02 +01:00
Andreas Schildbach
7b970e6001 build.gradle: update picocli to 4.7.1 2023-01-29 21:35:31 +01:00
Andreas Schildbach
8bd519624d build.gradle: update picocli to 4.7.0 2022-11-14 08:10:13 +01:00
Sean Gilligan
94ad7dd344 PeerMonitor: use CompletableFuture for lookupReverseDNS() and getAddr()
* Create threadpool for reverseDns (rather than use new Thread() repeatedly)
* For getAddr() run completion handler on callback thread (and eliminate new Thread())
* Add getHostName() method that handles case where peerAddress.getAddr() is null
2022-08-23 01:09:17 +02:00
Sean Gilligan
39d799e58f PeerMonitor: simplify getAddressForPeer() with trinary operator 2022-08-23 01:02:13 +02:00
Sean Gilligan
2dfd5befb9 PeerMonitor: use ConcurrentHashMap rather than manually synchronized HashMap
* Use ConcurrentHashMap for `reverseDnsLookups` and `addressMessages`
* Remove now-unnecessary `synchronized` blocks
2022-08-17 11:00:56 +02:00
Andreas Schildbach
83644530cd EncodedPrivateKey: migrate from NetworkParameters to Network 2022-08-17 09:34:04 +02:00
Andreas Schildbach
55d1919227 Address, LegacyAddress, SegwitAddress: migrate all usages of deprecated fromKey() to ECKey.toAddress() 2022-08-11 01:49:10 +02:00
Sean Gilligan
d5e2319eb7 Network, BitcoinNetwork: partial alt-net support
Distinguish between `Network` and `BitcoinNetwork` in the code
(some of our implementation supports alt-networks better than others
 and this commit doesn't try to fix them all, just make it more clear
 what is going on. Some may never be made 'generic')
2022-08-10 22:14:17 +02:00
Sean Gilligan
51f1d69e87 Address: deprecate fromString, replace with AddressParser
This change migrates from using `NetworkParameters` to `Network` for specifying the network and
also decouples from static methods in `Address` with an interface/implementation approach.

Note that there are 3 use cases for address parsing:

1. Any network is allowed - AddressParser.parseAddressAnyNetwork(String)
2. Parse for a specified network - AddressParser.parseAddress(String, Network)
3. Parse for a previously-specified (context dependent) network - AddressParser.Strict.parseAddress(String)

In most use cases, an AddressParser instance can be accessed through the Wallet,
which already knows the Network type and in this context validation for network makes
sense. This is why `Wallet` is implementing `AddressParser.Strict`

BitcoinURI allocates its own DefaultAddressParser for now, as do some other tests
and examples that don't have access to a Wallet

In the future DefaultAddressParser may be replaced by something loaded
via the ServiceLoader mechanism or other dynamically configured mechanism.
2022-08-03 18:14:48 +02:00
Sean Gilligan
02aa41e254 TestFeeLevel, DoubleSpend, SendRequest: construct WalletAppKit with BitcoinNetwork constant
This reduces usage of NetworkParameters in WalletAppKit-based examples and tools.
2022-08-01 10:00:06 +02:00
Sean Gilligan
30595af6e4 ForwardingService: use collectingAndThen() to simplify forwardingCoinSelector() 2022-07-29 10:53:57 +02:00
Sean Gilligan
15d0134937 ForwardingService: static method to create CoinSelector
This uses partial function application rather than creating a class
to create the parent-transaction only CoinSelector.
2022-07-29 10:47:30 +02:00
Andreas Schildbach
adb6bcc921 ForwardingService: make the forwarding a safe operation
By using a CoinSelector that selects exactly the outputs that have been sent to us,
we make sure that

* we exactly send the value that has been sent to us, minus fee
* if the incoming transaction became invalid (e.g. due to a re-org),
  our outgoing transaction would become invalid, too

Strictly speaking, after this change we would not need to wait for confirmations any
more.
2022-07-28 22:48:45 +02:00
Andreas Schildbach
509694d9ad ForwardingService: reduce redundant console output at startup 2022-07-28 15:00:20 +02:00
Sean Gilligan
62fecfa37c ForwardingService: don't wait for blockchain synchronization before entering RUNNING state
This will speed up synchronization because the .setMaxConnections() call
will occur before synchronization is finished and the necessary number of Peers
will be found sooner.

Also IMO this a better example because most apps should not block while syncing the chain.
2022-07-28 14:45:07 +02:00
Sean Gilligan
6be2fd4999 ForwardingService: add directory parameter for wallet files
This will allow integration tests to put the files in a temporary directory
and is a good practice in general.
2022-07-28 13:27:03 +02:00
Sean Gilligan
fb6add760b ForwardingService: improve the implementation of close()
* Don't try to remove listener (access .wallet()) unless kit.isRunning()
* Don't wait for termination, just call kit.stopAsync()
* Add some JavaDoc
2022-07-19 09:28:42 +02:00
Sean Gilligan
498d638915 ForwardingService: properly handle shutdown
* ForwardingService to implement AutoClosable and use try-with-resources
* Add `kit.stopAsync()` and `kit.awaitTerminated()` in `close()`
2022-07-19 02:24:06 +02:00
Andreas Schildbach
9fc5d32abd ForwardingService: upper-case two constants 2022-07-18 23:23:39 +02:00
Andreas Schildbach
be744c2fe1 ForwardingService: infer network from address
This means for mainnet and testnet, you don't have to provide the network name.
It will be inferred from the address. For signet and regtest however the network
name is still needed.
2022-07-18 23:05:44 +02:00
Sean Gilligan
165804965e ForwardingService: convert to CompletableFuture
* Use `CompletableFuture` for all asynchronous operations
* Use `thenCompose` to chain them
* sendTransaction takes a SendRequest and returns a TransactionBroadcast
* The main "CoinsReceived" listener method uses one .thenCompose() for
  completing/signing/preparing-to-broadcast the transaction and another for waiting
  for it to be confirmed by peers.
2022-07-18 21:55:47 +02:00
Andreas Schildbach
e1585cebac ForwardingService: print the hash of the forwarding transaction earlier 2022-07-17 19:53:11 +02:00
Andreas Schildbach
691cd46267 ForwardingService: limit the number of peer connections required
Nowadays on testnet or signet it takes a long time to discover enough bloom-enabled peers.
2022-07-17 19:42:57 +02:00
Sean Gilligan
50f46651b4 ForwardingService: move getPrefix() to end of file
This is meant to make the coming refactoring to CompletableFuture more
readable. It was in the middle of three main methods.
2022-07-17 00:13:19 +02:00
Sean Gilligan
95fb0ec3a4 ForwardingService: move println's and busy wait from waitForCoins() to forward()
This is in preparation for a refactoring to CompletableFuture, coming in a future commit.
2022-07-16 23:26:23 +02:00
Andreas Schildbach
c9835eb668 ForwardingService: support segwit addresses as receive address
This also potentially fixes the wallet not detecting incoming payments,
because it's looking for the wrong script type.
2022-07-16 22:54:30 +02:00
Andreas Schildbach
5259cc1d72 ForwardingService: replace copyright with generic statement 2022-07-16 21:44:04 +02:00
Sean Gilligan
ed525652a4 ForwardingService: extract method waitForConfirmation() 2022-07-16 11:52:28 +02:00
Sean Gilligan
68cacbebbc ForwardingService: rename one of the two forward() methods to clear up confusion 2022-07-16 11:42:37 +02:00
Sean Gilligan
a057cd04f6 ForwardingService: simplify argument parsing 2022-07-15 22:37:51 +02:00
Sean Gilligan
8e4cae391c ForwardingService: split main() into main() and forward() 2022-07-15 19:54:21 +02:00
Sean Gilligan
ccba23bd29 ForwardingSevice: add an address parameter to forwardCoins()
This makes forwardCoins() a little more generically-useful and
simplifies the coming conversion to CompletableFuture.
2022-07-15 15:59:28 +02:00
Sean Gilligan
a06134cc18 ForwardingService: simplify getPrefix()
Use network.toString(). This also adds support for SIGNET. It changes the
filename for MAINNET, but as this is just an example I don't think we really
need to preserve backward-compatibility for the filename.
2022-07-15 15:53:43 +02:00
Andreas Schildbach
95b063f3f4 ForwardingService: fix context not initialized 2022-07-14 10:44:50 +02:00
Sean Gilligan
d29c80a1ed ForwardingService: use BitcoinNetwork.fromString() to parse network CLI parameter 2022-07-13 23:32:51 +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
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
Andreas Schildbach
bca5faaba2 ForwardingService: fix testnet parameter in parseNetwork() 2022-07-10 20:51:24 +02:00
Sean Gilligan
42639c2d11 ForwardingService: add signet support 2022-07-10 00:05:40 +02:00
Sean Gilligan
24d0e68725 ForwardingService: move network argument parsing to parseNetwork()
Also adds an explicit "main" option.
2022-07-10 00:04:21 +02:00
Sean Gilligan
e5dc4f0c24 ForwardingService: remove unused imports 2022-07-09 23:39:32 +02:00
Sean Gilligan
cbe1833e04 ForwardingService: create singleton class, simplify main() 2022-07-09 22:24:15 +02:00
Sean Gilligan
d3599482c8 ForwardingService: extract getPrefix() 2022-07-09 22:21:18 +02:00
Sean Gilligan
a8e43b1b15 ForwardingService: use BitcoinNetwork where possible 2022-07-09 20:51:50 +02:00
Sean Gilligan
89fb6fe0a8 ForwardingService: extract requiredConfirmations to a variable 2022-07-09 12:18:22 +02:00
Sean Gilligan
44d0576ce4 org.bitcoinj.base: move Base58, Bech32, AddressFormatException to base 2022-06-23 11:48:01 +02:00
Sean Gilligan
0645a835de org.bitcoinj.base: move Script.ScriptType to a top level type in base 2022-06-22 18:13:34 +02:00
Sean Gilligan
93cc0ac9c5 org.bitcoinj.base: move Sha256Hash and byte/math Utils members to base
* move o.b.core.Sha256Hash to o.b.base.Sha256Hash
* move byte and math utility methods from o.b.core.Utils to a new
  o.b.base.ByteUtils class
2022-06-22 17:40:50 +02:00
Sean Gilligan
84e737acdf org.bitcoinj.base: introduce new package that provides fundamental types with minimal dependencies
This also moves Coin, Fiat, its parent Monetary and the related MonetaryFormat into the new base package.

See the provided package-info.java for details.
2022-06-21 19:25:47 +02:00
Andreas Schildbach
837b614906 ForwardingService, PrivateKeys: also parse segwit addresses from arguments 2022-05-01 00:12:22 +02:00
Andreas Schildbach
eb71e0b0c6 DoubleSpend, SendRequest: migrate hardcoded addresses to segwit 2022-05-01 00:10:28 +02:00
Sean Gilligan
c3896e6caf examples/tools: use explicit script type and wallet structure
* Explicitly use P2WPKH (this changes behavior to segwit)
* Explicitly use BIP32 (this is the same behavior as before)
2022-04-30 23:24:25 +02:00
Sean Gilligan
a6e5c88ce8 build.gradle: add detailed deprecation warnings to all modules 2022-04-19 10:07:55 +02:00
Sean Gilligan
1219e0d7b0 InternalUtils: replace Guava Joiner and Splitter with native JDK equivalent
Also deprecate the old Joiner and Splitter related members of Utils.
2022-04-10 16:20:00 +02:00
Sean Gilligan
003b6dc52d SendRequest: migrate from ListenableFuture to CompletableFuture 2022-03-07 22:33:27 +01:00
Sean Gilligan
b8c72c996a FetchTransactions, PrintPeers: more CompletableFuture conversions 2022-03-07 14:39:50 +01:00
Sean Gilligan
eb56d71f8f TransactionConfidence: Convert to CompletableFuture 2022-03-04 13:04:41 -08:00
Andreas Schildbach
52babf52b0 LevelDBBlockStore, LevelDBFullPrunedBlockStore: remove LevelDB-based block stores 2022-03-04 18:27:40 +01:00
Sean Gilligan
9db8b49c50 Convert TransactionBroadcast, Wallet.doMaintenance() to CompletableFuture
* Use ListenableCompletableFuture on all public APIs
* Use CompletableFuture internally, in example, and in tests
* Add new FutureUtils class
* Add 2 new static methods to ListenableCompletableFuture
2022-02-24 20:48:54 +01:00
Sean Gilligan
7626b27850 build.gradle: update picocli to 4.6.3 2022-02-18 09:02:24 +01:00
Sean Gilligan
ea208935ff build.gradle: Update SLF4J to 1.7.36
Starting with version 1.7.36, SLF4J releases are reproducible.
2022-02-18 08:54:36 +01:00
Sean Gilligan
0d67977ca1 build.gradle: Update examples and tools submodules to JDK 11 2022-01-04 03:03:44 +01:00
Andreas Schildbach
d3d5edbcbd NetworkEnum: delete unused class from examples 2021-12-25 11:26:47 +01:00
Sean Gilligan
a2cf303655 build.gradle: require JDK 11 for the build
Uses javac -release option to validate API for older JDK.
2021-12-24 11:35:37 +01:00
Andreas Schildbach
0b5d40e49f Remove references to a specific testnet faucet. 2021-10-22 09:08:21 +02:00
Sean Gilligan
6da10f8641 build.gradle: Update SLF4J to 1.7.32. 2021-09-17 11:51:11 +02:00
Andreas Schildbach
e407240b7e Support BIP133 feefilter messages. 2021-05-03 16:23:51 +02:00
Andreas Schildbach
1db44fb4f1 PeerMonitor: Show an additional column with the results of an getaddr request. 2021-04-22 16:50:07 +02:00
Andreas Schildbach
04a71b09af PeerMonitor: Increase initial size of window. 2021-04-22 16:02:19 +02:00
Andreas Schildbach
39bb7faafb PeerMonitor: Simplify a switch-case. 2021-04-22 15:59:09 +02:00
Andreas Schildbach
ffb02ae760 Script: Deprecate non-segwit variant of correctlySpends(). 2021-03-07 09:43:55 +01:00
Andreas Schildbach
8906e7cc27 Transaction: Add toHexString() for converting a transaction to raw hex format. 2021-02-16 11:26:09 +01:00
Andreas Schildbach
4c094ef193 WalletTool, BuildCheckpoints, FetchBlock: Migrate parsing of command line options from JOpt to picocli. 2021-02-11 16:15:16 +01:00
Andreas Schildbach
f0bbb92bcf ForwardingService: Get rid of unused forwardCoins() method argument. 2020-10-24 16:45:04 +02:00
Andreas Schildbach
b6b221ae1b Apply "Anonymous type has shorter lambda alternative" refactoring. 2020-09-07 21:13:14 +02:00
Andreas Schildbach
c08a4d97d3 Apply "Anonymous type can be replaced with lambda" refactoring. 2020-09-07 21:13:14 +02:00
Andreas Schildbach
4847a9df27 Apply "Explicit generic type can be replaced with <>" refactoring. 2020-09-07 21:10:44 +02:00
Andreas Schildbach
7d9f109ee1 Peer: Deprecate a redundant constructor. 2020-03-04 17:34:11 +01:00
Andreas Schildbach
06bd0a841e PeerDiscovery: Change getPeers() return type from array to list.
This gets rid of a lot of array/list conversions.
2020-03-04 12:35:02 +01:00
Sean Gilligan
e4c6b98536 Make Guava an api dependency using java-library
Use the Gradle java-library plugin to make Guava an `api`
dependency since Guava types are used in the bitcoinj public API.

This allows us to remove explicit dependencies on
Guava in the other modules.
2020-02-29 15:28:09 -08:00
Andreas Schildbach
0112e3ccbe Update slf4j to 1.7.30. 2020-01-23 01:16:58 +01:00
Andreas Schildbach
68538e57af Update Guava to 28.2-android. 2020-01-23 01:09:35 +01:00