diff --git a/src/main/java/com/sparrowwallet/drongo/KeyDerivation.java b/src/main/java/com/sparrowwallet/drongo/KeyDerivation.java index 123f046..8a01a0f 100644 --- a/src/main/java/com/sparrowwallet/drongo/KeyDerivation.java +++ b/src/main/java/com/sparrowwallet/drongo/KeyDerivation.java @@ -61,7 +61,7 @@ public class KeyDerivation { String[] parsedNodes = path.replace("M", "").replace("m", "").split("/"); for (String n : parsedNodes) { n = n.replaceAll(" ", ""); - if (n.length() == 0) continue; + if (n.isEmpty()) continue; boolean isHard = n.endsWith("H") || n.endsWith("h") || n.endsWith("'"); if (isHard) n = n.substring(0, n.length() - 1); if (n.equals("*")) n = Integer.toString(wildcardReplacement); diff --git a/src/main/java/com/sparrowwallet/drongo/OutputDescriptor.java b/src/main/java/com/sparrowwallet/drongo/OutputDescriptor.java index 8476e9f..6c58406 100644 --- a/src/main/java/com/sparrowwallet/drongo/OutputDescriptor.java +++ b/src/main/java/com/sparrowwallet/drongo/OutputDescriptor.java @@ -434,12 +434,12 @@ public class OutputDescriptor { if(extendedKey.getKey().hasPrivKey()) { ExtendedKey privateExtendedKey = extendedKey; List derivation = keyDerivation.getDerivation(); - int depth = derivation.size() == 0 ? scriptType.getDefaultDerivation().size() : derivation.size(); + int depth = derivation.isEmpty() ? scriptType.getDefaultDerivation().size() : derivation.size(); DeterministicKey prvKey = extendedKey.getKey(); DeterministicKey pubKey = new DeterministicKey(prvKey.getPath(), prvKey.getChainCode(), prvKey.getPubKey(), depth, extendedKey.getParentFingerprint()); extendedKey = new ExtendedKey(pubKey, pubKey.getParentFingerprint(), extendedKey.getKeyChildNumber()); - if(derivation.size() == 0) { + if(derivation.isEmpty()) { masterPrivateKeyMap.put(extendedKey, privateExtendedKey); } } diff --git a/src/main/java/com/sparrowwallet/drongo/SecureString.java b/src/main/java/com/sparrowwallet/drongo/SecureString.java index 2cbb608..04ab6f2 100644 --- a/src/main/java/com/sparrowwallet/drongo/SecureString.java +++ b/src/main/java/com/sparrowwallet/drongo/SecureString.java @@ -10,7 +10,7 @@ import java.util.Arrays; * This is not a string but a CharSequence that can be cleared of its memory. * Important for handling passwords. Represents text that should be kept * confidential, such as by deleting it from computer memory when no longer - * needed or garbaged collected. + * needed or garbage collected. */ public class SecureString implements CharSequence { diff --git a/src/main/java/com/sparrowwallet/drongo/Utils.java b/src/main/java/com/sparrowwallet/drongo/Utils.java index 554c279..0e0f0f2 100644 --- a/src/main/java/com/sparrowwallet/drongo/Utils.java +++ b/src/main/java/com/sparrowwallet/drongo/Utils.java @@ -160,22 +160,22 @@ public class Utils { /** Parse 4 bytes from the byte array (starting at the offset) as unsigned 32-bit integer in little endian format. */ public static long readUint32(byte[] bytes, int offset) { - return (bytes[offset] & 0xffl) | - ((bytes[offset + 1] & 0xffl) << 8) | - ((bytes[offset + 2] & 0xffl) << 16) | - ((bytes[offset + 3] & 0xffl) << 24); + return (bytes[offset] & 0xffL) | + ((bytes[offset + 1] & 0xffL) << 8) | + ((bytes[offset + 2] & 0xffL) << 16) | + ((bytes[offset + 3] & 0xffL) << 24); } /** Parse 8 bytes from the byte array (starting at the offset) as signed 64-bit integer in little endian format. */ public static long readInt64(byte[] bytes, int offset) { - return (bytes[offset] & 0xffl) | - ((bytes[offset + 1] & 0xffl) << 8) | - ((bytes[offset + 2] & 0xffl) << 16) | - ((bytes[offset + 3] & 0xffl) << 24) | - ((bytes[offset + 4] & 0xffl) << 32) | - ((bytes[offset + 5] & 0xffl) << 40) | - ((bytes[offset + 6] & 0xffl) << 48) | - ((bytes[offset + 7] & 0xffl) << 56); + return (bytes[offset] & 0xffL) | + ((bytes[offset + 1] & 0xffL) << 8) | + ((bytes[offset + 2] & 0xffL) << 16) | + ((bytes[offset + 3] & 0xffL) << 24) | + ((bytes[offset + 4] & 0xffL) << 32) | + ((bytes[offset + 5] & 0xffL) << 40) | + ((bytes[offset + 6] & 0xffL) << 48) | + ((bytes[offset + 7] & 0xffL) << 56); } /** Parse 2 bytes from the byte array (starting at the offset) as unsigned 16-bit integer in little endian format. */ @@ -197,10 +197,10 @@ public class Utils { /** Parse 4 bytes from the stream as unsigned 32-bit integer in little endian format. */ public static long readUint32FromStream(InputStream is) { try { - return (is.read() & 0xffl) | - ((is.read() & 0xffl) << 8) | - ((is.read() & 0xffl) << 16) | - ((is.read() & 0xffl) << 24); + return (is.read() & 0xffL) | + ((is.read() & 0xffL) << 8) | + ((is.read() & 0xffL) << 16) | + ((is.read() & 0xffL) << 24); } catch (IOException x) { throw new RuntimeException(x); } diff --git a/src/main/java/com/sparrowwallet/drongo/WatchWallet.java b/src/main/java/com/sparrowwallet/drongo/WatchWallet.java index 64b723f..5fe4ac5 100644 --- a/src/main/java/com/sparrowwallet/drongo/WatchWallet.java +++ b/src/main/java/com/sparrowwallet/drongo/WatchWallet.java @@ -9,10 +9,10 @@ import java.util.List; public class WatchWallet { private static final int LOOK_AHEAD_LIMIT = 500; - private String name; - private OutputDescriptor outputDescriptor; + private final String name; + private final OutputDescriptor outputDescriptor; - private HashMap> addresses = new HashMap<>(LOOK_AHEAD_LIMIT*2); + private final HashMap> addresses = new HashMap<>(LOOK_AHEAD_LIMIT*2); public WatchWallet(String name, String descriptor) { this.name = name; diff --git a/src/main/java/com/sparrowwallet/drongo/crypto/DeterministicHierarchy.java b/src/main/java/com/sparrowwallet/drongo/crypto/DeterministicHierarchy.java index 6f4abb6..1846b3d 100644 --- a/src/main/java/com/sparrowwallet/drongo/crypto/DeterministicHierarchy.java +++ b/src/main/java/com/sparrowwallet/drongo/crypto/DeterministicHierarchy.java @@ -34,7 +34,7 @@ public class DeterministicHierarchy { */ public DeterministicKey get(List path) throws HDDerivationException { if(!keys.containsKey(path)) { - if(path.size() == 0) { + if(path.isEmpty()) { throw new IllegalArgumentException("Can't derive the master key: nothing to derive from."); } diff --git a/src/main/java/com/sparrowwallet/drongo/crypto/DeterministicKey.java b/src/main/java/com/sparrowwallet/drongo/crypto/DeterministicKey.java index 9d4d588..3219a1f 100644 --- a/src/main/java/com/sparrowwallet/drongo/crypto/DeterministicKey.java +++ b/src/main/java/com/sparrowwallet/drongo/crypto/DeterministicKey.java @@ -160,7 +160,7 @@ public class DeterministicKey extends ECKey { /** Returns the last element of the path returned by {@link DeterministicKey#getPath()} */ public ChildNumber getChildNumber() { - return childNumberPath.size() == 0 ? ChildNumber.ZERO : childNumberPath.get(childNumberPath.size() - 1); + return childNumberPath.isEmpty() ? ChildNumber.ZERO : childNumberPath.get(childNumberPath.size() - 1); } public byte[] getChainCode() { diff --git a/src/main/java/com/sparrowwallet/drongo/crypto/ECKey.java b/src/main/java/com/sparrowwallet/drongo/crypto/ECKey.java index 676e193..d4ac19a 100644 --- a/src/main/java/com/sparrowwallet/drongo/crypto/ECKey.java +++ b/src/main/java/com/sparrowwallet/drongo/crypto/ECKey.java @@ -625,7 +625,7 @@ public class ECKey { * format generated by signmessage/verifymessage RPCs and GUI menu options. They are intended for humans to verify * their communications with each other, hence the base64 format and the fact that the input is text. * - * @param message Some piece of human readable text. + * @param message Some piece of human-readable text. * @param signatureBase64 The Bitcoin-format message signature in base64 * @param electrumFormat Whether to generate a key following Electrum's approach of regarding P2SH-P2WSH as the same as P2PKH uncompressed * @throws SignatureException If the public key could not be recovered or if there was a signature format error. diff --git a/src/main/java/com/sparrowwallet/drongo/protocol/Base58.java b/src/main/java/com/sparrowwallet/drongo/protocol/Base58.java index 017b5d6..290fd7b 100644 --- a/src/main/java/com/sparrowwallet/drongo/protocol/Base58.java +++ b/src/main/java/com/sparrowwallet/drongo/protocol/Base58.java @@ -132,7 +132,7 @@ public class Base58 { * @return the decoded data bytes */ public static byte[] decode(String input) { - if (input.length() == 0) { + if (input.isEmpty()) { return new byte[0]; } // Convert the base58-encoded ASCII chars to a base58 byte sequence (base58 digits). diff --git a/src/main/java/com/sparrowwallet/drongo/protocol/Bech32.java b/src/main/java/com/sparrowwallet/drongo/protocol/Bech32.java index b625fec..d7b5845 100644 --- a/src/main/java/com/sparrowwallet/drongo/protocol/Bech32.java +++ b/src/main/java/com/sparrowwallet/drongo/protocol/Bech32.java @@ -126,7 +126,7 @@ public class Bech32 { /** Encode a Bech32 string. */ public static String encode(String hrp, Encoding encoding, final byte[] values) { - if(hrp.length() < 1) { + if(hrp.isEmpty()) { throw new ProtocolException("Human-readable part is too short"); } diff --git a/src/main/java/com/sparrowwallet/drongo/protocol/Transaction.java b/src/main/java/com/sparrowwallet/drongo/protocol/Transaction.java index 1390a23..35e399b 100644 --- a/src/main/java/com/sparrowwallet/drongo/protocol/Transaction.java +++ b/src/main/java/com/sparrowwallet/drongo/protocol/Transaction.java @@ -393,7 +393,7 @@ public class Transaction extends ChildMessage { } public void verify() throws VerificationException { - if (inputs.size() == 0 || outputs.size() == 0) + if (inputs.isEmpty() || outputs.isEmpty()) throw new VerificationException.EmptyInputsOrOutputs(); if (this.getMessageSize() > MAX_BLOCK_SIZE) throw new VerificationException.LargerThanMaxBlockSize(); @@ -464,7 +464,7 @@ public class Transaction extends ChildMessage { // This step has no purpose beyond being synchronized with Bitcoin Core's bugs. OP_CODESEPARATOR // is a legacy holdover from a previous, broken design of executing scripts that shipped in Bitcoin 0.1. - // It was seriously flawed and would have let anyone take anyone elses money. Later versions switched to + // It was seriously flawed and would have let anyone take anyone else's money. Later versions switched to // the design we use today where scripts are executed independently but share a stack. This left the // OP_CODESEPARATOR instruction having no purpose as it was only meant to be used internally, not actually // ever put into scripts. Deleting OP_CODESEPARATOR is a step that should never be required but if we don't diff --git a/src/main/java/com/sparrowwallet/drongo/wallet/Bip39MnemonicCode.java b/src/main/java/com/sparrowwallet/drongo/wallet/Bip39MnemonicCode.java index a32b291..a11b421 100644 --- a/src/main/java/com/sparrowwallet/drongo/wallet/Bip39MnemonicCode.java +++ b/src/main/java/com/sparrowwallet/drongo/wallet/Bip39MnemonicCode.java @@ -121,7 +121,7 @@ public class Bip39MnemonicCode { throw new MnemonicException.MnemonicLengthException("Word list size must be multiple of three words."); } - if (words.size() == 0) { + if (words.isEmpty()) { throw new MnemonicException.MnemonicLengthException("Word list is empty."); } diff --git a/src/main/java/com/sparrowwallet/drongo/wallet/PresetUtxoSelector.java b/src/main/java/com/sparrowwallet/drongo/wallet/PresetUtxoSelector.java index 64728b4..14d85ac 100644 --- a/src/main/java/com/sparrowwallet/drongo/wallet/PresetUtxoSelector.java +++ b/src/main/java/com/sparrowwallet/drongo/wallet/PresetUtxoSelector.java @@ -29,7 +29,7 @@ public class PresetUtxoSelector extends SingleSetUtxoSelector { @Override public Collection select(long targetValue, Collection candidates) { - List flattenedCandidates = candidates.stream().flatMap(outputGroup -> outputGroup.getUtxos().stream()).collect(Collectors.toList()); + List flattenedCandidates = candidates.stream().flatMap(outputGroup -> outputGroup.getUtxos().stream()).toList(); List utxos = new ArrayList<>(); //Don't use equals() here as we don't want to consider height which may change as txes are confirmed diff --git a/src/main/java/com/sparrowwallet/drongo/wallet/SeedQR.java b/src/main/java/com/sparrowwallet/drongo/wallet/SeedQR.java index e26c06e..4e2f3f9 100644 --- a/src/main/java/com/sparrowwallet/drongo/wallet/SeedQR.java +++ b/src/main/java/com/sparrowwallet/drongo/wallet/SeedQR.java @@ -20,7 +20,7 @@ public class SeedQR { List indexes = IntStream.iterate(0, i -> i + 4).limit((int)Math.ceil(seedQr.length() / 4.0)) .mapToObj(i -> seedQr.substring(i, Math.min(i + 4, seedQr.length()))) .map(Integer::parseInt) - .collect(Collectors.toList()); + .toList(); List words = new ArrayList<>(indexes.size()); for(Integer index : indexes) { diff --git a/src/test/java/com/sparrowwallet/drongo/wallet/WalletTest.java b/src/test/java/com/sparrowwallet/drongo/wallet/WalletTest.java index 4015ea2..9be6e2d 100644 --- a/src/test/java/com/sparrowwallet/drongo/wallet/WalletTest.java +++ b/src/test/java/com/sparrowwallet/drongo/wallet/WalletTest.java @@ -17,9 +17,13 @@ import org.junit.jupiter.api.Test; import java.util.List; public class WalletTest { + private static final String words = "absent essay fox snake vast pumpkin height crouch silent bulb excuse razor"; + + private static final String words2 = "chef huge whisper year move obscure post pepper play minute foster lawn"; + + @Test public void encryptTest() throws MnemonicException { - String words = "absent essay fox snake vast pumpkin height crouch silent bulb excuse razor"; DeterministicSeed seed = new DeterministicSeed(words, "pp", 0, DeterministicSeed.Type.BIP39); Wallet wallet = new Wallet(); wallet.setPolicyType(PolicyType.SINGLE); @@ -107,7 +111,6 @@ public class WalletTest { @Test public void p2pkhDerivationTest() throws MnemonicException { - String words = "absent essay fox snake vast pumpkin height crouch silent bulb excuse razor"; DeterministicSeed seed = new DeterministicSeed(words, "pp", 0, DeterministicSeed.Type.BIP39); Wallet wallet = new Wallet(); wallet.setPolicyType(PolicyType.SINGLE); @@ -124,7 +127,6 @@ public class WalletTest { @Test public void p2shP2wpkhDerivationTest() throws MnemonicException { - String words = "absent essay fox snake vast pumpkin height crouch silent bulb excuse razor"; DeterministicSeed seed = new DeterministicSeed(words, "pp", 0, DeterministicSeed.Type.BIP39); Wallet wallet = new Wallet(); wallet.setPolicyType(PolicyType.SINGLE); @@ -141,7 +143,6 @@ public class WalletTest { @Test public void p2wpkhDerivationTest() throws MnemonicException { - String words = "absent essay fox snake vast pumpkin height crouch silent bulb excuse razor"; DeterministicSeed seed = new DeterministicSeed(words, "pp", 0, DeterministicSeed.Type.BIP39); Wallet wallet = new Wallet(); wallet.setPolicyType(PolicyType.SINGLE); @@ -158,10 +159,8 @@ public class WalletTest { @Test public void p2shDerivationTest() throws MnemonicException { - String words = "absent essay fox snake vast pumpkin height crouch silent bulb excuse razor"; DeterministicSeed seed = new DeterministicSeed(words, "pp", 0, DeterministicSeed.Type.BIP39); - String words2 = "chef huge whisper year move obscure post pepper play minute foster lawn"; DeterministicSeed seed2 = new DeterministicSeed(words2, "", 0, DeterministicSeed.Type.BIP39); Wallet wallet = new Wallet(); @@ -185,10 +184,8 @@ public class WalletTest { @Test public void p2shP2wshDerivationTest() throws MnemonicException { - String words = "absent essay fox snake vast pumpkin height crouch silent bulb excuse razor"; DeterministicSeed seed = new DeterministicSeed(words, "pp", 0, DeterministicSeed.Type.BIP39); - String words2 = "chef huge whisper year move obscure post pepper play minute foster lawn"; DeterministicSeed seed2 = new DeterministicSeed(words2, "", 0, DeterministicSeed.Type.BIP39); Wallet wallet = new Wallet(); @@ -212,10 +209,8 @@ public class WalletTest { @Test public void p2wshDerivationTest() throws MnemonicException { - String words = "absent essay fox snake vast pumpkin height crouch silent bulb excuse razor"; DeterministicSeed seed = new DeterministicSeed(words, "pp", 0, DeterministicSeed.Type.BIP39); - String words2 = "chef huge whisper year move obscure post pepper play minute foster lawn"; DeterministicSeed seed2 = new DeterministicSeed(words2, "", 0, DeterministicSeed.Type.BIP39); Wallet wallet = new Wallet();