From 1c6bbb4b6b1fb806aad9c1d494092838598c2a14 Mon Sep 17 00:00:00 2001 From: Jon Spock Date: Mon, 6 Feb 2017 18:13:35 -0800 Subject: [PATCH] Add PivxParams file and make sure unit test passes --- .../validation/AltCoinAddressValidator.java | 9 ++- .../util/validation/params/PivxParams.java | 78 +++++++++++++++++++ 2 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 gui/src/main/java/io/bitsquare/gui/util/validation/params/PivxParams.java diff --git a/gui/src/main/java/io/bitsquare/gui/util/validation/AltCoinAddressValidator.java b/gui/src/main/java/io/bitsquare/gui/util/validation/AltCoinAddressValidator.java index d6dfb6a64a..f737b4bbea 100644 --- a/gui/src/main/java/io/bitsquare/gui/util/validation/AltCoinAddressValidator.java +++ b/gui/src/main/java/io/bitsquare/gui/util/validation/AltCoinAddressValidator.java @@ -20,6 +20,7 @@ package io.bitsquare.gui.util.validation; import io.bitsquare.gui.util.validation.altcoins.ByteballAddressValidator; import io.bitsquare.gui.util.validation.params.IOPParams; +import io.bitsquare.gui.util.validation.params.PivxParams; import org.bitcoinj.core.Address; import org.bitcoinj.core.AddressFormatException; import org.bitcoinj.params.MainNetParams; @@ -72,11 +73,11 @@ public final class AltCoinAddressValidator extends InputValidator { } else { return regexTestFailed; } - /*case "PIVX": - if (input.matches("^[D][a-km-zA-HJ-NP-Z1-9]{25,34}$")) { + case "PIVX": + if (input.matches("^[D][a-km-zA-HJ-NP-Z1-9]{25,34}$")) { if (verifyChecksum(input)) { try { - new Address(MainNetParams.get(), input); + new Address(PivxParams.get(), input); return new ValidationResult(true); } catch (AddressFormatException e) { return new ValidationResult(false, getErrorMessage(e)); @@ -86,7 +87,7 @@ public final class AltCoinAddressValidator extends InputValidator { } } else { return regexTestFailed; - }*/ + } case "IOP": if (input.matches("^[p][a-km-zA-HJ-NP-Z1-9]{25,34}$")) { if (verifyChecksum(input)) { diff --git a/gui/src/main/java/io/bitsquare/gui/util/validation/params/PivxParams.java b/gui/src/main/java/io/bitsquare/gui/util/validation/params/PivxParams.java new file mode 100644 index 0000000000..ed24312039 --- /dev/null +++ b/gui/src/main/java/io/bitsquare/gui/util/validation/params/PivxParams.java @@ -0,0 +1,78 @@ +/* + * This file is part of Bitsquare. + * + * Bitsquare 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. + * + * Bitsquare 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 Bitsquare. If not, see . + */ + +package io.bitsquare.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 PivxParams extends NetworkParameters { + + private static PivxParams instance; + + public static synchronized PivxParams get() { + if (instance == null) { + instance = new PivxParams(); + } + return instance; + } + + // We only use the properties needed for address validation + public PivxParams() { + super(); + addressHeader = 30; + p2shHeader = 13; + acceptableAddressCodes = new int[]{addressHeader, p2shHeader}; + } + + // default dummy implementations, not used... + @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; + } +}