Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Support for UCA coin and BKEX exchange #449

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public enum CryptoCurrency {
TKN("TokenCard"),
TRTL("TurtleCoin"),
TRX("Tron"),
UCA("UCA"),
USDS("StableUSD"),
USDT("Tether"),
VIA("Viacoin"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*************************************************************************************
* Copyright (C) 2014-2020 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.ucacoin;

import com.generalbytes.batm.server.coinutil.AddressFormatException;
import com.generalbytes.batm.server.coinutil.Base58;
import com.generalbytes.batm.server.extensions.ICryptoAddressValidator;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class UcacoinAddressValidator implements ICryptoAddressValidator {
private static final Logger log = LoggerFactory.getLogger("batm.master.extensions.UcacoinAddressValidator");

@Override
public boolean isAddressValid(String address) {
if (address.startsWith("U")) {
try {
Base58.decodeToBigInteger(address);
Base58.decodeChecked(address);
} catch (AddressFormatException e) {
log.error("Error", e);
return false;
}
return true;
}else return false;
}

@Override
public boolean isPaperWalletSupported() {
return false;
}

@Override
public boolean mustBeBase58Address() {
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*************************************************************************************
* Copyright (C) 2014-2020 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.ucacoin;

import com.generalbytes.batm.common.currencies.CryptoCurrency;
import com.generalbytes.batm.common.currencies.FiatCurrency;
import com.generalbytes.batm.server.extensions.*;
import com.generalbytes.batm.server.extensions.extra.ucacoin.wallets.UcacoinRPCWallet;
import com.generalbytes.batm.server.extensions.extra.ucacoin.exchanges.bkex.BkexExchange;

import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class UcacoinExtension extends AbstractExtension{

private static final Logger LOG = LoggerFactory.getLogger("batm.master.bkexExchange");

@Override
public String getName() {
return "BATM Ucacoin extension";
}

@Override
public IWallet createWallet(String walletLogin, String tunnelPassword) {
if (walletLogin !=null && !walletLogin.trim().isEmpty()) {
StringTokenizer st = new StringTokenizer(walletLogin,":");
String walletType = st.nextToken();

if ("ucacoind".equalsIgnoreCase(walletType)) {
//"ucacoind: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 UcacoinRPCWallet(rpcURL,accountName);
}
}
if ("ucademo".equalsIgnoreCase(walletType)) {

String fiatCurrency = st.nextToken();
String walletAddress = "";
if (st.hasMoreTokens()) {
walletAddress = st.nextToken();
}

if (fiatCurrency != null && walletAddress != null) {
return new DummyExchangeAndWalletAndSource(fiatCurrency, CryptoCurrency.UCA.getCode(), walletAddress);
}
}
}
return null;
}

@Override
public ICryptoAddressValidator createAddressValidator(String cryptoCurrency) {
if (CryptoCurrency.UCA.getCode().equalsIgnoreCase(cryptoCurrency)) {
return new UcacoinAddressValidator();
}
return null;
}

@Override
public IRateSource createRateSource(String sourceLogin) {
if (sourceLogin != null && !sourceLogin.trim().isEmpty()) {
StringTokenizer st = new StringTokenizer(sourceLogin,":");
String exchangeType = st.nextToken();

if ("bkexRateSource".equalsIgnoreCase(exchangeType)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make "bkexRateSource" lowercase = "bkexratesource"
don't forget to fix also xml.

String preferredFiatCurrency = CryptoCurrency.USDT.getCode();

if (st.hasMoreTokens()) {
preferredFiatCurrency = st.nextToken().toUpperCase();
}

return BkexExchange.asRateSource(preferredFiatCurrency);
}

}
return null;
}
@Override
public Set<String> getSupportedCryptoCurrencies() {
Set<String> result = new HashSet<String>();
result.add(CryptoCurrency.UCA.getCode());
return result;
}

@Override
public IExchange createExchange(String paramString) {
if ((paramString != null) && (!paramString.trim().isEmpty())) {
StringTokenizer paramTokenizer = new StringTokenizer(paramString, ":");
String prefix = paramTokenizer.nextToken();
if ("bkex".equalsIgnoreCase(prefix)) {
String apiKey = paramTokenizer.nextToken();
String apiSecret = paramTokenizer.nextToken();
String preferredFiatCurrency = FiatCurrency.USD.getCode();
if (paramTokenizer.hasMoreTokens()) {
preferredFiatCurrency = paramTokenizer.nextToken().toUpperCase();
}
return BkexExchange.asExchange(apiKey, apiSecret, preferredFiatCurrency);
}
}

return null;
}
}
Loading