diff --git a/assets/src/main/java/bisq/asset/coins/MonetaryUnit.java b/assets/src/main/java/bisq/asset/coins/MonetaryUnit.java new file mode 100644 index 00000000000..99f337f2f0b --- /dev/null +++ b/assets/src/main/java/bisq/asset/coins/MonetaryUnit.java @@ -0,0 +1,56 @@ +/* + * 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 MonetaryUnit extends Coin { + + public MonetaryUnit() { + super("MonetaryUnit", "MUE", new MonetaryUnitAddressValidator()); + } + + + public static class MonetaryUnitAddressValidator extends Base58BitcoinAddressValidator { + + public MonetaryUnitAddressValidator() { + super(new MonetaryUnitParams()); + } + + @Override + public AddressValidationResult validate(String address) { + if (!address.matches("^[7][a-km-zA-HJ-NP-Z1-9]{25,34}$")) + return AddressValidationResult.invalidStructure(); + + return super.validate(address); + } + } + + + public static class MonetaryUnitParams extends NetworkParametersAdapter { + + public MonetaryUnitParams() { + addressHeader = 16; + p2shHeader = 76; + 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 96349c48e36..f2cc233019f 100644 --- a/assets/src/main/resources/META-INF/services/bisq.asset.Asset +++ b/assets/src/main/resources/META-INF/services/bisq.asset.Asset @@ -83,6 +83,7 @@ bisq.asset.coins.MFCoin bisq.asset.coins.MicroCoin bisq.asset.coins.MobitGlobal bisq.asset.coins.Monero +bisq.asset.coins.MonetaryUnit bisq.asset.coins.Motion bisq.asset.coins.Myriadcoin bisq.asset.coins.Namecoin diff --git a/assets/src/test/java/bisq/asset/coins/MonetaryUnitTest.java b/assets/src/test/java/bisq/asset/coins/MonetaryUnitTest.java new file mode 100644 index 00000000000..b6bb2242b95 --- /dev/null +++ b/assets/src/test/java/bisq/asset/coins/MonetaryUnitTest.java @@ -0,0 +1,46 @@ +/* + * 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 MonetaryUnitTest extends AbstractAssetTest { + + public MonetaryUnitTest() { + super(new MonetaryUnit()); + } + + @Test + public void testValidAddresses() { + assertValidAddress("7VjG4Vjnu488k14QdpxswKk1acVgySqV6c"); + assertValidAddress("7U42XyYEf7CsLsaq84mRxMaMfst7f3r4By"); + assertValidAddress("7hbLQSY9SnyHf1RwiTniMt8vT94x7pqJEr"); + assertValidAddress("7oM4HbCStpDQ8imocHPVjNWGVj9gg54erh"); + assertValidAddress("7SUheC6Xp12G9CCgoMJ2dT8e9zwnFRwjrU"); + } + + @Test + public void testInvalidAddresses() { + assertInvalidAddress("0U42XyYEf7CsLsaq84mRxMaMfst7f3r4By"); + assertInvalidAddress("#7VjG4Vjnu488k14QdpxswKk1acVgySqV6c"); + assertInvalidAddress("7SUheC6Xp12G9CCgoMJ2dT8e9zwnFRwjr"); + assertInvalidAddress("7AUheX6X"); + } +}