Skip to content

Commit

Permalink
Merge pull request #895 from drocek/BATM-5752_added_optional_paramete…
Browse files Browse the repository at this point in the history
…rs_to_bitgo

BATM-5752: added optional parameters to BitGo
  • Loading branch information
Houskov authored Jan 23, 2024
2 parents 9692dcb + e50ff33 commit 442c025
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 23 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# buildscript - project id
projectGroup=com.generalbytes.batm.public
projectVersion=1.3.6
projectVersion=1.3.7

# buildscript - common dependency versions
bitrafaelVersion=1.0.44
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*************************************************************************************
* Copyright (C) 2014-2020 GENERAL BYTES s.r.o. All rights reserved.
* Copyright (C) 2014-2024 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
Expand Down Expand Up @@ -285,9 +285,11 @@ public IWallet createWallet(String walletLogin, String tunnelPassword) {
String proxyUrl = st.nextToken("\n").replaceFirst(":", "");
return new BitcoreWallet(apiKey, proxyUrl);
} else if ("bitgo".equalsIgnoreCase(walletType) || "bitgonoforward".equalsIgnoreCase(walletType)) {
// bitgo:host:port:token:wallet_address:wallet_passphrase:num_blocks
// bitgo:host:port:token:wallet_address:wallet_passphrase:num_blocks:fee_rate:max_fee_rate
// but host is optionally including the "http://" and port is optional,
// num_blocks is an optional integer greater than 2 and it's used to calculate mining fee.
// num_blocks is an optional integer greater than 2 and it's used to calculate mining fee,
// fee_rate is an optional integer defined fee rate,
// max_fee_rate is an optional integer defined maximum fee rate.
// bitgo:http://localhost:80:token:wallet_address:wallet_passphrase
// bitgo:http://localhost:token:wallet_address:wallet_passphrase
// bitgo:localhost:token:wallet_address:wallet_passphrase
Expand Down Expand Up @@ -322,22 +324,22 @@ public IWallet createWallet(String walletLogin, String tunnelPassword) {
host = tunnelAddress.getHostString();
port = tunnelAddress.getPort();

String blocks;
int num;
Integer numBlocks = 2;
if(st.hasMoreTokens()){
blocks = st.nextToken();
num = Integer.parseInt(blocks);
if(num > 2) {
numBlocks = num;
}
int numBlocks = 2;
if (st.hasMoreTokens()) {
int number = Integer.parseInt(st.nextToken());
if (number > 2) {
numBlocks = number;
}
}

Integer feeRate = st.hasMoreTokens() ? Integer.parseInt(st.nextToken()) : null;
Integer maxFeeRate = st.hasMoreTokens() ? Integer.parseInt(st.nextToken()) : null;

if ("bitgonoforward".equalsIgnoreCase(walletType)) {
return new BitgoWalletWithUniqueAddresses(scheme, host, port, token, walletId, walletPassphrase, numBlocks);
return new BitgoWalletWithUniqueAddresses(scheme, host, port, token, walletId, walletPassphrase, numBlocks, feeRate, maxFeeRate);
}

return new BitgoWallet(scheme, host, port, token, walletId, walletPassphrase, numBlocks);
return new BitgoWallet(scheme, host, port, token, walletId, walletPassphrase, numBlocks, feeRate, maxFeeRate);

} else if ("coinbasewallet2".equalsIgnoreCase(walletType)
|| "coinbasewallet2noforward".equalsIgnoreCase(walletType)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*************************************************************************************
* Copyright (C) 2014-2020 GENERAL BYTES s.r.o. All rights reserved.
* Copyright (C) 2014-2024 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
Expand Down Expand Up @@ -57,6 +57,8 @@ public class BitgoWallet implements IWallet, ICanSendMany {
protected String url;
protected static final Integer readTimeout = 90 * 1000; //90 seconds
protected Integer numBlocks;
protected Integer feeRate;
protected Integer maxFeeRate;

protected static final Map<String, String> cryptoCurrencies = new HashMap<String, String>() {
{
Expand Down Expand Up @@ -93,10 +95,16 @@ private int pow10Exp(BigDecimal val) {
};

public BitgoWallet(String scheme, String host, int port, String token, String walletId, String walletPassphrase, Integer numBlocks) {
this(scheme, host, port, token, walletId, walletPassphrase, numBlocks, null, null);
}

public BitgoWallet(String scheme, String host, int port, String token, String walletId, String walletPassphrase, Integer numBlocks, Integer feeRate, Integer maxFeeRate) {
this.walletId = walletId;
this.walletPassphrase = walletPassphrase;
this.url = new HttpUrl.Builder().scheme(scheme).host(host).port(port).build().toString();
this.numBlocks = numBlocks;
this.feeRate = feeRate;
this.maxFeeRate = maxFeeRate;

ClientConfig config = new ClientConfig();
config.setHttpReadTimeout(readTimeout);
Expand Down Expand Up @@ -146,7 +154,7 @@ public String sendMany(Collection<Transfer> transfers, String cryptoCurrency, St
@Override
public String sendCoins(String destinationAddress, BigDecimal amount, String cryptoCurrency, String description) {
try {
final BitGoCoinRequest request = new BitGoCoinRequest(destinationAddress, toSatoshis(amount, cryptoCurrency), walletPassphrase, description, this.numBlocks);
final BitGoCoinRequest request = new BitGoCoinRequest(destinationAddress, toSatoshis(amount, cryptoCurrency), walletPassphrase, description, this.numBlocks, this.feeRate, this.maxFeeRate);
String bitgoCryptoCurrency = cryptoCurrencies.get(cryptoCurrency);
return getResultTxId(api.sendCoins(bitgoCryptoCurrency, this.walletId, request));
} catch (HttpStatusIOException hse) {
Expand All @@ -172,7 +180,7 @@ private Integer getDecimals(String cryptoCurrency) {

@Override
public String getCryptoAddress(String cryptoCurrency) {
if(cryptoCurrency == null) {
if (cryptoCurrency == null) {
cryptoCurrency = getPreferredCryptoCurrency();
}
String bitgoCryptoCurrency = cryptoCurrencies.get(cryptoCurrency);
Expand All @@ -181,18 +189,18 @@ public String getCryptoAddress(String cryptoCurrency) {
}
try {
final Map<String, Object> response = api.getWalletById(bitgoCryptoCurrency, walletId);
if(response == null || response.isEmpty()) {
if (response == null || response.isEmpty()) {
return null;
}

Object receiveAddressObj = response.get("receiveAddress");
if(receiveAddressObj == null || !(receiveAddressObj instanceof Map)) {
if (!(receiveAddressObj instanceof Map)) {
return null;
}

Map receiveAddressMap = (Map)receiveAddressObj;
Object addressObj = receiveAddressMap.get("address");
if(addressObj == null || !(addressObj instanceof String)) {
if (!(addressObj instanceof String)) {
return null;
}
return (String)addressObj;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*************************************************************************************
* Copyright (C) 2014-2020 GENERAL BYTES s.r.o. All rights reserved.
* Copyright (C) 2014-2024 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
Expand Down Expand Up @@ -46,6 +46,10 @@ public BitgoWalletWithUniqueAddresses(String scheme, String host, int port, Stri
super(scheme, host, port, token, walletId, walletPassphrase, numBlocks);
}

public BitgoWalletWithUniqueAddresses(String scheme, String host, int port, String token, String walletId, String walletPassphrase, Integer numBlocks, Integer feeRate, Integer maxFeeRate) {
super(scheme, host, port, token, walletId, walletPassphrase, numBlocks, feeRate, maxFeeRate);
}

@Override
public String generateNewDepositCryptoAddress(String cryptoCurrency, String label) {
if (cryptoCurrency == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*************************************************************************************
* Copyright (C) 2014-2020 GENERAL BYTES s.r.o. All rights reserved.
* Copyright (C) 2014-2024 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
Expand All @@ -23,6 +23,8 @@ public class BitGoCoinRequest {
private String walletPassphrase;
private Integer numBlocks;
private String comment;
private Integer feeRate;
private Integer maxFeeRate;


public BitGoCoinRequest(String address, String amount, String walletPassphrase, String comment, Integer numBlocks) {
Expand All @@ -33,6 +35,13 @@ public BitGoCoinRequest(String address, String amount, String walletPassphrase,
this.comment = comment;
}

public BitGoCoinRequest(String address, String amount, String walletPassphrase, String comment, Integer numBlocks, Integer feeRate, Integer maxFeeRate) {
this(address, amount, walletPassphrase, comment, numBlocks);

this.feeRate = feeRate;
this.maxFeeRate = maxFeeRate;
}

public String getAddress() {
return address;
}
Expand Down Expand Up @@ -72,4 +81,20 @@ public String getComment() {
public void setComment(String comment){
this.comment = comment;
}

public Integer getFeeRate() {
return feeRate;
}

public void setFeeRate(Integer feeRate) {
this.feeRate = feeRate;
}

public Integer getMaxFeeRate() {
return maxFeeRate;
}

public void setMaxFeeRate(Integer maxFeeRate) {
this.maxFeeRate = maxFeeRate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
<param name="wallet_id" />
<param name="wallet_passphrase" />
<param name="num_blocks" />
<param name="fee_rate" />
<param name="max_fee_rate" />
<cryptocurrency buyonly="true">BCH</cryptocurrency>
<cryptocurrency>BTC</cryptocurrency>
<cryptocurrency>LTC</cryptocurrency>
Expand All @@ -54,6 +56,8 @@
<param name="wallet_id" />
<param name="wallet_passphrase" />
<param name="num_blocks" />
<param name="fee_rate" />
<param name="max_fee_rate" />
<cryptocurrency buyonly="true">BCH</cryptocurrency>
<cryptocurrency>BTC</cryptocurrency>
<cryptocurrency>LTC</cryptocurrency>
Expand Down

0 comments on commit 442c025

Please sign in to comment.