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:
parent
5638387d3a
commit
1ff5d05200
@ -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
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user