/** * Locates a keypair from the basicKeyChain given the hash of the public key. This is needed when finding out which * key we need to use to redeem a transaction output. * * @return ECKey object or null if no such key was found. */ @Override @Nullable public ECKey findKeyFromPubHash(byte[] pubkeyHash) { keyChainGroupLock.lock(); try { return keyChainGroup.findKeyFromPubHash(pubkeyHash); } finally { keyChainGroupLock.unlock(); } }
/** * Locates a keypair from the basicKeyChain given the hash of the public key. This is needed when finding out which * key we need to use to redeem a transaction output. * * @return ECKey object or null if no such key was found. */ @Override @Nullable public ECKey findKeyFromPubHash(byte[] pubkeyHash) { keyChainGroupLock.lock(); try { return keyChainGroup.findKeyFromPubHash(pubkeyHash); } finally { keyChainGroupLock.unlock(); } }
/** * Locates a keypair from the basicKeyChain given the hash of the public key. This is needed when finding out which * key we need to use to redeem a transaction output. * * @return ECKey object or null if no such key was found. */ @Override @Nullable public ECKey findKeyFromPubHash(byte[] pubkeyHash) { keyChainGroupLock.lock(); try { return keyChainGroup.findKeyFromPubHash(pubkeyHash); } finally { keyChainGroupLock.unlock(); } }
/** * Locates a keypair from the basicKeyChain given the hash of the public key. This is needed when finding out which * key we need to use to redeem a transaction output. * * @return ECKey object or null if no such key was found. */ @Override @Nullable public ECKey findKeyFromPubHash(byte[] pubkeyHash) { keyChainGroupLock.lock(); try { return keyChainGroup.findKeyFromPubHash(pubkeyHash); } finally { keyChainGroupLock.unlock(); } }
@Test public void findKey() throws Exception { ECKey a = group.freshKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); ECKey b = group.freshKey(KeyChain.KeyPurpose.CHANGE); ECKey c = new ECKey(); ECKey d = new ECKey(); // Not imported. group.importKeys(c); assertTrue(group.hasKey(a)); assertTrue(group.hasKey(b)); assertTrue(group.hasKey(c)); assertFalse(group.hasKey(d)); ECKey result = group.findKeyFromPubKey(a.getPubKey()); assertEquals(a, result); result = group.findKeyFromPubKey(b.getPubKey()); assertEquals(b, result); result = group.findKeyFromPubHash(a.getPubKeyHash()); assertEquals(a, result); result = group.findKeyFromPubHash(b.getPubKeyHash()); assertEquals(b, result); result = group.findKeyFromPubKey(c.getPubKey()); assertEquals(c, result); result = group.findKeyFromPubHash(c.getPubKeyHash()); assertEquals(c, result); assertNull(group.findKeyFromPubKey(d.getPubKey())); assertNull(group.findKeyFromPubHash(d.getPubKeyHash())); }