mirror of
https://github.com/sparrowwallet/drongo.git
synced 2024-12-25 01:26:45 +00:00
ensure consistent xpub ordering when copying output descriptors without child derivations
This commit is contained in:
parent
3cb3d322a0
commit
64a3f1c00b
1 changed files with 15 additions and 2 deletions
|
@ -15,6 +15,7 @@ import java.math.BigInteger;
|
|||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.sparrowwallet.drongo.KeyDerivation.parsePath;
|
||||
|
||||
|
@ -681,7 +682,19 @@ public class OutputDescriptor {
|
|||
}
|
||||
|
||||
public OutputDescriptor copy(boolean includeChildDerivations) {
|
||||
return new OutputDescriptor(scriptType, multisigThreshold, extendedPublicKeys,
|
||||
includeChildDerivations ? mapChildrenDerivations : Collections.emptyMap(), mapExtendedPublicKeyLabels, extendedMasterPrivateKeys);
|
||||
Map<ExtendedKey, KeyDerivation> copyExtendedPublicKeys = new LinkedHashMap<>(extendedPublicKeys);
|
||||
Map<ExtendedKey, String> copyChildDerivations = new LinkedHashMap<>(mapChildrenDerivations);
|
||||
Map<ExtendedKey, String> copyExtendedPublicKeyLabels = new LinkedHashMap<>(mapExtendedPublicKeyLabels);
|
||||
Map<ExtendedKey, ExtendedKey> copyExtendedMasterPrivateKeys = new LinkedHashMap<>(extendedMasterPrivateKeys);
|
||||
|
||||
if(!includeChildDerivations) {
|
||||
//Ensure consistent xpub order by sorting on the first receive address
|
||||
Map<ExtendedKey, String> childDerivations = copyExtendedPublicKeys.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, _ -> "/0/0"));
|
||||
OutputDescriptor copyFirstReceive = new OutputDescriptor(scriptType, multisigThreshold, copyExtendedPublicKeys, childDerivations);
|
||||
OutputDescriptor copySortedXpubs = OutputDescriptor.getOutputDescriptor(copyFirstReceive.toString());
|
||||
return new OutputDescriptor(scriptType, multisigThreshold, copySortedXpubs.extendedPublicKeys, Collections.emptyMap(), copyExtendedPublicKeyLabels, copyExtendedMasterPrivateKeys);
|
||||
}
|
||||
|
||||
return new OutputDescriptor(scriptType, multisigThreshold, copyExtendedPublicKeys, copyChildDerivations, copyExtendedPublicKeyLabels, copyExtendedMasterPrivateKeys);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue