Added NuBits files and resources
This commit is contained in:
parent
1630e5a728
commit
9813472c5a
Binary file not shown.
After Width: | Height: | Size: 57 KiB |
|
@ -0,0 +1,45 @@
|
||||||
|
package com.generalbytes.batm.server.extensions.extra.nubits;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by woolly_sammoth on 11/12/14.
|
||||||
|
*/
|
||||||
|
public class NubitsAddressValidator implements ICryptoAddressValidator {
|
||||||
|
@Override
|
||||||
|
public boolean isAddressValid(String address) {
|
||||||
|
boolean result = isNubitsAddressValid(address);
|
||||||
|
if (!result) {
|
||||||
|
result = isPaperWalletSupported() && ExtensionsUtil.isValidEmailAddress(address);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isNubitsAddressValid(String address) {
|
||||||
|
if (address.startsWith("B")) {
|
||||||
|
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,97 @@
|
||||||
|
package com.generalbytes.batm.server.extensions.extra.nubits;
|
||||||
|
|
||||||
|
import com.generalbytes.batm.server.extensions.*;
|
||||||
|
import com.generalbytes.batm.server.extensions.extra.nubits.NubitsAddressValidator;
|
||||||
|
import com.generalbytes.batm.server.extensions.extra.nubits.sources.FixPriceRateSource;
|
||||||
|
import com.generalbytes.batm.server.extensions.extra.nubits.wallets.nud.NubitsRPCWallet;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by woolly_sammoth on 11/12/14.
|
||||||
|
*/
|
||||||
|
public class NubitsExtension implements IExtension{
|
||||||
|
@Override
|
||||||
|
public String getName() { return "BATM Nubits 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 ("nudd".equalsIgnoreCase(walletType)) {
|
||||||
|
//"nud: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 NubitsRPCWallet(rpcURL,accountName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ICryptoAddressValidator createAddressValidator(String cryptoCurrency) {
|
||||||
|
if (ICurrencies.NBT.equalsIgnoreCase(cryptoCurrency)) {
|
||||||
|
return new NubitsAddressValidator();
|
||||||
|
}
|
||||||
|
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 ("nbtfix".equalsIgnoreCase(exchangeType)) {
|
||||||
|
BigDecimal rate = BigDecimal.ZERO;
|
||||||
|
if (st.hasMoreTokens()) {
|
||||||
|
try {
|
||||||
|
rate = new BigDecimal(st.nextToken());
|
||||||
|
} catch (Throwable e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new FixPriceRateSource(rate);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
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.NBT);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
package com.generalbytes.batm.server.extensions.extra.nubits.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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by woolly_sammoth on 11/12/14.
|
||||||
|
*/
|
||||||
|
public class FixPriceRateSource implements IRateSource {
|
||||||
|
private BigDecimal rate = BigDecimal.ZERO;
|
||||||
|
|
||||||
|
public FixPriceRateSource(BigDecimal rate) {
|
||||||
|
this.rate = rate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<String> getCryptoCurrencies() {
|
||||||
|
Set<String> result = new HashSet<String>();
|
||||||
|
result.add(ICurrencies.NBT);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BigDecimal getExchangeRateLast(String cryptoCurrency, String fiatCurrency) {
|
||||||
|
if (ICurrencies.ICG.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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,106 @@
|
||||||
|
package com.generalbytes.batm.server.extensions.extra.nubits.wallets.nud;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by woolly_sammoth on 11/12/14.
|
||||||
|
*/
|
||||||
|
public class NubitsRPCWallet implements IWallet{
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(NubitsRPCWallet.class);
|
||||||
|
private static final String CRYPTO_CURRENCY = ICurrencies.NBT;
|
||||||
|
|
||||||
|
public NubitsRPCWallet(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("Nud wallet error: unknown cryptocurrency.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("Nud 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("Nud 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("Nud 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue