mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-01-19 05:33:44 +01:00
Wallet: Add findKeyFromAddress() convenience method.
This commit is contained in:
parent
68c5a622d2
commit
492b3c7f8d
@ -1042,6 +1042,18 @@ public class Wallet extends BaseTaggableObject
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Locates a keypair from the wallet given the corresponding address.
|
||||
* @return ECKey or null if no such key was found.
|
||||
*/
|
||||
public ECKey findKeyFromAddress(Address address) {
|
||||
final ScriptType scriptType = address.getOutputScriptType();
|
||||
if (scriptType == ScriptType.P2PKH || scriptType == ScriptType.P2WPKH)
|
||||
return findKeyFromPubHash(address.getHash());
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Locates a keypair from the basicKeyChain given the raw public key bytes.
|
||||
* @return ECKey or null if no such key was found.
|
||||
|
@ -1493,7 +1493,7 @@ public class WalletTool {
|
||||
} else {
|
||||
try {
|
||||
Address address = LegacyAddress.fromBase58(wallet.getParams(), addr);
|
||||
key = wallet.findKeyFromPubHash(address.getHash());
|
||||
key = wallet.findKeyFromAddress(address);
|
||||
} catch (AddressFormatException e) {
|
||||
System.err.println(addr + " does not parse as a Bitcoin address of the right network parameters.");
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user