Merge branch 'deeponion-master' into Development

# Conflicts:
#	gui/src/main/java/io/bisq/gui/util/validation/AltCoinAddressValidator.java
#	gui/src/test/java/io/bisq/gui/util/validation/AltCoinAddressValidatorTest.java
This commit is contained in:
Manfred Karrer 2018-01-09 21:44:06 +01:00
commit 5d217aa347
No known key found for this signature in database
GPG Key ID: 401250966A6B2C46
4 changed files with 114 additions and 1 deletions

View File

@ -105,6 +105,7 @@ public class CurrencyUtil {
result.add(new CryptoCurrency("DASH", "Dash"));
result.add(new CryptoCurrency("DCT", "DECENT"));
result.add(new CryptoCurrency("DCR", "Decred"));
result.add(new CryptoCurrency("ONION", "DeepOnion"));
if (!baseCurrencyCode.equals("DOGE"))
result.add(new CryptoCurrency("DOGE", "Dogecoin"));
result.add(new CryptoCurrency("DMC", "DynamicCoin"));

View File

@ -367,7 +367,7 @@ public final class AltCoinAddressValidator extends InputValidator {
} catch (AddressFormatException e) {
return new ValidationResult(false, getErrorMessage(e));
}
case "CAGE":
case "CAGE":
if (input.matches("^[D][a-zA-Z0-9]{26,34}$")) {
//noinspection ConstantConditions
try {
@ -398,6 +398,15 @@ public final class AltCoinAddressValidator extends InputValidator {
else
return new ValidationResult(true);
// Add new coins at the end...
case "ONION":
try {
Address.fromBase58(OnionParams.get(), input);
return new ValidationResult(true);
} catch (AddressFormatException e) {
return new ValidationResult(false, getErrorMessage(e));
}
// 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 OnionParams extends NetworkParameters {
private static OnionParams instance;
public static synchronized OnionParams get() {
if (instance == null) {
instance = new OnionParams();
}
return instance;
}
// We only use the properties needed for address validation
public OnionParams() {
super();
addressHeader = 31;
p2shHeader = 78;
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

@ -472,4 +472,19 @@ public class AltCoinAddressValidatorTest {
assertFalse(validator.validate("2a65Aca4D5fC5B5C859090a6c34d16413539822g").isValid);
assertFalse(validator.validate("").isValid);
}
@Test
public void testONION() {
AltCoinAddressValidator validator = new AltCoinAddressValidator();
validator.setCurrencyCode("ONION");
assertTrue(validator.validate("DbkkqXwdiWJNcpfw49f2xzTVEbvL1SYWDm").isValid);
assertTrue(validator.validate("DetWWdj7VUTDg1yMhjgRfzvwTf4rRSoywK").isValid);
assertTrue(validator.validate("Dr5aiywUzZgYHvrQgrCsk6qhxhFzM8VVUM").isValid);
assertFalse(validator.validate("17VZNX1SN5NtKa8UQFxwQbFeFc3iqRYhemqq").isValid);
assertFalse(validator.validate("17VZNX1SN5NtKa8UQFxwQbFeFc3iqRYheO").isValid);
assertFalse(validator.validate("1HQQgsvLTgN9xD9hNmAgAreakzVzQUSLSH#").isValid);
assertFalse(validator.validate("").isValid);
}
}