prepare futurocoin

This commit is contained in:
Artur Kowalski 2018-05-09 12:53:32 +02:00
parent 816ad04497
commit 6b957d2115
10 changed files with 485 additions and 0 deletions

View File

@ -29,6 +29,7 @@ public interface ICurrencies {
public static final String DASH = "DASH";
public static final String DOGE = "DOGE";
public static final String FLASH = "FLASH";// FLASH Coin
public static final String FTO = "FTO";
public static final String MAX = "MAX";
public static final String LEO = "LEO";
public static final String NLG = "NLG";

View File

@ -0,0 +1,34 @@
package com.generalbytes.batm.server.extensions.extra.futurocoin;
import com.generalbytes.batm.server.coinutil.AddressFormatException;
import com.generalbytes.batm.server.coinutil.Base58;
import com.generalbytes.batm.server.extensions.ICryptoAddressValidator;
public class FuturocoinAddressValidator implements ICryptoAddressValidator {
@Override
public boolean isAddressValid(String address) {
if (address.startsWith("F") || address.startsWith("6")) {
try {
Base58.decodeToBigInteger(address);
Base58.decodeChecked(address);
} catch (AddressFormatException e) {
e.printStackTrace();
return false;
}
return true;
}else{
return false;
}
}
@Override
public boolean mustBeBase58Address() {
return true;
}
@Override
public boolean isPaperWalletSupported() {
return false;
}
}

View File

@ -0,0 +1,133 @@
/*************************************************************************************
* 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.futurocoin;
import com.generalbytes.batm.server.extensions.*;
import com.generalbytes.batm.server.extensions.extra.futurocoin.sources.FixPriceRateSource;
import com.generalbytes.batm.server.extensions.extra.futurocoin.sources.yobit.YobitRateSource;
import com.generalbytes.batm.server.extensions.extra.futurocoin.wallets.futurocoind.FuturocoinRPCWallet;
import com.generalbytes.batm.server.extensions.watchlist.IWatchList;
import java.math.BigDecimal;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;
//import com.generalbytes.batm.server.extensions.extra.dogecoin.sources.chainso.ChainSoRateSource;
//import com.generalbytes.batm.server.extensions.extra.dogecoin.wallets.blockio.BlockIOWallet;
public class FuturocoinExtension implements IExtension{
@Override
public String getName() {
return "BATM Futurocoin 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 ("futurocoind".equalsIgnoreCase(walletType)) {
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 FuturocoinRPCWallet(rpcURL,accountName);
}
}
}
return null;
}
@Override
public ICryptoAddressValidator createAddressValidator(String cryptoCurrency) {
if (ICurrencies.FTO.equalsIgnoreCase(cryptoCurrency)) {
return new FuturocoinAddressValidator();
}
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 ("futurocoinfix".equalsIgnoreCase(exchangeType)) {
BigDecimal rate = BigDecimal.ZERO;
if (st.hasMoreTokens()) {
try {
rate = new BigDecimal(st.nextToken());
} catch (Throwable e) {
}
}
String preferedFiatCurrency = ICurrencies.USD;
if (st.hasMoreTokens()) {
preferedFiatCurrency = st.nextToken().toUpperCase();
}
return new FixPriceRateSource(rate, preferedFiatCurrency);
} else if ("yobit".equalsIgnoreCase(exchangeType)) {
return new YobitRateSource();
}
}
return null;
}
@Override
public Set<String> getSupportedCryptoCurrencies() {
Set<String> result = new HashSet<String>();
result.add(ICurrencies.FTO);
return result;
}
@Override
public Set<String> getSupportedWatchListsNames() {
return null;
}
@Override
public IWatchList getWatchList(String name) {
return null;
}
}

View File

@ -0,0 +1,50 @@
package com.generalbytes.batm.server.extensions.extra.futurocoin.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 woolly_sammoth on 11/12/14.
*/
public class FixPriceRateSource implements IRateSource {
private BigDecimal rate = BigDecimal.ZERO;
private String preferedFiatCurrency = ICurrencies.USD;
public FixPriceRateSource(BigDecimal rate, String preferedFiatCurrency) {
this.rate = rate;
if (ICurrencies.USD.equalsIgnoreCase(preferedFiatCurrency)) {
this.preferedFiatCurrency = ICurrencies.USD;
}
}
@Override
public Set<String> getCryptoCurrencies() {
Set<String> result = new HashSet<String>();
result.add(ICurrencies.FTO);
return result;
}
@Override
public BigDecimal getExchangeRateLast(String cryptoCurrency, String fiatCurrency) {
if (ICurrencies.FTO.equalsIgnoreCase(cryptoCurrency)) {
return rate;
}
return null;
}
@Override
public Set<String> getFiatCurrencies() {
Set<String> result = new HashSet<String>();
result.add(ICurrencies.USD);
return result;
}
@Override
public String getPreferredFiatCurrency() {
return preferedFiatCurrency;
}
}

View File

@ -0,0 +1,18 @@
package com.generalbytes.batm.server.extensions.extra.futurocoin.sources.yobit;
import com.generalbytes.batm.server.extensions.extra.futurocoin.sources.yobit.dto.Ticker;
import com.generalbytes.batm.server.extensions.extra.futurocoin.sources.yobit.dto.YobitResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("/api/3/")
@Produces(MediaType.APPLICATION_JSON)
public interface IYobitAPI {
@GET
@Path("ticker/{cryptocurrency}_{fiatcurrency}")
YobitResponse getTicker(@PathParam("cryptocurrency") String cryptoCurrency, @PathParam("fiatcurrency") String fiatCurrency);
}

View File

@ -0,0 +1,49 @@
package com.generalbytes.batm.server.extensions.extra.futurocoin.sources.yobit;
import com.generalbytes.batm.server.extensions.ICurrencies;
import com.generalbytes.batm.server.extensions.IRateSource;
import com.generalbytes.batm.server.extensions.extra.bitcoin.sources.bity.IBity;
import com.generalbytes.batm.server.extensions.extra.futurocoin.sources.yobit.dto.Ticker;
import com.generalbytes.batm.server.extensions.extra.futurocoin.sources.yobit.dto.YobitResponse;
import java.math.BigDecimal;
import java.util.HashSet;
import java.util.Set;
public class YobitRateSource implements IRateSource {
private IYobitAPI api;
public YobitRateSource() {
api = RestProxyFactory.createProxy(IBity.class, "https://yobit.net");
}
@Override
public Set<String> getCryptoCurrencies() {
Set<String> result = new HashSet<String>();
result.add(ICurrencies.FTO);
return result;
}
@Override
public Set<String> getFiatCurrencies() {
Set<String> result = new HashSet<String>();
result.add(ICurrencies.USD);
return result;
}
@Override
public BigDecimal getExchangeRateLast(String cryptoCurrency, String fiatCurrency) {
if (!getFiatCurrencies().contains(fiatCurrency) || !getCryptoCurrencies().contains(cryptoCurrency)) {
return null;
}
YobitResponse response = api.getTicker(cryptoCurrency.toLowerCase(), fiatCurrency.toLowerCase());
return response.getFot_usd().getLast();
}
@Override
public String getPreferredFiatCurrency() {
return ICurrencies.USD;
}
}

View File

@ -0,0 +1,87 @@
package com.generalbytes.batm.server.extensions.extra.futurocoin.sources.yobit.dto;
import java.math.BigDecimal;
public class Ticker {
private BigDecimal high;
private BigDecimal low;
private BigDecimal avg;
private BigDecimal vol;
private BigDecimal vol_cur;
private BigDecimal last;
private BigDecimal buy;
private BigDecimal sell;
private long updated;
public BigDecimal getHigh() {
return high;
}
public void setHigh(BigDecimal high) {
this.high = high;
}
public BigDecimal getLow() {
return low;
}
public void setLow(BigDecimal low) {
this.low = low;
}
public BigDecimal getAvg() {
return avg;
}
public void setAvg(BigDecimal avg) {
this.avg = avg;
}
public BigDecimal getVol() {
return vol;
}
public void setVol(BigDecimal vol) {
this.vol = vol;
}
public BigDecimal getVol_cur() {
return vol_cur;
}
public void setVol_cur(BigDecimal vol_cur) {
this.vol_cur = vol_cur;
}
public BigDecimal getLast() {
return last;
}
public void setLast(BigDecimal last) {
this.last = last;
}
public BigDecimal getBuy() {
return buy;
}
public void setBuy(BigDecimal buy) {
this.buy = buy;
}
public BigDecimal getSell() {
return sell;
}
public void setSell(BigDecimal sell) {
this.sell = sell;
}
public long getUpdated() {
return updated;
}
public void setUpdated(long updated) {
this.updated = updated;
}
}

View File

@ -0,0 +1,13 @@
package com.generalbytes.batm.server.extensions.extra.futurocoin.sources.yobit.dto;
public class YobitResponse {
private Ticker fot_usd;
public Ticker getFot_usd() {
return fot_usd;
}
public void setFot_usd(Ticker fot_usd) {
this.fot_usd = fot_usd;
}
}

View File

@ -0,0 +1,100 @@
package com.generalbytes.batm.server.extensions.extra.futurocoin.wallets.futurocoind;
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 java.math.BigDecimal;
import java.net.MalformedURLException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class FuturocoinRPCWallet implements IWallet {
private static final Logger log = LoggerFactory.getLogger(FuturocoinRPCWallet.class);
private static final String CRYPTO_CURRENCY = ICurrencies.FTO;
public FuturocoinRPCWallet(String rpcURL, String accountName) {
this.rpcURL = rpcURL;
this.accountName = accountName;
}
private String rpcURL;
private String accountName;
@Override
public Set<String> getCryptoCurrencies() {
Set<String> result = new HashSet<String>();
result.add(CRYPTO_CURRENCY);
return result;
}
@Override
public String getPreferredCryptoCurrency() {
return CRYPTO_CURRENCY;
}
@Override
public String sendCoins(String destinationAddress, BigDecimal amount, String cryptoCurrency, String description) {
if (!CRYPTO_CURRENCY.equalsIgnoreCase(cryptoCurrency)) {
log.error("Futurocoind wallet error: unknown cryptocurrency.");
return null;
}
log.info("Futurocoind 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("Futurocoind wallet error: unknown cryptocurrency.");
return null;
}
try {
List<String> 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("Futurocoind wallet error: unknown cryptocurrency: " + cryptoCurrency);
return null;
}
try {
double balance = getClient(rpcURL).getBalance(accountName);
return BigDecimal.valueOf(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;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB