DogeAPI replaced by Block.io and Chain.so
This commit is contained in:
parent
39645db25c
commit
b397b6624e
|
@ -20,10 +20,12 @@
|
|||
<cryptologo cryptocurrency="BTC" file="btc.png"/>
|
||||
</extension>
|
||||
<extension class="com.generalbytes.batm.server.extensions.extra.dogecoin.DogecoinExtension">
|
||||
<wallet prefix="dogeapi" name="DogeAPI Wallet">
|
||||
<wallet prefix="blockio" name="Block.io Wallet">
|
||||
<param name="apikey" />
|
||||
<param name="pin" />
|
||||
<cryptocurrency>DOGE</cryptocurrency>
|
||||
<cryptocurrency>BTC</cryptocurrency>
|
||||
<cryptocurrency>LTC</cryptocurrency>
|
||||
</wallet>
|
||||
<wallet prefix="dogecoind" name="Dogecoind">
|
||||
<param name="protocol" />
|
||||
|
@ -34,7 +36,7 @@
|
|||
<param name="accountname" />
|
||||
<cryptocurrency>DOGE</cryptocurrency>
|
||||
</wallet>
|
||||
<ratesource prefix="dogeapi" name="DogeAPI.com" >
|
||||
<ratesource prefix="chainso" name="Chain.so - Cryptsy" >
|
||||
<cryptocurrency>DOGE</cryptocurrency>
|
||||
</ratesource>
|
||||
<ratesource prefix="dogefix" name ="Fix Price" >
|
||||
|
|
|
@ -18,9 +18,9 @@
|
|||
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.sources.chainso.ChainSoRateSource;
|
||||
import com.generalbytes.batm.server.extensions.extra.dogecoin.wallets.blockio.BlockIOWallet;
|
||||
import com.generalbytes.batm.server.extensions.extra.dogecoin.wallets.dogecoind.DogecoindRPCWallet;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
@ -43,10 +43,10 @@ public class DogecoinExtension implements IExtension{
|
|||
StringTokenizer st = new StringTokenizer(walletLogin,":");
|
||||
String walletType = st.nextToken();
|
||||
|
||||
if ("dogeapi".equalsIgnoreCase(walletType)) {
|
||||
if ("blockio".equalsIgnoreCase(walletType)) {
|
||||
String apikey = st.nextToken();
|
||||
String pin = st.nextToken();
|
||||
return new DogeAPIWallet(apikey,pin);
|
||||
return new BlockIOWallet(apikey,pin);
|
||||
}else if ("dogecoind".equalsIgnoreCase(walletType)) {
|
||||
//"dogecoind:protocol:user:password:ip:port:accountname"
|
||||
|
||||
|
@ -86,13 +86,12 @@ public class DogecoinExtension implements IExtension{
|
|||
|
||||
@Override
|
||||
public IRateSource createRateSource(String sourceLogin) {
|
||||
//NOTE: (Bitstamp is in built-in extension)
|
||||
if (sourceLogin != null && !sourceLogin.trim().isEmpty()) {
|
||||
StringTokenizer st = new StringTokenizer(sourceLogin,":");
|
||||
String exchangeType = st.nextToken();
|
||||
|
||||
if ("dogeapi".equalsIgnoreCase(exchangeType)) {
|
||||
return new DogeAPIRateSource();
|
||||
if ("chainso".equalsIgnoreCase(exchangeType)) {
|
||||
return new ChainSoRateSource();
|
||||
}else if ("dogefix".equalsIgnoreCase(exchangeType)) {
|
||||
BigDecimal rate = BigDecimal.ZERO;
|
||||
if (st.hasMoreTokens()) {
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
package com.generalbytes.batm.server.extensions.extra.dogecoin.sources.chainso;
|
||||
|
||||
/**
|
||||
* Created by b00lean on 8/11/14.
|
||||
*/
|
||||
public class ChainSoPrice {
|
||||
private String price;
|
||||
private String price_base;
|
||||
private String exchange;
|
||||
private long time;
|
||||
|
||||
public String getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(String price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public String getPrice_base() {
|
||||
return price_base;
|
||||
}
|
||||
|
||||
public void setPrice_base(String price_base) {
|
||||
this.price_base = price_base;
|
||||
}
|
||||
|
||||
public String getExchange() {
|
||||
return exchange;
|
||||
}
|
||||
|
||||
public void setExchange(String exchange) {
|
||||
this.exchange = exchange;
|
||||
}
|
||||
|
||||
public long getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(long time) {
|
||||
this.time = time;
|
||||
}
|
||||
}
|
|
@ -1,45 +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.dogecoin.sources;
|
||||
package com.generalbytes.batm.server.extensions.extra.dogecoin.sources.chainso;
|
||||
|
||||
import com.generalbytes.batm.server.extensions.ICurrencies;
|
||||
import com.generalbytes.batm.server.extensions.IRateSource;
|
||||
import com.generalbytes.batm.server.extensions.extra.dogecoin.wallets.dogeapi.DogeAPIResponse;
|
||||
import com.generalbytes.batm.server.extensions.extra.dogecoin.wallets.dogeapi.IDogeAPIv2;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import si.mazi.rescu.RestProxyFactory;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class DogeAPIRateSource implements IRateSource{
|
||||
private static final Logger log = LoggerFactory.getLogger(DogeAPIRateSource.class);
|
||||
/**
|
||||
* Created by b00lean on 8/11/14.
|
||||
*/
|
||||
public class ChainSoRateSource implements IRateSource{
|
||||
private static final Logger log = LoggerFactory.getLogger(ChainSoRateSource.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 IDogeAPIv2 api;
|
||||
private IChainSo api;
|
||||
|
||||
|
||||
public DogeAPIRateSource() {
|
||||
api = RestProxyFactory.createProxy(IDogeAPIv2.class, "https://www.dogeapi.com");
|
||||
public ChainSoRateSource() {
|
||||
api = RestProxyFactory.createProxy(IChainSo.class, "https://chain.so");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -57,7 +43,7 @@ public class DogeAPIRateSource implements IRateSource{
|
|||
BigDecimal amount = rateAmounts.get(key);
|
||||
if (amount == null) {
|
||||
BigDecimal result = getExchangeRateLastSync(cryptoCurrency, fiatCurrency);
|
||||
log.debug("Called dogeapi exchange for rate: " + key + " = " + result);
|
||||
log.debug("Called chain.so exchange for rate: " + key + " = " + result);
|
||||
rateAmounts.put(key,result);
|
||||
rateTimes.put(key,now+MAXIMUM_ALLOWED_TIME_OFFSET);
|
||||
return result;
|
||||
|
@ -68,7 +54,7 @@ public class DogeAPIRateSource implements IRateSource{
|
|||
}else{
|
||||
//do the job;
|
||||
BigDecimal result = getExchangeRateLastSync(cryptoCurrency, fiatCurrency);
|
||||
log.debug("Called dogeapi exchange for rate: " + key + " = " + result);
|
||||
log.debug("Called chain.so exchange for rate: " + key + " = " + result);
|
||||
rateAmounts.put(key,result);
|
||||
rateTimes.put(key,now+MAXIMUM_ALLOWED_TIME_OFFSET);
|
||||
return result;
|
||||
|
@ -85,14 +71,17 @@ public class DogeAPIRateSource implements IRateSource{
|
|||
if (!ICurrencies.USD.equalsIgnoreCase(fiatCurrency)) {
|
||||
return null;
|
||||
}
|
||||
DogeAPIResponse response = api.getInfo();
|
||||
if (response != null && response.getData() != null) {
|
||||
DogeAPIResponse.Data.Info info = response.getData().getInfo();
|
||||
if (info != null) {
|
||||
return info.getDoge_usd();
|
||||
|
||||
ChainSoResponse response = api.getPrices(cryptoCurrency,fiatCurrency);
|
||||
if (response != null && response.getData() != null && response.getData().getPrices() != null) {
|
||||
ChainSoPrice[] prices = response.getData().getPrices();
|
||||
for (int i = 0; i < prices.length; i++) {
|
||||
ChainSoPrice price = prices[i];
|
||||
if ("cryptsy".equalsIgnoreCase(price.getExchange()) && fiatCurrency.equalsIgnoreCase(price.getPrice_base())) {
|
||||
return new BigDecimal(price.getPrice());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
package com.generalbytes.batm.server.extensions.extra.dogecoin.sources.chainso;
|
||||
|
||||
/**
|
||||
* Created by b00lean on 8/11/14.
|
||||
*/
|
||||
public class ChainSoResponse {
|
||||
private String status;
|
||||
private Data data;
|
||||
|
||||
public class Data {
|
||||
private String network;
|
||||
private ChainSoPrice[] prices;
|
||||
|
||||
public String getNetwork() {
|
||||
return network;
|
||||
}
|
||||
|
||||
public void setNetwork(String network) {
|
||||
this.network = network;
|
||||
}
|
||||
|
||||
public ChainSoPrice[] getPrices() {
|
||||
return prices;
|
||||
}
|
||||
|
||||
public void setPrices(ChainSoPrice[] prices) {
|
||||
this.prices = prices;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public Data getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public void setData(Data data) {
|
||||
this.data = data;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.generalbytes.batm.server.extensions.extra.dogecoin.sources.chainso;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Created by b00lean on 8/11/14.
|
||||
*/
|
||||
@Path("/api/v2/")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public interface IChainSo {
|
||||
@GET
|
||||
@Path("get_price/{crypto_currency}/{fiat_currency}")
|
||||
ChainSoResponse getPrices(@PathParam("crypto_currency") String crypto_currency, @PathParam("fiat_currency") String fiat_currency);
|
||||
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
package com.generalbytes.batm.server.extensions.extra.dogecoin.wallets.blockio;
|
||||
|
||||
/**
|
||||
* Created by b00lean on 8/11/14.
|
||||
*/
|
||||
public class BlockIOAddress {
|
||||
private int user_id;
|
||||
private String address;
|
||||
private String label;
|
||||
private String available_balance;
|
||||
private String unconfirmed_sent_balance;
|
||||
private String unconfirmed_received_balance;
|
||||
|
||||
public BlockIOAddress() {
|
||||
}
|
||||
|
||||
public int getUser_id() {
|
||||
return user_id;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public String getUnconfirmed_sent_balance() {
|
||||
return unconfirmed_sent_balance;
|
||||
}
|
||||
|
||||
public String getUnconfirmed_received_balance() {
|
||||
return unconfirmed_received_balance;
|
||||
}
|
||||
|
||||
public void setUser_id(int user_id) {
|
||||
this.user_id = user_id;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public void setUnconfirmed_sent_balance(String unconfirmed_sent_balance) {
|
||||
this.unconfirmed_sent_balance = unconfirmed_sent_balance;
|
||||
}
|
||||
|
||||
public void setUnconfirmed_received_balance(String unconfirmed_received_balance) {
|
||||
this.unconfirmed_received_balance = unconfirmed_received_balance;
|
||||
}
|
||||
|
||||
public String getAvailable_balance() {
|
||||
return available_balance;
|
||||
}
|
||||
|
||||
public void setAvailable_balance(String available_balance) {
|
||||
this.available_balance = available_balance;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package com.generalbytes.batm.server.extensions.extra.dogecoin.wallets.blockio;
|
||||
|
||||
/**
|
||||
* Created by b00lean on 8/11/14.
|
||||
*/
|
||||
public class BlockIOResponseAddresses {
|
||||
private String status;
|
||||
private BlockIOData data;
|
||||
|
||||
public BlockIOResponseAddresses() {
|
||||
}
|
||||
|
||||
public class BlockIOData {
|
||||
private String network;
|
||||
private BlockIOAddress[] addresses;
|
||||
|
||||
public BlockIOData() {
|
||||
}
|
||||
|
||||
public String getNetwork() {
|
||||
return network;
|
||||
}
|
||||
|
||||
public BlockIOAddress[] getAddresses() {
|
||||
return addresses;
|
||||
}
|
||||
|
||||
public void setNetwork(String network) {
|
||||
this.network = network;
|
||||
}
|
||||
|
||||
public void setAddresses(BlockIOAddress[] addresses) {
|
||||
this.addresses = addresses;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public BlockIOData getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public void setData(BlockIOData data) {
|
||||
this.data = data;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
package com.generalbytes.batm.server.extensions.extra.dogecoin.wallets.blockio;
|
||||
|
||||
/**
|
||||
* Created by b00lean on 8/11/14.
|
||||
*/
|
||||
public class BlockIOResponseBalance {
|
||||
private String status;
|
||||
private BlockIOData data;
|
||||
|
||||
public BlockIOResponseBalance() {
|
||||
}
|
||||
|
||||
public class BlockIOData {
|
||||
private String network;
|
||||
private String available_balance;
|
||||
private String unconfirmed_sent_balance;
|
||||
private String unconfirmed_received_balance;
|
||||
|
||||
|
||||
public BlockIOData() {
|
||||
}
|
||||
|
||||
public String getNetwork() {
|
||||
return network;
|
||||
}
|
||||
|
||||
public void setNetwork(String network) {
|
||||
this.network = network;
|
||||
}
|
||||
|
||||
public String getAvailable_balance() {
|
||||
return available_balance;
|
||||
}
|
||||
|
||||
public void setAvailable_balance(String available_balance) {
|
||||
this.available_balance = available_balance;
|
||||
}
|
||||
|
||||
public String getUnconfirmed_sent_balance() {
|
||||
return unconfirmed_sent_balance;
|
||||
}
|
||||
|
||||
public void setUnconfirmed_sent_balance(String unconfirmed_sent_balance) {
|
||||
this.unconfirmed_sent_balance = unconfirmed_sent_balance;
|
||||
}
|
||||
|
||||
public String getUnconfirmed_received_balance() {
|
||||
return unconfirmed_received_balance;
|
||||
}
|
||||
|
||||
public void setUnconfirmed_received_balance(String unconfirmed_received_balance) {
|
||||
this.unconfirmed_received_balance = unconfirmed_received_balance;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public BlockIOData getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public void setData(BlockIOData data) {
|
||||
this.data = data;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,124 @@
|
|||
package com.generalbytes.batm.server.extensions.extra.dogecoin.wallets.blockio;
|
||||
|
||||
/**
|
||||
* Created by b00lean on 8/11/14.
|
||||
*/
|
||||
public class BlockIOResponseWithdrawal {
|
||||
private String status;
|
||||
private BlockIOData data;
|
||||
|
||||
public BlockIOResponseWithdrawal() {
|
||||
}
|
||||
|
||||
public class BlockIOData {
|
||||
private String error_message;
|
||||
private String txid;
|
||||
private String available_balance;
|
||||
private String max_withdrawal_available;
|
||||
private String minimum_balance_needed;
|
||||
private String estimated_network_fee;
|
||||
|
||||
private String amount_withdrawn;
|
||||
private String amount_sent;
|
||||
private String network_fee;
|
||||
private String blockio_fee;
|
||||
|
||||
public String getTxid() {
|
||||
return txid;
|
||||
}
|
||||
|
||||
public void setTxid(String txid) {
|
||||
this.txid = txid;
|
||||
}
|
||||
|
||||
public String getAmount_withdrawn() {
|
||||
return amount_withdrawn;
|
||||
}
|
||||
|
||||
public void setAmount_withdrawn(String amount_withdrawn) {
|
||||
this.amount_withdrawn = amount_withdrawn;
|
||||
}
|
||||
|
||||
public String getAmount_sent() {
|
||||
return amount_sent;
|
||||
}
|
||||
|
||||
public void setAmount_sent(String amount_sent) {
|
||||
this.amount_sent = amount_sent;
|
||||
}
|
||||
|
||||
public String getNetwork_fee() {
|
||||
return network_fee;
|
||||
}
|
||||
|
||||
public void setNetwork_fee(String network_fee) {
|
||||
this.network_fee = network_fee;
|
||||
}
|
||||
|
||||
public String getBlockio_fee() {
|
||||
return blockio_fee;
|
||||
}
|
||||
|
||||
public void setBlockio_fee(String blockio_fee) {
|
||||
this.blockio_fee = blockio_fee;
|
||||
}
|
||||
|
||||
public String getError_message() {
|
||||
return error_message;
|
||||
}
|
||||
|
||||
public void setError_message(String error_message) {
|
||||
this.error_message = error_message;
|
||||
}
|
||||
|
||||
public String getAvailable_balance() {
|
||||
return available_balance;
|
||||
}
|
||||
|
||||
public void setAvailable_balance(String available_balance) {
|
||||
this.available_balance = available_balance;
|
||||
}
|
||||
|
||||
public String getMax_withdrawal_available() {
|
||||
return max_withdrawal_available;
|
||||
}
|
||||
|
||||
public void setMax_withdrawal_available(String max_withdrawal_available) {
|
||||
this.max_withdrawal_available = max_withdrawal_available;
|
||||
}
|
||||
|
||||
public String getMinimum_balance_needed() {
|
||||
return minimum_balance_needed;
|
||||
}
|
||||
|
||||
public void setMinimum_balance_needed(String minimum_balance_needed) {
|
||||
this.minimum_balance_needed = minimum_balance_needed;
|
||||
}
|
||||
|
||||
public String getEstimated_network_fee() {
|
||||
return estimated_network_fee;
|
||||
}
|
||||
|
||||
public void setEstimated_network_fee(String estimated_network_fee) {
|
||||
this.estimated_network_fee = estimated_network_fee;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public BlockIOData getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public void setData(BlockIOData data) {
|
||||
this.data = data;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
package com.generalbytes.batm.server.extensions.extra.dogecoin.wallets.blockio;
|
||||
|
||||
import com.generalbytes.batm.server.extensions.ICurrencies;
|
||||
import com.generalbytes.batm.server.extensions.IWallet;
|
||||
import si.mazi.rescu.RestProxyFactory;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Created by b00lean on 8/11/14.
|
||||
*/
|
||||
public class BlockIOWallet implements IWallet {
|
||||
private String apiKey;
|
||||
private String pin;
|
||||
|
||||
private IBlockIO api;
|
||||
|
||||
public BlockIOWallet(String apiKey, String pin) {
|
||||
this.apiKey = apiKey;
|
||||
this.pin = pin;
|
||||
api = RestProxyFactory.createProxy(IBlockIO.class, "https://block.io");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getCryptoCurrencies() {
|
||||
Set<String> result = new HashSet<String>();
|
||||
result.add(ICurrencies.BTC);
|
||||
result.add(ICurrencies.LTC);
|
||||
result.add(ICurrencies.DOGE);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferredCryptoCurrency() {
|
||||
return ICurrencies.DOGE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCryptoAddress(String cryptoCurrency) {
|
||||
if (!(cryptoCurrency.equalsIgnoreCase(ICurrencies.DOGE) || cryptoCurrency.equalsIgnoreCase(ICurrencies.BTC) || cryptoCurrency.equalsIgnoreCase(ICurrencies.LTC))) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
BlockIOResponseAddresses response = api.getAddresses(apiKey);
|
||||
if (response != null && response.getData() != null && response.getData().getAddresses() != null && response.getData().getAddresses().length> 0) {
|
||||
return response.getData().getAddresses()[0].getAddress();
|
||||
}
|
||||
}catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BigDecimal getCryptoBalance(String cryptoCurrency) {
|
||||
if (!(cryptoCurrency.equalsIgnoreCase(ICurrencies.DOGE) || cryptoCurrency.equalsIgnoreCase(ICurrencies.BTC) || cryptoCurrency.equalsIgnoreCase(ICurrencies.LTC))) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
BlockIOResponseBalance response = api.getBalance(apiKey);
|
||||
if (response != null && response.getData() != null && response.getData().getAvailable_balance() != null ) {
|
||||
return new BigDecimal(response.getData().getAvailable_balance());
|
||||
}
|
||||
}catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String sendCoins(String destinationAddress, BigDecimal amount, String cryptoCurrency) {
|
||||
if (!(cryptoCurrency.equalsIgnoreCase(ICurrencies.DOGE) || cryptoCurrency.equalsIgnoreCase(ICurrencies.BTC) || cryptoCurrency.equalsIgnoreCase(ICurrencies.LTC))) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
BlockIOResponseWithdrawal response = api.withdraw(apiKey, pin, amount.toPlainString(), destinationAddress);
|
||||
if (response != null && response.getStatus() != null && "success".equalsIgnoreCase(response.getStatus()) && response.getData() != null && response.getData().getTxid() !=null) {
|
||||
return response.getData().getTxid();
|
||||
}
|
||||
}catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.generalbytes.batm.server.extensions.extra.dogecoin.wallets.blockio;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Created by b00lean on 8/11/14.
|
||||
*/
|
||||
@Path("/api/v1/")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public interface IBlockIO {
|
||||
@GET
|
||||
@Path("get_my_addresses/?api_key={apikey}")
|
||||
BlockIOResponseAddresses getAddresses(@PathParam("apikey") String apikey);
|
||||
|
||||
@GET
|
||||
@Path("get_balance/?api_key={apikey}")
|
||||
BlockIOResponseBalance getBalance(@PathParam("apikey") String apikey);
|
||||
|
||||
@GET
|
||||
@Path("withdraw/?api_key={apikey}&amount={amount}&payment_address={payment_address}&pin={pin}")
|
||||
BlockIOResponseWithdrawal withdraw(@PathParam("apikey") String apikey, @PathParam("pin") String pin, @PathParam("amount") String amount, @PathParam("payment_address") String payment_address);
|
||||
|
||||
}
|
|
@ -1,146 +0,0 @@
|
|||
/*************************************************************************************
|
||||
* 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.dogecoin.wallets.dogeapi;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class DogeAPIResponse {
|
||||
private Data data;
|
||||
|
||||
public class Data {
|
||||
private String[] addresses;
|
||||
private BigDecimal balance;
|
||||
private String txid;
|
||||
private Info info;
|
||||
|
||||
|
||||
public class Info {
|
||||
private BigDecimal difficulty;
|
||||
private BigDecimal network_hashrate;
|
||||
private BigDecimal doge_usd;
|
||||
private BigDecimal doge_btc;
|
||||
private BigDecimal five_min_btc_change;
|
||||
private BigDecimal five_min_usd_change;
|
||||
private int api_version;
|
||||
|
||||
public BigDecimal getDifficulty() {
|
||||
return difficulty;
|
||||
}
|
||||
|
||||
public void setDifficulty(BigDecimal difficulty) {
|
||||
this.difficulty = difficulty;
|
||||
}
|
||||
|
||||
public BigDecimal getNetwork_hashrate() {
|
||||
return network_hashrate;
|
||||
}
|
||||
|
||||
public void setNetwork_hashrate(BigDecimal network_hashrate) {
|
||||
this.network_hashrate = network_hashrate;
|
||||
}
|
||||
|
||||
public BigDecimal getDoge_usd() {
|
||||
return doge_usd;
|
||||
}
|
||||
|
||||
public void setDoge_usd(BigDecimal doge_usd) {
|
||||
this.doge_usd = doge_usd;
|
||||
}
|
||||
|
||||
public BigDecimal getDoge_btc() {
|
||||
return doge_btc;
|
||||
}
|
||||
|
||||
public void setDoge_btc(BigDecimal doge_btc) {
|
||||
this.doge_btc = doge_btc;
|
||||
}
|
||||
|
||||
@JsonProperty("5min_btc_change")
|
||||
public BigDecimal getFive_min_btc_change() {
|
||||
return five_min_btc_change;
|
||||
}
|
||||
|
||||
@JsonProperty("5min_btc_change")
|
||||
public void setFive_min_btc_change(BigDecimal five_min_btc_change) {
|
||||
this.five_min_btc_change = five_min_btc_change;
|
||||
}
|
||||
|
||||
@JsonProperty("5min_usd_change")
|
||||
public BigDecimal getFive_min_usd_change() {
|
||||
return five_min_usd_change;
|
||||
}
|
||||
|
||||
@JsonProperty("5min_usd_change")
|
||||
public void setFive_min_usd_change(BigDecimal five_min_usd_change) {
|
||||
this.five_min_usd_change = five_min_usd_change;
|
||||
}
|
||||
|
||||
public int getApi_version() {
|
||||
return api_version;
|
||||
}
|
||||
|
||||
public void setApi_version(int api_version) {
|
||||
this.api_version = api_version;
|
||||
}
|
||||
}
|
||||
|
||||
public String[] getAddresses() {
|
||||
return addresses;
|
||||
}
|
||||
|
||||
public void setAddresses(String[] addresses) {
|
||||
this.addresses = addresses;
|
||||
}
|
||||
|
||||
public BigDecimal getBalance() {
|
||||
return balance;
|
||||
}
|
||||
|
||||
public void setBalance(BigDecimal balance) {
|
||||
this.balance = balance;
|
||||
}
|
||||
|
||||
public String getTxid() {
|
||||
return txid;
|
||||
}
|
||||
|
||||
public void setTxid(String txid) {
|
||||
this.txid = txid;
|
||||
}
|
||||
|
||||
public Info getInfo() {
|
||||
return info;
|
||||
}
|
||||
|
||||
public void setInfo(Info info) {
|
||||
this.info = info;
|
||||
}
|
||||
}
|
||||
|
||||
public Data getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(Data data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,93 +0,0 @@
|
|||
/*************************************************************************************
|
||||
* 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.dogecoin.wallets.dogeapi;
|
||||
|
||||
import com.generalbytes.batm.server.extensions.ICurrencies;
|
||||
import com.generalbytes.batm.server.extensions.IWallet;
|
||||
import si.mazi.rescu.RestProxyFactory;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class DogeAPIWallet implements IWallet{
|
||||
private String apiKey;
|
||||
private IDogeAPIv2 api;
|
||||
private String pin;
|
||||
|
||||
public DogeAPIWallet(String apiKey, String pin) {
|
||||
this.apiKey = apiKey;
|
||||
this.pin = pin;
|
||||
|
||||
api = RestProxyFactory.createProxy(IDogeAPIv2.class, "https://www.dogeapi.com");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getCryptoCurrencies() {
|
||||
Set<String> result = new HashSet<String>();
|
||||
result.add(ICurrencies.DOGE);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferredCryptoCurrency() {
|
||||
return ICurrencies.DOGE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCryptoAddress(String cryptoCurrency) {
|
||||
if (!cryptoCurrency.equalsIgnoreCase(ICurrencies.DOGE)) {
|
||||
return null;
|
||||
}
|
||||
DogeAPIResponse response = api.getAddresses(apiKey);
|
||||
|
||||
if (response != null && response.getData() != null && response.getData().getAddresses() != null && response.getData().getAddresses().length > 0) {
|
||||
return response.getData().getAddresses()[0];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BigDecimal getCryptoBalance(String cryptoCurrency) {
|
||||
if (!cryptoCurrency.equalsIgnoreCase(ICurrencies.DOGE)) {
|
||||
return null;
|
||||
}
|
||||
DogeAPIResponse response = api.getBalance(apiKey);
|
||||
|
||||
if (response != null && response.getData() != null && response.getData().getBalance() != null) {
|
||||
return response.getData().getBalance();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String sendCoins(String destinationAddress, BigDecimal amount, String cryptoCurrency) {
|
||||
if (!cryptoCurrency.equalsIgnoreCase(ICurrencies.DOGE)) {
|
||||
return null;
|
||||
}
|
||||
DogeAPIResponse withdraw = api.withdraw(apiKey, pin, amount, destinationAddress);
|
||||
if (withdraw != null && withdraw.getData() != null) {
|
||||
return withdraw.getData().getTxid();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
/*************************************************************************************
|
||||
* 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.dogecoin.wallets.dogeapi;
|
||||
|
||||
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;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Path("/wow/v2/")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public interface IDogeAPIv2 {
|
||||
|
||||
@GET
|
||||
@Path("?api_key={apikey}&a=get_my_addresses")
|
||||
DogeAPIResponse getAddresses(@PathParam("apikey") String apikey);
|
||||
|
||||
@GET
|
||||
@Path("?api_key={apikey}&a=get_balance")
|
||||
DogeAPIResponse getBalance(@PathParam("apikey") String apikey);
|
||||
|
||||
@GET
|
||||
@Path("?api_key={apikey}&a=withdraw&amount_doge={amount}&pin={pin}&payment_address={address}")
|
||||
DogeAPIResponse withdraw(@PathParam("apikey") String apikey, @PathParam("pin") String pin, @PathParam("amount") BigDecimal amount, @PathParam("address") String destinationAddress);
|
||||
|
||||
@GET
|
||||
@Path("?a=get_info")
|
||||
DogeAPIResponse getInfo();
|
||||
|
||||
}
|
Loading…
Reference in New Issue