mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-02-23 14:40:40 +01:00
KeyBag: Rename method findKeyFromPubHash() to findKeyFromPubKeyHash().
This commit is contained in:
parent
53908d8939
commit
a5fd9c6848
10 changed files with 29 additions and 29 deletions
|
@ -143,7 +143,7 @@ public class TransactionOutPoint extends ChildMessage {
|
|||
Script connectedScript = connectedOutput.getScriptPubKey();
|
||||
if (ScriptPattern.isPayToPubKeyHash(connectedScript)) {
|
||||
byte[] addressBytes = ScriptPattern.extractHashFromPayToPubKeyHash(connectedScript);
|
||||
return keyBag.findKeyFromPubHash(addressBytes);
|
||||
return keyBag.findKeyFromPubKeyHash(addressBytes);
|
||||
} else if (ScriptPattern.isPayToPubKey(connectedScript)) {
|
||||
byte[] pubkeyBytes = ScriptPattern.extractKeyFromPayToPubKey(connectedScript);
|
||||
return keyBag.findKeyFromPubKey(pubkeyBytes);
|
||||
|
@ -166,7 +166,7 @@ public class TransactionOutPoint extends ChildMessage {
|
|||
Script connectedScript = connectedOutput.getScriptPubKey();
|
||||
if (ScriptPattern.isPayToPubKeyHash(connectedScript)) {
|
||||
byte[] addressBytes = ScriptPattern.extractHashFromPayToPubKeyHash(connectedScript);
|
||||
return RedeemData.of(keyBag.findKeyFromPubHash(addressBytes), connectedScript);
|
||||
return RedeemData.of(keyBag.findKeyFromPubKeyHash(addressBytes), connectedScript);
|
||||
} else if (ScriptPattern.isPayToPubKey(connectedScript)) {
|
||||
byte[] pubkeyBytes = ScriptPattern.extractKeyFromPayToPubKey(connectedScript);
|
||||
return RedeemData.of(keyBag.findKeyFromPubKey(pubkeyBytes), connectedScript);
|
||||
|
|
|
@ -63,8 +63,8 @@ public class DecryptingKeyBag implements KeyBag {
|
|||
|
||||
@Nullable
|
||||
@Override
|
||||
public ECKey findKeyFromPubHash(byte[] pubKeyHash) {
|
||||
return maybeDecrypt(target.findKeyFromPubHash(pubKeyHash));
|
||||
public ECKey findKeyFromPubKeyHash(byte[] pubKeyHash) {
|
||||
return maybeDecrypt(target.findKeyFromPubKeyHash(pubKeyHash));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
|
|
@ -32,7 +32,7 @@ public interface KeyBag {
|
|||
* @return ECKey object or null if no such key was found.
|
||||
*/
|
||||
@Nullable
|
||||
ECKey findKeyFromPubHash(byte[] pubKeyHash);
|
||||
ECKey findKeyFromPubKeyHash(byte[] pubKeyHash);
|
||||
|
||||
/**
|
||||
* Locates a keypair from the keychain given the raw public key bytes.
|
||||
|
|
|
@ -388,7 +388,7 @@ public class KeyChainGroup implements KeyBag {
|
|||
|
||||
@Nullable
|
||||
@Override
|
||||
public ECKey findKeyFromPubHash(byte[] pubKeyHash) {
|
||||
public ECKey findKeyFromPubKeyHash(byte[] pubKeyHash) {
|
||||
ECKey result;
|
||||
if ((result = basic.findKeyFromPubHash(pubKeyHash)) != null)
|
||||
return result;
|
||||
|
|
|
@ -65,7 +65,7 @@ public class KeyTimeCoinSelector implements CoinSelector {
|
|||
if (ScriptPattern.isPayToPubKey(scriptPubKey)) {
|
||||
controllingKey = wallet.findKeyFromPubKey(ScriptPattern.extractKeyFromPayToPubKey(scriptPubKey));
|
||||
} else if (ScriptPattern.isPayToPubKeyHash(scriptPubKey)) {
|
||||
controllingKey = wallet.findKeyFromPubHash(ScriptPattern.extractHashFromPayToPubKeyHash(scriptPubKey));
|
||||
controllingKey = wallet.findKeyFromPubKeyHash(ScriptPattern.extractHashFromPayToPubKeyHash(scriptPubKey));
|
||||
} else {
|
||||
log.info("Skipping tx output {} because it's not of simple form.", output);
|
||||
continue;
|
||||
|
|
|
@ -997,10 +997,10 @@ public class Wallet extends BaseTaggableObject
|
|||
*/
|
||||
@Override
|
||||
@Nullable
|
||||
public ECKey findKeyFromPubHash(byte[] pubKeyHash) {
|
||||
public ECKey findKeyFromPubKeyHash(byte[] pubKeyHash) {
|
||||
keyChainGroupLock.lock();
|
||||
try {
|
||||
return keyChainGroup.findKeyFromPubHash(pubKeyHash);
|
||||
return keyChainGroup.findKeyFromPubKeyHash(pubKeyHash);
|
||||
} finally {
|
||||
keyChainGroupLock.unlock();
|
||||
}
|
||||
|
@ -1029,7 +1029,7 @@ public class Wallet extends BaseTaggableObject
|
|||
|
||||
@Override
|
||||
public boolean isPubKeyHashMine(byte[] pubKeyHash) {
|
||||
return findKeyFromPubHash(pubKeyHash) != null;
|
||||
return findKeyFromPubKeyHash(pubKeyHash) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1049,7 +1049,7 @@ public class Wallet extends BaseTaggableObject
|
|||
public ECKey findKeyFromAddress(Address address) {
|
||||
final ScriptType scriptType = address.getOutputScriptType();
|
||||
if (scriptType == ScriptType.P2PKH || scriptType == ScriptType.P2WPKH)
|
||||
return findKeyFromPubHash(address.getHash());
|
||||
return findKeyFromPubKeyHash(address.getHash());
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
@ -4163,7 +4163,7 @@ public class Wallet extends BaseTaggableObject
|
|||
RedeemData data = findRedeemDataFromScriptHash(ScriptPattern.extractHashFromPayToScriptHash(script));
|
||||
return data != null && canSignFor(data.redeemScript);
|
||||
} else if (ScriptPattern.isPayToPubKeyHash(script)) {
|
||||
ECKey key = findKeyFromPubHash(ScriptPattern.extractHashFromPayToPubKeyHash(script));
|
||||
ECKey key = findKeyFromPubKeyHash(ScriptPattern.extractHashFromPayToPubKeyHash(script));
|
||||
return key != null && (key.isEncrypted() || key.hasPrivKey());
|
||||
} else if (ScriptPattern.isSentToMultisig(script)) {
|
||||
for (ECKey pubkey : script.getPubKeys()) {
|
||||
|
@ -4941,7 +4941,7 @@ public class Wallet extends BaseTaggableObject
|
|||
ECKey key = null;
|
||||
Script redeemScript = null;
|
||||
if (ScriptPattern.isPayToPubKeyHash(script)) {
|
||||
key = findKeyFromPubHash(ScriptPattern.extractHashFromPayToPubKeyHash(script));
|
||||
key = findKeyFromPubKeyHash(ScriptPattern.extractHashFromPayToPubKeyHash(script));
|
||||
checkNotNull(key, "Coin selection includes unspendable outputs");
|
||||
} else if (ScriptPattern.isPayToScriptHash(script)) {
|
||||
redeemScript = findRedeemDataFromScriptHash(ScriptPattern.extractHashFromPayToScriptHash(script)).redeemScript;
|
||||
|
|
|
@ -111,11 +111,11 @@ public class WalletProtobufSerializerTest {
|
|||
assertEquals(0, wallet1.getTransactions(true).size());
|
||||
assertEquals(Coin.ZERO, wallet1.getBalance());
|
||||
assertArrayEquals(myKey.getPubKey(),
|
||||
wallet1.findKeyFromPubHash(myKey.getPubKeyHash()).getPubKey());
|
||||
wallet1.findKeyFromPubKeyHash(myKey.getPubKeyHash()).getPubKey());
|
||||
assertArrayEquals(myKey.getPrivKeyBytes(),
|
||||
wallet1.findKeyFromPubHash(myKey.getPubKeyHash()).getPrivKeyBytes());
|
||||
wallet1.findKeyFromPubKeyHash(myKey.getPubKeyHash()).getPrivKeyBytes());
|
||||
assertEquals(myKey.getCreationTimeSeconds(),
|
||||
wallet1.findKeyFromPubHash(myKey.getPubKeyHash()).getCreationTimeSeconds());
|
||||
wallet1.findKeyFromPubKeyHash(myKey.getPubKeyHash()).getCreationTimeSeconds());
|
||||
assertEquals(mScriptCreationTime,
|
||||
wallet1.getWatchedScripts().get(0).getCreationTimeSeconds());
|
||||
assertEquals(1, wallet1.getWatchedScripts().size());
|
||||
|
@ -198,8 +198,8 @@ public class WalletProtobufSerializerTest {
|
|||
myWallet = new Wallet(UNITTEST);
|
||||
myWallet.importKey(myKey);
|
||||
Wallet wallet1 = roundTrip(myWallet);
|
||||
assertArrayEquals(myKey.getPubKey(), wallet1.findKeyFromPubHash(myKey.getPubKeyHash()).getPubKey());
|
||||
assertArrayEquals(myKey.getPrivKeyBytes(), wallet1.findKeyFromPubHash(myKey.getPubKeyHash()).getPrivKeyBytes());
|
||||
assertArrayEquals(myKey.getPubKey(), wallet1.findKeyFromPubKeyHash(myKey.getPubKeyHash()).getPubKey());
|
||||
assertArrayEquals(myKey.getPrivKeyBytes(), wallet1.findKeyFromPubKeyHash(myKey.getPubKeyHash()).getPrivKeyBytes());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -335,11 +335,11 @@ public class WalletProtobufSerializerTest {
|
|||
assertEquals(0, wallet1.getTransactions(true).size());
|
||||
assertEquals(Coin.ZERO, wallet1.getBalance());
|
||||
assertArrayEquals(myKey.getPubKey(),
|
||||
wallet1.findKeyFromPubHash(myKey.getPubKeyHash()).getPubKey());
|
||||
wallet1.findKeyFromPubKeyHash(myKey.getPubKeyHash()).getPubKey());
|
||||
assertArrayEquals(myKey.getPrivKeyBytes(),
|
||||
wallet1.findKeyFromPubHash(myKey.getPubKeyHash()).getPrivKeyBytes());
|
||||
wallet1.findKeyFromPubKeyHash(myKey.getPubKeyHash()).getPrivKeyBytes());
|
||||
assertEquals(myKey.getCreationTimeSeconds(),
|
||||
wallet1.findKeyFromPubHash(myKey.getPubKeyHash()).getCreationTimeSeconds());
|
||||
wallet1.findKeyFromPubKeyHash(myKey.getPubKeyHash()).getCreationTimeSeconds());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -160,16 +160,16 @@ public class KeyChainGroupTest {
|
|||
assertEquals(a, result);
|
||||
result = group.findKeyFromPubKey(b.getPubKey());
|
||||
assertEquals(b, result);
|
||||
result = group.findKeyFromPubHash(a.getPubKeyHash());
|
||||
result = group.findKeyFromPubKeyHash(a.getPubKeyHash());
|
||||
assertEquals(a, result);
|
||||
result = group.findKeyFromPubHash(b.getPubKeyHash());
|
||||
result = group.findKeyFromPubKeyHash(b.getPubKeyHash());
|
||||
assertEquals(b, result);
|
||||
result = group.findKeyFromPubKey(c.getPubKey());
|
||||
assertEquals(c, result);
|
||||
result = group.findKeyFromPubHash(c.getPubKeyHash());
|
||||
result = group.findKeyFromPubKeyHash(c.getPubKeyHash());
|
||||
assertEquals(c, result);
|
||||
assertNull(group.findKeyFromPubKey(d.getPubKey()));
|
||||
assertNull(group.findKeyFromPubHash(d.getPubKeyHash()));
|
||||
assertNull(group.findKeyFromPubKeyHash(d.getPubKeyHash()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -2940,7 +2940,7 @@ public class WalletTest extends TestWithWallet {
|
|||
assertEquals(THREE_CENTS.subtract(tx.getFee()), tx.getValueSentToMe(wallet));
|
||||
// TX sends to one of our addresses (for now we ignore married wallets).
|
||||
final Address toAddress = tx.getOutput(0).getScriptPubKey().getToAddress(UNITTEST);
|
||||
final ECKey rotatingToKey = wallet.findKeyFromPubHash(toAddress.getHash());
|
||||
final ECKey rotatingToKey = wallet.findKeyFromPubKeyHash(toAddress.getHash());
|
||||
assertNotNull(rotatingToKey);
|
||||
assertFalse(wallet.isKeyRotating(rotatingToKey));
|
||||
assertEquals(3, tx.getInputs().size());
|
||||
|
@ -2956,7 +2956,7 @@ public class WalletTest extends TestWithWallet {
|
|||
sendMoneyToWallet(wallet, AbstractBlockChain.NewBlockType.BEST_CHAIN, CENT, LegacyAddress.fromKey(UNITTEST, key1));
|
||||
wallet.doMaintenance(null, true);
|
||||
tx = broadcaster.waitForTransactionAndSucceed();
|
||||
assertNotNull(wallet.findKeyFromPubHash(tx.getOutput(0).getScriptPubKey().getPubKeyHash()));
|
||||
assertNotNull(wallet.findKeyFromPubKeyHash(tx.getOutput(0).getScriptPubKey().getPubKeyHash()));
|
||||
log.info("Unexpected thing: {}", tx);
|
||||
assertEquals(Coin.valueOf(19300), tx.getFee());
|
||||
assertEquals(1, tx.getInputs().size());
|
||||
|
@ -3047,7 +3047,7 @@ public class WalletTest extends TestWithWallet {
|
|||
List<Transaction> txns = wallet.doMaintenance(null, false).get();
|
||||
assertEquals(1, txns.size());
|
||||
Address output = txns.get(0).getOutput(0).getScriptPubKey().getToAddress(UNITTEST);
|
||||
ECKey usedKey = wallet.findKeyFromPubHash(output.getHash());
|
||||
ECKey usedKey = wallet.findKeyFromPubKeyHash(output.getHash());
|
||||
assertEquals(goodKey.getCreationTimeSeconds(), usedKey.getCreationTimeSeconds());
|
||||
assertEquals(goodKey.getCreationTimeSeconds(), wallet.freshReceiveKey().getCreationTimeSeconds());
|
||||
assertEquals("mrM3TpCnav5YQuVA1xLercCGJH4DXujMtv", LegacyAddress.fromKey(UNITTEST, usedKey).toString());
|
||||
|
|
|
@ -64,7 +64,7 @@ public class GenerateLowSTests {
|
|||
final ECKey key = new ECKey(secureRandom);
|
||||
final KeyBag bag = new KeyBag() {
|
||||
@Override
|
||||
public ECKey findKeyFromPubHash(byte[] pubKeyHash) {
|
||||
public ECKey findKeyFromPubKeyHash(byte[] pubKeyHash) {
|
||||
return key;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue