diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index af939e65..76e08734 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -25,6 +25,8 @@ + + diff --git a/src/main/java/bisq/asset/AbstractAsset.java b/src/main/java/bisq/asset/AbstractAsset.java new file mode 100644 index 00000000..8050f14b --- /dev/null +++ b/src/main/java/bisq/asset/AbstractAsset.java @@ -0,0 +1,32 @@ +package bisq.asset; + +import static org.apache.commons.lang3.Validate.notBlank; +import static org.apache.commons.lang3.Validate.notNull; + +public abstract class AbstractAsset implements Asset { + + private final String name; + private final String tickerSymbol; + private final AddressValidator addressValidator; + + public AbstractAsset(String name, String tickerSymbol, AddressValidator addressValidator) { + this.name = notBlank(name); + this.tickerSymbol = notBlank(tickerSymbol); + this.addressValidator = notNull(addressValidator); + } + + @Override + public final String getName() { + return name; + } + + @Override + public final String getTickerSymbol() { + return tickerSymbol; + } + + @Override + public final AddressValidationResult validateAddress(String address) { + return addressValidator.validate(address); + } +} diff --git a/src/main/java/bisq/asset/AddressValidationResult.java b/src/main/java/bisq/asset/AddressValidationResult.java new file mode 100644 index 00000000..b426415c --- /dev/null +++ b/src/main/java/bisq/asset/AddressValidationResult.java @@ -0,0 +1,65 @@ +/* + * This file is part of Bisq. + * + * Bisq is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bisq is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bisq. If not, see . + */ + +package bisq.asset; + +public class AddressValidationResult { + + public static AddressValidationResult VALID = new AddressValidationResult(true); + + private final boolean isValid; + private String message; + private String i18nKey; + + private AddressValidationResult(boolean isValid) { + this.isValid = isValid; + } + + private AddressValidationResult(boolean isValid, String message, String i18nKey) { + this(isValid); + this.message = message; + this.i18nKey = i18nKey; + } + + public boolean isValid() { + return isValid; + } + + public String getI18nKey() { + return i18nKey; + } + + public String getMessage() { + return message; + } + + public static AddressValidationResult validAddress() { + return VALID; + } + + public static AddressValidationResult invalidStructure() { + return new AddressValidationResult(false, "", "validation.altcoin.wrongStructure"); + } + + public static AddressValidationResult invalidAddress(String cause) { + return new AddressValidationResult(false, cause, "validation.altcoin.invalidAddress"); + } + + public static AddressValidationResult invalidAddress(Throwable cause) { + return invalidAddress(cause.getMessage()); + } +} diff --git a/src/main/java/bisq/asset/AddressValidator.java b/src/main/java/bisq/asset/AddressValidator.java new file mode 100644 index 00000000..0fe72cd2 --- /dev/null +++ b/src/main/java/bisq/asset/AddressValidator.java @@ -0,0 +1,23 @@ +/* + * This file is part of Bisq. + * + * Bisq is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bisq is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bisq. If not, see . + */ + +package bisq.asset; + +public interface AddressValidator { + + AddressValidationResult validate(String address); +} diff --git a/src/main/java/bisq/asset/Asset.java b/src/main/java/bisq/asset/Asset.java new file mode 100644 index 00000000..d74adb00 --- /dev/null +++ b/src/main/java/bisq/asset/Asset.java @@ -0,0 +1,10 @@ +package bisq.asset; + +public interface Asset { + + String getName(); + + String getTickerSymbol(); + + AddressValidationResult validateAddress(String address); +} diff --git a/src/main/java/bisq/asset/AssetRegistry.java b/src/main/java/bisq/asset/AssetRegistry.java new file mode 100644 index 00000000..eddb0827 --- /dev/null +++ b/src/main/java/bisq/asset/AssetRegistry.java @@ -0,0 +1,38 @@ +/* + * This file is part of Bisq. + * + * Bisq is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bisq is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bisq. If not, see . + */ + +package bisq.asset; + +import java.util.ArrayList; +import java.util.List; +import java.util.ServiceLoader; +import java.util.stream.Stream; + +public class AssetRegistry { + + private static final List registeredAssets = new ArrayList<>(); + + static { + for (Asset asset : ServiceLoader.load(Asset.class)) { + registeredAssets.add(asset); + } + } + + public Stream stream() { + return registeredAssets.stream(); + } +} diff --git a/src/main/java/bisq/asset/Base58BitcoinAddressValidator.java b/src/main/java/bisq/asset/Base58BitcoinAddressValidator.java new file mode 100644 index 00000000..616bbbab --- /dev/null +++ b/src/main/java/bisq/asset/Base58BitcoinAddressValidator.java @@ -0,0 +1,47 @@ +/* + * This file is part of Bisq. + * + * Bisq is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bisq is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bisq. If not, see . + */ + +package bisq.asset; + +import org.bitcoinj.core.Address; +import org.bitcoinj.core.AddressFormatException; +import org.bitcoinj.core.NetworkParameters; +import org.bitcoinj.params.MainNetParams; + +public class Base58BitcoinAddressValidator implements AddressValidator { + + private final NetworkParameters networkParameters; + + public Base58BitcoinAddressValidator() { + this(MainNetParams.get()); + } + + public Base58BitcoinAddressValidator(NetworkParameters networkParameters) { + this.networkParameters = networkParameters; + } + + @Override + public AddressValidationResult validate(String address) { + try { + Address.fromBase58(networkParameters, address); + } catch (AddressFormatException ex) { + return AddressValidationResult.invalidAddress(ex); + } + + return AddressValidationResult.validAddress(); + } +} diff --git a/src/main/java/bisq/asset/Coin.java b/src/main/java/bisq/asset/Coin.java new file mode 100644 index 00000000..19cf8838 --- /dev/null +++ b/src/main/java/bisq/asset/Coin.java @@ -0,0 +1,38 @@ +/* + * This file is part of Bisq. + * + * Bisq is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bisq is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bisq. If not, see . + */ + +package bisq.asset; + +public abstract class Coin extends AbstractAsset { + + public enum Network { MAINNET, TESTNET, REGTEST } + + private final Network network; + + public Coin(String name, String tickerSymbol, AddressValidator addressValidator) { + this(name, tickerSymbol, addressValidator, Network.MAINNET); + } + + public Coin(String name, String tickerSymbol, AddressValidator addressValidator, Network network) { + super(name, tickerSymbol, addressValidator); + this.network = network; + } + + public Network getNetwork() { + return network; + } +} diff --git a/src/main/java/bisq/asset/Erc20Token.java b/src/main/java/bisq/asset/Erc20Token.java new file mode 100644 index 00000000..86a33e3c --- /dev/null +++ b/src/main/java/bisq/asset/Erc20Token.java @@ -0,0 +1,25 @@ +/* + * This file is part of Bisq. + * + * Bisq is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bisq is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bisq. If not, see . + */ + +package bisq.asset; + +public abstract class Erc20Token extends Token { + + public Erc20Token(String name, String tickerSymbol) { + super(name, tickerSymbol, new EtherAddressValidator()); + } +} diff --git a/src/main/java/bisq/asset/EtherAddressValidator.java b/src/main/java/bisq/asset/EtherAddressValidator.java new file mode 100644 index 00000000..10d5003c --- /dev/null +++ b/src/main/java/bisq/asset/EtherAddressValidator.java @@ -0,0 +1,26 @@ +/* + * This file is part of Bisq. + * + * Bisq is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bisq is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bisq. If not, see . + */ + +package bisq.asset; + +public class EtherAddressValidator extends RegexAddressValidator { + + public EtherAddressValidator() { + // https://github.com/ethereum/web3.js/blob/master/lib/utils/utils.js#L403 + super("^(0x)?[0-9a-fA-F]{40}$"); + } +} diff --git a/src/main/java/bisq/core/payment/validation/params/ICHParams.java b/src/main/java/bisq/asset/NetworkParametersAdapter.java similarity index 76% rename from src/main/java/bisq/core/payment/validation/params/ICHParams.java rename to src/main/java/bisq/asset/NetworkParametersAdapter.java index 7b42ade5..62ed257b 100644 --- a/src/main/java/bisq/core/payment/validation/params/ICHParams.java +++ b/src/main/java/bisq/asset/NetworkParametersAdapter.java @@ -15,7 +15,7 @@ * along with Bisq. If not, see . */ -package bisq.core.payment.validation.params; +package bisq.asset; import org.bitcoinj.core.BitcoinSerializer; import org.bitcoinj.core.Block; @@ -27,26 +27,8 @@ import org.bitcoinj.store.BlockStoreException; import org.bitcoinj.utils.MonetaryFormat; -public class ICHParams extends NetworkParameters { +public abstract class NetworkParametersAdapter extends NetworkParameters { - private static ICHParams instance; - - public static synchronized ICHParams get() { - if (instance == null) { - instance = new ICHParams(); - } - return instance; - } - - // We only use the properties needed for address validation - public ICHParams() { - super(); - addressHeader = 23; - p2shHeader = 13; - acceptableAddressCodes = new int[]{addressHeader, p2shHeader}; - } - - // default dummy implementations, not used... @Override public String getPaymentProtocolId() { return PAYMENT_PROTOCOL_ID_MAINNET; diff --git a/src/main/java/bisq/core/payment/PaymentModule.java b/src/main/java/bisq/asset/RegexAddressValidator.java similarity index 62% rename from src/main/java/bisq/core/payment/PaymentModule.java rename to src/main/java/bisq/asset/RegexAddressValidator.java index 5ced826b..1855b068 100644 --- a/src/main/java/bisq/core/payment/PaymentModule.java +++ b/src/main/java/bisq/asset/RegexAddressValidator.java @@ -15,22 +15,21 @@ * along with Bisq. If not, see . */ -package bisq.core.payment; +package bisq.asset; -import bisq.core.payment.validation.AssetProviderRegistry; +public class RegexAddressValidator implements AddressValidator { -import bisq.common.app.AppModule; + private final String regex; -import org.springframework.core.env.Environment; - -public class PaymentModule extends AppModule { - - public PaymentModule(Environment environment) { - super(environment); + public RegexAddressValidator(String regex) { + this.regex = regex; } @Override - protected final void configure() { - bind(AssetProviderRegistry.class).toInstance(AssetProviderRegistry.getInstance()); + public AddressValidationResult validate(String address) { + if (!address.matches(regex)) + return AddressValidationResult.invalidStructure(); + + return AddressValidationResult.validAddress(); } } diff --git a/src/main/java/bisq/asset/Token.java b/src/main/java/bisq/asset/Token.java new file mode 100644 index 00000000..215c87a3 --- /dev/null +++ b/src/main/java/bisq/asset/Token.java @@ -0,0 +1,25 @@ +/* + * This file is part of Bisq. + * + * Bisq is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bisq is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bisq. If not, see . + */ + +package bisq.asset; + +public abstract class Token extends AbstractAsset { + + public Token(String name, String tickerSymbol, AddressValidator addressValidator) { + super(name, tickerSymbol, addressValidator); + } +} diff --git a/src/main/java/bisq/asset/coins/Bitcoin.java b/src/main/java/bisq/asset/coins/Bitcoin.java new file mode 100644 index 00000000..74154062 --- /dev/null +++ b/src/main/java/bisq/asset/coins/Bitcoin.java @@ -0,0 +1,57 @@ +/* + * This file is part of Bisq. + * + * Bisq is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bisq is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bisq. If not, see . + */ + +package bisq.asset.coins; + +import bisq.asset.Base58BitcoinAddressValidator; +import bisq.asset.Coin; + +import org.bitcoinj.core.NetworkParameters; +import org.bitcoinj.params.MainNetParams; +import org.bitcoinj.params.RegTestParams; +import org.bitcoinj.params.TestNet3Params; + +public abstract class Bitcoin extends Coin { + + public Bitcoin(Network network, NetworkParameters networkParameters) { + super("Bitcoin", "BTC", new Base58BitcoinAddressValidator(networkParameters), network); + } + + + public static class Mainnet extends Bitcoin { + + public Mainnet() { + super(Network.MAINNET, MainNetParams.get()); + } + } + + + public static class Testnet extends Bitcoin { + + public Testnet() { + super(Network.TESTNET, TestNet3Params.get()); + } + } + + + public static class Regtest extends Bitcoin { + + public Regtest() { + super(Network.REGTEST, RegTestParams.get()); + } + } +} diff --git a/src/main/java/bisq/asset/coins/BitcoinCash.java b/src/main/java/bisq/asset/coins/BitcoinCash.java new file mode 100644 index 00000000..b5e08305 --- /dev/null +++ b/src/main/java/bisq/asset/coins/BitcoinCash.java @@ -0,0 +1,11 @@ +package bisq.asset.coins; + +import bisq.asset.Base58BitcoinAddressValidator; +import bisq.asset.Coin; + +public class BitcoinCash extends Coin { + + public BitcoinCash() { + super("Bitcoin Cash", "BCH", new Base58BitcoinAddressValidator()); + } +} diff --git a/src/main/java/bisq/asset/coins/Ether.java b/src/main/java/bisq/asset/coins/Ether.java new file mode 100644 index 00000000..bb534c34 --- /dev/null +++ b/src/main/java/bisq/asset/coins/Ether.java @@ -0,0 +1,28 @@ +/* + * This file is part of Bisq. + * + * Bisq is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bisq is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bisq. If not, see . + */ + +package bisq.asset.coins; + +import bisq.asset.Coin; +import bisq.asset.EtherAddressValidator; + +public class Ether extends Coin { + + public Ether() { + super("Ether", "ETH", new EtherAddressValidator()); + } +} diff --git a/src/main/java/bisq/asset/coins/Instacash.java b/src/main/java/bisq/asset/coins/Instacash.java new file mode 100644 index 00000000..3b11eaa2 --- /dev/null +++ b/src/main/java/bisq/asset/coins/Instacash.java @@ -0,0 +1,61 @@ +/* + * This file is part of Bisq. + * + * Bisq is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bisq is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bisq. If not, see . + */ + +package bisq.asset.coins; + +import bisq.asset.AddressValidationResult; +import bisq.asset.AddressValidator; +import bisq.asset.Coin; +import bisq.asset.NetworkParametersAdapter; + +import org.bitcoinj.core.Address; +import org.bitcoinj.core.AddressFormatException; + +public class Instacash extends Coin { + + public Instacash() { + super("Instacash", "ICH", new InstacashAddressValidator()); + } + + + public static class InstacashAddressValidator implements AddressValidator { + + @Override + public AddressValidationResult validate(String address) { + if (!address.matches("^[A][a-km-zA-HJ-NP-Z1-9]{25,34}$")) + return AddressValidationResult.invalidStructure(); + + try { + Address.fromBase58(new InstacashParams(), address); + } catch (AddressFormatException ex) { + return AddressValidationResult.invalidAddress(ex); + } + + return AddressValidationResult.validAddress(); + } + } + + + public static class InstacashParams extends NetworkParametersAdapter { + + public InstacashParams() { + addressHeader = 23; + p2shHeader = 13; + acceptableAddressCodes = new int[]{addressHeader, p2shHeader}; + } + } +} diff --git a/src/main/java/bisq/asset/tokens/Ellaism.java b/src/main/java/bisq/asset/tokens/Ellaism.java new file mode 100644 index 00000000..9d745e9b --- /dev/null +++ b/src/main/java/bisq/asset/tokens/Ellaism.java @@ -0,0 +1,10 @@ +package bisq.asset.tokens; + +import bisq.asset.Erc20Token; + +public class Ellaism extends Erc20Token { + + public Ellaism() { + super("Ellaism", "ELLA"); + } +} diff --git a/src/main/java/bisq/core/locale/CurrencyUtil.java b/src/main/java/bisq/core/locale/CurrencyUtil.java index 4faff4c2..29432d0a 100644 --- a/src/main/java/bisq/core/locale/CurrencyUtil.java +++ b/src/main/java/bisq/core/locale/CurrencyUtil.java @@ -17,7 +17,9 @@ package bisq.core.locale; -import bisq.core.payment.validation.AssetProviderRegistry; +import bisq.asset.Asset; +import bisq.asset.AssetRegistry; +import bisq.asset.Token; import bisq.common.app.DevEnv; @@ -36,6 +38,9 @@ @Slf4j public class CurrencyUtil { + + private static final AssetRegistry assetRegistry = new AssetRegistry(); + private static String baseCurrencyCode = "BTC"; public static void setBaseCurrencyCode(String baseCurrencyCode) { @@ -92,21 +97,16 @@ public static List getAllSortedCryptoCurrencies() { return allSortedCryptoCurrencies; } - // Don't make a PR for adding a coin but follow the steps described here: - // https://forum.bisq.network/t/how-to-add-your-favorite-altcoin/ - public static List createAllSortedCryptoCurrenciesList() { - final List result = AssetProviderRegistry.getInstance() - .getProviders() - .stream() - .map(assetProvider -> new CryptoCurrency(assetProvider.getCurrencyCode(), assetProvider.getCurrencyName(), assetProvider.isAsset())) + private static List createAllSortedCryptoCurrenciesList() { + List result = assetRegistry.stream() + .filter(CurrencyUtil::assetIsNotBaseCurrency) + .map(CurrencyUtil::assetToCryptoCurrency) .collect(Collectors.toList()); result.add(new CryptoCurrency("BETR", "Better Betting", true)); if (DevEnv.DAO_TRADING_ACTIVATED) result.add(new CryptoCurrency("BSQ", "Bisq Token")); - if (!baseCurrencyCode.equals("BTC")) - result.add(new CryptoCurrency("BTC", "Bitcoin")); result.add(new CryptoCurrency("BCHC", "Bitcoin Clashic")); result.add(new CryptoCurrency("BTG", "Bitcoin Gold")); result.add(new CryptoCurrency("BURST", "Burstcoin")); @@ -124,7 +124,6 @@ public static List createAllSortedCryptoCurrenciesList() { result.add(new CryptoCurrency("DOGE", "Dogecoin")); result.add(new CryptoCurrency("DMC", "DynamicCoin")); result.add(new CryptoCurrency("ESP", "Espers")); - result.add(new CryptoCurrency("ETH", "Ether")); result.add(new CryptoCurrency("ETC", "Ether Classic")); result.add(new CryptoCurrency("XIN", "Infinity Economics")); result.add(new CryptoCurrency("IOP", "Internet Of People")); @@ -194,7 +193,6 @@ public static List createAllSortedCryptoCurrenciesList() { result.add(new CryptoCurrency("QWARK", "Qwark", true)); result.add(new CryptoCurrency("GEO", "GeoCoin", true)); result.add(new CryptoCurrency("GRANS", "10grans", true)); - result.add(new CryptoCurrency("ICH", "ICH")); result.add(new CryptoCurrency("PHR", "Phore")); result.sort(TradeCurrency::compareTo); @@ -407,4 +405,12 @@ public static String getNameAndCode(String currencyCode) { public static TradeCurrency getDefaultTradeCurrency() { return GlobalSettings.getDefaultTradeCurrency(); } + + private static boolean assetIsNotBaseCurrency(Asset asset) { + return !asset.getTickerSymbol().equals(baseCurrencyCode); + } + + private static CryptoCurrency assetToCryptoCurrency(Asset asset) { + return new CryptoCurrency(asset.getTickerSymbol(), asset.getName(), asset instanceof Token); + } } diff --git a/src/main/java/bisq/core/payment/validation/AbstractAssetProvider.java b/src/main/java/bisq/core/payment/validation/AbstractAssetProvider.java deleted file mode 100644 index 06d1e9f0..00000000 --- a/src/main/java/bisq/core/payment/validation/AbstractAssetProvider.java +++ /dev/null @@ -1,20 +0,0 @@ -package bisq.core.payment.validation; - -import bisq.core.locale.Res; -import bisq.core.util.validation.InputValidator; - -import org.bitcoinj.core.AddressFormatException; - -import org.jetbrains.annotations.NotNull; - -public abstract class AbstractAssetProvider implements AssetProvider { - - protected InputValidator.ValidationResult getRegexTestFailed() { - return new InputValidator.ValidationResult(false, Res.get("validation.altcoin.wrongStructure", getCurrencyCode())); - } - - @NotNull - protected String getErrorMessage(AddressFormatException e) { - return Res.get("validation.altcoin.invalidAddress", getCurrencyCode(), e.getMessage()); - } -} diff --git a/src/main/java/bisq/core/payment/validation/AltCoinAddressValidator.java b/src/main/java/bisq/core/payment/validation/AltCoinAddressValidator.java index 274b0d8d..708eaf7a 100644 --- a/src/main/java/bisq/core/payment/validation/AltCoinAddressValidator.java +++ b/src/main/java/bisq/core/payment/validation/AltCoinAddressValidator.java @@ -18,6 +18,11 @@ package bisq.core.payment.validation; import bisq.core.app.BisqEnvironment; +import bisq.asset.AddressValidationResult; +import bisq.asset.Coin; +import bisq.asset.Asset; +import bisq.asset.AssetRegistry; +import bisq.core.btc.BaseCurrencyNetwork; import bisq.core.locale.Res; import bisq.core.payment.validation.altcoins.ByteballAddressValidator; import bisq.core.payment.validation.altcoins.KOTOAddressValidator; @@ -31,7 +36,6 @@ import bisq.core.payment.validation.params.AlcParams; import bisq.core.payment.validation.params.CageParams; import bisq.core.payment.validation.params.CreaParams; -import bisq.core.payment.validation.params.ICHParams; import bisq.core.payment.validation.params.IOPParams; import bisq.core.payment.validation.params.ODNParams; import bisq.core.payment.validation.params.OctocoinParams; @@ -67,6 +71,8 @@ import com.google.inject.Inject; +import java.util.Optional; + import lombok.extern.slf4j.Slf4j; import org.jetbrains.annotations.NotNull; @@ -74,12 +80,12 @@ @Slf4j public final class AltCoinAddressValidator extends InputValidator { - private final AssetProviderRegistry assetProviderRegistry; + private final AssetRegistry assetRegistry; private String currencyCode; @Inject - public AltCoinAddressValidator(AssetProviderRegistry assetProviderRegistry) { - this.assetProviderRegistry = assetProviderRegistry; + public AltCoinAddressValidator(AssetRegistry assetRegistry) { + this.assetRegistry = assetRegistry; } /////////////////////////////////////////////////////////////////////////////////////////// @@ -101,38 +107,21 @@ public ValidationResult validate(String input) { ValidationResult regexTestFailed = new ValidationResult(false, Res.get("validation.altcoin.wrongStructure", currencyCode)); - final AssetProvider assetProvider = assetProviderRegistry.getProviderByCurrencyCode(currencyCode); - if (null != assetProvider) { - return assetProvider.validateAddress(input); + Optional asset = assetRegistry.stream() + .filter(this::assetMatchesSelectedCurrencyCode) + .filter(this::assetIsNotBaseCurrencyForDifferentNetwork) + .findFirst(); + + if (asset.isPresent()) { + AddressValidationResult addressValidationResult = asset.get().validateAddress(input); + + if (addressValidationResult.isValid()) + return new ValidationResult(true); + + return new ValidationResult(false, Res.get(addressValidationResult.getI18nKey(), asset.get().getTickerSymbol(), addressValidationResult.getMessage())); } + switch (currencyCode) { - case "BTC": - try { - switch (BisqEnvironment.getBaseCurrencyNetwork()) { - case BTC_MAINNET: - Address.fromBase58(MainNetParams.get(), input); - break; - case BTC_TESTNET: - Address.fromBase58(TestNet3Params.get(), input); - break; - case BTC_REGTEST: - Address.fromBase58(RegTestParams.get(), input); - break; - case LTC_MAINNET: - case LTC_TESTNET: - case LTC_REGTEST: - case DASH_MAINNET: - case DASH_TESTNET: - case DASH_REGTEST: - // We cannot use MainNetParams because that would be one of the other base currencies, - // so we cloned the MainNetParams to BtcMainNetParamsForValidation - Address.fromBase58(BtcMainNetParamsForValidation.get(), input); - return new ValidationResult(true); - } - return new ValidationResult(true); - } catch (AddressFormatException e) { - return new ValidationResult(false, getErrorMessage(e)); - } case "BSQ": if (!input.startsWith("B")) return new ValidationResult(false, Res.get("validation.altcoin.invalidAddress", @@ -208,12 +197,6 @@ public ValidationResult validate(String input) { } catch (AddressFormatException e) { return new ValidationResult(false, getErrorMessage(e)); } - case "ETH": - // https://github.com/ethereum/web3.js/blob/master/lib/utils/utils.js#L403 - if (!input.matches("^(0x)?[0-9a-fA-F]{40}$")) - return regexTestFailed; - else - return new ValidationResult(true); case "PIVX": if (input.matches("^[D][a-km-zA-HJ-NP-Z1-9]{25,34}$")) { //noinspection ConstantConditions @@ -560,18 +543,6 @@ public ValidationResult validate(String input) { return regexTestFailed; else return new ValidationResult(true); - case "ICH": - if (input.matches("^[A][a-km-zA-HJ-NP-Z1-9]{25,34}$")) { - //noinspection ConstantConditions - try { - Address.fromBase58(ICHParams.get(), input); - return new ValidationResult(true); - } catch (AddressFormatException e) { - return new ValidationResult(false, getErrorMessage(e)); - } - } else { - return regexTestFailed; - } case "PHR": if (input.matches("^[P][a-km-zA-HJ-NP-Z1-9]{25,34}$")) { //noinspection ConstantConditions @@ -597,4 +568,17 @@ public ValidationResult validate(String input) { private String getErrorMessage(AddressFormatException e) { return Res.get("validation.altcoin.invalidAddress", currencyCode, e.getMessage()); } + + private boolean assetMatchesSelectedCurrencyCode(Asset a) { + return currencyCode.equals(a.getTickerSymbol()); + } + + private boolean assetIsNotBaseCurrencyForDifferentNetwork(Asset asset) { + BaseCurrencyNetwork baseCurrencyNetwork = BisqEnvironment.getBaseCurrencyNetwork(); + + return !(asset instanceof Coin) + || !asset.getTickerSymbol().equals(baseCurrencyNetwork.getCurrencyCode()) + || (((Coin) asset).getNetwork().name().equals(baseCurrencyNetwork.getNetwork())); + } + } diff --git a/src/main/java/bisq/core/payment/validation/AssetProvider.java b/src/main/java/bisq/core/payment/validation/AssetProvider.java deleted file mode 100644 index ba26d2a8..00000000 --- a/src/main/java/bisq/core/payment/validation/AssetProvider.java +++ /dev/null @@ -1,14 +0,0 @@ -package bisq.core.payment.validation; - -import bisq.core.util.validation.InputValidator; - -public interface AssetProvider { - - String getCurrencyCode(); - - String getCurrencyName(); - - boolean isAsset(); - - InputValidator.ValidationResult validateAddress(String input); -} diff --git a/src/main/java/bisq/core/payment/validation/AssetProviderRegistry.java b/src/main/java/bisq/core/payment/validation/AssetProviderRegistry.java deleted file mode 100644 index 2304426d..00000000 --- a/src/main/java/bisq/core/payment/validation/AssetProviderRegistry.java +++ /dev/null @@ -1,60 +0,0 @@ -package bisq.core.payment.validation; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.ServiceLoader; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -public final class AssetProviderRegistry { - - private Map providers; - - private static AssetProviderRegistry instance; - - public static AssetProviderRegistry getInstance() { - if (null == instance) { - instance = new AssetProviderRegistry(); - } - return instance; - } - - private AssetProviderRegistry() { - } - - @Nullable - public AssetProvider getProviderByCurrencyCode(String code) { - return getProvidersMap().get(code); - } - - @Nonnull - public Collection getProviders() { - return Collections.unmodifiableCollection(getProvidersMap().values()); - } - - @Nonnull - private Map getProvidersMap() { - if (null == providers) { - initProviders(); - } - return providers; - } - - private void initProviders() { - providers = new HashMap<>(); - for (AssetProvider provider : ServiceLoader.load(AssetProvider.class)) { - String currencyCode = provider.getCurrencyCode(); - AssetProvider existingProvider = providers.get(currencyCode); - if (null != existingProvider) { - final String providerClassName = provider.getClass().getCanonicalName(); - final String existingProviderClassName = existingProvider.getClass().getCanonicalName(); - String message = String.format("AssetProvider %s wants to register itself for asset %s which is already registered with %s", providerClassName, currencyCode, existingProviderClassName); - throw new RuntimeException(message); - } - providers.put(currencyCode, provider); - } - } -} diff --git a/src/main/java/bisq/core/payment/validation/altcoins/bch/BchAssetProvider.java b/src/main/java/bisq/core/payment/validation/altcoins/bch/BchAssetProvider.java deleted file mode 100644 index 461404c9..00000000 --- a/src/main/java/bisq/core/payment/validation/altcoins/bch/BchAssetProvider.java +++ /dev/null @@ -1,36 +0,0 @@ -package bisq.core.payment.validation.altcoins.bch; - -import bisq.core.payment.validation.AbstractAssetProvider; -import bisq.core.payment.validation.params.btc.BtcMainNetParamsForValidation; -import bisq.core.util.validation.InputValidator; - -import org.bitcoinj.core.Address; -import org.bitcoinj.core.AddressFormatException; - -public class BchAssetProvider extends AbstractAssetProvider { - - @Override - public String getCurrencyCode() { - return "BCH"; - } - - @Override - public String getCurrencyName() { - return "Bitcoin Cash"; - } - - @Override - public boolean isAsset() { - return false; - } - - @Override - public InputValidator.ValidationResult validateAddress(String input) { - try { - Address.fromBase58(BtcMainNetParamsForValidation.get(), input); - return new InputValidator.ValidationResult(true); - } catch (AddressFormatException e) { - return new InputValidator.ValidationResult(false, getErrorMessage(e)); - } - } -} diff --git a/src/main/java/bisq/core/payment/validation/altcoins/ella/EllaAssetProvider.java b/src/main/java/bisq/core/payment/validation/altcoins/ella/EllaAssetProvider.java deleted file mode 100644 index ae84c21e..00000000 --- a/src/main/java/bisq/core/payment/validation/altcoins/ella/EllaAssetProvider.java +++ /dev/null @@ -1,32 +0,0 @@ -package bisq.core.payment.validation.altcoins.ella; - -import bisq.core.payment.validation.AbstractAssetProvider; -import bisq.core.util.validation.InputValidator; - -public class EllaAssetProvider extends AbstractAssetProvider { - - @Override - public String getCurrencyCode() { - return "ELLA"; - } - - @Override - public String getCurrencyName() { - return "Ellaism"; - } - - @Override - public boolean isAsset() { - return false; - } - - @Override - public InputValidator.ValidationResult validateAddress(String input) { - // https://github.com/ethereum/web3.js/blob/master/lib/utils/utils.js#L403 - if (!input.matches("^(0x)?[0-9a-fA-F]{40}$")) { - return getRegexTestFailed(); - } else { - return new InputValidator.ValidationResult(true); - } - } -} diff --git a/src/main/resources/META-INF/services/bisq.asset.Asset b/src/main/resources/META-INF/services/bisq.asset.Asset new file mode 100644 index 00000000..6fd2351b --- /dev/null +++ b/src/main/resources/META-INF/services/bisq.asset.Asset @@ -0,0 +1,7 @@ +bisq.asset.coins.Bitcoin$Mainnet +bisq.asset.coins.Bitcoin$Regtest +bisq.asset.coins.Bitcoin$Testnet +bisq.asset.coins.BitcoinCash +bisq.asset.coins.Ether +bisq.asset.coins.Instacash +bisq.asset.tokens.Ellaism diff --git a/src/main/resources/META-INF/services/bisq.core.payment.validation.AssetProvider b/src/main/resources/META-INF/services/bisq.core.payment.validation.AssetProvider deleted file mode 100644 index c31497bf..00000000 --- a/src/main/resources/META-INF/services/bisq.core.payment.validation.AssetProvider +++ /dev/null @@ -1,2 +0,0 @@ -bisq.core.payment.validation.altcoins.bch.BchAssetProvider -bisq.core.payment.validation.altcoins.ella.EllaAssetProvider diff --git a/src/test/java/bisq/asset/AbstractAssetTest.java b/src/test/java/bisq/asset/AbstractAssetTest.java new file mode 100644 index 00000000..94eae9df --- /dev/null +++ b/src/test/java/bisq/asset/AbstractAssetTest.java @@ -0,0 +1,63 @@ +/* + * This file is part of Bisq. + * + * Bisq is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bisq is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bisq. If not, see . + */ + +package bisq.asset; + +import bisq.core.btc.BaseCurrencyNetwork; +import bisq.core.locale.Res; + +import org.junit.Before; +import org.junit.Test; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +public abstract class AbstractAssetTest { + + protected final Asset asset; + + public AbstractAssetTest(Asset asset) { + this.asset = asset; + } + + @Before + public void setup() { + BaseCurrencyNetwork baseCurrencyNetwork = BaseCurrencyNetwork.BTC_MAINNET; + Res.setBaseCurrencyCode(baseCurrencyNetwork.getCurrencyCode()); + Res.setBaseCurrencyName(baseCurrencyNetwork.getCurrencyName()); + } + + @Test + public void testBlank() { + assertInvalidAddress(""); + } + + @Test + public abstract void testValidAddresses(); + + @Test + public abstract void testInvalidAddresses(); + + protected void assertValidAddress(String address) { + AddressValidationResult result = asset.validateAddress(address); + assertThat(result.getMessage(), result.isValid(), is(true)); + } + + protected void assertInvalidAddress(String address) { + assertThat(asset.validateAddress(address).isValid(), is(false)); + } +} diff --git a/src/test/java/bisq/asset/coins/BitcoinCashTest.java b/src/test/java/bisq/asset/coins/BitcoinCashTest.java new file mode 100644 index 00000000..68b8f2f0 --- /dev/null +++ b/src/test/java/bisq/asset/coins/BitcoinCashTest.java @@ -0,0 +1,26 @@ +package bisq.asset.coins; + +import bisq.asset.AbstractAssetTest; + +import org.junit.Test; + +public class BitcoinCashTest extends AbstractAssetTest { + + public BitcoinCashTest() { + super(new BitcoinCash()); + } + + @Test + public void testValidAddresses() { + assertValidAddress("1HQQgsvLTgN9xD9hNmAgAreakzVzQUSLSH"); + assertValidAddress("1MEbUJ5v5MdDEqFJGz4SZp58KkaLdmXZ85"); + assertValidAddress("34dvotXMg5Gxc37TBVV2e5GUAfCFu7Ms4g"); + } + + @Test + public void testInvalidAddresses() { + assertInvalidAddress("21HQQgsvLTgN9xD9hNmAgAreakzVzQUSLSHa"); + assertInvalidAddress("1HQQgsvLTgN9xD9hNmAgAreakzVzQUSLSHs"); + assertInvalidAddress("1HQQgsvLTgN9xD9hNmAgAreakzVzQUSLSH#"); + } +} diff --git a/src/test/java/bisq/asset/coins/BitcoinTest.java b/src/test/java/bisq/asset/coins/BitcoinTest.java new file mode 100644 index 00000000..5f3dee7c --- /dev/null +++ b/src/test/java/bisq/asset/coins/BitcoinTest.java @@ -0,0 +1,27 @@ +package bisq.asset.coins; + +import bisq.asset.AbstractAssetTest; + +import org.junit.Test; + +public class BitcoinTest extends AbstractAssetTest { + + public BitcoinTest() { + super(new Bitcoin.Mainnet()); + } + + @Test + public void testValidAddresses() { + assertValidAddress("17VZNX1SN5NtKa8UQFxwQbFeFc3iqRYhem"); + assertValidAddress("3EktnHQD7RiAE6uzMj2ZifT9YgRrkSgzQX"); + assertValidAddress("1111111111111111111114oLvT2"); + assertValidAddress("1BitcoinEaterAddressDontSendf59kuE"); + } + + @Test + public void testInvalidAddresses() { + assertInvalidAddress("17VZNX1SN5NtKa8UQFxwQbFeFc3iqRYhemqq"); + assertInvalidAddress("17VZNX1SN5NtKa8UQFxwQbFeFc3iqRYheO"); + assertInvalidAddress("17VZNX1SN5NtKa8UQFxwQbFeFc3iqRYhek#"); + } +} diff --git a/src/test/java/bisq/asset/coins/InstacashTest.java b/src/test/java/bisq/asset/coins/InstacashTest.java new file mode 100644 index 00000000..0309ae2d --- /dev/null +++ b/src/test/java/bisq/asset/coins/InstacashTest.java @@ -0,0 +1,29 @@ +package bisq.asset.coins; + +import bisq.asset.AbstractAssetTest; + +import org.junit.Test; + +public class InstacashTest extends AbstractAssetTest { + + public InstacashTest() { + super(new Instacash()); + } + + @Test + public void testValidAddresses() { + assertValidAddress("AYx4EqKhomeMu2CTMx1AHdNMkjv6ygnvji"); + assertValidAddress("AcWyvE7texXcCsPLvW1btXhLimrDMpNdAu"); + assertValidAddress("AMfLeLotcvgaHQW374NmHZgs1qXF8P6kjc"); + } + + @Test + public void testInvalidAddresses() { + assertInvalidAddress("aYzyJYqhnxF738QjqMqTku5Wft7x4GhVCr"); + assertInvalidAddress("DYzyJYqhnxF738QjqMqTku5Wft7x4GhVCr"); + assertInvalidAddress("xYzyJYqhnxF738QjqMqTku5Wft7x4GhVCr"); + assertInvalidAddress("1YzyJYqhnxF738QjqMqTku5Wft7x4GhVCr"); + assertInvalidAddress( + "AYzyJYqhnxF738QjqMqTku5Wft7x4GhVCr5vcz2NZLUDsoXGp5rAFUjKnb7DdkFbLp7aSpejCcC4FTxsVvDxq9YKSprzf"); + } +} diff --git a/src/test/java/bisq/asset/tokens/EllaismTest.java b/src/test/java/bisq/asset/tokens/EllaismTest.java new file mode 100644 index 00000000..4337710d --- /dev/null +++ b/src/test/java/bisq/asset/tokens/EllaismTest.java @@ -0,0 +1,25 @@ +package bisq.asset.tokens; + +import bisq.asset.AbstractAssetTest; + +import org.junit.Test; + +public class EllaismTest extends AbstractAssetTest { + + public EllaismTest() { + super(new Ellaism()); + } + + @Test + public void testValidAddresses() { + assertValidAddress("0x65767ec6d4d3d18a200842352485cdc37cbf3a21"); + assertValidAddress("65767ec6d4d3d18a200842352485cdc37cbf3a21"); + } + + @Test + public void testInvalidAddresses() { + assertInvalidAddress("0x65767ec6d4d3d18a200842352485cdc37cbf3a216"); + assertInvalidAddress("0x65767ec6d4d3d18a200842352485cdc37cbf3a2g"); + assertInvalidAddress("65767ec6d4d3d18a200842352485cdc37cbf3a2g"); + } +} diff --git a/src/test/java/bisq/core/payment/validation/AbstractAltcoinAddressValidatorTest.java b/src/test/java/bisq/core/payment/validation/AbstractAltcoinAddressValidatorTest.java index b61a8b5c..83df4e6b 100644 --- a/src/test/java/bisq/core/payment/validation/AbstractAltcoinAddressValidatorTest.java +++ b/src/test/java/bisq/core/payment/validation/AbstractAltcoinAddressValidatorTest.java @@ -2,26 +2,22 @@ import bisq.core.app.BisqEnvironment; import bisq.core.btc.BaseCurrencyNetwork; +import bisq.asset.AssetRegistry; import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; -import org.jetbrains.annotations.NotNull; - import org.junit.Before; public abstract class AbstractAltcoinAddressValidatorTest { + protected AltCoinAddressValidator validator = new AltCoinAddressValidator(new AssetRegistry()); + @Before public void setup() { - final BaseCurrencyNetwork baseCurrencyNetwork = BisqEnvironment.getBaseCurrencyNetwork(); - final String currencyCode = baseCurrencyNetwork.getCurrencyCode(); + BaseCurrencyNetwork baseCurrencyNetwork = BisqEnvironment.getBaseCurrencyNetwork(); + String currencyCode = baseCurrencyNetwork.getCurrencyCode(); Res.setBaseCurrencyCode(currencyCode); Res.setBaseCurrencyName(baseCurrencyNetwork.getCurrencyName()); CurrencyUtil.setBaseCurrencyCode(currencyCode); } - - @NotNull - protected AltCoinAddressValidator getAltCoinAddressValidator() { - return new AltCoinAddressValidator(AssetProviderRegistry.getInstance()); - } } diff --git a/src/test/java/bisq/core/payment/validation/AltCoinAddressValidatorTest.java b/src/test/java/bisq/core/payment/validation/AltCoinAddressValidatorTest.java index 07d4be2a..08cb23a2 100644 --- a/src/test/java/bisq/core/payment/validation/AltCoinAddressValidatorTest.java +++ b/src/test/java/bisq/core/payment/validation/AltCoinAddressValidatorTest.java @@ -26,7 +26,6 @@ public class AltCoinAddressValidatorTest extends AbstractAltcoinAddressValidator @Test public void testBTC() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("BTC"); assertTrue(validator.validate("17VZNX1SN5NtKa8UQFxwQbFeFc3iqRYhem").isValid); @@ -42,7 +41,6 @@ public void testBTC() { @Test public void testBSQ() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("BSQ"); assertTrue(validator.validate("B17VZNX1SN5NtKa8UQFxwQbFeFc3iqRYhem").isValid); @@ -58,7 +56,6 @@ public void testBSQ() { @Test public void testLTC() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("LTC"); assertTrue(validator.validate("Lg3PX8wRWmApFCoCMAsPF5P9dPHYQHEWKW").isValid); @@ -73,7 +70,6 @@ public void testLTC() { @Test public void testDOGE() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("DOGE"); assertTrue(validator.validate("DEa7damK8MsbdCJztidBasZKVsDLJifWfE").isValid); @@ -88,7 +84,6 @@ public void testDOGE() { @Test public void testDASH() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("DASH"); assertTrue(validator.validate("XjNms118hx6dGyBqsrVMTbzMUmxDVijk7Y").isValid); @@ -103,7 +98,6 @@ public void testDASH() { @Test public void testETH() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("ETH"); assertTrue(validator.validate("0x2a65Aca4D5fC5B5C859090a6c34d164135398226").isValid); @@ -117,7 +111,6 @@ public void testETH() { @Test public void testPIVX() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("PIVX"); assertTrue(validator.validate("DFJku78A14HYwPSzC5PtUmda7jMr5pbD2B").isValid); @@ -133,7 +126,6 @@ public void testPIVX() { @Test public void testIOP() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("IOP"); assertTrue(validator.validate("pKbz7iRUSiUaTgh4UuwQCnc6pWZnyCGWxM").isValid); @@ -145,7 +137,6 @@ public void testIOP() { @Test public void test888() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("888"); assertTrue(validator.validate("8TP9rh3SH6n9cSLmV22vnSNNw56LKGpLra").isValid); @@ -160,7 +151,6 @@ public void test888() { @Test public void testGBYTE() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("GBYTE"); assertTrue(validator.validate("BN7JXKXWEG4BVJ7NW6Q3Z7SMJNZJYM3G").isValid); @@ -174,7 +164,6 @@ public void testGBYTE() { @Test public void testNXT() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("NXT"); assertTrue(validator.validate("NXT-JM2U-U4AE-G7WF-3NP9F").isValid); @@ -192,7 +181,6 @@ public void testNXT() { // Added at 0.6.0 @Test public void testDCT() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("DCT"); assertTrue(validator.validate("ud6910c2790bda53bcc53cb131f8fa3bf").isValid); @@ -210,7 +198,6 @@ public void testDCT() { @Test public void testPNC() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("PNC"); assertTrue(validator.validate("3AB1qXhaU3hK5oAPQfwzN3QkM8LxAgL8vB").isValid); @@ -225,7 +212,6 @@ public void testPNC() { @Test public void testWAC() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("WAC"); assertTrue(validator.validate("WfEnB3VGrBqW7uamJMymymEwxMBYQKELKY").isValid); @@ -241,7 +227,6 @@ public void testWAC() { @Test public void testZEN() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("ZEN"); assertTrue(validator.validate("znk62Ey7ptTyHgYLaLDTEwhLF6uN1DXTBfa").isValid); @@ -258,7 +243,6 @@ public void testZEN() { @Test public void testXCN() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("XCN"); assertTrue(validator.validate("CT49DTNo5itqYoAD6XTGyTKbe8z5nGY2D5").isValid); @@ -279,7 +263,6 @@ public void testXCN() { @Test public void testTRC() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("TRC"); assertTrue(validator.validate("1Bys8pZaKo4GTWcpArMg92cBgYqij8mKXt").isValid); @@ -298,7 +281,6 @@ public void testTRC() { @Test public void testINXT() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("INXT"); assertTrue(validator.validate("0x2a65Aca4D5fC5B5C859090a6c34d164135398226").isValid); @@ -312,7 +294,6 @@ public void testINXT() { @Test public void testPART() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("PART"); assertTrue(validator.validate("PZdYWHgyhuG7NHVCzEkkx3dcLKurTpvmo6").isValid); assertTrue(validator.validate("RJAPhgckEgRGVPZa9WoGSWW24spskSfLTQ").isValid); @@ -328,7 +309,6 @@ public void testPART() { // Added 0.6.1 @Test public void testMDC() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("MDC"); assertTrue(validator.validate("mHUisRLQ4vMXrWrVfGfiEHuD3KZqiUNvzH").isValid); @@ -342,7 +322,6 @@ public void testMDC() { @Test public void testBCHC() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("BCHC"); assertTrue(validator.validate("1HQQgsvLTgN9xD9hNmAgAreakzVzQUSLSH").isValid); @@ -357,7 +336,6 @@ public void testBCHC() { @Test public void testBTG() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("BTG"); assertTrue(validator.validate("AehvQ57Fp168uY592LCUYBbyNEpiRAPufb").isValid); @@ -373,7 +351,6 @@ public void testBTG() { // Added 0.6.2 @Test public void testCAGE() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("CAGE"); assertTrue(validator.validate("Db97PgfdBDhXk8DmrDhrUPyydTCELn8YSb").isValid); @@ -389,7 +366,6 @@ public void testCAGE() { @Test public void testCRED() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("CRED"); assertTrue(validator.validate("0x65767ec6d4d3d18a200842352485cdc37cbf3a21").isValid); @@ -403,7 +379,6 @@ public void testCRED() { @Test public void testXSPEC() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("XSPEC"); assertTrue(validator.validate("SUZRHjTLSCr581qLsGqMqBD5f3oW2JHckn").isValid); @@ -419,7 +394,6 @@ public void testXSPEC() { // Added 0.6.3 @Test public void testWILD() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("WILD"); assertTrue(validator.validate("0x2a65Aca4D5fC5B5C859090a6c34d164135398226").isValid); @@ -433,7 +407,6 @@ public void testWILD() { @Test public void testONION() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("ONION"); assertTrue(validator.validate("DbkkqXwdiWJNcpfw49f2xzTVEbvL1SYWDm").isValid); @@ -449,7 +422,6 @@ public void testONION() { // Added 0.6.4 @Test public void testCREA() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("CREA"); assertTrue(validator.validate("CGjh99QdHxCE6g9pGUucCJNeUyQPRJr4fE").isValid); @@ -464,7 +436,6 @@ public void testCREA() { @Test public void testXIN() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("XIN"); assertTrue(validator.validate("XIN-FXFA-LR6Y-QZAW-9V4SX").isValid); @@ -487,7 +458,6 @@ public void testXIN() { // Added 0.6.5 @Test public void testBETR() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("BETR"); assertTrue(validator.validate("0x2a65Aca4D5fC5B5C859090a6c34d164135398226").isValid); @@ -501,7 +471,6 @@ public void testBETR() { @Test public void testMVT() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("MVT"); assertTrue(validator.validate("0x2a65Aca4D5fC5B5C859090a6c34d164135398226").isValid); @@ -515,7 +484,6 @@ public void testMVT() { @Test public void testREF() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("REF"); assertTrue(validator.validate("0x2a65Aca4D5fC5B5C859090a6c34d164135398226").isValid); @@ -530,7 +498,6 @@ public void testREF() { // Added 0.6.6 @Test public void testSTL() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("STL"); assertTrue(validator.validate("Se3x7sVdvUnMMn2KoYLyYVHMJGRoB2R3V8K3LYuHAiEXgVac7vsmFiXUC8dSpJnjXDfwytKsQJV6HFH8MjwPagTJ2Aha46RZM").isValid); @@ -544,7 +511,6 @@ public void testSTL() { @Test public void testDAI() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("DAI"); assertTrue(validator.validate("0x2a65Aca4D5fC5B5C859090a6c34d164135398226").isValid); @@ -558,7 +524,6 @@ public void testDAI() { @Test public void testYTN() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("YTN"); assertTrue(validator.validate("YTgSv7bk5x5p6te3uf3HbUwgnf7zEJM4Jn").isValid); assertTrue(validator.validate("YVz19KtQUfyTP4AJS8sbRBqi7dkGTL2ovd").isValid); @@ -574,7 +539,6 @@ public void testYTN() { @Test public void testDARX() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("DARX"); assertTrue(validator.validate("RN8spHmkV6ZtRsquaTJMRZJujRQkkDNh2G").isValid); @@ -588,7 +552,6 @@ public void testDARX() { @Test public void testODN() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("ODN"); assertTrue(validator.validate("XEfyuzk8yTp5eA9eVUeCW2PFbCFtNb6Jgv").isValid); @@ -604,7 +567,6 @@ public void testODN() { @Test public void testCDT() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("CDT"); assertTrue(validator.validate("DM7BjopQ3bGYxSPZ4yhfttxqnDrEkyc3sw").isValid); @@ -622,7 +584,6 @@ public void testCDT() { @Test public void testDGM() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("DGM"); assertTrue(validator.validate("DvaAgcLKrno2AC7kYhHVDCrkhx2xHFpXUf").isValid); @@ -636,7 +597,6 @@ public void testDGM() { @Test public void testSCS() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("SCS"); assertTrue(validator.validate("SNrVzPaFVCQGH4Rdch2EuhoyeWMfgWqk1J").isValid); @@ -652,7 +612,6 @@ public void testSCS() { @Test public void testSOS() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("SOS"); assertTrue(validator.validate("0x2a65Aca4D5fC5B5C859090a6c34d164135398226").isValid); @@ -666,7 +625,6 @@ public void testSOS() { @Test public void testACH() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("ACH"); assertTrue(validator.validate("AciV7ZyJDpCg7kGGmbo97VjgjpVZkXRTMD").isValid); @@ -681,7 +639,6 @@ public void testACH() { @Test public void testVDN() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("VDN"); assertTrue(validator.validate("DG1KpSsSXd3uitgwHaA1i6T1Bj1hWEwAxB").isValid); @@ -700,7 +657,6 @@ public void testVDN() { // Added 0.7.0 @Test public void testALC() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("ALC"); assertTrue(validator.validate("AQJTNtWcP7opxuR52Lf5vmoQTC8EHQ6GxV").isValid); @@ -716,7 +672,6 @@ public void testALC() { @Test public void testDIN() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("DIN"); assertTrue(validator.validate("DBmvak2TM8GpeiR3ZEVWAHWFZeiw9FG7jK").isValid); @@ -732,7 +687,6 @@ public void testDIN() { @Test public void testStraya() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("NAH"); assertTrue(validator.validate("SZHa3vS9ctDJwx3BziaqgN3zQMkYpgyP7f").isValid); @@ -748,7 +702,6 @@ public void testStraya() { @Test public void testROI() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("ROI"); assertTrue(validator.validate("RSdzB2mFpQ6cR3HmEopbaRBjrEMWAwXBYn").isValid); @@ -763,7 +716,6 @@ public void testROI() { @Test public void testWMCC() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("WMCC"); assertTrue(validator.validate("wc1qke2es507uz0dcfx7eyvlfuemwys8xem48vp5rw").isValid); @@ -782,7 +734,6 @@ public void testWMCC() { @Test public void testRTO() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("RTO"); assertTrue(validator.validate("AHT1tiauD1GKvLnSL2RVuug1arn3cvFYw7PX5cUmCkM9MHuBn8yrGoHGHXP8ZV9FUR5Y5ntvhanwCMp8FK5bmLrqKxq7BRj").isValid); @@ -796,7 +747,6 @@ public void testRTO() { @Test public void testKOTO() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("KOTO"); assertTrue(validator.validate("k13dNgJJjf1SCU2Xv2jLnuUb5Q7zZx7P9vW").isValid); @@ -813,7 +763,6 @@ public void testKOTO() { @Test public void testUBQ() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("UBQ"); assertTrue(validator.validate("0x2a65Aca4D5fC5B5C859090a6c34d164135398226").isValid); @@ -827,7 +776,6 @@ public void testUBQ() { @Test public void testQWARK() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("QWARK"); assertTrue(validator.validate("0x2a65Aca4D5fC5B5C859090a6c34d164135398226").isValid); @@ -841,7 +789,6 @@ public void testQWARK() { @Test public void testGEO() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("GEO"); assertTrue(validator.validate("0x2a65Aca4D5fC5B5C859090a6c34d164135398226").isValid); @@ -855,7 +802,6 @@ public void testGEO() { @Test public void testGRANS() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("GRANS"); assertTrue(validator.validate("0x2a65Aca4D5fC5B5C859090a6c34d164135398226").isValid); @@ -869,7 +815,6 @@ public void testGRANS() { @Test public void testICH() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("ICH"); assertTrue(validator.validate("AYx4EqKhomeMu2CTMx1AHdNMkjv6ygnvji").isValid); @@ -888,7 +833,6 @@ public void testICH() { @Test public void testPHR() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); validator.setCurrencyCode("PHR"); assertTrue(validator.validate("PJCKDPyvfbf1yV7mYNeJ8Zb47hKRwVPYDj").isValid); diff --git a/src/test/java/bisq/core/payment/validation/altcoins/bch/BchAssetProviderTest.java b/src/test/java/bisq/core/payment/validation/altcoins/bch/BchAssetProviderTest.java deleted file mode 100644 index ab84c4bc..00000000 --- a/src/test/java/bisq/core/payment/validation/altcoins/bch/BchAssetProviderTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package bisq.core.payment.validation.altcoins.bch; - -import bisq.core.payment.validation.AbstractAltcoinAddressValidatorTest; -import bisq.core.payment.validation.AltCoinAddressValidator; - -import org.junit.Test; - -import static junit.framework.TestCase.assertFalse; -import static org.junit.Assert.assertTrue; - -public class BchAssetProviderTest extends AbstractAltcoinAddressValidatorTest { - - @Test - public void testBCH() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); - validator.setCurrencyCode("BCH"); - - assertTrue(validator.validate("1HQQgsvLTgN9xD9hNmAgAreakzVzQUSLSH").isValid); - assertTrue(validator.validate("1MEbUJ5v5MdDEqFJGz4SZp58KkaLdmXZ85").isValid); - assertTrue(validator.validate("34dvotXMg5Gxc37TBVV2e5GUAfCFu7Ms4g").isValid); - - assertFalse(validator.validate("21HQQgsvLTgN9xD9hNmAgAreakzVzQUSLSHa").isValid); - assertFalse(validator.validate("1HQQgsvLTgN9xD9hNmAgAreakzVzQUSLSHs").isValid); - assertFalse(validator.validate("1HQQgsvLTgN9xD9hNmAgAreakzVzQUSLSH#").isValid); - assertFalse(validator.validate("").isValid); - } - -} diff --git a/src/test/java/bisq/core/payment/validation/altcoins/ella/EllaAssetProviderTest.java b/src/test/java/bisq/core/payment/validation/altcoins/ella/EllaAssetProviderTest.java deleted file mode 100644 index b136fe70..00000000 --- a/src/test/java/bisq/core/payment/validation/altcoins/ella/EllaAssetProviderTest.java +++ /dev/null @@ -1,27 +0,0 @@ -package bisq.core.payment.validation.altcoins.ella; - -import bisq.core.payment.validation.AbstractAltcoinAddressValidatorTest; -import bisq.core.payment.validation.AltCoinAddressValidator; - -import org.junit.Test; - -import static junit.framework.TestCase.assertFalse; -import static org.junit.Assert.assertTrue; - -public class EllaAssetProviderTest extends AbstractAltcoinAddressValidatorTest { - - @Test - public void testELLA() { - AltCoinAddressValidator validator = getAltCoinAddressValidator(); - validator.setCurrencyCode("ELLA"); - - assertTrue(validator.validate("0x65767ec6d4d3d18a200842352485cdc37cbf3a21").isValid); - assertTrue(validator.validate("65767ec6d4d3d18a200842352485cdc37cbf3a21").isValid); - - assertFalse(validator.validate("0x65767ec6d4d3d18a200842352485cdc37cbf3a216").isValid); - assertFalse(validator.validate("0x65767ec6d4d3d18a200842352485cdc37cbf3a2g").isValid); - assertFalse(validator.validate("65767ec6d4d3d18a200842352485cdc37cbf3a2g").isValid); - assertFalse(validator.validate("").isValid); - } - -}