Add Bitcore (BTX)

Added Bitcore (BTX) to batm
This commit is contained in:
dArkjON 2017-12-01 19:13:20 +01:00
parent 45b4f4e4d6
commit c47c779ab1
7 changed files with 376 additions and 0 deletions

View File

@ -21,6 +21,7 @@ package com.generalbytes.batm.server.extensions;
public interface ICurrencies {
public static final String BTC = "BTC";
public static final String BCH = "BCH"; //Bitcoin Cash
public static final String BTX = "BTX"; //BitCore
public static final String ETH = "ETH";
public static final String LTC = "LTC";
public static final String DEX = "DEX";

View File

@ -0,0 +1,52 @@
/*************************************************************************************
* Copyright (C) 2014-2016 GENERAL BYTES s.r.o. All rights reserved.
*
* This software may be distributed and modified under the terms of the GNU
* General Public License version 2 (GPL2) as published by the Free Software
* Foundation and appearing in the file GPL2.TXT included in the packaging of
* this file. Please note that GPL2 Section 2[b] requires that all works based
* on this software must also be made publicly available under the terms of
* the GPL2 ("Copyleft").
*
* Contact information
* -------------------
*
* GENERAL BYTES s.r.o.
* Web : http://www.generalbytes.com
*
************************************************************************************/
package com.generalbytes.batm.server.extensions.extra.bitcore;
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 BitCoreAddressValidator implements ICryptoAddressValidator {
@Override
public boolean isAddressValid(String address) {
if (address.startsWith("1") || address.startsWith("3")) {
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,129 @@
/*************************************************************************************
* Copyright (C) 2014-2016 GENERAL BYTES s.r.o. All rights reserved.
*
* This software may be distributed and modified under the terms of the GNU
* General Public License version 2 (GPL2) as published by the Free Software
* Foundation and appearing in the file GPL2.TXT included in the packaging of
* this file. Please note that GPL2 Section 2[b] requires that all works based
* on this software must also be made publicly available under the terms of
* the GPL2 ("Copyleft").
*
* Contact information
* -------------------
*
* GENERAL BYTES s.r.o.
* Web : http://www.generalbytes.com
*
************************************************************************************/
package com.generalbytes.batm.server.extensions.extra.bitcore;
import com.generalbytes.batm.server.extensions.*;
import com.generalbytes.batm.server.extensions.extra.bitcre.sources.FixPriceRateSource;
import com.generalbytes.batm.server.extensions.extra.bitcore.wallets.bitcored.BitcoredRPCWallet;
import com.generalbytes.batm.server.extensions.watchlist.IWatchList;
import java.math.BigDecimal;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;
public class BitcoreExtension implements IExtension{
@Override
public String getName() {
return "BATM Bitcore 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 ("bitcored".equalsIgnoreCase(walletType)) {
//"bitcored: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 BitcoredRPCWallet(rpcURL,accountName);
}
}
}
return null;
}
@Override
public ICryptoAddressValidator createAddressValidator(String cryptoCurrency) {
if (ICurrencies.START.equalsIgnoreCase(cryptoCurrency)) {
return new StartcoinAddressValidator();
}
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 ("startfix".equalsIgnoreCase(exchangeType)) {
BigDecimal rate = BigDecimal.ZERO;
if (st.hasMoreTokens()) {
try {
rate = new BigDecimal(st.nextToken());
} catch (Throwable e) {
}
}
String preferedFiatCurrency = ICurrencies.USD;
if (st.hasMoreTokens()) {
preferedFiatCurrency = st.nextToken().toUpperCase();
}
return new FixPriceRateSource(rate,preferedFiatCurrency);
}
}
return null;
}
@Override
public IPaymentProcessor createPaymentProcessor(String paymentProcessorLogin) {
return null; //no payment processors available
}
@Override
public Set<String> getSupportedCryptoCurrencies() {
Set<String> result = new HashSet<String>();
result.add(ICurrencies.START);
return result;
}
@Override
public Set<String> getSupportedWatchListsNames() {
return null;
}
@Override
public IWatchList getWatchList(String name) {
return null;
}
}

View File

@ -0,0 +1,53 @@
package com.generalbytes.batm.server.extensions.extra.bitcore.sources;
import com.generalbytes.batm.server.extensions.ICurrencies;
import com.generalbytes.batm.server.extensions.IRateSource;
import java.math.BigDecimal;
import java.util.HashSet;
import java.util.Set;
public class FixPriceRateSource implements IRateSource {
private BigDecimal rate = BigDecimal.ZERO;
private String preferedFiatCurrency = ICurrencies.USD;
public FixPriceRateSource(BigDecimal rate,String preferedFiatCurrency) {
this.rate = rate;
if (ICurrencies.CAD.equalsIgnoreCase(preferedFiatCurrency)) {
this.preferedFiatCurrency = ICurrencies.EUR;
}
if (ICurrencies.USD.equalsIgnoreCase(preferedFiatCurrency)) {
this.preferedFiatCurrency = ICurrencies.USD;
}
}
@Override
public Set<String> getCryptoCurrencies() {
Set<String> result = new HashSet<String>();
result.add(ICurrencies.BTX);
return result;
}
@Override
public BigDecimal getExchangeRateLast(String cryptoCurrency, String fiatCurrency) {
if (ICurrencies.BTX.equalsIgnoreCase(cryptoCurrency)) {
return rate;
}
return null;
}
@Override
public Set<String> getFiatCurrencies() {
Set<String> result = new HashSet<String>();
result.add(ICurrencies.USD);
result.add(ICurrencies.EUR);
return result;
}
@Override
public String getPreferredFiatCurrency() {
return preferedFiatCurrency;
}
}

View File

@ -0,0 +1,120 @@
/*************************************************************************************
* Copyright (C) 2014-2016 GENERAL BYTES s.r.o. All rights reserved.
*
* This software may be distributed and modified under the terms of the GNU
* General Public License version 2 (GPL2) as published by the Free Software
* Foundation and appearing in the file GPL2.TXT included in the packaging of
* this file. Please note that GPL2 Section 2[b] requires that all works based
* on this software must also be made publicly available under the terms of
* the GPL2 ("Copyleft").
*
* Contact information
* -------------------
*
* GENERAL BYTES s.r.o.
* Web : http://www.generalbytes.com
*
************************************************************************************/
package com.generalbytes.batm.server.extensions.extra.bitcore.wallets.bitcored;
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 BitcoredRPCWallet implements IWallet{
private static final Logger log = LoggerFactory.getLogger(BitcoredRPCWallet.class);
private static final String CRYPTO_CURRENCY = ICurrencies.BTX;
public BitcoredRPCWallet(String rpcURL, String accountName) {
this.rpcURL = rpcURL;
this.accountName = accountName;
}
private String rpcURL;
private String accountName;
@Override
public Set<String> getCryptoCurrencies() {
Set<String> result = new HashSet<String>();
result.add(CRYPTO_CURRENCY);
return result;
}
@Override
public String getPreferredCryptoCurrency() {
return CRYPTO_CURRENCY;
}
@Override
public String sendCoins(String destinationAddress, BigDecimal amount, String cryptoCurrency, String description) {
if (!CRYPTO_CURRENCY.equalsIgnoreCase(cryptoCurrency)) {
log.error("Bitcored wallet error: unknown cryptocurrency.");
return null;
}
log.info("Bitcored 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("Bitcored 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("Bitcored wallet error: unknown cryptocurrency: " + cryptoCurrency);
return null;
}
try {
double balance = getClient(rpcURL).getBalance(accountName);
return BigDecimal.valueOf(balance);
} catch (BitcoinException e) {
e.printStackTrace();
return null;
}
}
private BitcoinJSONRPCClient getClient(String rpcURL) {
try {
return new BitcoinJSONRPCClient(rpcURL);
} catch (MalformedURLException e) {
e.printStackTrace();
}
return null;
}
}

View File

@ -62,6 +62,7 @@
<cryptocurrency>DASH</cryptocurrency>
<cryptocurrency>XMR</cryptocurrency>
<cryptocurrency>POT</cryptocurrency>
<cryptocurrency>BTX</cryptocurrency>
</ratesource>
<paymentprocessor prefix="bitcoinpay" name="BitcoinPay.com" >
<param name="apikey" />
@ -345,5 +346,25 @@
<cryptologo cryptocurrency="DEX" file="dex.png"/>
<cryptologo cryptocurrency="BCH" file="bch.png"/>
</extension>
<extension class="com.generalbytes.batm.server.extensions.extra.bitcore.BitcoreExtension" >
<wallet prefix="bitcored" name="Bitcored">
<param name="protocol" />
<param name="user" />
<param name="password" />
<param name="host" />
<param name="port" />
<param name="accountname" />
<cryptocurrency>BTX</cryptocurrency>
</wallet>
<ratesource prefix="coinmarketcap" name ="coinmarketcap.com" >
<param name="fiatcurrency" />
<cryptocurrency>BTX</cryptocurrency>
</ratesource>
<ratesource prefix="btxfix" name ="Fix Price" >
<param name="price" />
<cryptocurrency>BTX</cryptocurrency>
</ratesource>
<cryptologo cryptocurrency="BTX" file="btx.png"/>
</extension>
<extension class="com.generalbytes.batm.server.extensions.extra.watchlists.BasicWatchlistsExtension" />
</extensions>

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB