Skip to content

Commit

Permalink
Merge: Sync changes from 1.4 to master
Browse files Browse the repository at this point in the history
Sync changes from 1.4 to master
  • Loading branch information
filipocelka authored Apr 5, 2024
2 parents 1f7bc9c + 76d06cb commit 5342e1e
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 1 deletion.
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.5.0
projectVersion=1.5.1

# buildscript - common dependency versions
bitrafaelVersion=1.0.44
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ 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 API Specification: https://developers.bitgo.com/api/express.wallet.sendcoins
//
// 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,
Expand Down Expand Up @@ -340,6 +342,9 @@ public IWallet createWallet(String walletLogin, String tunnelPassword) {

Integer feeRate = st.hasMoreTokens() ? Integer.parseInt(st.nextToken()) : null;
Integer maxFeeRate = st.hasMoreTokens() ? Integer.parseInt(st.nextToken()) : null;
if (feeRate != null && (maxFeeRate == null || feeRate > maxFeeRate)) {
maxFeeRate = feeRate;
}

if ("bitgonoforward".equalsIgnoreCase(walletType)) {
return new BitgoWalletWithUniqueAddresses(scheme, host, port, token, walletId, walletPassphrase, numBlocks, feeRate, maxFeeRate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,4 +282,12 @@ public String getUrl() {
public String getWalletId() {
return walletId;
}

public Integer getFeeRate() {
return feeRate;
}

public Integer getMaxFeeRate() {
return maxFeeRate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
************************************************************************************/
package com.generalbytes.batm.server.extensions.extra.bitcoin.wallets.bitgo.v2.dto;

import com.fasterxml.jackson.annotation.JsonInclude;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class BitGoCoinRequest {
private String address;
private String amount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,40 @@ private void testUrl(String expected, String walletLogin) {
Assert.assertEquals(expected, ((BitgoWallet)bitgowallet).getUrl());
}

@Test
public void testCreateWalletBitGoFees() {
// Both fee rate and max fee rate are set -> parse fee rate and max fee rate individually
doTestCreateWalletBitGoFees(createBitGoWalletUrl(1000, 2000), 1000, 2000);
// Max fee rate is lower than fee rate -> use fee rate as max fee rate
doTestCreateWalletBitGoFees(createBitGoWalletUrl(1000, 500), 1000, 1000);
// Max fee rate is not set -> use fee rate as max fee rate
doTestCreateWalletBitGoFees(createBitGoWalletUrl(1000, null), 1000, 1000);
// Neither fee rate nor max fee rate is set -> expect nulls
doTestCreateWalletBitGoFees(createBitGoWalletUrl(null, null), null, null);
}

private String createBitGoWalletUrl(Integer feeRate, Integer maxFeeRate) {
StringBuilder builder = new StringBuilder("bitgo:http://localhost:3080:tokentoken:wallet_address:wallet_passphrase:2");
if (feeRate != null) {
builder.append(":").append(feeRate);
if (maxFeeRate != null) {
builder.append(":").append(maxFeeRate);
}
}
return builder.toString();
}

private void doTestCreateWalletBitGoFees(String url, Integer expectedFeeRate, Integer expectedMaxFeeRate) {
final BitcoinExtension bitcoinExtension = new BitcoinExtension();
bitcoinExtension.init(new TestExtensionContext());
final IWallet wallet = bitcoinExtension.createWallet(url, null);
Assert.assertTrue(wallet instanceof BitgoWallet);
final BitgoWallet bitgoWallet = (BitgoWallet) wallet;
Assert.assertNotNull(bitgoWallet);
Assert.assertEquals(expectedFeeRate, bitgoWallet.getFeeRate());
Assert.assertEquals(expectedMaxFeeRate, bitgoWallet.getMaxFeeRate());
}

@Test
public void bitgoFullTokenTest() {
String wallet = "bitgo:http://localhost:3080:v2x8d5e9e46379dc328b2039a400a12b04ea986689b38107fd84cd339bc89e3fb21:5b20e3a9266bbe80095757489d84a6bb:Vranec8586";
Expand Down

0 comments on commit 5342e1e

Please sign in to comment.