mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-15 03:35:52 +00: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.
|
* 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.
|
||||||
|
@ -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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user