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

Getter for addresses watched by wallet.

This commit is contained in:
Andreas Schildbach 2014-07-15 14:37:47 +02:00
parent 15060572a9
commit 72b7929523
2 changed files with 25 additions and 0 deletions

View File

@ -695,6 +695,22 @@ public class Wallet extends BaseTaggableObject implements Serializable, BlockCha
}
}
/**
* Returns all addresses watched by this wallet.
*/
public List<Address> getWatchedAddresses() {
lock.lock();
try {
List<Address> addresses = new LinkedList<Address>();
for (Script script : watchedScripts)
if (script.isSentToAddress())
addresses.add(script.getToAddress(params));
return addresses;
} finally {
lock.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.

View File

@ -1188,6 +1188,15 @@ public class WalletTest extends TestWithWallet {
assertTrue(wallet.getBloomFilter(1e-12).contains(outPoint.bitcoinSerialize()));
}
@Test
public void getWatchedAddresses() throws Exception {
Address watchedAddress = new ECKey().toAddress(params);
wallet.addWatchedAddress(watchedAddress);
List<Address> watchedAddresses = wallet.getWatchedAddresses();
assertEquals(1, watchedAddresses.size());
assertEquals(watchedAddress, watchedAddresses.get(0));
}
@Test
public void marriedKeychainBloomFilter() throws Exception {
wallet = new Wallet(params);