From 1f7ed7f94ba129b089b845af39c772e8024daf46 Mon Sep 17 00:00:00 2001 From: Sean Gilligan Date: Sun, 17 Dec 2023 16:29:14 -0800 Subject: [PATCH] Wallet: improve JavaDoc for `fromMasterKey()` The JavaDoc was incorrect/incomplete. The changes add `@param`/`@return` items, fix errors, add important details. --- .../main/java/org/bitcoinj/wallet/Wallet.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/bitcoinj/wallet/Wallet.java b/core/src/main/java/org/bitcoinj/wallet/Wallet.java index 6ca156f5b..be07771ee 100644 --- a/core/src/main/java/org/bitcoinj/wallet/Wallet.java +++ b/core/src/main/java/org/bitcoinj/wallet/Wallet.java @@ -582,14 +582,22 @@ public class Wallet extends BaseTaggableObject } /** - * Creates a wallet that tracks payments to and from the HD key hierarchy rooted by the given spending key. This HAS - * to be an account key as returned by {@link DeterministicKeyChain#getWatchingKey()}. - * @param network network wallet will operate on + * Creates a spending wallet that tracks payments to and from a BIP32-style HD key hierarchy rooted by {@code masterKey} and + * {@code accountNumber}. The account path must be directly below the master key as in BIP-32. + *

+ * This method should not be used for BIP-43 compliant wallets or accounts not of the form {@code m/accountNumber'}. + *

+ * This wallet will not store the {@code masterKey}, only the account key. + * @param network network the wallet will operate on + * @param masterKey root private key (e.g. path {@code m}) + * @param outputScriptType type of addresses (aka output scripts) to generate for receiving + * @param accountNumber account number to append, resulting in an account path of {@code m/accountNumber'} + * @return newly created Wallet object */ public static Wallet fromMasterKey(Network network, DeterministicKey masterKey, ScriptType outputScriptType, ChildNumber accountNumber) { DeterministicKey accountKey = HDKeyDerivation.deriveChildKey(masterKey, accountNumber); - accountKey = accountKey.dropParent(); + accountKey = accountKey.dropParent(); // Drop the parent private key, so it won't be used or saved. Optional creationTime = masterKey.creationTime(); if (creationTime.isPresent()) accountKey.setCreationTime(creationTime.get());