batm_public/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/syscoin/SyscoinExtension.java

141 lines
5.0 KiB
Java

/*************************************************************************************
* Copyright (C) 2014-2016 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.syscoin;
import com.generalbytes.batm.server.extensions.*;
import com.generalbytes.batm.server.extensions.extra.syscoin.sources.FixPriceRateSource;
import com.generalbytes.batm.server.extensions.extra.dash.sources.coinmarketcap.CoinmarketcapRateSource;
import com.generalbytes.batm.server.extensions.extra.syscoin.wallets.syscoind.SyscoinRPCWallet;
import com.generalbytes.batm.server.extensions.watchlist.IWatchList;
import java.math.BigDecimal;
import java.util.*;
public class SyscoinExtension implements IExtension{
@Override
public String getName() {
return "BATM Syscoin extra extension";
}
@Override
public IExchange createExchange(String exchangeLogin) {
return null;
}
@Override
public IPaymentProcessor createPaymentProcessor(String paymentProcessorLogin) {
return null; //no payment processors available
}
@Override
public IWallet createWallet(String walletLogin) {
if (walletLogin !=null && !walletLogin.trim().isEmpty()) {
StringTokenizer st = new StringTokenizer(walletLogin,":");
String walletType = st.nextToken();
if ("syscoind".equalsIgnoreCase(walletType)) {
//"syscoind: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 SyscoinRPCWallet(rpcURL,accountName);
}
}
}
return null;
}
@Override
public ICryptoAddressValidator createAddressValidator(String cryptoCurrency) {
if (Currencies.SYS.equalsIgnoreCase(cryptoCurrency)) {
return new SyscoinAddressValidator();
}
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 ("syscoinfix".equalsIgnoreCase(exchangeType)) {
BigDecimal rate = BigDecimal.ZERO;
if (st.hasMoreTokens()) {
try {
rate = new BigDecimal(st.nextToken());
} catch (Throwable e) {
}
}
String preferedFiatCurrency = Currencies.USD;
if (st.hasMoreTokens()) {
preferedFiatCurrency = st.nextToken().toUpperCase();
}
return new FixPriceRateSource(rate, preferedFiatCurrency);
} else if ("coinmarketcap".equalsIgnoreCase(exchangeType)) {
String preferedFiatCurrency = Currencies.USD;
if (st.hasMoreTokens()) {
preferedFiatCurrency = st.nextToken().toUpperCase();
}
return new CoinmarketcapRateSource(preferedFiatCurrency);
}
}
return null;
}
@Override
public Set<String> getSupportedCryptoCurrencies() {
Set<String> result = new HashSet<String>();
result.add(Currencies.BTC);
result.add(Currencies.SYS);
result.add(Currencies.BTX);
result.add(Currencies.BCH);
result.add(Currencies.LTC);
result.add(Currencies.XMR);
result.add(Currencies.DASH);
result.add(Currencies.POT);
return result;
}
@Override
public Set<String> getSupportedWatchListsNames() {
return null;
}
@Override
public IWatchList getWatchList(String name) {
return null;
}
}