From c9835eb6684cdaf0c30490aa35abd55b533f2134 Mon Sep 17 00:00:00 2001 From: Andreas Schildbach Date: Sat, 16 Jul 2022 22:54:30 +0200 Subject: [PATCH] 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. --- .../main/java/org/bitcoinj/examples/ForwardingService.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/examples/src/main/java/org/bitcoinj/examples/ForwardingService.java b/examples/src/main/java/org/bitcoinj/examples/ForwardingService.java index e5d2cc2ee..2eb0cc804 100644 --- a/examples/src/main/java/org/bitcoinj/examples/ForwardingService.java +++ b/examples/src/main/java/org/bitcoinj/examples/ForwardingService.java @@ -22,7 +22,6 @@ import org.bitcoinj.core.Address; import org.bitcoinj.base.Coin; import org.bitcoinj.core.Context; import org.bitcoinj.core.InsufficientMoneyException; -import org.bitcoinj.core.LegacyAddress; import org.bitcoinj.core.NetworkParameters; import org.bitcoinj.core.Transaction; import org.bitcoinj.crypto.KeyCrypterException; @@ -44,7 +43,6 @@ public class ForwardingService { static final String usage = "Usage: address-to-send-back-to [mainnet|testnet|signet|regtest]"; static final int requiredConfirmations = 1; private final BitcoinNetwork network; - private final NetworkParameters params; private final Address forwardingAddress; private final WalletAppKit kit; @@ -89,7 +87,6 @@ public class ForwardingService { public ForwardingService(Address forwardingAddress, BitcoinNetwork network) { this.forwardingAddress = forwardingAddress; this.network = network; - this.params = NetworkParameters.of(network); // Start up a basic app using a class that automates some boilerplate. kit = new WalletAppKit(network, @@ -136,7 +133,7 @@ public class ForwardingService { waitForConfirmation(tx); }); - Address sendToAddress = LegacyAddress.fromKey(params, kit.wallet().currentReceiveKey()); + Address sendToAddress = kit.wallet().currentReceiveAddress(); System.out.println("Send coins to: " + sendToAddress); System.out.println("Waiting for coins to arrive. Press Ctrl-C to quit.");