From 7ff2f474f9ee0d0382014c8a5a701243ebbdd276 Mon Sep 17 00:00:00 2001 From: Cave Spectre Date: Fri, 21 Dec 2018 09:57:07 -0500 Subject: [PATCH] List Gamblecoin (GMCN) --- .../java/bisq/asset/coins/GambleCoin.java | 57 +++++++++++++++++++ .../META-INF/services/bisq.asset.Asset | 1 + .../java/bisq/asset/coins/GambleCoinTest.java | 45 +++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 assets/src/main/java/bisq/asset/coins/GambleCoin.java create mode 100644 assets/src/test/java/bisq/asset/coins/GambleCoinTest.java diff --git a/assets/src/main/java/bisq/asset/coins/GambleCoin.java b/assets/src/main/java/bisq/asset/coins/GambleCoin.java new file mode 100644 index 00000000000..a199219d940 --- /dev/null +++ b/assets/src/main/java/bisq/asset/coins/GambleCoin.java @@ -0,0 +1,57 @@ +/* + * 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.asset.coins; + +import bisq.asset.AddressValidationResult; +import bisq.asset.Base58BitcoinAddressValidator; +import bisq.asset.Coin; +import bisq.asset.NetworkParametersAdapter; + +public class GambleCoin extends Coin { + + public GambleCoin() { + super("GambleCoin", "GMCN", new GambleCoinAddressValidator()); + } + + + public static class GambleCoinAddressValidator extends Base58BitcoinAddressValidator { + + public GambleCoinAddressValidator() { + super(new GambleCoinParams()); + } + + @Override + public AddressValidationResult validate(String address) { + if (!address.matches("^[C][a-km-zA-HJ-NP-Z1-9]{33}$")) + return AddressValidationResult.invalidStructure(); + + return super.validate(address); + } + } + + + public static class GambleCoinParams extends NetworkParametersAdapter { + + public GambleCoinParams() { + super(); + addressHeader = 28; + p2shHeader = 18; + acceptableAddressCodes = new int[]{addressHeader, p2shHeader}; + } + } +} 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 ea99318ced0..5ef50be1afc 100644 --- a/assets/src/main/resources/META-INF/services/bisq.asset.Asset +++ b/assets/src/main/resources/META-INF/services/bisq.asset.Asset @@ -23,6 +23,7 @@ bisq.asset.coins.Dogecoin bisq.asset.coins.Dragonglass bisq.asset.coins.Ether bisq.asset.coins.EtherClassic +bisq.asset.coins.Gamblecoin bisq.asset.coins.Gridcoin bisq.asset.coins.Horizen bisq.asset.coins.Iridium diff --git a/assets/src/test/java/bisq/asset/coins/GambleCoinTest.java b/assets/src/test/java/bisq/asset/coins/GambleCoinTest.java new file mode 100644 index 00000000000..64e5d463308 --- /dev/null +++ b/assets/src/test/java/bisq/asset/coins/GambleCoinTest.java @@ -0,0 +1,45 @@ +/* + * 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.asset.coins; + +import bisq.asset.AbstractAssetTest; + +import org.junit.Test; + +public class GambleCoinTest extends AbstractAssetTest { + + public GambleCoinTest() { + super(new GambleCoin()); + } + + @Test + public void testValidAddresses() { + assertValidAddress("CKWCoP2Cog4gU3ARzNqGEqwDxNZNVEpPJP"); + assertValidAddress("CJmvkF84bW93o5E7RFe4VzWMSt4WcKo1nv"); + assertValidAddress("Caz2He7kZ8ir52CgAmQywCjm5hRjo3gLwT"); + assertValidAddress("CM2fRpzpxqyRvaWxtptEmRzpGCFE1qCA3V"); + } + + @Test + public void testInvalidAddresses() { + assertInvalidAddress("CKWCoP2C0g4gU3ARzNqGEqwDxNZNVEpPJP"); + assertInvalidAddress("CJmvkF84bW93o5E7RFe4VzWMSt4WcKo1nvx"); + assertInvalidAddress("Caz2He7kZ8ir52CgAmQywC#m5hRjo3gLwT"); + assertInvalidAddress("DM2fRpzpxqyRvaWxtptEmRzpGCFE1qCA3V"); + } +}