From 2fdece01ca02fdf9e4ad5e1b1ec9937515ea36a3 Mon Sep 17 00:00:00 2001 From: b00lean Date: Mon, 4 Aug 2014 09:43:26 +0200 Subject: [PATCH] Added LEOcoin support and fixprice rate source --- .../batm/server/extensions/ICurrencies.java | 1 + .../res/batm-extensions.xml | 32 +++++ server_extensions_extra/res/leo.png | Bin 0 -> 6515 bytes .../extra/bitcoin/BitcoinExtension.java | 11 ++ .../bitcoin/sources/FixPriceRateSource.java | 43 +++++++ .../extra/dogecoin/DogecoinExtension.java | 11 ++ .../dogecoin/sources/FixPriceRateSource.java | 43 +++++++ .../leocoin/LeocoinAddressValidator.java | 61 +++++++++ .../extra/leocoin/LeocoinExtension.java | 109 ++++++++++++++++ .../leocoin/sources/FixPriceRateSource.java | 43 +++++++ .../wallets/leocoind/LeocoindRPCWallet.java | 120 ++++++++++++++++++ .../extra/litecoin/LitecoinExtension.java | 12 ++ .../litecoin/sources/FixPriceRateSource.java | 43 +++++++ .../extra/maxcoin/MaxcoinExtension.java | 12 ++ .../maxcoin/sources/FixPriceRateSource.java | 43 +++++++ 15 files changed, 584 insertions(+) create mode 100644 server_extensions_extra/res/leo.png create mode 100644 server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/bitcoin/sources/FixPriceRateSource.java create mode 100644 server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/dogecoin/sources/FixPriceRateSource.java create mode 100644 server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/leocoin/LeocoinAddressValidator.java create mode 100644 server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/leocoin/LeocoinExtension.java create mode 100644 server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/leocoin/sources/FixPriceRateSource.java create mode 100644 server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/leocoin/wallets/leocoind/LeocoindRPCWallet.java create mode 100644 server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/litecoin/sources/FixPriceRateSource.java create mode 100644 server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/maxcoin/sources/FixPriceRateSource.java diff --git a/server_extensions_api/src/com/generalbytes/batm/server/extensions/ICurrencies.java b/server_extensions_api/src/com/generalbytes/batm/server/extensions/ICurrencies.java index ff97c72..dc446a5 100644 --- a/server_extensions_api/src/com/generalbytes/batm/server/extensions/ICurrencies.java +++ b/server_extensions_api/src/com/generalbytes/batm/server/extensions/ICurrencies.java @@ -23,6 +23,7 @@ public interface ICurrencies { public static final String LTC = "LTC"; public static final String DOGE = "DOGE"; public static final String MAX = "MAX"; + public static final String LEO = "LEO"; public static final String CZK = "CZK"; diff --git a/server_extensions_extra/res/batm-extensions.xml b/server_extensions_extra/res/batm-extensions.xml index 1288f52..0fa2239 100644 --- a/server_extensions_extra/res/batm-extensions.xml +++ b/server_extensions_extra/res/batm-extensions.xml @@ -13,6 +13,10 @@ BTC + + + BTC + @@ -33,6 +37,10 @@ DOGE + + + DOGE + @@ -49,6 +57,10 @@ LTC BTC + + + LTC + @@ -64,7 +76,27 @@ MAX + + + MAX + + + + + + + + + + LEO + + + + LEO + + + \ No newline at end of file diff --git a/server_extensions_extra/res/leo.png b/server_extensions_extra/res/leo.png new file mode 100644 index 0000000000000000000000000000000000000000..6242aeacd8459a5f0b2cdae2c0694937a4025ff0 GIT binary patch literal 6515 zcmV-(8I0zMP)3eo02y>e zSad^gZEa<4bO1wgWnpw>WFU8GbZ8()Nlj2!fese{02tdzL_t(|+U;F=bXC>W|Lt>! zH)n!`K}80s2nt082aq^mYqeTvZLx|Xt#xW^``M)(zIJ_;*7eoacC~(1TdN`n2!cp0 zPKe?|5ky2mMIZtO2ua91yy*^Se}B9rCQQk_c`tdu+iTsh7La?-J-@s6{_TDC*$2qV z2`zLYy-dx#(Ydy&p9)|Q7=;WJ0F+O}9%k~jzAuAq0t^X?5V(dVH3(ss+n{|WC-$9w z=Z!r_SJbZ)@kK;50YCtNAcAOlx7I(8_MQwtG6Mi)%Vjfjoy}M$ZC+a) z;TL|qBvcj-hh-MvG|It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^X)?-sd94+AxilJj=A)g> z@2}m|(A<;c>9_{Cy{uU}YXE@$UKzha6ZTXu5*OvjX3b|exjK!+o%t1rs6p9i`?fZj z%9@6_@@j2D-|_ge^8EnpOwrck65w{`TaCr-05gI@&}phd(|jB)4sm3(Pe%PdjzP4v z+N49w`q5tU(Er74TB;yQej`fW(rPQXwz5e)6N$;s0W{Xsn~nF}w>)vY%-eAro~&Cj zTdAxu6kR1jLjPAps5vVujkR8gR?flFig;vuKu}MpKHt z25BWtrn;`84jU_Lj4CPF)HPwPc)i-nWGy`*0q#tSi;Jn<`_U2JwRJ(KHC4#RD~QLE Z{|AyXBFk9`@@)VB002ovPDHLkV1g9MQ!)Sm literal 0 HcmV?d00001 diff --git a/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/bitcoin/BitcoinExtension.java b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/bitcoin/BitcoinExtension.java index 3d73747..1e6022d 100644 --- a/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/bitcoin/BitcoinExtension.java +++ b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/bitcoin/BitcoinExtension.java @@ -19,8 +19,10 @@ package com.generalbytes.batm.server.extensions.extra.bitcoin; import com.generalbytes.batm.server.extensions.*; import com.generalbytes.batm.server.extensions.extra.bitcoin.sources.BitcoinAverageRateSource; +import com.generalbytes.batm.server.extensions.extra.bitcoin.sources.FixPriceRateSource; import com.generalbytes.batm.server.extensions.extra.bitcoin.wallets.bitcoind.BATMBitcoindRPCWallet; +import java.math.BigDecimal; import java.util.*; public class BitcoinExtension implements IExtension{ @@ -82,6 +84,15 @@ public class BitcoinExtension implements IExtension{ if ("bitcoinaverage".equalsIgnoreCase(exchangeType)) { return new BitcoinAverageRateSource(); + }else if ("btcfix".equalsIgnoreCase(exchangeType)) { + BigDecimal rate = BigDecimal.ZERO; + if (st.hasMoreTokens()) { + try { + rate = new BigDecimal(st.nextToken()); + } catch (Throwable e) { + } + } + return new FixPriceRateSource(rate); } } return null; diff --git a/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/bitcoin/sources/FixPriceRateSource.java b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/bitcoin/sources/FixPriceRateSource.java new file mode 100644 index 0000000..386fb41 --- /dev/null +++ b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/bitcoin/sources/FixPriceRateSource.java @@ -0,0 +1,43 @@ +package com.generalbytes.batm.server.extensions.extra.bitcoin.sources; + +import com.generalbytes.batm.server.extensions.ICurrencies; +import com.generalbytes.batm.server.extensions.IRateSource; + +import java.math.BigDecimal; +import java.util.HashSet; +import java.util.Set; + +/** + * Created by b00lean on 7/31/14. + */ +public class FixPriceRateSource implements IRateSource { + private BigDecimal rate = BigDecimal.ZERO; + + public FixPriceRateSource(BigDecimal rate) { + this.rate = rate; + } + + @Override + public Set getCryptoCurrencies() { + Set result = new HashSet(); + result.add(ICurrencies.BTC); + return result; + } + + @Override + public BigDecimal getExchangeRateLast(String cryptoCurrency, String fiatCurrency) { + if (ICurrencies.BTC.equalsIgnoreCase(cryptoCurrency)) { + return rate; + } + return null; + } + + @Override + public Set getFiatCurrencies() { + Set result = new HashSet(); + result.add(ICurrencies.USD); + result.add(ICurrencies.EUR); + return result; + } + +} diff --git a/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/dogecoin/DogecoinExtension.java b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/dogecoin/DogecoinExtension.java index ab6a2b5..1522e14 100644 --- a/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/dogecoin/DogecoinExtension.java +++ b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/dogecoin/DogecoinExtension.java @@ -19,9 +19,11 @@ package com.generalbytes.batm.server.extensions.extra.dogecoin; import com.generalbytes.batm.server.extensions.*; import com.generalbytes.batm.server.extensions.extra.dogecoin.sources.DogeAPIRateSource; +import com.generalbytes.batm.server.extensions.extra.dogecoin.sources.FixPriceRateSource; import com.generalbytes.batm.server.extensions.extra.dogecoin.wallets.dogeapi.DogeAPIWallet; import com.generalbytes.batm.server.extensions.extra.dogecoin.wallets.dogecoind.DogecoindRPCWallet; +import java.math.BigDecimal; import java.util.*; public class DogecoinExtension implements IExtension{ @@ -91,6 +93,15 @@ public class DogecoinExtension implements IExtension{ if ("dogeapi".equalsIgnoreCase(exchangeType)) { return new DogeAPIRateSource(); + }else if ("dogefix".equalsIgnoreCase(exchangeType)) { + BigDecimal rate = BigDecimal.ZERO; + if (st.hasMoreTokens()) { + try { + rate = new BigDecimal(st.nextToken()); + } catch (Throwable e) { + } + } + return new FixPriceRateSource(rate); } } return null; diff --git a/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/dogecoin/sources/FixPriceRateSource.java b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/dogecoin/sources/FixPriceRateSource.java new file mode 100644 index 0000000..5c27f4b --- /dev/null +++ b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/dogecoin/sources/FixPriceRateSource.java @@ -0,0 +1,43 @@ +package com.generalbytes.batm.server.extensions.extra.dogecoin.sources; + +import com.generalbytes.batm.server.extensions.ICurrencies; +import com.generalbytes.batm.server.extensions.IRateSource; + +import java.math.BigDecimal; +import java.util.HashSet; +import java.util.Set; + +/** + * Created by b00lean on 7/31/14. + */ +public class FixPriceRateSource implements IRateSource { + private BigDecimal rate = BigDecimal.ZERO; + + public FixPriceRateSource(BigDecimal rate) { + this.rate = rate; + } + + @Override + public Set getCryptoCurrencies() { + Set result = new HashSet(); + result.add(ICurrencies.DOGE); + return result; + } + + @Override + public BigDecimal getExchangeRateLast(String cryptoCurrency, String fiatCurrency) { + if (!ICurrencies.DOGE.equalsIgnoreCase(cryptoCurrency)) { + return rate; + } + return null; + } + + @Override + public Set getFiatCurrencies() { + Set result = new HashSet(); + result.add(ICurrencies.USD); + result.add(ICurrencies.EUR); + return result; + } + +} diff --git a/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/leocoin/LeocoinAddressValidator.java b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/leocoin/LeocoinAddressValidator.java new file mode 100644 index 0000000..6f7f6bb --- /dev/null +++ b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/leocoin/LeocoinAddressValidator.java @@ -0,0 +1,61 @@ +/************************************************************************************* + * Copyright (C) 2014 GENERAL BYTES s.r.o. All rights reserved. + * + * This software may be distributed and modified under the terms of the GNU + * General Public License version 2 (GPL2) as published by the Free Software + * Foundation and appearing in the file GPL2.TXT included in the packaging of + * this file. Please note that GPL2 Section 2[b] requires that all works based + * on this software must also be made publicly available under the terms of + * the GPL2 ("Copyleft"). + * + * Contact information + * ------------------- + * + * GENERAL BYTES s.r.o. + * Web : http://www.generalbytes.com + * + ************************************************************************************/ +package com.generalbytes.batm.server.extensions.extra.leocoin; + +import com.generalbytes.batm.server.coinutil.AddressFormatException; +import com.generalbytes.batm.server.coinutil.Base58; +import com.generalbytes.batm.server.extensions.ExtensionsUtil; +import com.generalbytes.batm.server.extensions.ICryptoAddressValidator; + +public class LeocoinAddressValidator implements ICryptoAddressValidator { + + @Override + public boolean isAddressValid(String address) { + boolean result = isLeocoinAddressValid(address); + if (!result) { + result = isPaperWalletSupported() && ExtensionsUtil.isValidEmailAddress(address); + } + return result; + } + + private static boolean isLeocoinAddressValid(String address) { + if (address.startsWith("L")) { + try { + Base58.decodeToBigInteger(address); + Base58.decodeChecked(address); + } catch (AddressFormatException e) { + e.printStackTrace(); + return false; + } + return true; + }else{ + return false; + } + } + + @Override + public boolean isPaperWalletSupported() { + return false; + } + + @Override + public boolean mustBeBase58Address() { + return true; + } + +} diff --git a/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/leocoin/LeocoinExtension.java b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/leocoin/LeocoinExtension.java new file mode 100644 index 0000000..ddb7277 --- /dev/null +++ b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/leocoin/LeocoinExtension.java @@ -0,0 +1,109 @@ +/************************************************************************************* + * Copyright (C) 2014 GENERAL BYTES s.r.o. All rights reserved. + * + * This software may be distributed and modified under the terms of the GNU + * General Public License version 2 (GPL2) as published by the Free Software + * Foundation and appearing in the file GPL2.TXT included in the packaging of + * this file. Please note that GPL2 Section 2[b] requires that all works based + * on this software must also be made publicly available under the terms of + * the GPL2 ("Copyleft"). + * + * Contact information + * ------------------- + * + * GENERAL BYTES s.r.o. + * Web : http://www.generalbytes.com + * + ************************************************************************************/ +package com.generalbytes.batm.server.extensions.extra.leocoin; + +import com.generalbytes.batm.server.extensions.*; +import com.generalbytes.batm.server.extensions.extra.leocoin.sources.FixPriceRateSource; +import com.generalbytes.batm.server.extensions.extra.leocoin.wallets.leocoind.LeocoindRPCWallet; + +import java.math.BigDecimal; +import java.util.HashSet; +import java.util.Set; +import java.util.StringTokenizer; + +public class LeocoinExtension implements IExtension{ + @Override + public String getName() { + return "BATM Leocoin extension"; + } + + @Override + public IExchange createExchange(String exchangeLogin) { + return null; + } + + @Override + public IWallet createWallet(String walletLogin) { + if (walletLogin !=null && !walletLogin.trim().isEmpty()) { + StringTokenizer st = new StringTokenizer(walletLogin,":"); + String walletType = st.nextToken(); + + if ("leocoind".equalsIgnoreCase(walletType)) { + //"leocoind:protocol:user:password:ip:port:accountname" + + String protocol = st.nextToken(); + String username = st.nextToken(); + String password = st.nextToken(); + String hostname = st.nextToken(); + String port = st.nextToken(); + String accountName =""; + if (st.hasMoreTokens()) { + accountName = st.nextToken(); + } + + + if (protocol != null && username != null && password != null && hostname !=null && port != null && accountName != null) { + String rpcURL = protocol +"://" + username +":" + password + "@" + hostname +":" + port; + return new LeocoindRPCWallet(rpcURL,accountName); + } + } + } + return null; + } + + @Override + public ICryptoAddressValidator createAddressValidator(String cryptoCurrency) { + if (ICurrencies.LEO.equalsIgnoreCase(cryptoCurrency)) { + return new LeocoinAddressValidator(); + } + return null; + } + + @Override + public IPaperWalletGenerator createPaperWalletGenerator(String cryptoCurrency) { + return null; + } + + @Override + public IRateSource createRateSource(String sourceLogin) { + if (sourceLogin != null && !sourceLogin.trim().isEmpty()) { + StringTokenizer st = new StringTokenizer(sourceLogin,":"); + String exchangeType = st.nextToken(); + + if ("leofix".equalsIgnoreCase(exchangeType)) { + BigDecimal rate = BigDecimal.ZERO; + if (st.hasMoreTokens()) { + try { + rate = new BigDecimal(st.nextToken()); + } catch (Throwable e) { + } + } + return new FixPriceRateSource(rate); + } + + } + return null; + } + @Override + public Set getSupportedCryptoCurrencies() { + Set result = new HashSet(); + result.add(ICurrencies.LEO); + return result; + } + +} diff --git a/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/leocoin/sources/FixPriceRateSource.java b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/leocoin/sources/FixPriceRateSource.java new file mode 100644 index 0000000..792eda3 --- /dev/null +++ b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/leocoin/sources/FixPriceRateSource.java @@ -0,0 +1,43 @@ +package com.generalbytes.batm.server.extensions.extra.leocoin.sources; + +import com.generalbytes.batm.server.extensions.ICurrencies; +import com.generalbytes.batm.server.extensions.IRateSource; + +import java.math.BigDecimal; +import java.util.HashSet; +import java.util.Set; + +/** + * Created by b00lean on 7/31/14. + */ +public class FixPriceRateSource implements IRateSource { + private BigDecimal rate = BigDecimal.ZERO; + + public FixPriceRateSource(BigDecimal rate) { + this.rate = rate; + } + + @Override + public Set getCryptoCurrencies() { + Set result = new HashSet(); + result.add(ICurrencies.LEO); + return result; + } + + @Override + public BigDecimal getExchangeRateLast(String cryptoCurrency, String fiatCurrency) { + if (ICurrencies.LEO.equalsIgnoreCase(cryptoCurrency)) { + return rate; + } + return null; + } + + @Override + public Set getFiatCurrencies() { + Set result = new HashSet(); + result.add(ICurrencies.USD); + result.add(ICurrencies.EUR); + return result; + } + +} diff --git a/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/leocoin/wallets/leocoind/LeocoindRPCWallet.java b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/leocoin/wallets/leocoind/LeocoindRPCWallet.java new file mode 100644 index 0000000..d75e866 --- /dev/null +++ b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/leocoin/wallets/leocoind/LeocoindRPCWallet.java @@ -0,0 +1,120 @@ +/************************************************************************************* + * Copyright (C) 2014 GENERAL BYTES s.r.o. All rights reserved. + * + * This software may be distributed and modified under the terms of the GNU + * General Public License version 2 (GPL2) as published by the Free Software + * Foundation and appearing in the file GPL2.TXT included in the packaging of + * this file. Please note that GPL2 Section 2[b] requires that all works based + * on this software must also be made publicly available under the terms of + * the GPL2 ("Copyleft"). + * + * Contact information + * ------------------- + * + * GENERAL BYTES s.r.o. + * Web : http://www.generalbytes.com + * + ************************************************************************************/ +package com.generalbytes.batm.server.extensions.extra.leocoin.wallets.leocoind; + +import com.azazar.bitcoin.jsonrpcclient.BitcoinException; +import com.azazar.bitcoin.jsonrpcclient.BitcoinJSONRPCClient; +import com.generalbytes.batm.server.extensions.ICurrencies; +import com.generalbytes.batm.server.extensions.IWallet; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.math.BigDecimal; +import java.net.MalformedURLException; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class LeocoindRPCWallet implements IWallet{ + private static final Logger log = LoggerFactory.getLogger(LeocoindRPCWallet.class); + private static final String CRYPTO_CURRENCY = ICurrencies.LEO; + + public LeocoindRPCWallet(String rpcURL, String accountName) { + this.rpcURL = rpcURL; + this.accountName = accountName; + } + + private String rpcURL; + private String accountName; + + @Override + public Set getCryptoCurrencies() { + Set result = new HashSet(); + result.add(CRYPTO_CURRENCY); + return result; + + } + + @Override + public String getPreferredCryptoCurrency() { + return CRYPTO_CURRENCY; + } + + @Override + public String sendCoins(String destinationAddress, BigDecimal amount, String cryptoCurrency) { + if (!CRYPTO_CURRENCY.equalsIgnoreCase(cryptoCurrency)) { + log.error("Leocoind wallet error: unknown cryptocurrency."); + return null; + } + + log.info("Leocoind sending coins from " + accountName + " to: " + destinationAddress + " " + amount); + try { + String result = getClient(rpcURL).sendFrom(accountName, destinationAddress,amount.doubleValue()); + log.debug("result = " + result); + return result; + } catch (BitcoinException e) { + e.printStackTrace(); + return null; + } + } + + @Override + public String getCryptoAddress(String cryptoCurrency) { + if (!CRYPTO_CURRENCY.equalsIgnoreCase(cryptoCurrency)) { + log.error("Leocoind wallet error: unknown cryptocurrency."); + return null; + } + + try { + List addressesByAccount = getClient(rpcURL).getAddressesByAccount(accountName); + if (addressesByAccount == null || addressesByAccount.size() == 0) { + return null; + }else{ + return addressesByAccount.get(0); + } + } catch (BitcoinException e) { + e.printStackTrace(); + return null; + } + } + + @Override + public BigDecimal getCryptoBalance(String cryptoCurrency) { + if (!CRYPTO_CURRENCY.equalsIgnoreCase(cryptoCurrency)) { + log.error("Leocoind wallet error: unknown cryptocurrency: " + cryptoCurrency); + return null; + } + try { + double balance = getClient(rpcURL).getBalance(accountName); + return new BigDecimal(balance); + } catch (BitcoinException e) { + e.printStackTrace(); + return null; + } + } + + private BitcoinJSONRPCClient getClient(String rpcURL) { + try { + return new BitcoinJSONRPCClient(rpcURL); + } catch (MalformedURLException e) { + e.printStackTrace(); + } + return null; + } + +} diff --git a/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/litecoin/LitecoinExtension.java b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/litecoin/LitecoinExtension.java index 1f17d00..20de502 100644 --- a/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/litecoin/LitecoinExtension.java +++ b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/litecoin/LitecoinExtension.java @@ -18,9 +18,11 @@ package com.generalbytes.batm.server.extensions.extra.litecoin; import com.generalbytes.batm.server.extensions.*; +import com.generalbytes.batm.server.extensions.extra.litecoin.sources.FixPriceRateSource; import com.generalbytes.batm.server.extensions.extra.litecoin.sources.btce.BTCeRateSource; import com.generalbytes.batm.server.extensions.extra.litecoin.wallets.litecoind.LitecoindRPCWallet; +import java.math.BigDecimal; import java.util.*; public class LitecoinExtension implements IExtension{ @@ -84,7 +86,17 @@ public class LitecoinExtension implements IExtension{ if ("btce".equalsIgnoreCase(exchangeType)) { return new BTCeRateSource(); + }else if ("ltcfix".equalsIgnoreCase(exchangeType)) { + BigDecimal rate = BigDecimal.ZERO; + if (st.hasMoreTokens()) { + try { + rate = new BigDecimal(st.nextToken()); + } catch (Throwable e) { + } + } + return new FixPriceRateSource(rate); } + } return null; } diff --git a/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/litecoin/sources/FixPriceRateSource.java b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/litecoin/sources/FixPriceRateSource.java new file mode 100644 index 0000000..82f0933 --- /dev/null +++ b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/litecoin/sources/FixPriceRateSource.java @@ -0,0 +1,43 @@ +package com.generalbytes.batm.server.extensions.extra.litecoin.sources; + +import com.generalbytes.batm.server.extensions.ICurrencies; +import com.generalbytes.batm.server.extensions.IRateSource; + +import java.math.BigDecimal; +import java.util.HashSet; +import java.util.Set; + +/** + * Created by b00lean on 7/31/14. + */ +public class FixPriceRateSource implements IRateSource { + private BigDecimal rate = BigDecimal.ZERO; + + public FixPriceRateSource(BigDecimal rate) { + this.rate = rate; + } + + @Override + public Set getCryptoCurrencies() { + Set result = new HashSet(); + result.add(ICurrencies.LTC); + return result; + } + + @Override + public BigDecimal getExchangeRateLast(String cryptoCurrency, String fiatCurrency) { + if (ICurrencies.LTC.equalsIgnoreCase(cryptoCurrency)) { + return rate; + } + return null; + } + + @Override + public Set getFiatCurrencies() { + Set result = new HashSet(); + result.add(ICurrencies.USD); + result.add(ICurrencies.EUR); + return result; + } + +} diff --git a/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/maxcoin/MaxcoinExtension.java b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/maxcoin/MaxcoinExtension.java index de8df45..8e0f875 100644 --- a/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/maxcoin/MaxcoinExtension.java +++ b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/maxcoin/MaxcoinExtension.java @@ -18,9 +18,11 @@ package com.generalbytes.batm.server.extensions.extra.maxcoin; import com.generalbytes.batm.server.extensions.*; +import com.generalbytes.batm.server.extensions.extra.maxcoin.sources.FixPriceRateSource; import com.generalbytes.batm.server.extensions.extra.maxcoin.sources.MaxcoinTickerRateSource; import com.generalbytes.batm.server.extensions.extra.maxcoin.wallets.maxcoind.MaxcoindRPCWallet; +import java.math.BigDecimal; import java.util.HashSet; import java.util.Set; import java.util.StringTokenizer; @@ -86,7 +88,17 @@ public class MaxcoinExtension implements IExtension{ if ("maxcointicker".equalsIgnoreCase(exchangeType)) { return new MaxcoinTickerRateSource(); + }else if ("maxfix".equalsIgnoreCase(exchangeType)) { + BigDecimal rate = BigDecimal.ZERO; + if (st.hasMoreTokens()) { + try { + rate = new BigDecimal(st.nextToken()); + } catch (Throwable e) { + } + } + return new FixPriceRateSource(rate); } + } return null; } diff --git a/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/maxcoin/sources/FixPriceRateSource.java b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/maxcoin/sources/FixPriceRateSource.java new file mode 100644 index 0000000..e390d92 --- /dev/null +++ b/server_extensions_extra/src/com/generalbytes/batm/server/extensions/extra/maxcoin/sources/FixPriceRateSource.java @@ -0,0 +1,43 @@ +package com.generalbytes.batm.server.extensions.extra.maxcoin.sources; + +import com.generalbytes.batm.server.extensions.ICurrencies; +import com.generalbytes.batm.server.extensions.IRateSource; + +import java.math.BigDecimal; +import java.util.HashSet; +import java.util.Set; + +/** + * Created by b00lean on 7/31/14. + */ +public class FixPriceRateSource implements IRateSource { + private BigDecimal rate = BigDecimal.ZERO; + + public FixPriceRateSource(BigDecimal rate) { + this.rate = rate; + } + + @Override + public Set getCryptoCurrencies() { + Set result = new HashSet(); + result.add(ICurrencies.MAX); + return result; + } + + @Override + public BigDecimal getExchangeRateLast(String cryptoCurrency, String fiatCurrency) { + if (ICurrencies.MAX.equalsIgnoreCase(cryptoCurrency)) { + return rate; + } + return null; + } + + @Override + public Set getFiatCurrencies() { + Set result = new HashSet(); + result.add(ICurrencies.USD); + result.add(ICurrencies.EUR); + return result; + } + +}