From a23f40f4f4ec83a1ce706845530d53e9367a62e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Pl=C3=A1nsk=C3=BD?= <67519977+d0by1@users.noreply.github.com> Date: Fri, 5 Apr 2024 13:03:19 +0200 Subject: [PATCH 1/2] BATM-6066 BitGo optional parameters error fix (#906) * BATM-6066 max_fee_rate cannot be lower than fee_rate * BATM-6066 Add test for parsing BitGo wallet * BATM-6066 Exclude null parameters from BitGoCoinRequest: null != undefined * BATM-6066 Increase version --- gradle.properties | 2 +- .../extra/bitcoin/BitcoinExtension.java | 5 +++ .../bitcoin/wallets/bitgo/v2/BitgoWallet.java | 8 +++++ .../bitgo/v2/dto/BitGoCoinRequest.java | 3 ++ .../extra/bitcoin/BitcoinExtensionTest.java | 34 +++++++++++++++++++ 5 files changed, 51 insertions(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index e3b1315d7..a0264bb36 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ # buildscript - project id projectGroup=com.generalbytes.batm.public -projectVersion=1.4.6 +projectVersion=1.4.7 # buildscript - common dependency versions bitrafaelVersion=1.0.44 diff --git a/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/bitcoin/BitcoinExtension.java b/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/bitcoin/BitcoinExtension.java index e31130f10..ce2410314 100644 --- a/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/bitcoin/BitcoinExtension.java +++ b/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/bitcoin/BitcoinExtension.java @@ -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, @@ -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); diff --git a/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/bitcoin/wallets/bitgo/v2/BitgoWallet.java b/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/bitcoin/wallets/bitgo/v2/BitgoWallet.java index d33a42ded..4d4d8a98e 100644 --- a/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/bitcoin/wallets/bitgo/v2/BitgoWallet.java +++ b/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/bitcoin/wallets/bitgo/v2/BitgoWallet.java @@ -282,4 +282,12 @@ public String getUrl() { public String getWalletId() { return walletId; } + + public Integer getFeeRate() { + return feeRate; + } + + public Integer getMaxFeeRate() { + return maxFeeRate; + } } diff --git a/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/bitcoin/wallets/bitgo/v2/dto/BitGoCoinRequest.java b/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/bitcoin/wallets/bitgo/v2/dto/BitGoCoinRequest.java index 3f9ad4b85..d08b64693 100644 --- a/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/bitcoin/wallets/bitgo/v2/dto/BitGoCoinRequest.java +++ b/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/bitcoin/wallets/bitgo/v2/dto/BitGoCoinRequest.java @@ -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; diff --git a/server_extensions_extra/src/test/java/com/generalbytes/batm/server/extensions/extra/bitcoin/BitcoinExtensionTest.java b/server_extensions_extra/src/test/java/com/generalbytes/batm/server/extensions/extra/bitcoin/BitcoinExtensionTest.java index 98e11c180..1a6fb7dd4 100644 --- a/server_extensions_extra/src/test/java/com/generalbytes/batm/server/extensions/extra/bitcoin/BitcoinExtensionTest.java +++ b/server_extensions_extra/src/test/java/com/generalbytes/batm/server/extensions/extra/bitcoin/BitcoinExtensionTest.java @@ -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"; From a2fc1eac0161e8edbad9658f0ab97a63a37b70aa Mon Sep 17 00:00:00 2001 From: Filip Ocelka Date: Fri, 5 Apr 2024 13:12:12 +0200 Subject: [PATCH 2/2] Remove duplicate repo settings from build.gradle files (#907) --- batm_ssh_tunnel/build.gradle | 4 ---- server_extensions_examples/build.gradle | 1 - server_extensions_template/build.gradle | 1 - settings.gradle | 4 ++++ 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/batm_ssh_tunnel/build.gradle b/batm_ssh_tunnel/build.gradle index 3fede2f26..646b2f252 100644 --- a/batm_ssh_tunnel/build.gradle +++ b/batm_ssh_tunnel/build.gradle @@ -3,10 +3,6 @@ plugins { id("shared-build-conventions") } -repositories { - mavenCentral() -} - version = "1.0.0" application { diff --git a/server_extensions_examples/build.gradle b/server_extensions_examples/build.gradle index 275a5bf6b..1fade2898 100644 --- a/server_extensions_examples/build.gradle +++ b/server_extensions_examples/build.gradle @@ -1,6 +1,5 @@ plugins { id("shared-build-conventions") - id("shared-repositories-ext-conventions") } group = projectGroup diff --git a/server_extensions_template/build.gradle b/server_extensions_template/build.gradle index 32493ee0b..78226917c 100644 --- a/server_extensions_template/build.gradle +++ b/server_extensions_template/build.gradle @@ -1,6 +1,5 @@ plugins { id("shared-build-conventions") - id("shared-repositories-ext-conventions") } group = projectGroup diff --git a/settings.gradle b/settings.gradle index 1f15e385b..1d3365536 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,3 +1,7 @@ +dependencyResolutionManagement { + repositoriesMode = RepositoriesMode.PREFER_PROJECT +} + include ':server_extensions_api' include ':server_extensions_extra' include ':server_extensions_test'