From 68c5a622d25f1f53f24bf9ad833707d604364427 Mon Sep 17 00:00:00 2001 From: Andreas Schildbach Date: Fri, 1 Feb 2019 16:02:28 +0100 Subject: [PATCH] Wallet: Add isAddressMine() convenience method. --- core/src/main/java/org/bitcoinj/wallet/Wallet.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/src/main/java/org/bitcoinj/wallet/Wallet.java b/core/src/main/java/org/bitcoinj/wallet/Wallet.java index 50a7c73f..83165326 100644 --- a/core/src/main/java/org/bitcoinj/wallet/Wallet.java +++ b/core/src/main/java/org/bitcoinj/wallet/Wallet.java @@ -58,6 +58,7 @@ import org.bitcoinj.core.VerificationException; import org.bitcoinj.core.TransactionConfidence.*; import org.bitcoinj.crypto.*; import org.bitcoinj.script.*; +import org.bitcoinj.script.Script.ScriptType; import org.bitcoinj.signers.*; import org.bitcoinj.utils.*; import org.bitcoinj.wallet.Protos.Wallet.*; @@ -1015,6 +1016,17 @@ public class Wallet extends BaseTaggableObject } } + /** + * Returns true if the address is belongs to this wallet. + */ + public boolean isAddressMine(Address address) { + final ScriptType scriptType = address.getOutputScriptType(); + if (scriptType == ScriptType.P2PKH || scriptType == ScriptType.P2WPKH) + return isPubKeyHashMine(address.getHash()); + else + throw new IllegalArgumentException(address.toString()); + } + @Override public boolean isPubKeyHashMine(byte[] pubkeyHash) { return findKeyFromPubHash(pubkeyHash) != null;