mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-24 07:07:43 +01:00
Merge pull request #924 from Pranacoin/Development
Add new altcoin with code "PNC"
This commit is contained in:
commit
c6e5f7882d
4 changed files with 182 additions and 0 deletions
|
@ -23,8 +23,10 @@ import io.bisq.core.app.BisqEnvironment;
|
||||||
import io.bisq.gui.util.validation.altcoins.ByteballAddressValidator;
|
import io.bisq.gui.util.validation.altcoins.ByteballAddressValidator;
|
||||||
import io.bisq.gui.util.validation.altcoins.NxtReedSolomonValidator;
|
import io.bisq.gui.util.validation.altcoins.NxtReedSolomonValidator;
|
||||||
import io.bisq.gui.util.validation.altcoins.OctocoinAddressValidator;
|
import io.bisq.gui.util.validation.altcoins.OctocoinAddressValidator;
|
||||||
|
import io.bisq.gui.util.validation.altcoins.PNCAddressValidator;
|
||||||
import io.bisq.gui.util.validation.params.IOPParams;
|
import io.bisq.gui.util.validation.params.IOPParams;
|
||||||
import io.bisq.gui.util.validation.params.OctocoinParams;
|
import io.bisq.gui.util.validation.params.OctocoinParams;
|
||||||
|
import io.bisq.gui.util.validation.params.PNCParams;
|
||||||
import io.bisq.gui.util.validation.params.PivxParams;
|
import io.bisq.gui.util.validation.params.PivxParams;
|
||||||
import io.bisq.gui.util.validation.params.btc.BtcMainNetParams;
|
import io.bisq.gui.util.validation.params.btc.BtcMainNetParams;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
@ -245,6 +247,21 @@ public final class AltCoinAddressValidator extends InputValidator {
|
||||||
} catch (NxtReedSolomonValidator.DecodeException e) {
|
} catch (NxtReedSolomonValidator.DecodeException e) {
|
||||||
return wrongChecksum;
|
return wrongChecksum;
|
||||||
}
|
}
|
||||||
|
case "PNC":
|
||||||
|
if (input.matches("^[P3][a-km-zA-HJ-NP-Z1-9]{25,34}$")) {
|
||||||
|
if (PNCAddressValidator.ValidateAddress(input)) {
|
||||||
|
try {
|
||||||
|
Address.fromBase58(PNCParams.get(), input);
|
||||||
|
return new ValidationResult(true);
|
||||||
|
} catch (AddressFormatException e) {
|
||||||
|
return new ValidationResult(false, getErrorMessage(e));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return wrongChecksum;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return regexTestFailed;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
log.debug("Validation for AltCoinAddress not implemented yet. currencyCode: " + currencyCode);
|
log.debug("Validation for AltCoinAddress not implemented yet. currencyCode: " + currencyCode);
|
||||||
return validationResult;
|
return validationResult;
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
/*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.bisq.gui.util.validation.altcoins;
|
||||||
|
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class PNCAddressValidator {
|
||||||
|
private final static String ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
||||||
|
|
||||||
|
public static boolean ValidateAddress(String addr) {
|
||||||
|
if (addr.length() < 26 || addr.length() > 35) return false;
|
||||||
|
byte[] decoded = decodeBase58(addr, 58, 25);
|
||||||
|
if (decoded == null) return false;
|
||||||
|
|
||||||
|
byte[] hash = getSha256(decoded, 0, 21, 2);
|
||||||
|
return hash != null && Arrays.equals(Arrays.copyOfRange(hash, 0, 4), Arrays.copyOfRange(decoded, 21, 25));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static byte[] decodeBase58(String input, int base, int len) {
|
||||||
|
byte[] output = new byte[len];
|
||||||
|
for (int i = 0; i < input.length(); i++) {
|
||||||
|
char t = input.charAt(i);
|
||||||
|
|
||||||
|
int p = ALPHABET.indexOf(t);
|
||||||
|
if (p == -1) return null;
|
||||||
|
for (int j = len - 1; j >= 0; j--, p /= 256) {
|
||||||
|
p += base * (output[j] & 0xFF);
|
||||||
|
output[j] = (byte) (p % 256);
|
||||||
|
}
|
||||||
|
if (p != 0) return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static byte[] getSha256(byte[] data, int start, int len, int recursion) {
|
||||||
|
if (recursion == 0) return data;
|
||||||
|
|
||||||
|
try {
|
||||||
|
MessageDigest md = MessageDigest.getInstance("SHA-256");
|
||||||
|
md.update(Arrays.copyOfRange(data, start, start + len));
|
||||||
|
return getSha256(md.digest(), 0, 32, recursion - 1);
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,87 @@
|
||||||
|
/*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.bisq.gui.util.validation.params;
|
||||||
|
|
||||||
|
import org.bitcoinj.core.*;
|
||||||
|
import org.bitcoinj.store.BlockStore;
|
||||||
|
import org.bitcoinj.store.BlockStoreException;
|
||||||
|
import org.bitcoinj.utils.MonetaryFormat;
|
||||||
|
|
||||||
|
public class PNCParams extends NetworkParameters {
|
||||||
|
|
||||||
|
private static PNCParams instance;
|
||||||
|
|
||||||
|
public static synchronized PNCParams get() {
|
||||||
|
if (instance == null) {
|
||||||
|
instance = new PNCParams();
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PNCParams() {
|
||||||
|
super();
|
||||||
|
addressHeader = 55;
|
||||||
|
p2shHeader = 5;
|
||||||
|
acceptableAddressCodes = new int[] {addressHeader, p2shHeader};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPaymentProtocolId() {
|
||||||
|
return PAYMENT_PROTOCOL_ID_MAINNET;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void checkDifficultyTransitions(StoredBlock storedPrev, Block next, BlockStore blockStore) throws VerificationException, BlockStoreException {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Coin getMaxMoney() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Coin getMinNonDustOutput() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MonetaryFormat getMonetaryFormat() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUriScheme() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasMaxMoney() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BitcoinSerializer getSerializer(boolean parseRetain) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getProtocolVersionNum(ProtocolVersion version) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -135,4 +135,18 @@ public class AltCoinAddressValidatorTest {
|
||||||
assertFalse(validator.validate("NXT-JM2U-U4AE-G7WF-3Np9F").isValid);
|
assertFalse(validator.validate("NXT-JM2U-U4AE-G7WF-3Np9F").isValid);
|
||||||
assertFalse(validator.validate("NXT-2222-2222-2222-22222").isValid);
|
assertFalse(validator.validate("NXT-2222-2222-2222-22222").isValid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPNC() {
|
||||||
|
AltCoinAddressValidator validator = new AltCoinAddressValidator();
|
||||||
|
validator.setCurrencyCode("PNC");
|
||||||
|
|
||||||
|
assertTrue(validator.validate("3AB1qXhaU3hK5oAPQfwzN3QkM8LxAgL8vB").isValid);
|
||||||
|
assertTrue(validator.validate("PD57PGdk69yioZ6FD3zFNzVUeJhMf6Kti4").isValid);
|
||||||
|
|
||||||
|
assertFalse(validator.validate("3AB1qXhaU3hK5oAPQfwzN3QkM8LxAgL8v").isValid);
|
||||||
|
assertFalse(validator.validate("PD57PGdk69yioZ6FD3zFNzVUeJhMf6Kti42").isValid);
|
||||||
|
assertFalse(validator.validate("PD57PGdk69yioZ6FD3zFNzVUeJhMMMKti4").isValid);
|
||||||
|
assertFalse(validator.validate("PD57PG").isValid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue