Commit graph

4038 commits

Author SHA1 Message Date
Sean Gilligan
2bd3a8bcde TransactionBroadcast: use stream to simplify collecting sentFutures 2022-07-31 12:08:14 +02:00
Sean Gilligan
419dba9845 TransactionBroadcast: extract method dropPeerAfterBroadcastHandler(Peer)
Refactor the creation of this lambda to its own method.
2022-07-31 11:53:49 +02:00
Sean Gilligan
81fd758800 TransactionBroadcast: extract method broadcastOne(Peer)
* Move code to broadcast to one peer into broadcastOne(Peer) method
* Stop swallowing (but logging) exception thrown by peer.sendMessage(tx)
2022-07-31 11:37:31 +02:00
Sean Gilligan
e078421edd Context: re-add constructors that take params (as deprecated)
There are apps and libraries that are using these, we need to keep them as @Deprecated for
at least one release.
2022-07-30 14:13:40 +02:00
Andreas Schildbach
56419ded8e TransactionBroadcast: fix missing brace in JavaDoc 2022-07-30 13:35:10 +02:00
Sean Gilligan
32c58ad723 TransactionBroadcast: internally create/complete sentFuture
* Add a private member called `sentFuture` that completes when the broadcast
  is "sent" (written to buffer) to the broadcast peers
* Update the broadcast() method to track success/failure of the individual
  broadcast messages and update sentFuture when the individual messages complete.
  (This is done by using `thenComposeAsync`/`whenComplete`)
* Add comments and TODOs
2022-07-29 13:22:00 -07: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
Sean Gilligan
c89128c77b TransactionBroadcast: make 2 private members final 2022-07-29 10:28:21 +02:00
Sean Gilligan
5a1536df3b TransactionBroadcast: rename private future to seenFuture, add comments 2022-07-29 10:26:10 +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
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
900af2bde9 build.gradle: update JUnit 5 to 5.9.0 2022-07-28 20:50:06 +02:00
Andreas Schildbach
e12ad507ba WalletAppKitTest: fix using wrong annotation for disabling tests 2022-07-28 20:01:02 +02:00
Sean Gilligan
6b131a7780 WalletAppKitTest: new integration-test for WalletAppKit 2022-07-28 19:34:35 +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
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
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
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