Merge pull request #2 from Guldecoin-org/master
Guldencoin changes/fixes
This commit is contained in:
commit
2e20d37e94
|
@ -24,8 +24,7 @@ public interface ICurrencies {
|
|||
public static final String DOGE = "DOGE";
|
||||
public static final String MAX = "MAX";
|
||||
public static final String LEO = "LEO";
|
||||
public static final String GLD = "GLD";
|
||||
|
||||
public static final String NLG = "NLG";
|
||||
|
||||
public static final String CZK = "CZK";
|
||||
public static final String EUR = "EUR";
|
||||
|
|
|
@ -68,7 +68,7 @@ public class GuldencoinExtension implements IExtension{
|
|||
|
||||
@Override
|
||||
public ICryptoAddressValidator createAddressValidator(String cryptoCurrency) {
|
||||
if (ICurrencies.GLD.equalsIgnoreCase(cryptoCurrency)) {
|
||||
if (ICurrencies.NLG.equalsIgnoreCase(cryptoCurrency)) {
|
||||
return new GuldencoinAddressValidator();
|
||||
}
|
||||
return null;
|
||||
|
@ -102,7 +102,7 @@ public class GuldencoinExtension implements IExtension{
|
|||
@Override
|
||||
public Set<String> getSupportedCryptoCurrencies() {
|
||||
Set<String> result = new HashSet<String>();
|
||||
result.add(ICurrencies.GLD);
|
||||
result.add(ICurrencies.NLG);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,13 +20,13 @@ public class FixPriceRateSource implements IRateSource {
|
|||
@Override
|
||||
public Set<String> getCryptoCurrencies() {
|
||||
Set<String> result = new HashSet<String>();
|
||||
result.add(ICurrencies.GLD);
|
||||
result.add(ICurrencies.NLG);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getExchangeRateLast(String cryptoCurrency, String fiatCurrency) {
|
||||
if (ICurrencies.GLD.equalsIgnoreCase(cryptoCurrency)) {
|
||||
if (ICurrencies.NLG.equalsIgnoreCase(cryptoCurrency)) {
|
||||
return rate;
|
||||
}
|
||||
return null;
|
||||
|
@ -35,7 +35,6 @@ public class FixPriceRateSource implements IRateSource {
|
|||
@Override
|
||||
public Set<String> getFiatCurrencies() {
|
||||
Set<String> result = new HashSet<String>();
|
||||
result.add(ICurrencies.USD);
|
||||
result.add(ICurrencies.EUR);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,110 @@
|
|||
/*************************************************************************************
|
||||
* 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.guldencoin.sources;
|
||||
|
||||
import com.generalbytes.batm.server.extensions.ICurrencies;
|
||||
import com.generalbytes.batm.server.extensions.IRateSource;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import si.mazi.rescu.RestProxyFactory;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class GuldencoinTickerRateSource implements IRateSource{
|
||||
private static final Logger log = LoggerFactory.getLogger(GuldencoinTickerRateSource.class);
|
||||
|
||||
private static HashMap<String,BigDecimal> rateAmounts = new HashMap<String, BigDecimal>();
|
||||
private static HashMap<String,Long> rateTimes = new HashMap<String, Long>();
|
||||
private static final long MAXIMUM_ALLOWED_TIME_OFFSET = 30 * 1000; //30sec
|
||||
|
||||
private IGuldencoinTickerRateAPI api;
|
||||
|
||||
public GuldencoinTickerRateSource() {
|
||||
api = RestProxyFactory.createProxy(IGuldencoinTickerRateAPI.class, "https://markets.guldencoin.com");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getExchangeRateLast(String cryptoCurrency, String fiatCurrency) {
|
||||
if (!(ICurrencies.NLG.equalsIgnoreCase(cryptoCurrency))) {
|
||||
return null;
|
||||
}
|
||||
if (!(ICurrencies.EUR.equalsIgnoreCase(fiatCurrency))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String key = cryptoCurrency +"_" + fiatCurrency;
|
||||
synchronized (rateAmounts) {
|
||||
long now = System.currentTimeMillis();
|
||||
BigDecimal amount = rateAmounts.get(key);
|
||||
if (amount == null) {
|
||||
BigDecimal result = getExchangeRateLastSync(cryptoCurrency, fiatCurrency);
|
||||
log.debug("Called GuldencoinTicker exchange for rate: " + key + " = " + result);
|
||||
rateAmounts.put(key,result);
|
||||
rateTimes.put(key,now+MAXIMUM_ALLOWED_TIME_OFFSET);
|
||||
return result;
|
||||
}else {
|
||||
Long expirationTime = rateTimes.get(key);
|
||||
if (expirationTime > now) {
|
||||
return rateAmounts.get(key);
|
||||
}else{
|
||||
//do the job;
|
||||
BigDecimal result = getExchangeRateLastSync(cryptoCurrency, fiatCurrency);
|
||||
log.debug("Called GuldencoinTicker exchange for rate: " + key + " = " + result);
|
||||
rateAmounts.put(key,result);
|
||||
rateTimes.put(key,now+MAXIMUM_ALLOWED_TIME_OFFSET);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private BigDecimal getExchangeRateLastSync(String cryptoCurrency, String fiatCurrency) {
|
||||
if (!(ICurrencies.NLG.equalsIgnoreCase(cryptoCurrency))) {
|
||||
return null;
|
||||
}
|
||||
if (!(ICurrencies.EUR.equalsIgnoreCase(fiatCurrency))) {
|
||||
return null;
|
||||
}
|
||||
GuldencoinTickerResponse ticker = api.getTicker();
|
||||
if (ticker != null && ticker.getEUR() != null) {
|
||||
if (ICurrencies.EUR.equalsIgnoreCase(fiatCurrency)){
|
||||
return ticker.getEUR().getSell15m();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getCryptoCurrencies() {
|
||||
Set<String> result = new HashSet<String>();
|
||||
result.add(ICurrencies.NLG);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getFiatCurrencies() {
|
||||
Set<String> result = new HashSet<String>();
|
||||
result.add(ICurrencies.EUR);
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,143 @@
|
|||
/*************************************************************************************
|
||||
* 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.guldencoin.sources;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class GuldencoinTickerResponse {
|
||||
private EUR euro;
|
||||
private BTC btc;
|
||||
|
||||
public class BTC {
|
||||
private String code;
|
||||
private String symbol;
|
||||
private BigDecimal buy;
|
||||
private BigDecimal sell;
|
||||
private BigDecimal buy15m;
|
||||
private BigDecimal sell15m;
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getSymbol() {
|
||||
return symbol;
|
||||
}
|
||||
public void setSymbol(String symbol) {
|
||||
this.symbol = symbol;
|
||||
}
|
||||
|
||||
public String getBuy() {
|
||||
return buy;
|
||||
}
|
||||
public void setBuy(BigDecimal buy) {
|
||||
this.buy = buy;
|
||||
}
|
||||
|
||||
public String getSell() {
|
||||
return sell;
|
||||
}
|
||||
public void setSell(BigDecimal sell) {
|
||||
this.sell = sell;
|
||||
}
|
||||
|
||||
public String getBuy15m() {
|
||||
return buy15m;
|
||||
}
|
||||
public void setBuy15m(BigDecimal buy15m) {
|
||||
this.buy15m = buy15m;
|
||||
}
|
||||
|
||||
public String getSell15m() {
|
||||
return sell15m;
|
||||
}
|
||||
public void setSell15m(BigDecimal sell15m) {
|
||||
this.sell15m = sell15m;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class EUR {
|
||||
private String code;
|
||||
private String symbol;
|
||||
private BigDecimal buy;
|
||||
private BigDecimal sell;
|
||||
private BigDecimal buy15m;
|
||||
private BigDecimal sell15m;
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getSymbol() {
|
||||
return symbol;
|
||||
}
|
||||
public void setSymbol(String symbol) {
|
||||
this.symbol = symbol;
|
||||
}
|
||||
|
||||
public String getBuy() {
|
||||
return buy;
|
||||
}
|
||||
public void setBuy(BigDecimal buy) {
|
||||
this.buy = buy;
|
||||
}
|
||||
|
||||
public String getSell() {
|
||||
return sell;
|
||||
}
|
||||
public void setSell(BigDecimal sell) {
|
||||
this.sell = sell;
|
||||
}
|
||||
|
||||
public String getBuy15m() {
|
||||
return buy15m;
|
||||
}
|
||||
public void setBuy15m(BigDecimal buy15m) {
|
||||
this.buy15m = buy15m;
|
||||
}
|
||||
|
||||
public String getSell15m() {
|
||||
return sell15m;
|
||||
}
|
||||
public void setSell15m(BigDecimal sell15m) {
|
||||
this.sell15m = sell15m;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public EUR getEUR() {
|
||||
return euro;
|
||||
}
|
||||
public void setEUR(EUR euro) {
|
||||
this.euro = euro;
|
||||
}
|
||||
|
||||
public BTC getBTC() {
|
||||
return btc;
|
||||
}
|
||||
public void setBTC(BTC btc) {
|
||||
this.btc = btc;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
/*************************************************************************************
|
||||
* 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.guldencoin.sources;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
@Path("/api/v1/")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public interface IGuldencoinTickerRateAPI {
|
||||
@GET
|
||||
@Path("ticker")
|
||||
GuldencoinTickerResponse getTicker();
|
||||
}
|
|
@ -32,7 +32,7 @@ import java.util.Set;
|
|||
|
||||
public class GuldencoindRPCWallet implements IWallet{
|
||||
private static final Logger log = LoggerFactory.getLogger(GuldencoindRPCWallet.class);
|
||||
private static final String CRYPTO_CURRENCY = ICurrencies.GLD;
|
||||
private static final String CRYPTO_CURRENCY = ICurrencies.NLG;
|
||||
|
||||
public GuldencoindRPCWallet(String rpcURL, String accountName) {
|
||||
this.rpcURL = rpcURL;
|
||||
|
|
Loading…
Reference in New Issue