From 46e2b75bc8c7ae0f9e7e9a2df0e446d61043a773 Mon Sep 17 00:00:00 2001 From: woodser Date: Wed, 17 Aug 2022 14:19:00 -0400 Subject: [PATCH] support bitcoin cash address validation --- .../asset/BitcoinCashAddressValidator.java | 32 +++++++++++++++++++ .../java/bisq/asset/coins/BitcoinCash.java | 6 ++-- 2 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 assets/src/main/java/bisq/asset/BitcoinCashAddressValidator.java diff --git a/assets/src/main/java/bisq/asset/BitcoinCashAddressValidator.java b/assets/src/main/java/bisq/asset/BitcoinCashAddressValidator.java new file mode 100644 index 0000000000..7af317bf96 --- /dev/null +++ b/assets/src/main/java/bisq/asset/BitcoinCashAddressValidator.java @@ -0,0 +1,32 @@ +/* + * This file is part of Haveno. + * + * Haveno 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. + * + * Haveno 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 Haveno. If not, see . + */ + +package bisq.asset; + +/** + * Validates a Bitcoin Cash address. + */ +public class BitcoinCashAddressValidator extends RegexAddressValidator { + + public BitcoinCashAddressValidator() { + super("^([13][a-km-zA-HJ-NP-Z1-9]{25,34})|^((bitcoincash:)?(q|p)[a-z0-9]{41})|^((BITCOINCASH:)?(Q|P)[A-Z0-9]{41})$"); + } + + public BitcoinCashAddressValidator(String errorMessageI18nKey) { + super("^([13][a-km-zA-HJ-NP-Z1-9]{25,34})|^((bitcoincash:)?(q|p)[a-z0-9]{41})|^((BITCOINCASH:)?(Q|P)[A-Z0-9]{41})$", errorMessageI18nKey); + } +} diff --git a/assets/src/main/java/bisq/asset/coins/BitcoinCash.java b/assets/src/main/java/bisq/asset/coins/BitcoinCash.java index 487b8c96f2..e5237f7456 100644 --- a/assets/src/main/java/bisq/asset/coins/BitcoinCash.java +++ b/assets/src/main/java/bisq/asset/coins/BitcoinCash.java @@ -17,14 +17,12 @@ package bisq.asset.coins; -import bisq.asset.BitcoinAddressValidator; +import bisq.asset.BitcoinCashAddressValidator; import bisq.asset.Coin; -import org.bitcoinj.params.MainNetParams; - public class BitcoinCash extends Coin { public BitcoinCash() { - super("Bitcoin Cash", "BCH", new BitcoinAddressValidator(MainNetParams.get()), Network.MAINNET); // TODO: BCH address validation + super("Bitcoin Cash", "BCH", new BitcoinCashAddressValidator()); } }