Initial commit

This commit is contained in:
b00lean 2014-07-04 17:24:06 +02:00
parent 07c78f8ccf
commit 2f36249d13
44 changed files with 2561 additions and 0 deletions

View File

@ -0,0 +1,57 @@
<!--
*************************************************************************************
* 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
*
************************************************************************************
-->
<project name="batm_server_extensions_api" default="dist" basedir=".">
<description>
BATM server extensions API
</description>
<!-- set global properties for this build -->
<property name="src" location="src"/>
<property name="build" location="build"/>
<property name="dist" location="dist"/>
<property name="libs" location="libs"/>
<target name="init">
<tstamp/>
<delete dir="${build}" />
<mkdir dir="${build}"/>
</target>
<path id="classpath">
<fileset dir="${libs}" includes="**/*.jar"/>
</path>
<target name="compile" depends="init" description="compile the source " >
<javac srcdir="${src}" destdir="${build}" debug="true" debuglevel="lines,vars,source">
<classpath>
<path refid="classpath" />
</classpath>
</javac>
</target>
<target name="dist" depends="compile" description="generate the distribution" >
<mkdir dir="${dist}"/>
<jar jarfile="${dist}/${ant.project.name}.jar" basedir="${build}"/>
</target>
<target name="clean" description="clean up" >
<delete dir="${build}"/>
<delete dir="${dist}"/>
</target>
</project>

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,29 @@
/*************************************************************************************
* 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.coinutil;
@SuppressWarnings("serial")
public class AddressFormatException extends Exception {
public AddressFormatException() {
super();
}
public AddressFormatException(String message) {
super(message);
}
}

View File

@ -0,0 +1,223 @@
package com.generalbytes.batm.server.coinutil;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
/**
* <p>Base58 is a way to encode Bitcoin addresses as numbers and letters. Note that this is not the same base58 as used by
* Flickr, which you may see reference to around the internet.</p>
*
* <p>Satoshi says: why base-58 instead of standard base-64 encoding?<p>
*
* <ul>
* <li>Don't want 0OIl characters that look the same in some fonts and
* could be used to create visually identical looking account numbers.</li>
* <li>A string with non-alphanumeric characters is not as easily accepted as an account number.</li>
* <li>E-mail usually won't line-break if there's no punctuation to break at.</li>
* <li>Doubleclicking selects the whole number as one word if it's all alphanumeric.</li>
* </ul>
*/
public class Base58 {
private static final char[] ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
.toCharArray();
private static final int BASE_58 = ALPHABET.length;
private static final int BASE_256 = 256;
private static final int[] INDEXES = new int[128];
static {
for (int i = 0; i < INDEXES.length; i++) {
INDEXES[i] = -1;
}
for (int i = 0; i < ALPHABET.length; i++) {
INDEXES[ALPHABET[i]] = i;
}
}
public static String encode(byte[] input) {
if (input.length == 0) {
return "";
}
input = copyOfRange(input, 0, input.length);
// Count leading zeroes.
int zeroCount = 0;
while (zeroCount < input.length && input[zeroCount] == 0) {
++zeroCount;
}
// The actual encoding.
byte[] temp = new byte[input.length * 2];
int j = temp.length;
int startAt = zeroCount;
while (startAt < input.length) {
byte mod = divmod58(input, startAt);
if (input[startAt] == 0) {
++startAt;
}
temp[--j] = (byte) ALPHABET[mod];
}
// Strip extra '1' if there are some after decoding.
while (j < temp.length && temp[j] == ALPHABET[0]) {
++j;
}
// Add as many leading '1' as there were leading zeros.
while (--zeroCount >= 0) {
temp[--j] = (byte) ALPHABET[0];
}
byte[] output = copyOfRange(temp, j, temp.length);
try {
return new String(output, "US-ASCII");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e); // Cannot happen.
}
}
public static byte[] decode(String input) throws AddressFormatException {
if (input.length() == 0) {
return new byte[0];
}
byte[] input58 = new byte[input.length()];
//
// Transform the String to a base58 byte sequence
//
for (int i = 0; i < input.length(); ++i) {
char c = input.charAt(i);
int digit58 = -1;
if (c >= 0 && c < 128) {
digit58 = INDEXES[c];
}
if (digit58 < 0) {
throw new AddressFormatException("Illegal character " + c + " at " + i);
}
input58[i] = (byte) digit58;
}
//
// Count leading zeroes
//
int zeroCount = 0;
while (zeroCount < input58.length && input58[zeroCount] == 0) {
++zeroCount;
}
//
// The encoding
//
byte[] temp = new byte[input.length()];
int j = temp.length;
int startAt = zeroCount;
while (startAt < input58.length) {
byte mod = divmod256(input58, startAt);
if (input58[startAt] == 0) {
++startAt;
}
temp[--j] = mod;
}
//
// Do no add extra leading zeroes, move j to first non null byte.
//
while (j < temp.length && temp[j] == 0) {
++j;
}
return copyOfRange(temp, j - zeroCount, temp.length);
}
public static BigInteger decodeToBigInteger(String input) throws AddressFormatException {
byte[] bytes = decode(input);
// always return a positive BigInteger
return new BigInteger(1, bytes);
}
/**
* Uses the checksum in the last 4 bytes of the decoded data to verify the rest are correct. The checksum is
* removed from the returned data.
*
* @throws AddressFormatException if the input is not base 58 or the checksum does not validate.
*/
public static byte[] decodeChecked(String input) throws AddressFormatException {
byte tmp [] = decode(input);
if (tmp.length < 4)
throw new AddressFormatException("Input to short");
byte[] bytes = copyOfRange(tmp, 0, tmp.length - 4);
byte[] checksum = copyOfRange(tmp, tmp.length - 4, tmp.length);
tmp = doubleDigest(bytes);
byte[] hash = copyOfRange(tmp, 0, 4);
if (!Arrays.equals(checksum, hash))
throw new AddressFormatException("Checksum does not validate");
return bytes;
}
public static byte[] doubleDigest(byte[] input) {
return doubleDigest(input, 0, input.length);
}
/**
* Calculates the SHA-256 hash of the given byte range, and then hashes the resulting hash again. This is
* standard procedure in Bitcoin. The resulting hash is in big endian form.
*/
public static byte[] doubleDigest(byte[] input, int offset, int length) {
try {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
digest.update(input, offset, length);
byte[] first = digest.digest();
return digest.digest(first);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e); // Cannot happen.
}
}
//
// number -> number / 58, returns number % 58
//
private static byte divmod58(byte[] number, int startAt) {
int remainder = 0;
for (int i = startAt; i < number.length; i++) {
int digit256 = (int) number[i] & 0xFF;
int temp = remainder * BASE_256 + digit256;
number[i] = (byte) (temp / BASE_58);
remainder = temp % BASE_58;
}
return (byte) remainder;
}
//
// number -> number / 256, returns number % 256
//
private static byte divmod256(byte[] number58, int startAt) {
int remainder = 0;
for (int i = startAt; i < number58.length; i++) {
int digit58 = (int) number58[i] & 0xFF;
int temp = remainder * BASE_58 + digit58;
number58[i] = (byte) (temp / BASE_256);
remainder = temp % BASE_256;
}
return (byte) remainder;
}
private static byte[] copyOfRange(byte[] source, int from, int to) {
byte[] range = new byte[to - from];
System.arraycopy(source, from, range, 0, range.length);
return range;
}
}

View File

@ -0,0 +1,42 @@
/*************************************************************************************
* 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;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
public class ExtensionsUtil {
/**
* Check if specified string is valid email address
* @param email
* @return
*/
public static boolean isValidEmailAddress(String email) {
boolean result = true;
try {
InternetAddress emailAddr = new InternetAddress(email);
emailAddr.validate();
} catch (AddressException ex) {
result = false;
}
return result;
}
}

View File

@ -0,0 +1,45 @@
/*************************************************************************************
* 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;
/**
* Classes that implement this interface are used by server to validate user crypto address entry
*/
public interface ICryptoAddressValidator {
/**
* This method checks if provided address is valid for specified cryptocurrency
* @param address
* @return
*/
public boolean isAddressValid(String address);
/**
* returns true if cryproaddress of this cryptocurrency must be BASE58 checked when read by QR code scanner.
* @return
*/
public boolean mustBeBase58Address();
/**
* returns true if cryptoaddress can be email address later used for issuing paper wallets
* Please note that Paper wallet for specified cryptocurrency must exist
* @return
*/
public boolean isPaperWalletSupported();
}

View File

@ -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;
public interface ICurrencies {
public static final String BTC = "BTC";
public static final String LTC = "LTC";
public static final String DOGE = "DOGE";
public static final String CZK = "CZK";
public static final String EUR = "EUR";
public static final String USD = "USD";
public static final String NONE = "";
}

View File

@ -0,0 +1,79 @@
/*************************************************************************************
* 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;
import java.math.BigDecimal;
import java.util.Set;
/**
* This interface is used by master to purchase coins on crypto exchange like Bitstamp.net
*/
public interface IExchange {
/**
* Returns set of cryptocurrencies that crypto exchange supports
* @return
*/
public Set<String> getCryptoCurrencies();
/**
* Returns list of fiat currencies that crypto exchange supports (USD,EUR etc)
* @return
*/
public Set<String> getFiatCurrencies();
/**
* Returns fiat currency that is used for actual purchases of cryptocurrency by server
* @return
*/
public String getPreferredFiatCurrency();
/**
* Returns current balance of cryptocurrency on the exchange
* @param cryptoCurrency
* @return
*/
public BigDecimal getCryptoBalance(String cryptoCurrency);
/**
* Returns current balance of fiat money on the exchange
* @param fiatCurrency
* @return
*/
public BigDecimal getFiatBalance(String fiatCurrency);
/**
* This method is used for purchasing coins on the exchange using specified fiat currency to use.
* If something fails this method should return NULL otherwise it should return orderId or any other identifier that exchange provides for later tracking
* @param amount
* @param cryptoCurrency
* @param fiatCurrencyToUse
* @return
*/
public String purchaseCoins(BigDecimal amount, String cryptoCurrency, String fiatCurrencyToUse);
/**
* This method is used for withdrawing coins from the exchange by sending them to specified address
* @param destinationAddress
* @param amount
* @param cryptoCurrency
* @return
*/
public String sendCoins(String destinationAddress, BigDecimal amount, String cryptoCurrency);
}

View File

@ -0,0 +1,86 @@
/*************************************************************************************
* 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;
import java.util.Set;
/**
* This class provides information to the server about the available crypto currencies and represents
* the single point for creating objects later used for manipulating with the coins of supported cryptocurrencies
*/
public interface IExtension {
/**
* Returns the name of the extension.
* @return
*/
public String getName();
/**
* Returns list of crypto currencies that this extension supports
* @return
*/
public Set<String> getSupportedCryptoCurrencies();
/**
* This method is used for creating implementation of crypto exchange
* @param exchangeLogin
* @return
*
* @see com.generalbytes.batm.server.extensions.IExchange
*/
public IExchange createExchange(String exchangeLogin);
/**
* This method is used for creating implementation of coin price source
* @param sourceLogin
* @return
*
* @see com.generalbytes.batm.server.extensions.IRateSource
*/
public IRateSource createRateSource(String sourceLogin);
/**
* This method is used for creating implementation of cryptocurrency hot wallet used by the server
* @param walletLogin
* @return
*
* @see com.generalbytes.batm.server.extensions.IWallet
*/
public IWallet createWallet(String walletLogin);
/**
* This method is used for creating implementation cryptocurrency address validator used by the server
* @param cryptoCurrency
* @return
*
* @see com.generalbytes.batm.server.extensions.ICryptoAddressValidator
*/
public ICryptoAddressValidator createAddressValidator(String cryptoCurrency);
/**
* This method is used for creating implementation cryptocurrency paper wallet generator
* @param cryptoCurrency
* @return
*
* @see com.generalbytes.batm.server.extensions.IPaperWalletGenerator
* @see com.generalbytes.batm.server.extensions.IPaperWallet
*/
public IPaperWalletGenerator createPaperWalletGenerator(String cryptoCurrency);
}

View File

@ -0,0 +1,56 @@
/*************************************************************************************
* 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;
/**
* Classes implementing this interface represent crypto paper wallet generated by IPaperWalletGenerator
* @see com.generalbytes.batm.server.extensions.IPaperWalletGenerator
*/
public interface IPaperWallet {
/**
* Raw bytes that will be contained in file attached in email sent to customer.
* @return
*/
public byte[] getContent();
/**
* Public crypto address. This address is later used in log files and also as part of attachment filename
* @return
*/
public String getAddress();
/**
* Attachment extension (ie "zip")
* @return
*/
public String getFileExtension();
/**
* MIME Content type of the attachment (ie "application/zip")
* @return
*/
public String getContentType();
/**
* Returns message that will be in email's body (ie instructions what to do with the attachment - how to import private key to your wallet)
* @return
*/
public String getMessage();
}

View File

@ -0,0 +1,36 @@
/*************************************************************************************
* 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;
/**
* Classes implementing this interface are used by the server to generate paper wallets
*/
public interface IPaperWalletGenerator {
/**
* Please generate me a wallet that will have private key encrypted by provided on-time-password
* User language is provided produce paper wallet instructions in customer's language selected on the ATM
* @param cryptoCurrency
* @param onetimePassword
* @param userLanguage*
* @return
*
* @see com.generalbytes.batm.server.extensions.IPaperWallet
*/
public IPaperWallet generateWallet(String cryptoCurrency, String onetimePassword, String userLanguage);
}

View File

@ -0,0 +1,48 @@
/*************************************************************************************
* 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;
import java.math.BigDecimal;
import java.util.Set;
/**
* Classes implementing this interface are used by the server to obtain price of specified cryptocurrency in fiat currency
* Please note that it is recommended to implement some kind of price caching in this calls to avoid very frequent http calls resulting in banned IPs.
*/
public interface IRateSource {
/**
* This method returns list of supported crypto currencies
* @return
*/
public Set<String> getCryptoCurrencies();
/**
* This method returns list of supported fiat currencies
* @return
*/
public Set<String> getFiatCurrencies();
/**
* Returns current price of cryptocurrency in specified fiat currency
* @param cryptoCurrency
* @param fiatCurrency
* @return
*/
public BigDecimal getExchangeRateLast(String cryptoCurrency, String fiatCurrency);
}

View File

@ -0,0 +1,30 @@
/*************************************************************************************
* 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;
import java.math.BigDecimal;
import java.util.Set;
public interface IWallet {
public String sendCoins(String destinationAddress, BigDecimal amount, String cryptoCurrency); //returns txid
public String getCryptoAddress(String cryptoCurrency);
public Set<String> getCryptoCurrencies();
public String getPreferredCryptoCurrency();
public BigDecimal getCryptoBalance(String cryptoCurrency);
}

View File

@ -0,0 +1,67 @@
<!--
*************************************************************************************
* 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
*
************************************************************************************
-->
<project name="batm_server_extensions_extra" default="dist" basedir=".">
<description>
BATM server extra extensions
</description>
<!-- set global properties for this build -->
<property name="src" location="src"/>
<property name="res" location="res"/>
<property name="build" location="build"/>
<property name="dist" location="dist"/>
<property name="libs" location="libs"/>
<target name="init">
<tstamp/>
<delete dir="${build}" />
<mkdir dir="${build}"/>
</target>
<path id="classpath">
<fileset dir="${libs}" includes="**/*.jar"/>
<fileset dir="../server_extensions_api/libs" includes="**/*.jar"/>
<fileset dir="../server_extensions_api/dist" includes="**/*.jar"/>
</path>
<target name="compile" depends="init" description="compile the source " >
<javac srcdir="${src}" destdir="${build}" debug="true" debuglevel="lines,vars,source">
<classpath>
<path refid="classpath" />
</classpath>
</javac>
<copy todir="${build}">
<fileset dir="${res}">
<include name="**/*"/>
</fileset>
</copy>
</target>
<target name="dist" depends="compile" description="generate the distribution" >
<mkdir dir="${dist}"/>
<jar jarfile="${dist}/${ant.project.name}.jar" basedir="${build}"/>
</target>
<target name="clean" description="clean up" >
<delete dir="${build}"/>
<delete dir="${dist}"/>
</target>
</project>

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<extensions>
<extension class="com.generalbytes.batm.server.extensions.extra.bitcoin.BitcoinExtension" >
<wallet prefix="bitcoind" name="Bitcoin Core - bitcoind" >
<param name="protocol" />
<param name="user" />
<param name="password" />
<param name="host" />
<param name="port" />
<param name="accountname" />
<cryptocurrency>BTC</cryptocurrency>
</wallet>
<ratesource prefix="bitcoinaverage" name ="BitcoinAverage.com" >
<cryptocurrency>BTC</cryptocurrency>
</ratesource>
<cryptologo cryptocurrency="BTC" file="btc.png"/>
</extension>
<extension class="com.generalbytes.batm.server.extensions.extra.dogecoin.DogecoinExtension">
<wallet prefix="dogeapi" name="DogeAPI Wallet">
<param name="apikey" />
<param name="pin" />
<cryptocurrency>DOGE</cryptocurrency>
</wallet>
<wallet prefix="dogecoind" name="Dogecoind">
<param name="protocol" />
<param name="user" />
<param name="password" />
<param name="host" />
<param name="port" />
<param name="accountname" />
<cryptocurrency>DOGE</cryptocurrency>
</wallet>
<ratesource prefix="dogeapi" name="DogeAPI.com" >
<cryptocurrency>DOGE</cryptocurrency>
</ratesource>
<cryptologo cryptocurrency="DOGE" file="doge.png"/>
</extension>
<extension class="com.generalbytes.batm.server.extensions.extra.litecoin.LitecoinExtension" >
<wallet prefix="litecoind" name="Litecoind">
<param name="protocol" />
<param name="user" />
<param name="password" />
<param name="host" />
<param name="port" />
<param name="accountname" />
<cryptocurrency>LTC</cryptocurrency>
</wallet>
<ratesource prefix="btce" name="BTC-e.com" >
<cryptocurrency>LTC</cryptocurrency>
<cryptocurrency>BTC</cryptocurrency>
</ratesource>
<cryptologo cryptocurrency="LTC" file="ltc.png"/>
</extension>
</extensions>

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

View File

@ -0,0 +1,97 @@
/*************************************************************************************
* 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.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.wallets.bitcoind.BATMBitcoindRPCWallet;
import java.util.*;
public class BitcoinExtension implements IExtension{
@Override
public String getName() {
return "BATM Bitcoin extra extension";
}
@Override
public IExchange createExchange(String exchangeLogin) {
return null; //no BTC exchange available in open source version so far (Bitstamp is in built-in extension)
}
@Override
public IWallet createWallet(String walletLogin) {
if (walletLogin !=null && !walletLogin.trim().isEmpty()) {
StringTokenizer st = new StringTokenizer(walletLogin,":");
String walletType = st.nextToken();
if ("bitcoind".equalsIgnoreCase(walletType)) {
//"bitcoind: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 BATMBitcoindRPCWallet(rpcURL,accountName);
}
}
}
return null;
}
@Override
public ICryptoAddressValidator createAddressValidator(String cryptoCurrency) {
return null; //no BTC address validator in open source version so far (It is present in built-in extension)
}
@Override
public IPaperWalletGenerator createPaperWalletGenerator(String cryptoCurrency) {
return null; //no BTC paper wallet generator in open source version so far (It is present in built-in extension)
}
@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 ("bitcoinaverage".equalsIgnoreCase(exchangeType)) {
return new BitcoinAverageRateSource();
}
}
return null;
}
@Override
public Set<String> getSupportedCryptoCurrencies() {
Set<String> result = new HashSet<String>();
result.add(ICurrencies.BTC);
return result;
}
}

View File

@ -0,0 +1,77 @@
/*************************************************************************************
* 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.bitcoin.sources;
import java.math.BigDecimal;
public class BitcoinAverageRate {
private BigDecimal ask;
private BigDecimal bid;
private BigDecimal last;
private String timestamp;
private BigDecimal volume_btc;
private BigDecimal volume_percent;
public BigDecimal getAsk() {
return ask;
}
public void setAsk(BigDecimal ask) {
this.ask = ask;
}
public BigDecimal getBid() {
return bid;
}
public void setBid(BigDecimal bid) {
this.bid = bid;
}
public BigDecimal getLast() {
return last;
}
public void setLast(BigDecimal last) {
this.last = last;
}
public String getTimestamp() {
return timestamp;
}
public void setTimestamp(String timestamp) {
this.timestamp = timestamp;
}
public BigDecimal getVolume_btc() {
return volume_btc;
}
public void setVolume_btc(BigDecimal volume_btc) {
this.volume_btc = volume_btc;
}
public BigDecimal getVolume_percent() {
return volume_percent;
}
public void setVolume_percent(BigDecimal volume_percent) {
this.volume_percent = volume_percent;
}
}

View File

@ -0,0 +1,118 @@
/*************************************************************************************
* 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.bitcoin.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.*;
public class BitcoinAverageRateSource implements IRateSource{
private static final Logger log = LoggerFactory.getLogger(BitcoinAverageRateSource.class);
private static Map<String, String> fiatCurrenciesAndURLs = new HashMap<String, String>();
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
@Override
public BigDecimal getExchangeRateLast(String cryptoCurrency, String fiatCurrency) {
if (!ICurrencies.BTC.equalsIgnoreCase(cryptoCurrency)) {
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 bitcoinaverage 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 bitcoinaverage 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.BTC.equalsIgnoreCase(cryptoCurrency)) {
return null; //unsupported currency
}
if (fiatCurrenciesAndURLs.isEmpty()) {
loadFiatCurrencies();
}
String url = fiatCurrenciesAndURLs.get(fiatCurrency);
if (url != null) {
IBitcoinAverage api = RestProxyFactory.createProxy(IBitcoinAverage.class, url);
BitcoinAverageRate btcRate = api.getBTCRate();
if (btcRate != null) {
return btcRate.getLast();
}
return null;
}else {
return null; //unsupported fiat currency
}
}
@Override
public Set<String> getCryptoCurrencies() {
Set<String> result = new HashSet<String>();
result.add(ICurrencies.BTC);
return result;
}
@Override
public Set<String> getFiatCurrencies() {
if (fiatCurrenciesAndURLs == null || fiatCurrenciesAndURLs.isEmpty()) {
//load them from the website
loadFiatCurrencies();
}
Set<String> fiatCurrencies = fiatCurrenciesAndURLs.keySet();
return new HashSet<String>(fiatCurrencies);
}
private void loadFiatCurrencies() {
IBitcoinAverage api = RestProxyFactory.createProxy(IBitcoinAverage.class, "https://api.bitcoinaverage.com/ticker/global/");
HashMap<String, String> currenciesAndURLs = api.getFiatCurrenciesAndURLs();
if (fiatCurrenciesAndURLs != null) {
fiatCurrenciesAndURLs = currenciesAndURLs;
}
}
}

View File

@ -0,0 +1,39 @@
/*************************************************************************************
* 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.bitcoin.sources;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.HashMap;
@Path("/")
@Produces(MediaType.APPLICATION_JSON)
public interface IBitcoinAverage {
@GET
@Path("/")
HashMap<String,String> getFiatCurrenciesAndURLs();
@GET
@Path("/")
BitcoinAverageRate getBTCRate();
}

View File

@ -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.bitcoin.wallets.bitcoind;
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 BATMBitcoindRPCWallet implements IWallet{
private static final Logger log = LoggerFactory.getLogger(BATMBitcoindRPCWallet.class);
private static final String CRYPTO_CURRENCY = ICurrencies.BTC;
public BATMBitcoindRPCWallet(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) {
if (!CRYPTO_CURRENCY.equalsIgnoreCase(cryptoCurrency)) {
log.error("Bitcoind wallet error: unknown cryptocurrency.");
return null;
}
log.info("Bitcoind 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("Bitcoind 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("Bitcoind 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;
}
}

View File

@ -0,0 +1,60 @@
/*************************************************************************************
* 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;
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 DogecoinAddressValidator implements ICryptoAddressValidator {
@Override
public boolean isAddressValid(String address) {
boolean result = isDogecoinAddressValid(address);
if (!result) {
result = isPaperWalletSupported() && ExtensionsUtil.isValidEmailAddress(address);
}
return result;
}
private boolean isDogecoinAddressValid(String address) {
if (address.startsWith("D")) {
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;
}
}

View File

@ -0,0 +1,106 @@
/*************************************************************************************
* 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;
import com.generalbytes.batm.server.extensions.*;
import com.generalbytes.batm.server.extensions.extra.dogecoin.sources.DogeAPIRateSource;
import com.generalbytes.batm.server.extensions.extra.dogecoin.wallets.dogeapi.DogeAPIWallet;
import com.generalbytes.batm.server.extensions.extra.dogecoin.wallets.dogecoind.DogecoindRPCWallet;
import java.util.*;
public class DogecoinExtension implements IExtension{
@Override
public String getName() {
return "BATM Dogecoin extra 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 ("dogeapi".equalsIgnoreCase(walletType)) {
String apikey = st.nextToken();
String pin = st.nextToken();
return new DogeAPIWallet(apikey,pin);
}else if ("dogecoind".equalsIgnoreCase(walletType)) {
//"dogecoind: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 DogecoindRPCWallet(rpcURL,accountName);
}
}
}
return null;
}
@Override
public ICryptoAddressValidator createAddressValidator(String cryptoCurrency) {
if (ICurrencies.DOGE.equalsIgnoreCase(cryptoCurrency)) {
return new DogecoinAddressValidator();
}
return null;
}
@Override
public IPaperWalletGenerator createPaperWalletGenerator(String cryptoCurrency) {
return null;
}
@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();
}
}
return null;
}
@Override
public Set<String> getSupportedCryptoCurrencies() {
Set<String> result = new HashSet<String>();
result.add(ICurrencies.DOGE);
return result;
}
}

View File

@ -0,0 +1,112 @@
/*************************************************************************************
* 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;
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.*;
public class DogeAPIRateSource implements IRateSource{
private static final Logger log = LoggerFactory.getLogger(DogeAPIRateSource.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;
public DogeAPIRateSource() {
api = RestProxyFactory.createProxy(IDogeAPIv2.class, "https://www.dogeapi.com");
}
@Override
public BigDecimal getExchangeRateLast(String cryptoCurrency, String fiatCurrency) {
if (!ICurrencies.DOGE.equalsIgnoreCase(cryptoCurrency)) {
return null;
}
if (!ICurrencies.USD.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 dogeapi 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 dogeapi 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.DOGE.equalsIgnoreCase(cryptoCurrency)) {
return null;
}
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();
}
}
return null;
}
@Override
public Set<String> getCryptoCurrencies() {
Set<String> result = new HashSet<String>();
result.add(ICurrencies.DOGE);
return result;
}
@Override
public Set<String> getFiatCurrencies() {
Set<String> result = new HashSet<String>();
result.add(ICurrencies.USD);
return result;
}
}

View File

@ -0,0 +1,146 @@
/*************************************************************************************
* 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;
}
}

View File

@ -0,0 +1,93 @@
/*************************************************************************************
* 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;
}
}

View File

@ -0,0 +1,47 @@
/*************************************************************************************
* 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();
}

View File

@ -0,0 +1,119 @@
/*************************************************************************************
* 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.dogecoind;
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 DogecoindRPCWallet implements IWallet{
private static final Logger log = LoggerFactory.getLogger(DogecoindRPCWallet.class);
private static final String CRYPTO_CURRENCY = ICurrencies.DOGE;
public DogecoindRPCWallet(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) {
if (!CRYPTO_CURRENCY.equalsIgnoreCase(cryptoCurrency)) {
log.error("Dogecoind wallet error: unknown cryptocurrency.");
return null;
}
log.info("Dogecoind 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("Dogecoind 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("Dogecoind 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;
}
}

View File

@ -0,0 +1,60 @@
/*************************************************************************************
* 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.litecoin;
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 LitecoinAddressValidator implements ICryptoAddressValidator {
@Override
public boolean isAddressValid(String address) {
boolean result = isLitecoinAddressValid(address);
if (!result) {
result = isPaperWalletSupported() && ExtensionsUtil.isValidEmailAddress(address);
}
return result;
}
private boolean isLitecoinAddressValid(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;
}
}

View File

@ -0,0 +1,98 @@
/*************************************************************************************
* 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.litecoin;
import com.generalbytes.batm.server.extensions.*;
import com.generalbytes.batm.server.extensions.extra.litecoin.sources.btce.BTCeRateSource;
import com.generalbytes.batm.server.extensions.extra.litecoin.wallets.litecoind.LitecoindRPCWallet;
import java.util.*;
public class LitecoinExtension implements IExtension{
@Override
public String getName() {
return "BATM Litecoin 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 ("litecoind".equalsIgnoreCase(walletType)) {
//"litecoind: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 LitecoindRPCWallet(rpcURL,accountName);
}
}
}
return null;
}
@Override
public ICryptoAddressValidator createAddressValidator(String cryptoCurrency) {
if (ICurrencies.LTC.equalsIgnoreCase(cryptoCurrency)) {
return new LitecoinAddressValidator();
}
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 ("btce".equalsIgnoreCase(exchangeType)) {
return new BTCeRateSource();
}
}
return null;
}
@Override
public Set<String> getSupportedCryptoCurrencies() {
Set<String> result = new HashSet<String>();
result.add(ICurrencies.LTC);
return result;
}
}

View File

@ -0,0 +1,107 @@
/*************************************************************************************
* 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.litecoin.sources.btce;
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.*;
public class BTCeRateSource implements IRateSource{
private static final Logger log = LoggerFactory.getLogger(BTCeRateSource.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 IBTCeRateAPI api;
public BTCeRateSource() {
api = RestProxyFactory.createProxy(IBTCeRateAPI.class, "https://btc-e.com");
}
@Override
public BigDecimal getExchangeRateLast(String cryptoCurrency, String fiatCurrency) {
if (!(ICurrencies.BTC.equalsIgnoreCase(cryptoCurrency) || ICurrencies.LTC.equalsIgnoreCase(cryptoCurrency))) {
return null;
}
if (!(ICurrencies.USD.equalsIgnoreCase(fiatCurrency) || 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 BTC-e 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 BTC-e 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.BTC.equalsIgnoreCase(cryptoCurrency) || ICurrencies.LTC.equalsIgnoreCase(cryptoCurrency))) {
return null;
}
if (!(ICurrencies.USD.equalsIgnoreCase(fiatCurrency) || ICurrencies.EUR.equalsIgnoreCase(fiatCurrency))) {
return null;
}
BTCeResponse ticker = api.getTicker(cryptoCurrency.toLowerCase(), fiatCurrency.toLowerCase());
if (ticker != null && ticker.getTicker() != null) {
return ticker.getTicker().getBuy();
}
return null;
}
@Override
public Set<String> getCryptoCurrencies() {
Set<String> result = new HashSet<String>();
result.add(ICurrencies.BTC);
result.add(ICurrencies.LTC);
return result;
}
@Override
public Set<String> getFiatCurrencies() {
Set<String> result = new HashSet<String>();
result.add(ICurrencies.USD);
result.add(ICurrencies.EUR);
return result;
}
}

View File

@ -0,0 +1,127 @@
/*************************************************************************************
* 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.litecoin.sources.btce;
import java.math.BigDecimal;
public class BTCeResponse {
private Ticker ticker;
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;
private long server_time;
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;
}
public long getServer_time() {
return server_time;
}
public void setServer_time(long server_time) {
this.server_time = server_time;
}
}
public Ticker getTicker() {
return ticker;
}
public void setTicker(Ticker ticker) {
this.ticker = ticker;
}
}

View File

@ -0,0 +1,32 @@
/*************************************************************************************
* 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.litecoin.sources.btce;
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/2/")
@Produces(MediaType.APPLICATION_JSON)
public interface IBTCeRateAPI {
@GET
@Path("{cryptocurrency}_{fiatcurrency}/ticker")
BTCeResponse getTicker(@PathParam("cryptocurrency") String cryptoCurrency, @PathParam("fiatcurrency") String fiatCurrency);
}

View File

@ -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.litecoin.wallets.litecoind;
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 LitecoindRPCWallet implements IWallet{
private static final Logger log = LoggerFactory.getLogger(LitecoindRPCWallet.class);
private static final String CRYPTO_CURRENCY = ICurrencies.LTC;
public LitecoindRPCWallet(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) {
if (!CRYPTO_CURRENCY.equalsIgnoreCase(cryptoCurrency)) {
log.error("Litecoind wallet error: unknown cryptocurrency.");
return null;
}
log.info("Litecoind 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("Litecoind 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("Litecoind 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;
}
}