diff --git a/src/main/java/bisq/asset/coins/NewPowerCoin.java b/src/main/java/bisq/asset/coins/NewPowerCoin.java new file mode 100644 index 0000000..69cac4c --- /dev/null +++ b/src/main/java/bisq/asset/coins/NewPowerCoin.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 NewPowerCoin extends Coin { + + public NewPowerCoin() { + super("NewPowerCoin", "NPW", new NewPowerCoinAddressValidator()); + } + + + public static class NewPowerCoinAddressValidator extends Base58BitcoinAddressValidator { + + public NewPowerCoinAddressValidator() { + super(new NewPoserCoinParams()); + } + + @Override + public AddressValidationResult validate(String address) { + if (!address.matches("^[N][a-km-zA-HJ-NP-Z1-9]{25,34}$")) + return AddressValidationResult.invalidStructure(); + + return super.validate(address); + } + } + + + public static class NewPoserCoinParams extends NetworkParametersAdapter { + + public NewPoserCoinParams() { + addressHeader = 53; + p2shHeader = 13; + acceptableAddressCodes = new int[]{addressHeader, p2shHeader}; + } + } +} diff --git a/src/main/resources/META-INF/services/bisq.asset.Asset b/src/main/resources/META-INF/services/bisq.asset.Asset index 445a4f4..4553ccd 100644 --- a/src/main/resources/META-INF/services/bisq.asset.Asset +++ b/src/main/resources/META-INF/services/bisq.asset.Asset @@ -66,6 +66,7 @@ bisq.asset.coins.Monero bisq.asset.coins.Namecoin bisq.asset.coins.NavCoin bisq.asset.coins.NEETCOIN +bisq.asset.coins.NewPowerCoin bisq.asset.coins.Nilu bisq.asset.coins.Nimiq bisq.asset.coins.NuBits diff --git a/src/test/java/bisq/asset/coins/NewPowerCoinTest.java b/src/test/java/bisq/asset/coins/NewPowerCoinTest.java new file mode 100644 index 0000000..4b3dae7 --- /dev/null +++ b/src/test/java/bisq/asset/coins/NewPowerCoinTest.java @@ -0,0 +1,44 @@ +/* + * 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 NewPowerCoinTest extends AbstractAssetTest { + + public NewPowerCoinTest() { + super(new NewPowerCoin()); + } + + @Test + public void testValidAddresses() { + assertValidAddress("NXNc8LCAe2dHumQ9vTyogRXUzGw3PJHr55"); + assertValidAddress("NhWDeD4UaNK2Qj8oSKr9u7EAUkCFZxEsDr"); + assertValidAddress("NNTuHe4p5Xr8kyN2AJjJS9dcBoG1XQKkW6"); + assertValidAddress("NQebfM16pijp2KvFHTKQktD4y2cSKknQEg"); + } + + @Test + public void testInvalidAddresses() { + assertInvalidAddress("1111111111111111111111111111111111"); + assertInvalidAddress("2222222222222222222222222222222222"); + assertInvalidAddress("3333333333333333333333333333333333"); + } +}