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

Commit

Permalink
List InstaCash (ICH)
Browse files Browse the repository at this point in the history
  • Loading branch information
wqking committed Mar 20, 2018
1 parent ea29caf commit eef5ceb
Show file tree
Hide file tree
Showing 5 changed files with 126 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 @@ -186,6 +186,7 @@ public static List<CryptoCurrency> createAllSortedCryptoCurrenciesList() {
result.add(new CryptoCurrency("ROI", "ROIcoin"));
result.add(new CryptoCurrency("RTO", "Arto"));
result.add(new CryptoCurrency("KOTO", "Koto"));
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 @@ -540,6 +541,19 @@ public ValidationResult validate(String input) {
case "KOTO":
return KOTOAddressValidator.ValidateAddress(input);

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:
log.debug("Validation for AltCoinAddress not implemented yet. currencyCode: " + currencyCode);
Expand Down
93 changes: 93 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,93 @@
/*
* 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 @@ -300,6 +300,7 @@ private void printAllCurrencyStats() {
newlyAdded.add("WMCC");
newlyAdded.add("RTO");
newlyAdded.add("KOTO");
newlyAdded.add("ICH");

coinsWithValidator.addAll(newlyAdded);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -854,4 +854,21 @@ public void testKOTO() {
assertFalse(validator.validate("zkPRkLZKf4BuzBsC6r9Ls5suw1ZV9tCwiBTF5vcz2NZLUDsoXGp5rAFUjKnb7DdkFbLp7aSpejCcC4FTxsVvDxq9YKSprzf").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 eef5ceb

Please sign in to comment.