mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-01-18 13:22:42 +01:00
ForwardingService: extract method waitForConfirmation()
This commit is contained in:
parent
68cacbebbc
commit
ed525652a4
@ -25,6 +25,7 @@ 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;
|
||||
import org.bitcoinj.kits.WalletAppKit;
|
||||
import org.bitcoinj.utils.BriefLogFormatter;
|
||||
@ -133,15 +134,7 @@ public class ForwardingService {
|
||||
// be called in onSetupCompleted() above. But we don't do that here to demonstrate the more common
|
||||
// case of waiting for a block.
|
||||
|
||||
tx.getConfidence().getDepthFuture(requiredConfirmations).whenComplete((result, t) -> {
|
||||
if (result != null) {
|
||||
System.out.println("Confirmation received.");
|
||||
forwardCoins(forwardingAddress);
|
||||
} else {
|
||||
// This kind of future can't fail, just rethrow in case something weird happens.
|
||||
throw new RuntimeException(t);
|
||||
}
|
||||
});
|
||||
waitForConfirmation(tx);
|
||||
});
|
||||
|
||||
Address sendToAddress = LegacyAddress.fromKey(params, kit.wallet().currentReceiveKey());
|
||||
@ -153,6 +146,22 @@ public class ForwardingService {
|
||||
} catch (InterruptedException ignored) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for confirmation on a transaction.
|
||||
* @param tx the transaction we are waiting for
|
||||
*/
|
||||
void waitForConfirmation(Transaction tx) {
|
||||
tx.getConfidence().getDepthFuture(requiredConfirmations).whenComplete((result, t) -> {
|
||||
if (result != null) {
|
||||
System.out.println("Confirmation received.");
|
||||
forwardCoins(forwardingAddress);
|
||||
} else {
|
||||
// This kind of future can't fail, just rethrow in case something weird happens.
|
||||
throw new RuntimeException(t);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static String getPrefix(BitcoinNetwork network) {
|
||||
return String.format("forwarding-service-%s", network.toString());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user