From 024d24949636cd36e175d88ad62463ac98ea77ef Mon Sep 17 00:00:00 2001 From: Masao Hidemitsu Date: Wed, 21 Mar 2018 02:09:58 +0900 Subject: [PATCH] List NEETCOIN (NEET) --- .../java/bisq/core/locale/CurrencyUtil.java | 1 + .../validation/AltCoinAddressValidator.java | 8 ++ .../payment/validation/params/NEETParams.java | 88 +++++++++++++++++++ .../statistics/TradeStatisticsManager.java | 1 + .../AltCoinAddressValidatorTest.java | 19 ++++ 5 files changed, 117 insertions(+) create mode 100644 src/main/java/bisq/core/payment/validation/params/NEETParams.java diff --git a/src/main/java/bisq/core/locale/CurrencyUtil.java b/src/main/java/bisq/core/locale/CurrencyUtil.java index f2c42741..2cb1faf7 100644 --- a/src/main/java/bisq/core/locale/CurrencyUtil.java +++ b/src/main/java/bisq/core/locale/CurrencyUtil.java @@ -192,6 +192,7 @@ public static List createAllSortedCryptoCurrenciesList() { result.add(new CryptoCurrency("GRANS", "10grans", true)); result.add(new CryptoCurrency("ICH", "ICH")); result.add(new CryptoCurrency("PHR", "Phore")); + result.add(new CryptoCurrency("NEET", "NEETCOIN")); result.sort(TradeCurrency::compareTo); diff --git a/src/main/java/bisq/core/payment/validation/AltCoinAddressValidator.java b/src/main/java/bisq/core/payment/validation/AltCoinAddressValidator.java index 51b38a05..9400e3c1 100644 --- a/src/main/java/bisq/core/payment/validation/AltCoinAddressValidator.java +++ b/src/main/java/bisq/core/payment/validation/AltCoinAddressValidator.java @@ -40,6 +40,7 @@ import bisq.core.payment.validation.params.PNCParams; import bisq.core.payment.validation.params.PhoreParams; import bisq.core.payment.validation.params.PivxParams; +import bisq.core.payment.validation.params.NEETParams; import bisq.core.payment.validation.params.SpeedCashParams; import bisq.core.payment.validation.params.StrayaParams; import bisq.core.payment.validation.params.TerracoinParams; @@ -439,6 +440,13 @@ public ValidationResult validate(String input) { return regexTestFailed; else return new ValidationResult(true); + case "NEET": + try { + Address.fromBase58(NEETParams.get(), input); + return new ValidationResult(true); + } catch (AddressFormatException e) { + return new ValidationResult(false, getErrorMessage(e)); + } case "STL": if (!input.matches("^(Se)\\d[0-9A-Za-z]{94}$")) return regexTestFailed; diff --git a/src/main/java/bisq/core/payment/validation/params/NEETParams.java b/src/main/java/bisq/core/payment/validation/params/NEETParams.java new file mode 100644 index 00000000..5615d751 --- /dev/null +++ b/src/main/java/bisq/core/payment/validation/params/NEETParams.java @@ -0,0 +1,88 @@ +/* + * 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.core.payment.validation.params; + +import org.bitcoinj.core.*; +import org.bitcoinj.store.BlockStore; +import org.bitcoinj.store.BlockStoreException; +import org.bitcoinj.utils.MonetaryFormat; + +public class NEETParams extends NetworkParameters { + + private static NEETParams instance; + + public static synchronized NEETParams get() { + if (instance == null) { + instance = new NEETParams(); + } + return instance; + } + + // We only use the properties needed for address validation + public NEETParams() { + super(); + addressHeader = 53; + p2shHeader = 112; + acceptableAddressCodes = new int[]{addressHeader, p2shHeader}; + } + + // default dummy implementations, not used... + @Override + public String getPaymentProtocolId() { + return PAYMENT_PROTOCOL_ID_MAINNET; + } + + @Override + public void checkDifficultyTransitions(StoredBlock storedPrev, Block next, BlockStore blockStore) throws VerificationException, BlockStoreException { + } + + @Override + public Coin getMaxMoney() { + return null; + } + + @Override + public Coin getMinNonDustOutput() { + return null; + } + + @Override + public MonetaryFormat getMonetaryFormat() { + return null; + } + + @Override + public String getUriScheme() { + return null; + } + + @Override + public boolean hasMaxMoney() { + return false; + } + + @Override + public BitcoinSerializer getSerializer(boolean parseRetain) { + return null; + } + + @Override + public int getProtocolVersionNum(ProtocolVersion version) { + return 0; + } +} diff --git a/src/main/java/bisq/core/trade/statistics/TradeStatisticsManager.java b/src/main/java/bisq/core/trade/statistics/TradeStatisticsManager.java index 236baa37..82c5d220 100644 --- a/src/main/java/bisq/core/trade/statistics/TradeStatisticsManager.java +++ b/src/main/java/bisq/core/trade/statistics/TradeStatisticsManager.java @@ -306,6 +306,7 @@ private void printAllCurrencyStats() { newlyAdded.add("GEO"); newlyAdded.add("GRANS"); newlyAdded.add("ICH"); + newlyAdded.add("NEET"); coinsWithValidator.addAll(newlyAdded); diff --git a/src/test/java/bisq/core/payment/validation/AltCoinAddressValidatorTest.java b/src/test/java/bisq/core/payment/validation/AltCoinAddressValidatorTest.java index 697af326..0abd5c9f 100644 --- a/src/test/java/bisq/core/payment/validation/AltCoinAddressValidatorTest.java +++ b/src/test/java/bisq/core/payment/validation/AltCoinAddressValidatorTest.java @@ -948,4 +948,23 @@ public void testPHR() { assertFalse(validator.validate("P0r3vQ7SkqLELsYGM6qeRumyfPx3366uyU9").isValid); assertFalse(validator.validate("").isValid); } + + @Test + public void testNEET() { + AltCoinAddressValidator validator = new AltCoinAddressValidator(); + validator.setCurrencyCode("NEET"); + + assertTrue(validator.validate("NW69jcXy7T4cBsjVZ1GVtjNv4XrNa6ZA4o").isValid); + assertTrue(validator.validate("Nac1o79vQVkVk1BGmusDN8JrckPcDAvXVS").isValid); + assertTrue(validator.validate("nDjqdvK7X7MgPCtyzEukcRm1LxEy7LEZVh").isValid); + assertTrue(validator.validate("nJA1pCA2HaYrYwg3zcNs2FJSGtaYFriPca").isValid); + + assertFalse(validator.validate("NW69jcXy7T4cBsjVZ1GVtjNv4XrNa6ZA4oo").isValid); + assertFalse(validator.validate("NW69jcXy7T4cBsjVZ1GVtjNv4XrNa6ZA4").isValid); + assertFalse(validator.validate("NW69jcXy7T4cBsjVZ1GVtjNv4XrNa6ZA4o#").isValid); + assertFalse(validator.validate("nDjqdvK7X7MgPCtyzEukcRm1LxEy7LEZVhh").isValid); + assertFalse(validator.validate("nDjqdvK7X7MgPCtyzEukcRm1LxEy7LEZV").isValid); + assertFalse(validator.validate("nDjqdvK7X7MgPCtyzEukcRm1LxEy7LEZVh#").isValid); + assertFalse(validator.validate("").isValid); + } }