Wallet: Add isAddressMine() convenience method.

This commit is contained in:
Andreas Schildbach
2019-02-01 16:02:28 +01:00
parent e3e4e3f32a
commit 68c5a622d2

View File

@@ -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;