From 0bb6300d84ddb3e15a9df9f2e71532f9f0233868 Mon Sep 17 00:00:00 2001 From: Masao Hidemitsu Date: Wed, 21 Mar 2018 01:53:31 +0900 Subject: [PATCH] List Kumacoin (KUMA) --- .../java/bisq/core/locale/CurrencyUtil.java | 1 + .../validation/AltCoinAddressValidator.java | 8 ++ .../payment/validation/params/KumaParams.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/KumaParams.java diff --git a/src/main/java/bisq/core/locale/CurrencyUtil.java b/src/main/java/bisq/core/locale/CurrencyUtil.java index f2c42741..1750f341 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("KUMA", "Kumacoin")); 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..fdc6b37d 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.KumaParams; 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 "KUMA": + try { + Address.fromBase58(KumaParams.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/KumaParams.java b/src/main/java/bisq/core/payment/validation/params/KumaParams.java new file mode 100644 index 00000000..156be0a5 --- /dev/null +++ b/src/main/java/bisq/core/payment/validation/params/KumaParams.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 KumaParams extends NetworkParameters { + + private static KumaParams instance; + + // We only use the properties needed for address validation + public KumaParams() { + super(); + addressHeader = 45; + p2shHeader = 8; + acceptableAddressCodes = new int[]{addressHeader, p2shHeader}; + } + + public static synchronized KumaParams get() { + if (instance == null) { + instance = new KumaParams(); + } + return instance; + } + + // 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..a610c8a2 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("KUMA"); 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..33b73df3 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 testKUMA() { + AltCoinAddressValidator validator = new AltCoinAddressValidator(); + validator.setCurrencyCode("KUMA"); + + assertTrue(validator.validate("KKeZ46ELdrcnB9TT8R7GiU3cdd29gA6mQm").isValid); + assertTrue(validator.validate("KD5xtaJFmKpR5fqJGApfisMT2Mh4uNZdLF").isValid); + assertTrue(validator.validate("4FmFUcHecwkepmAtwFZoJGJUnQsLMqKY3k").isValid); + assertTrue(validator.validate("4EvJMtRRnkCtaocadbr6CQUP2qRh6Pwcjp").isValid); + + assertFalse(validator.validate("KKeZ46ELdrcnB9TT8R7GiU3cdd29gA6mQmm").isValid); + assertFalse(validator.validate("KKeZ46ELdrcnB9TT8R7GiU3cdd29gA6mQ").isValid); + assertFalse(validator.validate("KKeZ46ELdrcnB9TT8R7GiU3cdd29gA6mQm#").isValid); + assertFalse(validator.validate("4FmFUcHecwkepmAtwFZoJGJUnQsLMqKY3kk").isValid); + assertFalse(validator.validate("4FmFUcHecwkepmAtwFZoJGJUnQsLMqKY3").isValid); + assertFalse(validator.validate("4FmFUcHecwkepmAtwFZoJGJUnQsLMqKY3k#").isValid); + assertFalse(validator.validate("").isValid); + } }