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

Add Sell Option to the Verum Coin #829

Open
wants to merge 10 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 @@ -94,6 +94,7 @@ public class CoinGeckoRateSource implements IRateSource {
CRYPTOCURRENCIES.put(CryptoCurrency.USDTTRON.getCode(), "tether"); // using USDT for rate source
CRYPTOCURRENCIES.put(CryptoCurrency.USDS.getCode(), "stableusd");
CRYPTOCURRENCIES.put(CryptoCurrency.VIA.getCode(), "viacoin");
CRYPTOCURRENCIES.put(CryptoCurrency.VERUM.getCode(), "verum-coin");
CRYPTOCURRENCIES.put(CryptoCurrency.VOLTZ.getCode(), "voltz");
CRYPTOCURRENCIES.put(CryptoCurrency.WDC.getCode(), "worldcoin");
CRYPTOCURRENCIES.put(CryptoCurrency.XMR.getCode(), "monero");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public class CoinPaprikaRateSource implements IRateSource {
CRYPTOCURRENCIES.put(CryptoCurrency.USDT.getCode(), "usdt-tether");
CRYPTOCURRENCIES.put(CryptoCurrency.USDTTRON.getCode(), "usdt-tether"); // using USDT for rate source
CRYPTOCURRENCIES.put(CryptoCurrency.VIA.getCode(), "via-viacoin");
CRYPTOCURRENCIES.put(CryptoCurrency.VERUM.getCode(), "verum-verum-coin");
CRYPTOCURRENCIES.put(CryptoCurrency.VOLTZ.getCode(), "voltz-voltz");
CRYPTOCURRENCIES.put(CryptoCurrency.WDC.getCode(), "wdc-worldcoin");
CRYPTOCURRENCIES.put(CryptoCurrency.XMR.getCode(), "xmr-monero");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*************************************************************************************
* 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.verumcoin;

import com.generalbytes.batm.server.extensions.CryptoCurrencyDefinition;
import com.generalbytes.batm.common.currencies.CryptoCurrency;
import com.generalbytes.batm.server.extensions.payment.IPaymentSupport;

public class VerumcoinDefinition extends CryptoCurrencyDefinition{
private IPaymentSupport paymentSupport = new VerumcoinPaymentSupport();

public VerumcoinDefinition() {
super(CryptoCurrency.VERUM.getCode(), "Verumcoin", "verumcoin","https://verumchain.info");
}

@Override
public IPaymentSupport getPaymentSupport() {
return paymentSupport;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package com.generalbytes.batm.server.extensions.extra.verumcoin;

import com.generalbytes.batm.common.currencies.CryptoCurrency;
import com.generalbytes.batm.server.extensions.ICryptoCurrencyDefinition;
import com.generalbytes.batm.common.currencies.FiatCurrency;
import com.generalbytes.batm.server.extensions.*;
import com.generalbytes.batm.server.extensions.FixPriceRateSource;
Expand All @@ -31,6 +32,8 @@

public class VerumcoinExtension extends AbstractExtension{

private static final ICryptoCurrencyDefinition DEFINITION = new VerumcoinDefinition();

@Override
public String getName() {
return "BATM Verumcoin extension";
Expand All @@ -52,21 +55,21 @@ public IWallet createWallet(String walletLogin, String tunnelPassword) {
String password = st.nextToken();
String hostname = st.nextToken();
int port = Integer.parseInt(st.nextToken());
String label = "";
String accountName = "";
if (st.hasMoreTokens()) {
label = st.nextToken();
accountName = st.nextToken();
}

InetSocketAddress tunnelAddress = ctx.getTunnelManager().connectIfNeeded(walletLogin, tunnelPassword, InetSocketAddress.createUnresolved(hostname, port));
hostname = tunnelAddress.getHostString();
port = tunnelAddress.getPort();

if (protocol != null && username != null && password != null && hostname !=null && label != null) {
if (protocol != null && username != null && password != null && hostname !=null && accountName != null) {
String rpcURL = protocol +"://" + username +":" + password + "@" + hostname +":" + port;
if ("verumcoindnoforward".equalsIgnoreCase(walletType)) {
return new VerumcoindUniqueAddressRPCWallet(rpcURL);
return new VerumcoindUniqueAddressRPCWallet(rpcURL, accountName);
}
return new VerumcoindRPCWallet(rpcURL, label);
return new VerumcoindRPCWallet(rpcURL, accountName);
}
}
}
Expand Down Expand Up @@ -118,4 +121,12 @@ public Set<String> getSupportedCryptoCurrencies() {
result.add(CryptoCurrency.VERUM.getCode());
return result;
}

@Override
public Set<ICryptoCurrencyDefinition> getCryptoCurrencyDefinitions() {
Set<ICryptoCurrencyDefinition> result = new HashSet<>();
result.add(DEFINITION);
return result;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*************************************************************************************
* 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.verumcoin;

import com.generalbytes.batm.common.currencies.CryptoCurrency;
import com.generalbytes.batm.server.extensions.ICryptoAddressValidator;
import com.generalbytes.batm.server.extensions.extra.common.AbstractRPCPaymentSupport;
import com.generalbytes.batm.server.extensions.extra.common.RPCClient;
import com.generalbytes.batm.server.extensions.payment.PaymentRequest;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.concurrent.TimeUnit;

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

public class VerumcoinPaymentSupport extends AbstractRPCPaymentSupport {
private static final Logger log = LoggerFactory.getLogger(VerumcoinPaymentSupport.class);

private VerumcoinAddressValidator addressValidator = new VerumcoinAddressValidator();

private static final long MAXIMUM_WAIT_FOR_POSSIBLE_REFUND_MILLIS = TimeUnit.DAYS.toMillis(3); // 3 days
private static final long MAXIMUM_WATCHING_TIME_MILLIS = TimeUnit.DAYS.toMillis(3); // 3 days (exactly plus Sell Offer Expiration 5-120 minutes)

@Override
public String getCurrency() {
return CryptoCurrency.VERUM.getCode();
}

@Override
public long getMaximumWatchingTimeMillis() {
return MAXIMUM_WATCHING_TIME_MILLIS;
}

@Override
public long getMaximumWaitForPossibleRefundInMillis() {
return MAXIMUM_WAIT_FOR_POSSIBLE_REFUND_MILLIS;
}

@Override
public BigDecimal getMinimumNetworkFee(RPCClient client) {
return client.getNetworkInfo().relayFee();
}

@Override
public ICryptoAddressValidator getAddressValidator() {
return addressValidator;
}

@Override
public int calculateTransactionSize(int numberOfInputs, int numberOfOutputs) {
return (numberOfInputs * 149) + (numberOfOutputs * 34) + 10;
}

@Override
public BigDecimal calculateTxFee(int numberOfInputs, int numberOfOutputs, RPCClient client) {
final int transactionSize = calculateTransactionSize(numberOfInputs, numberOfOutputs);
try {
BigDecimal estimate = new BigDecimal(client.getEstimateFee());
if (BigDecimal.ZERO.compareTo(estimate) == 0 || estimate.compareTo(new BigDecimal("-1")) == 0 ) {
//bitcoind is clueless
return getMinimumNetworkFee(client);
}
return estimate.divide(new BigDecimal("1000"), RoundingMode.UP).multiply(new BigDecimal(transactionSize));
} catch (Exception e) {
log.error("CUSTOM VERUM LOG", e);
return getMinimumNetworkFee(client);
}
}

@Override
public String getSigHashType() {
return "ALL";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Bitcoin-JSON-RPC-Client License
*
* Copyright (c) 2013, Mikhail Yevchenko.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the
* Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
* THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.generalbytes.batm.server.extensions.extra.verumcoin.wallets;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Map;

import wf.bitcoin.krotjson.HexCoder;

class MapWrapper {

public final Map m;

public MapWrapper(Map m) {
this.m = m;
}

public Boolean mapBool(String key) {
return mapBool(m, key);
}

public Integer mapInt(String key) {
return mapInt(m, key);
}

public Long mapLong(String key) {
return mapLong(m, key);
}

public String mapStr(String key) {
return mapStr(m, key);
}

public Date mapCTime(String key) {
return mapCTime(m, key);
}

public BigDecimal mapBigDecimal(String key) {
return mapBigDecimal(m, key);
}

public byte[] mapHex(String key) {
return mapHex(m, key);
}

public static Boolean mapBool(Map m, String key) {
Object val = m.get(key);
return val instanceof Boolean ? (Boolean) val : Boolean.FALSE;
}

public static BigDecimal mapBigDecimal(Map m, String key) {
Object val = m.get(key);
return val instanceof BigDecimal ? (BigDecimal) val : new BigDecimal((String) val);
}

public static Integer mapInt(Map m, String key) {
Object val = m.get(key);
return val instanceof Number ? ((Number) val).intValue() : null;
}

public static Long mapLong(Map m, String key) {
Object val = m.get(key);
return val instanceof Number ? ((Number) val).longValue() : null;
}

public static String mapStr(Map m, String key) {
Object v = m.get(key);
return v == null ? null : String.valueOf(v);
}

public static Date mapCTime(Map m, String key) {
Object v = m.get(key);
return v == null ? null : new Date(mapLong(m, key) * 1000);
}

public static byte[] mapHex(Map m, String key) {
Object v = m.get(key);
return v == null ? null : HexCoder.decode((String) v);
}

@Override
public String toString() {
return String.valueOf(m);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*************************************************************************************
* 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.verumcoin.wallets;

import wf.bitcoin.javabitcoindrpcclient.BitcoindRpcClient.Transaction;

public interface VerumcoinTransaction extends Transaction {
boolean instantlock();
boolean instantlock_internal();
}
Loading
Loading