From eef5cebc8b44435a9bdc677453fa25f355848697 Mon Sep 17 00:00:00 2001 From: wqking Date: Tue, 20 Mar 2018 11:41:29 +0800 Subject: [PATCH 1/2] List InstaCash (ICH) --- .../java/bisq/core/locale/CurrencyUtil.java | 1 + .../validation/AltCoinAddressValidator.java | 14 +++ .../payment/validation/params/ICHParams.java | 93 +++++++++++++++++++ .../statistics/TradeStatisticsManager.java | 1 + .../AltCoinAddressValidatorTest.java | 17 ++++ 5 files changed, 126 insertions(+) create mode 100644 src/main/java/bisq/core/payment/validation/params/ICHParams.java diff --git a/src/main/java/bisq/core/locale/CurrencyUtil.java b/src/main/java/bisq/core/locale/CurrencyUtil.java index 610b38a0..fe26f78d 100644 --- a/src/main/java/bisq/core/locale/CurrencyUtil.java +++ b/src/main/java/bisq/core/locale/CurrencyUtil.java @@ -186,6 +186,7 @@ public static List createAllSortedCryptoCurrenciesList() { result.add(new CryptoCurrency("ROI", "ROIcoin")); result.add(new CryptoCurrency("RTO", "Arto")); result.add(new CryptoCurrency("KOTO", "Koto")); + result.add(new CryptoCurrency("ICH", "ICH")); 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 572a59e3..ddd7690e 100644 --- a/src/main/java/bisq/core/payment/validation/AltCoinAddressValidator.java +++ b/src/main/java/bisq/core/payment/validation/AltCoinAddressValidator.java @@ -31,6 +31,7 @@ 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; @@ -540,6 +541,19 @@ public ValidationResult validate(String input) { case "KOTO": return KOTOAddressValidator.ValidateAddress(input); + 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; + } + // Add new coins at the end... default: log.debug("Validation for AltCoinAddress not implemented yet. currencyCode: " + currencyCode); diff --git a/src/main/java/bisq/core/payment/validation/params/ICHParams.java b/src/main/java/bisq/core/payment/validation/params/ICHParams.java new file mode 100644 index 00000000..e70a1f70 --- /dev/null +++ b/src/main/java/bisq/core/payment/validation/params/ICHParams.java @@ -0,0 +1,93 @@ +/* + * 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.BitcoinSerializer; +import org.bitcoinj.core.Block; +import org.bitcoinj.core.Coin; +import org.bitcoinj.core.NetworkParameters; +import org.bitcoinj.core.StoredBlock; +import org.bitcoinj.core.VerificationException; +import org.bitcoinj.store.BlockStore; +import org.bitcoinj.store.BlockStoreException; +import org.bitcoinj.utils.MonetaryFormat; + +public class ICHParams 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; + } + + @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 b9491622..809f788b 100644 --- a/src/main/java/bisq/core/trade/statistics/TradeStatisticsManager.java +++ b/src/main/java/bisq/core/trade/statistics/TradeStatisticsManager.java @@ -300,6 +300,7 @@ private void printAllCurrencyStats() { newlyAdded.add("WMCC"); newlyAdded.add("RTO"); newlyAdded.add("KOTO"); + newlyAdded.add("ICH"); 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 6d519eee..e5d19e1c 100644 --- a/src/test/java/bisq/core/payment/validation/AltCoinAddressValidatorTest.java +++ b/src/test/java/bisq/core/payment/validation/AltCoinAddressValidatorTest.java @@ -854,4 +854,21 @@ public void testKOTO() { assertFalse(validator.validate("zkPRkLZKf4BuzBsC6r9Ls5suw1ZV9tCwiBTF5vcz2NZLUDsoXGp5rAFUjKnb7DdkFbLp7aSpejCcC4FTxsVvDxq9YKSprzf").isValid); assertFalse(validator.validate("").isValid); } + + @Test + public void testICH() { + AltCoinAddressValidator validator = new AltCoinAddressValidator(); + validator.setCurrencyCode("ICH"); + + assertTrue(validator.validate("AYx4EqKhomeMu2CTMx1AHdNMkjv6ygnvji").isValid); + assertTrue(validator.validate("AcWyvE7texXcCsPLvW1btXhLimrDMpNdAu").isValid); + assertTrue(validator.validate("AMfLeLotcvgaHQW374NmHZgs1qXF8P6kjc").isValid); + + assertFalse(validator.validate("aYzyJYqhnxF738QjqMqTku5Wft7x4GhVCr").isValid); + assertFalse(validator.validate("DYzyJYqhnxF738QjqMqTku5Wft7x4GhVCr").isValid); + assertFalse(validator.validate("xYzyJYqhnxF738QjqMqTku5Wft7x4GhVCr").isValid); + assertFalse(validator.validate("1YzyJYqhnxF738QjqMqTku5Wft7x4GhVCr").isValid); + assertFalse(validator.validate("AYzyJYqhnxF738QjqMqTku5Wft7x4GhVCr5vcz2NZLUDsoXGp5rAFUjKnb7DdkFbLp7aSpejCcC4FTxsVvDxq9YKSprzf").isValid); + assertFalse(validator.validate("").isValid); + } } From 3e3cdaf86f80a85d0e74f43d67f08e48d8bca93f Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Tue, 20 Mar 2018 11:26:23 +0100 Subject: [PATCH 2/2] Wrap code at 120 characters (bisq-network/style#3) --- .../java/bisq/core/payment/validation/params/ICHParams.java | 3 ++- .../core/payment/validation/AltCoinAddressValidatorTest.java | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/bisq/core/payment/validation/params/ICHParams.java b/src/main/java/bisq/core/payment/validation/params/ICHParams.java index e70a1f70..7b42ade5 100644 --- a/src/main/java/bisq/core/payment/validation/params/ICHParams.java +++ b/src/main/java/bisq/core/payment/validation/params/ICHParams.java @@ -53,7 +53,8 @@ public String getPaymentProtocolId() { } @Override - public void checkDifficultyTransitions(StoredBlock storedPrev, Block next, BlockStore blockStore) throws VerificationException, BlockStoreException { + public void checkDifficultyTransitions(StoredBlock storedPrev, Block next, BlockStore blockStore) + throws VerificationException, BlockStoreException { } @Override diff --git a/src/test/java/bisq/core/payment/validation/AltCoinAddressValidatorTest.java b/src/test/java/bisq/core/payment/validation/AltCoinAddressValidatorTest.java index b450e0b7..bc0c6215 100644 --- a/src/test/java/bisq/core/payment/validation/AltCoinAddressValidatorTest.java +++ b/src/test/java/bisq/core/payment/validation/AltCoinAddressValidatorTest.java @@ -943,7 +943,9 @@ public void testICH() { assertFalse(validator.validate("DYzyJYqhnxF738QjqMqTku5Wft7x4GhVCr").isValid); assertFalse(validator.validate("xYzyJYqhnxF738QjqMqTku5Wft7x4GhVCr").isValid); assertFalse(validator.validate("1YzyJYqhnxF738QjqMqTku5Wft7x4GhVCr").isValid); - assertFalse(validator.validate("AYzyJYqhnxF738QjqMqTku5Wft7x4GhVCr5vcz2NZLUDsoXGp5rAFUjKnb7DdkFbLp7aSpejCcC4FTxsVvDxq9YKSprzf").isValid); + assertFalse(validator.validate( + "AYzyJYqhnxF738QjqMqTku5Wft7x4GhVCr5vcz2NZLUDsoXGp5rAFUjKnb7DdkFbLp7aSpejCcC4FTxsVvDxq9YKSprzf" + ).isValid); assertFalse(validator.validate("").isValid); } }