3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-01-31 15:22:16 +00:00

HD wallets: add a Wallet.getKeyChainSeed method.

This commit is contained in:
Mike Hearn 2014-03-26 20:29:38 +01:00
parent 5638387d3a
commit 1ff5d05200
2 changed files with 22 additions and 0 deletions

View File

@ -573,6 +573,22 @@ public class Wallet extends BaseTaggableObject implements Serializable, BlockCha
return findKeyFromPubKey(pubkey) != null;
}
/**
* Returns the immutable seed for the current active HD chain.
* @throws com.google.bitcoin.core.ECKey.MissingPrivateKeyException if the seed is unavailable (watching wallet)
*/
public DeterministicSeed getKeyChainSeed() {
lock.lock();
try {
DeterministicSeed seed = keychain.getActiveKeyChain().getSeed();
if (seed == null)
throw new ECKey.MissingPrivateKeyException();
return seed;
} finally {
lock.unlock();
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Serialization support

View File

@ -98,6 +98,12 @@ public class WalletTest extends TestWithWallet {
super.tearDown();
}
@Test
public void getSeedAsWords1() {
// Can't verify much here as the wallet is random each time. We could fix the RNG for the unit tests and solve.
assertEquals(12, wallet.getKeyChainSeed().toMnemonicCode().size());
}
@Test
public void basicSpending() throws Exception {
basicSpendingCommon(wallet, myAddress, new ECKey().toAddress(params), false);