3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-15 11:45:51 +00:00

Wallet: Add findKeyFromAddress() convenience method.

This commit is contained in:
Andreas Schildbach 2019-02-01 17:12:35 +01:00
parent 68c5a622d2
commit 492b3c7f8d
2 changed files with 13 additions and 1 deletions

View File

@ -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. * Locates a keypair from the basicKeyChain given the raw public key bytes.
* @return ECKey or null if no such key was found. * @return ECKey or null if no such key was found.

View File

@ -1493,7 +1493,7 @@ public class WalletTool {
} else { } else {
try { try {
Address address = LegacyAddress.fromBase58(wallet.getParams(), addr); Address address = LegacyAddress.fromBase58(wallet.getParams(), addr);
key = wallet.findKeyFromPubHash(address.getHash()); key = wallet.findKeyFromAddress(address);
} catch (AddressFormatException e) { } catch (AddressFormatException e) {
System.err.println(addr + " does not parse as a Bitcoin address of the right network parameters."); System.err.println(addr + " does not parse as a Bitcoin address of the right network parameters.");
return; return;