Skip to content
This repository has been archived by the owner on Jun 17, 2020. It is now read-only.

Commit

Permalink
Merge pull request #21 from wqking/master
Browse files Browse the repository at this point in the history
* wqking-master:
  Wrap code at 120 characters (bisq-network/style#3)
  List InstaCash (ICH)
  • Loading branch information
cbeams committed Mar 20, 2018
2 parents 27a0430 + 3e3cdaf commit 6bfc94b
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/java/bisq/core/locale/CurrencyUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ public static List<CryptoCurrency> createAllSortedCryptoCurrenciesList() {
result.add(new CryptoCurrency("QWARK", "Qwark", true));
result.add(new CryptoCurrency("GEO", "GeoCoin", true));
result.add(new CryptoCurrency("GRANS", "10grans"));
result.add(new CryptoCurrency("ICH", "ICH"));

result.sort(TradeCurrency::compareTo);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import bisq.core.payment.validation.params.AlcParams;
import bisq.core.payment.validation.params.CageParams;
import bisq.core.payment.validation.params.CreaParams;
import bisq.core.payment.validation.params.ICHParams;
import bisq.core.payment.validation.params.IOPParams;
import bisq.core.payment.validation.params.ODNParams;
import bisq.core.payment.validation.params.OctocoinParams;
Expand Down Expand Up @@ -573,6 +574,18 @@ public ValidationResult validate(String input) {
return regexTestFailed;
else
return new ValidationResult(true);
case "ICH":
if (input.matches("^[A][a-km-zA-HJ-NP-Z1-9]{25,34}$")) {
//noinspection ConstantConditions
try {
Address.fromBase58(ICHParams.get(), input);
return new ValidationResult(true);
} catch (AddressFormatException e) {
return new ValidationResult(false, getErrorMessage(e));
}
} else {
return regexTestFailed;
}

// Add new coins at the end...
default:
Expand Down
94 changes: 94 additions & 0 deletions src/main/java/bisq/core/payment/validation/params/ICHParams.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* 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 bisq.core.payment.validation.params;

import org.bitcoinj.core.BitcoinSerializer;
import org.bitcoinj.core.Block;
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.core.StoredBlock;
import org.bitcoinj.core.VerificationException;
import org.bitcoinj.store.BlockStore;
import org.bitcoinj.store.BlockStoreException;
import org.bitcoinj.utils.MonetaryFormat;

public class ICHParams extends NetworkParameters {

private static ICHParams instance;

public static synchronized ICHParams get() {
if (instance == null) {
instance = new ICHParams();
}
return instance;
}

// We only use the properties needed for address validation
public ICHParams() {
super();
addressHeader = 23;
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;
}

@Override
public BitcoinSerializer getSerializer(boolean parseRetain) {
return null;
}

@Override
public int getProtocolVersionNum(ProtocolVersion version) {
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ private void printAllCurrencyStats() {
newlyAdded.add("QWARK");
newlyAdded.add("GEO");
newlyAdded.add("GRANS");
newlyAdded.add("ICH");

coinsWithValidator.addAll(newlyAdded);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -929,4 +929,23 @@ public void testGRANS() {
assertFalse(validator.validate("2a65Aca4D5fC5B5C859090a6c34d16413539822g").isValid);
assertFalse(validator.validate("").isValid);
}

@Test
public void testICH() {
AltCoinAddressValidator validator = new AltCoinAddressValidator();
validator.setCurrencyCode("ICH");

assertTrue(validator.validate("AYx4EqKhomeMu2CTMx1AHdNMkjv6ygnvji").isValid);
assertTrue(validator.validate("AcWyvE7texXcCsPLvW1btXhLimrDMpNdAu").isValid);
assertTrue(validator.validate("AMfLeLotcvgaHQW374NmHZgs1qXF8P6kjc").isValid);

assertFalse(validator.validate("aYzyJYqhnxF738QjqMqTku5Wft7x4GhVCr").isValid);
assertFalse(validator.validate("DYzyJYqhnxF738QjqMqTku5Wft7x4GhVCr").isValid);
assertFalse(validator.validate("xYzyJYqhnxF738QjqMqTku5Wft7x4GhVCr").isValid);
assertFalse(validator.validate("1YzyJYqhnxF738QjqMqTku5Wft7x4GhVCr").isValid);
assertFalse(validator.validate(
"AYzyJYqhnxF738QjqMqTku5Wft7x4GhVCr5vcz2NZLUDsoXGp5rAFUjKnb7DdkFbLp7aSpejCcC4FTxsVvDxq9YKSprzf"
).isValid);
assertFalse(validator.validate("").isValid);
}
}

0 comments on commit 6bfc94b

Please sign in to comment.