From f58d07a6231ae7862a423508da0dd384cddefe05 Mon Sep 17 00:00:00 2001 From: Sean Gilligan Date: Sun, 26 Mar 2023 08:35:02 -0700 Subject: [PATCH] ForwardingService: `start()` returns receiving address --- .../org/bitcoinj/examples/ForwardingService.java | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/examples/src/main/java/org/bitcoinj/examples/ForwardingService.java b/examples/src/main/java/org/bitcoinj/examples/ForwardingService.java index c9ced7fcc..38419682c 100644 --- a/examples/src/main/java/org/bitcoinj/examples/ForwardingService.java +++ b/examples/src/main/java/org/bitcoinj/examples/ForwardingService.java @@ -91,10 +91,10 @@ public class ForwardingService implements AutoCloseable { // Create the Service (and WalletKit) try (ForwardingService forwardingService = new ForwardingService(directory, address, network)) { // Start the Service (and WalletKit) - forwardingService.start(); + Address receivingAddress = forwardingService.start(); // After we start listening, we can tell the user the receiving address - System.out.printf("Waiting to receive coins on: %s\n", forwardingService.receivingAddress()); + System.out.printf("Waiting to receive coins on: %s\n", receivingAddress); System.out.println("Press Ctrl-C to quit."); try { @@ -124,8 +124,9 @@ public class ForwardingService implements AutoCloseable { /** * Start the WalletAppKit + * @return The receiving address for the forwarding wallet */ - public void start() { + public Address start() { if (network == BitcoinNetwork.REGTEST) { // Regression test mode is designed for testing and development only, so there's no public network for it. // If you pick this mode, you're expected to be running a local "bitcoind -regtest" instance. @@ -139,6 +140,7 @@ public class ForwardingService implements AutoCloseable { // Start listening and forwarding kit.wallet().addCoinsReceivedEventListener(listener); + return kit.wallet().currentReceiveAddress(); } /** @@ -242,13 +244,6 @@ public class ForwardingService implements AutoCloseable { return future; } - /** - * @return The current receiving address of the forwarding wallet - */ - public Address receivingAddress() { - return kit.wallet().currentReceiveAddress(); - } - static String getPrefix(BitcoinNetwork network) { return String.format("forwarding-service-%s", network.toString()); }