Added ODN Address Validation

This commit is contained in:
Manbearpixel 2018-02-05 10:22:17 -06:00
parent ed0148bfee
commit abe20f1b97
4 changed files with 114 additions and 1 deletions

View File

@ -252,6 +252,8 @@ public class TradeStatisticsManager {
newlyAdded.add("MVT");
newlyAdded.add("REF");
newlyAdded.add("ODN");
coinsWithValidator.addAll(newlyAdded);

View File

@ -438,8 +438,15 @@ public final class AltCoinAddressValidator extends InputValidator {
return regexTestFailed;
else
return new ValidationResult(true);
case "ODN":
try {
Address.fromBase58(ODNParams.get(), input);
return new ValidationResult(true);
} catch (AddressFormatException e) {
return new ValidationResult(false, getErrorMessage(e));
}
// Add new coins at the end...
// Add new coins at the end...
default:
log.debug("Validation for AltCoinAddress not implemented yet. currencyCode: " + currencyCode);
return validationResult;

View File

@ -0,0 +1,88 @@
/*
* 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 ODNParams extends NetworkParameters {
private static ODNParams instance;
public static synchronized ODNParams get() {
if (instance == null) {
instance = new ODNParams();
}
return instance;
}
// We only use the properties needed for address validation
public ODNParams() {
super();
addressHeader = 75; // networkVersion (0x4b)
p2shHeader = -1; // TODO ??privateKeyPrefix 203 (0xcb) tbd?
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;
}
@Override
public BitcoinSerializer getSerializer(boolean parseRetain) {
return null;
}
@Override
public int getProtocolVersionNum(ProtocolVersion version) {
return 0;
}
}

View File

@ -429,6 +429,22 @@ public class AltCoinAddressValidatorTest {
assertFalse(validator.validate("").isValid);
}
@Test
public void testODN() {
AltCoinAddressValidator validator = new AltCoinAddressValidator();
validator.setCurrencyCode("ODN");
assertTrue(validator.validate("XEfyuzk8yTp5eA9eVUeCW2PFbCFtNb6Jgv").isValid);
assertTrue(validator.validate("XJegzjV2GK9CeQLNNcc5GVSSqTkv1XMxSF").isValid);
assertTrue(validator.validate("XLfvvLuwjUrz2kf5gghEmUPFE3vFvwfEiL").isValid);
assertTrue(validator.validate("XNC1e9TfUApfBsH9JCubioS5XGuwFLbsP4").isValid);
assertFalse(validator.validate("17VZNX1SN5NtKa8UQFxwQbFeFc3iqRYhemqq").isValid);
assertFalse(validator.validate("0x2a65Aca4D5fC5B5C859090a6c34d1641353982266").isValid);
assertFalse(validator.validate("SSnwqFBiyqK1n4BV7kPX86iesev2NobhEo").isValid);
assertFalse(validator.validate("").isValid);
}
@Test
public void testCRED() {
AltCoinAddressValidator validator = new AltCoinAddressValidator();