-
Notifications
You must be signed in to change notification settings - Fork 241
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
phffmn
wants to merge
8
commits into
GENERALBYTESCOM:master
Choose a base branch
from
phffmn:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...n/java/com/generalbytes/batm/server/extensions/extra/ucacoin/UcacoinAddressValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
135 changes: 135 additions & 0 deletions
135
...src/main/java/com/generalbytes/batm/server/extensions/extra/ucacoin/UcacoinExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) { | ||
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; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.