From e91b96227f0fa4392a7b119588ecd193e58d081a Mon Sep 17 00:00:00 2001 From: woodser Date: Wed, 16 Feb 2022 11:12:48 -0500 Subject: [PATCH] support Bitcoin Cash --- .../java/bisq/asset/coins/BitcoinCash.java | 30 +++++++++++++ .../META-INF/services/bisq.asset.Asset | 1 + .../bisq/asset/coins/BitcoinCashTest.java | 44 +++++++++++++++++++ .../java/bisq/core/locale/CurrencyUtil.java | 5 +-- .../bisq/core/locale/CurrencyUtilTest.java | 1 - .../bisq/daemon/grpc/GrpcPriceService.java | 2 +- 6 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 assets/src/main/java/bisq/asset/coins/BitcoinCash.java create mode 100644 assets/src/test/java/bisq/asset/coins/BitcoinCashTest.java diff --git a/assets/src/main/java/bisq/asset/coins/BitcoinCash.java b/assets/src/main/java/bisq/asset/coins/BitcoinCash.java new file mode 100644 index 00000000..487b8c96 --- /dev/null +++ b/assets/src/main/java/bisq/asset/coins/BitcoinCash.java @@ -0,0 +1,30 @@ +/* + * 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.coins; + +import bisq.asset.BitcoinAddressValidator; +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 + } +} diff --git a/assets/src/main/resources/META-INF/services/bisq.asset.Asset b/assets/src/main/resources/META-INF/services/bisq.asset.Asset index 66b37c4b..e17bf173 100644 --- a/assets/src/main/resources/META-INF/services/bisq.asset.Asset +++ b/assets/src/main/resources/META-INF/services/bisq.asset.Asset @@ -15,6 +15,7 @@ bisq.asset.coins.Bitcoin$Mainnet bisq.asset.coins.Bitcoin$Regtest bisq.asset.coins.BitcoinRhodium bisq.asset.coins.Bitcoin$Testnet +bisq.asset.coins.BitcoinCash bisq.asset.coins.BitDaric bisq.asset.coins.Bitmark bisq.asset.coins.Bitzec diff --git a/assets/src/test/java/bisq/asset/coins/BitcoinCashTest.java b/assets/src/test/java/bisq/asset/coins/BitcoinCashTest.java new file mode 100644 index 00000000..2fb96bc1 --- /dev/null +++ b/assets/src/test/java/bisq/asset/coins/BitcoinCashTest.java @@ -0,0 +1,44 @@ +/* + * 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.coins; + +import bisq.asset.AbstractAssetTest; + +import org.junit.Test; + +public class BitcoinCashTest extends AbstractAssetTest { + + public BitcoinCashTest() { + super(new BitcoinCash()); + } + + @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/core/src/main/java/bisq/core/locale/CurrencyUtil.java b/core/src/main/java/bisq/core/locale/CurrencyUtil.java index 094ea0d6..781f3713 100644 --- a/core/src/main/java/bisq/core/locale/CurrencyUtil.java +++ b/core/src/main/java/bisq/core/locale/CurrencyUtil.java @@ -135,17 +135,16 @@ public class CurrencyUtil { public static List getMainCryptoCurrencies() { final List result = new ArrayList<>(); result.add(new CryptoCurrency("BTC", "Bitcoin")); - result.add(new CryptoCurrency("LTC", "Litecoin")); + result.add(new CryptoCurrency("BCH", "Bitcoin Cash")); result.add(new CryptoCurrency("ETH", "Ether")); + result.add(new CryptoCurrency("LTC", "Litecoin")); result.add(new CryptoCurrency("ZEC", "Zcash")); result.sort(TradeCurrency::compareTo); - return result; } public static List getRemovedCryptoCurrencies() { final List currencies = new ArrayList<>(); - currencies.add(new CryptoCurrency("BCH", "Bitcoin Cash")); currencies.add(new CryptoCurrency("BCHC", "Bitcoin Clashic")); currencies.add(new CryptoCurrency("ACH", "AchieveCoin")); currencies.add(new CryptoCurrency("SC", "Siacoin")); diff --git a/core/src/test/java/bisq/core/locale/CurrencyUtilTest.java b/core/src/test/java/bisq/core/locale/CurrencyUtilTest.java index 31b7a007..913ab962 100644 --- a/core/src/test/java/bisq/core/locale/CurrencyUtilTest.java +++ b/core/src/test/java/bisq/core/locale/CurrencyUtilTest.java @@ -98,7 +98,6 @@ public class CurrencyUtilTest { @Test public void testGetNameAndCodeOfRemovedAsset() { - assertEquals("Bitcoin Cash (BCH)", CurrencyUtil.getNameAndCode("BCH")); assertEquals("N/A (XYZ)", CurrencyUtil.getNameAndCode("XYZ")); } diff --git a/daemon/src/main/java/bisq/daemon/grpc/GrpcPriceService.java b/daemon/src/main/java/bisq/daemon/grpc/GrpcPriceService.java index 4439ab1f..055e36cd 100644 --- a/daemon/src/main/java/bisq/daemon/grpc/GrpcPriceService.java +++ b/daemon/src/main/java/bisq/daemon/grpc/GrpcPriceService.java @@ -116,7 +116,7 @@ class GrpcPriceService extends PriceImplBase { return getCustomRateMeteringInterceptor(coreApi.getConfig().appDataDir, this.getClass()) .or(() -> Optional.of(CallRateMeteringInterceptor.valueOf( new HashMap<>() {{ - put(getGetMarketPriceMethod().getFullMethodName(), new GrpcCallRateMeter(10, SECONDS)); + put(getGetMarketPriceMethod().getFullMethodName(), new GrpcCallRateMeter(20, SECONDS)); }} ))); }