mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-20 10:22:18 +01:00
Add altcoin validation for btc. ltc and doge. change order of base currency network to avoid to break port assignment by enum ordinal. add btc to altcoin list if not base currency.
This commit is contained in:
parent
7bd9ba6fb0
commit
edb71d1d86
@ -19,8 +19,10 @@ package io.bisq.common.locale;
|
||||
|
||||
import com.google.protobuf.Message;
|
||||
import io.bisq.generated.protobuffer.PB;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public final class CryptoCurrency extends TradeCurrency {
|
||||
// http://boschista.deviantart.com/journal/Cool-ASCII-Symbols-214218618
|
||||
private final static String PREFIX = "✦ ";
|
||||
|
@ -17,6 +17,9 @@
|
||||
|
||||
package io.bisq.common.locale;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@EqualsAndHashCode
|
||||
public class CurrencyTuple {
|
||||
public final String code;
|
||||
public final String name;
|
||||
|
@ -25,6 +25,12 @@ import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
public class CurrencyUtil {
|
||||
private static String baseCurrencyCode = "BTC";
|
||||
|
||||
public static void setBaseCurrencyNetwork(String baseCurrencyCode) {
|
||||
CurrencyUtil.baseCurrencyCode = baseCurrencyCode;
|
||||
}
|
||||
|
||||
private static List<FiatCurrency> allSortedFiatCurrencies;
|
||||
|
||||
private static List<FiatCurrency> createAllSortedFiatCurrenciesList() {
|
||||
@ -67,9 +73,11 @@ public class CurrencyUtil {
|
||||
return list;
|
||||
}
|
||||
|
||||
private static final List<CryptoCurrency> allSortedCryptoCurrencies = createAllSortedCryptoCurrenciesList();
|
||||
private static List<CryptoCurrency> allSortedCryptoCurrencies;
|
||||
|
||||
public static List<CryptoCurrency> getAllSortedCryptoCurrencies() {
|
||||
if (allSortedCryptoCurrencies == null)
|
||||
allSortedCryptoCurrencies = createAllSortedCryptoCurrenciesList();
|
||||
return allSortedCryptoCurrencies;
|
||||
}
|
||||
|
||||
@ -86,7 +94,9 @@ public class CurrencyUtil {
|
||||
result.add(new CryptoCurrency("REP", "Augur", true));
|
||||
result.add(new CryptoCurrency("BATL", "Battlestars"));
|
||||
result.add(new CryptoCurrency("BIGUP", "BigUp"));
|
||||
result.add(new CryptoCurrency("BSQ", "bisq Token"));
|
||||
result.add(new CryptoCurrency("BSQ", "Bisq Token"));
|
||||
if (!baseCurrencyCode.equals("BTC"))
|
||||
result.add(new CryptoCurrency("BTC", "Bitcoin"));
|
||||
result.add(new CryptoCurrency("BITAUD", "BitAUD", true));
|
||||
result.add(new CryptoCurrency("BITCHF", "BitCHF", true));
|
||||
result.add(new CryptoCurrency("BITCNY", "BitCNY", true));
|
||||
@ -116,7 +126,8 @@ public class CurrencyUtil {
|
||||
result.add(new CryptoCurrency("DGB", "Digibyte"));
|
||||
result.add(new CryptoCurrency("DRS", "Digital Rupees"));
|
||||
result.add(new CryptoCurrency("DGD", "DigixDAO Tokens", true));
|
||||
result.add(new CryptoCurrency("DOGE", "Dogecoin"));
|
||||
if (!baseCurrencyCode.equals("DOGE"))
|
||||
result.add(new CryptoCurrency("DOGE", "Dogecoin"));
|
||||
result.add(new CryptoCurrency("DMC", "DynamicCoin"));
|
||||
result.add(new CryptoCurrency("EMC", "Emercoin"));
|
||||
result.add(new CryptoCurrency("EURT", "EUR Tether"));
|
||||
@ -144,7 +155,8 @@ public class CurrencyUtil {
|
||||
result.add(new CryptoCurrency("LBC", "LBRY Credits"));
|
||||
result.add(new CryptoCurrency("LTBC", "LTBcoin"));
|
||||
result.add(new CryptoCurrency("LSK", "Lisk"));
|
||||
result.add(new CryptoCurrency("LTC", "Litecoin"));
|
||||
if (!baseCurrencyCode.equals("LTC"))
|
||||
result.add(new CryptoCurrency("LTC", "Litecoin"));
|
||||
result.add(new CryptoCurrency("MAID", "MaidSafeCoin"));
|
||||
result.add(new CryptoCurrency("MKR", "Maker", true));
|
||||
result.add(new CryptoCurrency("MXT", "MarteXcoin"));
|
||||
@ -226,20 +238,22 @@ public class CurrencyUtil {
|
||||
|
||||
public static List<CryptoCurrency> getMainCryptoCurrencies() {
|
||||
final List<CryptoCurrency> result = new ArrayList<>();
|
||||
result.add(new CryptoCurrency("BSQ", "bisq Token"));
|
||||
result.add(new CryptoCurrency("XMR", "Monero"));
|
||||
result.add(new CryptoCurrency("ZEC", "Zcash"));
|
||||
result.add(new CryptoCurrency("NMC", "Namecoin"));
|
||||
result.add(new CryptoCurrency("SC", "Siacoin"));
|
||||
result.add(new CryptoCurrency("BSQ", "Bisq Token"));
|
||||
if (!baseCurrencyCode.equals("BTC"))
|
||||
result.add(new CryptoCurrency("BTC", "Bitcoin"));
|
||||
result.add(new CryptoCurrency("DASH", "Dash"));
|
||||
result.add(new CryptoCurrency("DCR", "Decred"));
|
||||
if (!baseCurrencyCode.equals("DOGE"))
|
||||
result.add(new CryptoCurrency("DOGE", "Dogecoin"));
|
||||
result.add(new CryptoCurrency("ETH", "Ether"));
|
||||
result.add(new CryptoCurrency("ETC", "Ether Classic"));
|
||||
result.add(new CryptoCurrency("STEEM", "STEEM"));
|
||||
if (!baseCurrencyCode.equals("LTC"))
|
||||
result.add(new CryptoCurrency("LTC", "Litecoin"));
|
||||
result.add(new CryptoCurrency("XMR", "Monero"));
|
||||
result.add(new CryptoCurrency("MT", "Mycelium Token", true));
|
||||
result.add(new CryptoCurrency("REP", "Augur", true));
|
||||
result.add(new CryptoCurrency("LTC", "Litecoin"));
|
||||
result.add(new CryptoCurrency("DASH", "Dash"));
|
||||
result.add(new CryptoCurrency("DOGE", "Dogecoin"));
|
||||
|
||||
result.add(new CryptoCurrency("NMC", "Namecoin"));
|
||||
result.add(new CryptoCurrency("SC", "Siacoin"));
|
||||
result.add(new CryptoCurrency("ZEC", "Zcash"));
|
||||
result.sort(TradeCurrency::compareTo);
|
||||
return result;
|
||||
}
|
||||
@ -341,10 +355,6 @@ public class CurrencyUtil {
|
||||
return getNameByCode(currencyCode) + " (" + currencyCode + ")";
|
||||
}
|
||||
|
||||
private static Locale getLocale() {
|
||||
return GlobalSettings.getLocale();
|
||||
}
|
||||
|
||||
public static TradeCurrency getDefaultTradeCurrency() {
|
||||
return GlobalSettings.getDefaultTradeCurrency();
|
||||
}
|
||||
|
@ -25,13 +25,13 @@ import org.bitcoinj.params.TestNet3Params;
|
||||
import org.libdohj.params.*;
|
||||
|
||||
public enum BaseCurrencyNetwork {
|
||||
LTC_MAINNET(LitecoinMainNetParams.get(), "LTC", "MAINNET", "Litecoin"),
|
||||
LTC_TESTNET(LitecoinTestNet3Params.get(), "LTC", "TESTNET", "Litecoin"),
|
||||
LTC_REGTEST(LitecoinRegTestParams.get(), "LTC", "REGTEST", "Litecoin"),
|
||||
|
||||
BTC_MAINNET(MainNetParams.get(), "BTC", "MAINNET", "Bitcoin"),
|
||||
BTC_TESTNET(TestNet3Params.get(), "BTC", "TESTNET", "Bitcoin"),
|
||||
BTC_REGTEST(RegTestParams.get(), "BTC", "REGTEST", "Bitcoin"),
|
||||
|
||||
LTC_MAINNET(LitecoinMainNetParams.get(), "LTC", "MAINNET", "Litecoin"),
|
||||
LTC_TESTNET(LitecoinTestNet3Params.get(), "LTC", "TESTNET", "Litecoin"),
|
||||
LTC_REGTEST(LitecoinRegTestParams.get(), "LTC", "REGTEST", "Litecoin"),
|
||||
|
||||
DOGE_MAINNET(DogecoinMainNetParams.get(), "DOGE", "MAINNET", "Dogecoin"),
|
||||
DOGE_TESTNET(DogecoinTestNet3Params.get(), "DOGE", "TESTNET", "Dogecoin")/*,
|
||||
|
@ -93,6 +93,7 @@ public abstract class PaymentAccount implements PersistablePayload {
|
||||
|
||||
public static PaymentAccount fromProto(PB.PaymentAccount proto, CoreProtoResolver coreProtoResolver) {
|
||||
PaymentAccount account = PaymentAccountFactory.getPaymentAccount(PaymentMethod.getPaymentMethodById(proto.getPaymentMethod().getId()));
|
||||
account.getTradeCurrencies().clear();
|
||||
account.setId(proto.getId());
|
||||
account.setCreationDate(proto.getCreationDate());
|
||||
account.setAccountName(proto.getAccountName());
|
||||
|
@ -28,6 +28,7 @@ import io.bisq.common.app.Log;
|
||||
import io.bisq.common.app.Version;
|
||||
import io.bisq.common.crypto.LimitedKeyStrengthException;
|
||||
import io.bisq.common.handlers.ResultHandler;
|
||||
import io.bisq.common.locale.CurrencyUtil;
|
||||
import io.bisq.common.locale.Res;
|
||||
import io.bisq.common.proto.persistable.PersistedDataHost;
|
||||
import io.bisq.common.storage.Storage;
|
||||
@ -65,6 +66,7 @@ import io.bisq.gui.main.debug.DebugView;
|
||||
import io.bisq.gui.main.overlays.popups.Popup;
|
||||
import io.bisq.gui.main.overlays.windows.*;
|
||||
import io.bisq.gui.util.ImageUtil;
|
||||
import io.bisq.gui.util.validation.AltCoinAddressValidator;
|
||||
import io.bisq.network.p2p.P2PService;
|
||||
import javafx.application.Application;
|
||||
import javafx.application.Platform;
|
||||
@ -170,7 +172,11 @@ public class BisqApp extends Application {
|
||||
Res.setBaseCurrencyName(baseCurrencyNetwork.getCurrencyName());
|
||||
|
||||
Restrictions.setBaseCurrencyNetwork(baseCurrencyNetwork);
|
||||
|
||||
|
||||
CurrencyUtil.setBaseCurrencyNetwork(baseCurrencyNetwork.getCurrencyCode());
|
||||
|
||||
AltCoinAddressValidator.setNetwork(baseCurrencyNetwork.getNetwork());
|
||||
|
||||
try {
|
||||
// Guice
|
||||
bisqAppModule = new BisqAppModule(bisqEnvironment, primaryStage);
|
||||
|
@ -436,14 +436,15 @@ public class CreateOfferView extends ActivatableViewAndModel<AnchorPane, CreateO
|
||||
if (paymentAccount != null) {
|
||||
currencyComboBox.setVisible(paymentAccount.hasMultipleCurrencies());
|
||||
if (paymentAccount.hasMultipleCurrencies()) {
|
||||
currencyComboBox.setItems(FXCollections.observableArrayList(paymentAccount.getTradeCurrencies()));
|
||||
final List<TradeCurrency> tradeCurrencies = paymentAccount.getTradeCurrencies();
|
||||
currencyComboBox.setItems(FXCollections.observableArrayList(tradeCurrencies));
|
||||
|
||||
// we select comboBox following the user currency, if user currency not available in account, we select first
|
||||
TradeCurrency tradeCurrency = model.getTradeCurrency();
|
||||
if (paymentAccount.getTradeCurrencies().contains(tradeCurrency))
|
||||
if (tradeCurrencies.contains(tradeCurrency))
|
||||
currencyComboBox.getSelectionModel().select(tradeCurrency);
|
||||
else
|
||||
currencyComboBox.getSelectionModel().select(paymentAccount.getTradeCurrencies().get(0));
|
||||
currencyComboBox.getSelectionModel().select(tradeCurrencies.get(0));
|
||||
|
||||
model.onPaymentAccountSelected(paymentAccount);
|
||||
} else {
|
||||
|
@ -25,17 +25,29 @@ import io.bisq.gui.util.validation.altcoins.OctocoinAddressValidator;
|
||||
import io.bisq.gui.util.validation.params.IOPParams;
|
||||
import io.bisq.gui.util.validation.params.OctocoinParams;
|
||||
import io.bisq.gui.util.validation.params.PivxParams;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bitcoinj.core.Address;
|
||||
import org.bitcoinj.core.AddressFormatException;
|
||||
import org.bitcoinj.params.MainNetParams;
|
||||
import org.bitcoinj.params.RegTestParams;
|
||||
import org.bitcoinj.params.TestNet3Params;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.libdohj.params.*;
|
||||
|
||||
@Slf4j
|
||||
public final class AltCoinAddressValidator extends InputValidator {
|
||||
private static final Logger log = LoggerFactory.getLogger(AltCoinAddressValidator.class);
|
||||
|
||||
private String currencyCode;
|
||||
private static String network;
|
||||
|
||||
public static void setNetwork(String network) {
|
||||
AltCoinAddressValidator.network = network;
|
||||
}
|
||||
|
||||
public static String getNetwork() {
|
||||
return network;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Public methods
|
||||
@ -62,6 +74,58 @@ public final class AltCoinAddressValidator extends InputValidator {
|
||||
Res.get("validation.altcoin.wrongStructure", currencyCode));
|
||||
|
||||
switch (currencyCode) {
|
||||
case "BTC":
|
||||
try {
|
||||
switch (network) {
|
||||
case "MAINNET":
|
||||
Address.fromBase58(MainNetParams.get(), input);
|
||||
break;
|
||||
case "TESTNET":
|
||||
Address.fromBase58(TestNet3Params.get(), input);
|
||||
break;
|
||||
case "REGTEST":
|
||||
Address.fromBase58(RegTestParams.get(), input);
|
||||
break;
|
||||
}
|
||||
return new ValidationResult(true);
|
||||
} catch (AddressFormatException e) {
|
||||
return new ValidationResult(false, getErrorMessage(e));
|
||||
}
|
||||
case "LTC":
|
||||
try {
|
||||
switch (network) {
|
||||
case "MAINNET":
|
||||
Address.fromBase58(LitecoinMainNetParams.get(), input);
|
||||
break;
|
||||
case "TESTNET":
|
||||
Address.fromBase58(LitecoinTestNet3Params.get(), input);
|
||||
break;
|
||||
case "REGTEST":
|
||||
Address.fromBase58(LitecoinRegTestParams.get(), input);
|
||||
break;
|
||||
}
|
||||
return new ValidationResult(true);
|
||||
} catch (AddressFormatException e) {
|
||||
return new ValidationResult(false, getErrorMessage(e));
|
||||
}
|
||||
case "DOGE":
|
||||
try {
|
||||
switch (network) {
|
||||
case "MAINNET":
|
||||
Address.fromBase58(DogecoinMainNetParams.get(), input);
|
||||
break;
|
||||
case "TESTNET":
|
||||
Address.fromBase58(DogecoinTestNet3Params.get(), input);
|
||||
break;
|
||||
case "REGTEST":
|
||||
// TODO
|
||||
//Address.fromBase58(DogecoinRegTestParams.get(), input);
|
||||
break;
|
||||
}
|
||||
return new ValidationResult(true);
|
||||
} catch (AddressFormatException e) {
|
||||
return new ValidationResult(false, getErrorMessage(e));
|
||||
}
|
||||
case "ETH":
|
||||
// https://github.com/ethereum/web3.js/blob/master/lib/utils/utils.js#L403
|
||||
if (!input.matches("^(0x)?[0-9a-fA-F]{40}$"))
|
||||
@ -69,22 +133,6 @@ public final class AltCoinAddressValidator extends InputValidator {
|
||||
else
|
||||
return new ValidationResult(true);
|
||||
// Example for BTC, though for BTC we use the BitcoinJ library address check
|
||||
case "BTC":
|
||||
// taken form: https://stackoverflow.com/questions/21683680/regex-to-match-bitcoin-addresses
|
||||
if (input.matches("^[13][a-km-zA-HJ-NP-Z1-9]{25,34}$")) {
|
||||
//noinspection ConstantConditions
|
||||
if (verifyChecksum(input))
|
||||
try {
|
||||
Address.fromBase58(MainNetParams.get(), input);
|
||||
return new ValidationResult(true);
|
||||
} catch (AddressFormatException e) {
|
||||
return new ValidationResult(false, getErrorMessage(e));
|
||||
}
|
||||
else
|
||||
return wrongChecksum;
|
||||
} else {
|
||||
return regexTestFailed;
|
||||
}
|
||||
case "PIVX":
|
||||
if (input.matches("^[D][a-km-zA-HJ-NP-Z1-9]{25,34}$")) {
|
||||
//noinspection ConstantConditions
|
||||
|
Loading…
Reference in New Issue
Block a user