add support for BTCP
This commit is contained in:
parent
e4cafbfeb2
commit
fbf7a1e9ae
|
@ -25,6 +25,7 @@ import java.util.List;
|
|||
public class Currencies {
|
||||
public static final String BTC = "BTC";
|
||||
public static final String BCH = "BCH"; //Bitcoin Cash
|
||||
public static final String BTCP = "BTCP"; //Bitcoin Private
|
||||
public static final String BTX = "BTX"; //BitCore
|
||||
public static final String ETH = "ETH";
|
||||
public static final String LTC = "LTC";
|
||||
|
@ -74,6 +75,7 @@ public class Currencies {
|
|||
List<String> crypto = new ArrayList<>();
|
||||
crypto.add(BTC);
|
||||
crypto.add(BCH);
|
||||
crypto.add(BTCP);
|
||||
crypto.add(BTX);
|
||||
crypto.add(ETH);
|
||||
crypto.add(LTC);
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
package com.generalbytes.batm.server.extensions.extra.bitcoinprivate;
|
||||
|
||||
import com.generalbytes.batm.server.coinutil.AddressFormatException;
|
||||
import com.generalbytes.batm.server.coinutil.Base58;
|
||||
import com.generalbytes.batm.server.extensions.ICryptoAddressValidator;
|
||||
|
||||
/**
|
||||
* Created by Pega88 on 6/8/18.
|
||||
*/
|
||||
public class BitcoinPrivateAddressValidator implements ICryptoAddressValidator {
|
||||
@Override
|
||||
public boolean isAddressValid(String address) {
|
||||
if (address.startsWith("b1") || address.startsWith("bx") || address.startsWith("zk")) {
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,120 @@
|
|||
package com.generalbytes.batm.server.extensions.extra.bitcoinprivate;
|
||||
|
||||
import com.generalbytes.batm.server.extensions.*;
|
||||
import com.generalbytes.batm.server.extensions.extra.bitcoinprivate.sources.FixPriceRateSource;
|
||||
import com.generalbytes.batm.server.extensions.extra.bitcoinprivate.wallets.btcpd.BitcoinPrivateRPCWallet;
|
||||
import com.generalbytes.batm.server.extensions.extra.dash.sources.coinmarketcap.CoinmarketcapRateSource;
|
||||
import com.generalbytes.batm.server.extensions.watchlist.IWatchList;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
/**
|
||||
* Created by Pega88 on 6/8/18.
|
||||
*/
|
||||
public class BitcoinPrivateExtension implements IExtension {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "BATM Bitcoin Private extra extension";
|
||||
}
|
||||
|
||||
@Override
|
||||
public IExchange createExchange(String exchangeLogin) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPaymentProcessor createPaymentProcessor(String paymentProcessorLogin) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWallet createWallet(String walletLogin) {
|
||||
if (walletLogin != null && !walletLogin.trim().isEmpty()) {
|
||||
StringTokenizer st = new StringTokenizer(walletLogin, ":");
|
||||
String walletType = st.nextToken();
|
||||
|
||||
if ("btcpd".equalsIgnoreCase(walletType)) {
|
||||
String protocol = st.nextToken();
|
||||
String username = st.nextToken();
|
||||
String password = st.nextToken();
|
||||
String hostname = st.nextToken();
|
||||
String port = st.nextToken();
|
||||
String accountName = "";
|
||||
if (st.hasMoreTokens()) {
|
||||
accountName = st.nextToken();
|
||||
}
|
||||
|
||||
|
||||
if (protocol != null && username != null && password != null && hostname != null && port != null && accountName != null) {
|
||||
String rpcURL = protocol + "://" + username + ":" + password + "@" + hostname + ":" + port;
|
||||
return new BitcoinPrivateRPCWallet(rpcURL, accountName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICryptoAddressValidator createAddressValidator(String cryptoCurrency) {
|
||||
if (Currencies.BTCP.equalsIgnoreCase(cryptoCurrency)) {
|
||||
return new BitcoinPrivateAddressValidator();
|
||||
}
|
||||
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 ("coinmarketcap".equalsIgnoreCase(exchangeType)) {
|
||||
String preferedFiatCurrency = Currencies.USD;
|
||||
if (st.hasMoreTokens()) {
|
||||
preferedFiatCurrency = st.nextToken().toUpperCase();
|
||||
}
|
||||
return new CoinmarketcapRateSource(preferedFiatCurrency);
|
||||
} else if ("btcpfix".equalsIgnoreCase(exchangeType)) {
|
||||
BigDecimal rate = BigDecimal.ZERO;
|
||||
if (st.hasMoreTokens()) {
|
||||
try {
|
||||
rate = new BigDecimal(st.nextToken());
|
||||
} catch (Throwable e) {
|
||||
}
|
||||
}
|
||||
String preferedFiatCurrency = Currencies.USD;
|
||||
if (st.hasMoreTokens()) {
|
||||
preferedFiatCurrency = st.nextToken().toUpperCase();
|
||||
}
|
||||
return new FixPriceRateSource(rate, preferedFiatCurrency);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getSupportedCryptoCurrencies() {
|
||||
Set<String> result = new HashSet<>();
|
||||
result.add(Currencies.BTCP);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getSupportedWatchListsNames() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWatchList getWatchList(String name) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
package com.generalbytes.batm.server.extensions.extra.bitcoinprivate.sources;
|
||||
|
||||
import com.generalbytes.batm.server.extensions.Currencies;
|
||||
|
||||
import com.generalbytes.batm.server.extensions.IRateSource;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Created by Pega88 on 6/8/18.
|
||||
*/
|
||||
public class FixPriceRateSource implements IRateSource {
|
||||
private BigDecimal rate = BigDecimal.ZERO;
|
||||
|
||||
private String preferedFiatCurrency = Currencies.USD;
|
||||
|
||||
public FixPriceRateSource(BigDecimal rate,String preferedFiatCurrency) {
|
||||
this.rate = rate;
|
||||
if (Currencies.EUR.equalsIgnoreCase(preferedFiatCurrency)) {
|
||||
this.preferedFiatCurrency = Currencies.EUR;
|
||||
}
|
||||
if (Currencies.USD.equalsIgnoreCase(preferedFiatCurrency)) {
|
||||
this.preferedFiatCurrency = Currencies.USD;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getCryptoCurrencies() {
|
||||
Set<String> result = new HashSet<>();
|
||||
result.add(Currencies.BTCP);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getExchangeRateLast(String cryptoCurrency, String fiatCurrency) {
|
||||
if (Currencies.BTCP.equalsIgnoreCase(cryptoCurrency)) {
|
||||
return rate;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getFiatCurrencies() {
|
||||
Set<String> result = new HashSet<>();
|
||||
result.add(Currencies.USD);
|
||||
result.add(Currencies.EUR);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferredFiatCurrency() {
|
||||
return preferedFiatCurrency;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,106 @@
|
|||
package com.generalbytes.batm.server.extensions.extra.bitcoinprivate.wallets.btcpd;
|
||||
|
||||
import com.azazar.bitcoin.jsonrpcclient.BitcoinException;
|
||||
import com.azazar.bitcoin.jsonrpcclient.BitcoinJSONRPCClient;
|
||||
import com.generalbytes.batm.server.extensions.Currencies;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Created by Pega88 on 6/8/18.
|
||||
*/
|
||||
public class BitcoinPrivateRPCWallet implements IWallet {
|
||||
private static final Logger log = LoggerFactory.getLogger(BitcoinPrivateRPCWallet.class);
|
||||
private static final String CRYPTO_CURRENCY = Currencies.BTCP;
|
||||
|
||||
public BitcoinPrivateRPCWallet(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("btcpd wallet error: unknown cryptocurrency.");
|
||||
return null;
|
||||
}
|
||||
|
||||
log.info("btcpd 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("btcpd 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("btcpd 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;
|
||||
}
|
||||
}
|
|
@ -41,6 +41,7 @@ public class CoinmarketcapRateSource implements IRateSource {
|
|||
coinIDs.put(Currencies.XMR, 328);
|
||||
coinIDs.put(Currencies.POT, 122);
|
||||
coinIDs.put(Currencies.FLASH, 1755);
|
||||
coinIDs.put(Currencies.BTCP, 2575);
|
||||
}
|
||||
|
||||
public CoinmarketcapRateSource() {
|
||||
|
@ -60,6 +61,7 @@ public class CoinmarketcapRateSource implements IRateSource {
|
|||
result.add(Currencies.XMR);
|
||||
result.add(Currencies.POT);
|
||||
result.add(Currencies.FLASH);
|
||||
result.add(Currencies.BTCP);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -65,6 +65,7 @@
|
|||
<cryptocurrency>XMR</cryptocurrency>
|
||||
<cryptocurrency>POT</cryptocurrency>
|
||||
<cryptocurrency>BTX</cryptocurrency>
|
||||
<cryptocurrency>BTCP</cryptocurrency>
|
||||
</ratesource>
|
||||
<paymentprocessor prefix="bitcoinpay" name="BitcoinPay.com" >
|
||||
<param name="apikey" />
|
||||
|
@ -482,4 +483,20 @@
|
|||
</ratesource>
|
||||
<cryptologo cryptocurrency="FTO" file="fto.png"/>
|
||||
</extension>
|
||||
<extension class="com.generalbytes.batm.server.extensions.extra.bitcoinprivate.BitcoinPrivateExtension" >
|
||||
<wallet prefix="btcpd" name="Bitcoinprivated">
|
||||
<param name="protocol" />
|
||||
<param name="user" />
|
||||
<param name="password" />
|
||||
<param name="host" />
|
||||
<param name="port" />
|
||||
<param name="accountname" />
|
||||
<cryptocurrency>BTCP</cryptocurrency>
|
||||
</wallet>
|
||||
<ratesource prefix="btcpfix" name ="Fix Price" >
|
||||
<param name="price" />
|
||||
<cryptocurrency>BTCP</cryptocurrency>
|
||||
</ratesource>
|
||||
<cryptologo cryptocurrency="BTCP" file="btcp.png"/>
|
||||
</extension>
|
||||
</extensions>
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
Loading…
Reference in New Issue