diff --git a/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/wallet/txs/WalletTransactionListItem.java b/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/wallet/txs/WalletTransactionListItem.java index cf7c6eece8..a7a714828e 100644 --- a/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/wallet/txs/WalletTransactionListItem.java +++ b/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/wallet/txs/WalletTransactionListItem.java @@ -50,7 +50,7 @@ public WalletTransactionListItem(Transaction transaction) { dateString = DateFormatter.formatDate(date); timeString = DateFormatter.formatTime(date); txId = transaction.getTxId(); - amount = transaction.getAmount(); + amount = Coin.asBtcFromValue(transaction.getAmount()); amountAsString = AmountFormatter.formatAmount(amount); confirmations = transaction.getConfirmations(); confirmationsAsString = String.valueOf(confirmations); diff --git a/wallets/bitcoind/bitcoind/build.gradle.kts b/wallets/bitcoind/bitcoind/build.gradle.kts index ed53d74049..b2af4646c1 100644 --- a/wallets/bitcoind/bitcoind/build.gradle.kts +++ b/wallets/bitcoind/bitcoind/build.gradle.kts @@ -1,16 +1,12 @@ plugins { id("bisq.java-library") id("bisq.java-integration-tests") - id("bisq.protobuf") } dependencies { - implementation("bisq:persistence") - implementation(project(":core")) implementation(project(":json-rpc")) - implementation(libs.typesafe.config) implementation(libs.jeromq) integrationTestImplementation(project(":regtest")) diff --git a/wallets/bitcoind/bitcoind/src/integrationTest/java/bisq/wallets/bitcoind/BitcoindSendAndListTxsIntegrationTests.java b/wallets/bitcoind/bitcoind/src/integrationTest/java/bisq/wallets/bitcoind/BitcoindSendAndListTxsIntegrationTests.java index 56e9d60132..85ca058343 100644 --- a/wallets/bitcoind/bitcoind/src/integrationTest/java/bisq/wallets/bitcoind/BitcoindSendAndListTxsIntegrationTests.java +++ b/wallets/bitcoind/bitcoind/src/integrationTest/java/bisq/wallets/bitcoind/BitcoindSendAndListTxsIntegrationTests.java @@ -63,7 +63,7 @@ public void sendBtcAndListTxs() throws MalformedURLException, InterruptedExcepti BitcoindListTransactionsResponse.Entry firstTx = txs.getFirst(); assertEquals(firstTxReceiverAddress, firstTx.getAddress()); assertEquals("receive", firstTx.getCategory()); - assertEquals(100000000, firstTx.getAmount().getValue()); + assertEquals(100000000, firstTx.getAmount()); assertEquals(1, firstTx.getConfirmations()); assertEquals(0, firstTx.getWalletconflicts().length); assertEquals("no", firstTx.getBip125Replaceable()); @@ -71,7 +71,7 @@ public void sendBtcAndListTxs() throws MalformedURLException, InterruptedExcepti BitcoindListTransactionsResponse.Entry secondTx = txs.get(1); assertEquals(secondTxReceiverAddress, secondTx.getAddress()); assertEquals("receive", secondTx.getCategory()); - assertEquals(100000000, secondTx.getAmount().getValue()); + assertEquals(100000000, secondTx.getAmount()); assertEquals(1, secondTx.getConfirmations()); assertEquals(0, secondTx.getWalletconflicts().length); assertEquals("no", secondTx.getBip125Replaceable()); @@ -79,7 +79,7 @@ public void sendBtcAndListTxs() throws MalformedURLException, InterruptedExcepti BitcoindListTransactionsResponse.Entry thirdTx = txs.get(2); assertEquals(thirdTxReceiverAddress, thirdTx.getAddress()); assertEquals("receive", thirdTx.getCategory()); - assertEquals(100000000, thirdTx.getAmount().getValue()); + assertEquals(100000000, thirdTx.getAmount()); assertEquals(1, thirdTx.getConfirmations()); assertEquals(0, thirdTx.getWalletconflicts().length); assertEquals("no", thirdTx.getBip125Replaceable()); diff --git a/wallets/bitcoind/bitcoind/src/main/java/bisq/wallets/bitcoind/rpc/responses/BitcoindListTransactionsResponse.java b/wallets/bitcoind/bitcoind/src/main/java/bisq/wallets/bitcoind/rpc/responses/BitcoindListTransactionsResponse.java index bca0d211a4..39acca6751 100644 --- a/wallets/bitcoind/bitcoind/src/main/java/bisq/wallets/bitcoind/rpc/responses/BitcoindListTransactionsResponse.java +++ b/wallets/bitcoind/bitcoind/src/main/java/bisq/wallets/bitcoind/rpc/responses/BitcoindListTransactionsResponse.java @@ -17,12 +17,12 @@ package bisq.wallets.bitcoind.rpc.responses; -import bisq.common.monetary.Coin; import bisq.wallets.core.model.TransactionInfo; import bisq.wallets.json_rpc.JsonRpcResponse; import com.squareup.moshi.Json; import lombok.Getter; +import java.math.BigDecimal; import java.util.Date; import java.util.List; import java.util.Optional; @@ -59,8 +59,8 @@ public static class Entry implements TransactionInfo { private boolean abandoned; @Override - public Coin getAmount() { - return Coin.asBtcFromFaceValue(amount); + public long getAmount() { + return doubleValueToLong(amount, 8); } @Override @@ -68,4 +68,12 @@ public Optional getDate() { return Optional.of(new Date(time * 1000L)); } } + + private static long doubleValueToLong(double value, int precision) { + double max = BigDecimal.valueOf(Long.MAX_VALUE).movePointLeft(precision).doubleValue(); + if (value > max) { + throw new ArithmeticException("Provided value would lead to an overflow"); + } + return BigDecimal.valueOf(value).movePointRight(precision).longValue(); + } } diff --git a/wallets/bitcoind/core/src/main/java/bisq/wallets/core/model/Transaction.java b/wallets/bitcoind/core/src/main/java/bisq/wallets/core/model/Transaction.java index 7748aba150..6f19a2c92b 100644 --- a/wallets/bitcoind/core/src/main/java/bisq/wallets/core/model/Transaction.java +++ b/wallets/bitcoind/core/src/main/java/bisq/wallets/core/model/Transaction.java @@ -17,7 +17,6 @@ package bisq.wallets.core.model; -import bisq.common.monetary.Coin; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -35,7 +34,7 @@ public class Transaction { private final int height; private final Optional date; private final int confirmations; - private final Coin amount; + private final long amount; private final boolean incoming; public Transaction(String txId, @@ -45,7 +44,7 @@ public Transaction(String txId, int height, Optional date, int confirmations, - Coin amount, + long amount, boolean incoming) { this.txId = txId; diff --git a/wallets/bitcoind/core/src/main/java/bisq/wallets/core/model/TransactionInfo.java b/wallets/bitcoind/core/src/main/java/bisq/wallets/core/model/TransactionInfo.java index b6384002fc..7698924a60 100644 --- a/wallets/bitcoind/core/src/main/java/bisq/wallets/core/model/TransactionInfo.java +++ b/wallets/bitcoind/core/src/main/java/bisq/wallets/core/model/TransactionInfo.java @@ -17,15 +17,13 @@ package bisq.wallets.core.model; -import bisq.common.monetary.Coin; - import java.util.Date; import java.util.Optional; public interface TransactionInfo { String getTxId(); - Coin getAmount(); + long getAmount(); int getConfirmations(); diff --git a/wallets/electrum/src/main/java/bisq/wallets/electrum/rpc/responses/ElectrumOnChainTransactionResponse.java b/wallets/electrum/src/main/java/bisq/wallets/electrum/rpc/responses/ElectrumOnChainTransactionResponse.java index 4fe60f6890..0e93ad7898 100644 --- a/wallets/electrum/src/main/java/bisq/wallets/electrum/rpc/responses/ElectrumOnChainTransactionResponse.java +++ b/wallets/electrum/src/main/java/bisq/wallets/electrum/rpc/responses/ElectrumOnChainTransactionResponse.java @@ -17,7 +17,6 @@ package bisq.wallets.electrum.rpc.responses; -import bisq.common.monetary.Coin; import bisq.wallets.core.model.TransactionInfo; import com.squareup.moshi.Json; import lombok.Getter; @@ -56,8 +55,8 @@ public class ElectrumOnChainTransactionResponse implements TransactionInfo { private Integer txPosInBlock; @Override - public Coin getAmount() { - return Coin.parseBtc(bcValue); + public long getAmount() { + return Long.parseLong(bcBalance); } @Override diff --git a/wallets/elementsd/build.gradle.kts b/wallets/elementsd/build.gradle.kts index ba32f8f5eb..af707770c5 100644 --- a/wallets/elementsd/build.gradle.kts +++ b/wallets/elementsd/build.gradle.kts @@ -10,6 +10,7 @@ dependencies { implementation("bitcoind:core") implementation("bitcoind:bitcoind") implementation("bitcoind:json-rpc") + implementation("wallets:wallet") integrationTestImplementation("bitcoind:regtest") -} \ No newline at end of file +} diff --git a/wallets/elementsd/src/integrationTest/java/bisq/wallets/elementsd/ElementsdSendAndListTxsIntegrationTests.java b/wallets/elementsd/src/integrationTest/java/bisq/wallets/elementsd/ElementsdSendAndListTxsIntegrationTests.java index 7bf6180247..118f9fb6e7 100644 --- a/wallets/elementsd/src/integrationTest/java/bisq/wallets/elementsd/ElementsdSendAndListTxsIntegrationTests.java +++ b/wallets/elementsd/src/integrationTest/java/bisq/wallets/elementsd/ElementsdSendAndListTxsIntegrationTests.java @@ -50,7 +50,7 @@ public void sendLBtcAndListTxs() throws InterruptedException { ElementsdListTransactionsResponse.Entry firstTx = txs.getFirst(); assertEquals(firstTxId, firstTx.getTxId()); assertEquals("receive", firstTx.getCategory()); - assertEquals(100000000, firstTx.getAmount().getValue()); + assertEquals(100000000, firstTx.getAmount()); assertEquals(1, firstTx.getConfirmations()); assertEquals(3, firstTx.getBlockheight()); assertEquals(0, firstTx.getWalletconflicts().length); @@ -59,7 +59,7 @@ public void sendLBtcAndListTxs() throws InterruptedException { ElementsdListTransactionsResponse.Entry secondTx = txs.get(1); assertEquals(secondTxId, secondTx.getTxId()); assertEquals("receive", secondTx.getCategory()); - assertEquals(100000000, secondTx.getAmount().getValue()); + assertEquals(100000000, secondTx.getAmount()); assertEquals(1, secondTx.getConfirmations()); assertEquals(3, secondTx.getBlockheight()); assertEquals(0, secondTx.getWalletconflicts().length); @@ -68,7 +68,7 @@ public void sendLBtcAndListTxs() throws InterruptedException { ElementsdListTransactionsResponse.Entry thirdTx = txs.get(2); assertEquals(thirdTxId, thirdTx.getTxId()); assertEquals("receive", thirdTx.getCategory()); - assertEquals(100000000, thirdTx.getAmount().getValue()); + assertEquals(100000000, thirdTx.getAmount()); assertEquals(1, thirdTx.getConfirmations()); assertEquals(3, thirdTx.getBlockheight()); assertEquals(0, thirdTx.getWalletconflicts().length); diff --git a/wallets/settings.gradle.kts b/wallets/settings.gradle.kts index b069bd6200..2d4f3fe6d2 100644 --- a/wallets/settings.gradle.kts +++ b/wallets/settings.gradle.kts @@ -20,5 +20,6 @@ include("electrum") include("elementsd") include("process") +include("wallet") -rootProject.name = "wallets" \ No newline at end of file +rootProject.name = "wallets" diff --git a/wallets/wallet/build.gradle.kts b/wallets/wallet/build.gradle.kts new file mode 100644 index 0000000000..70c9aa80a9 --- /dev/null +++ b/wallets/wallet/build.gradle.kts @@ -0,0 +1,15 @@ +plugins { + id("bisq.java-library") + id("bisq.java-integration-tests") + id("bisq.protobuf") +} + +dependencies { + implementation("bisq:persistence") + + implementation("bitcoind:core") + implementation("bitcoind:bitcoind") + implementation("bitcoind:json-rpc") + + implementation(libs.typesafe.config) +} \ No newline at end of file diff --git a/wallets/bitcoind/bitcoind/src/main/java/bisq/wallets/bitcoind/AbstractBitcoindWalletService.java b/wallets/wallet/src/main/java/bisq/wallets/bitcoind/AbstractBitcoindWalletService.java similarity index 100% rename from wallets/bitcoind/bitcoind/src/main/java/bisq/wallets/bitcoind/AbstractBitcoindWalletService.java rename to wallets/wallet/src/main/java/bisq/wallets/bitcoind/AbstractBitcoindWalletService.java diff --git a/wallets/bitcoind/bitcoind/src/main/java/bisq/wallets/bitcoind/BitcoinWallet.java b/wallets/wallet/src/main/java/bisq/wallets/bitcoind/BitcoinWallet.java similarity index 96% rename from wallets/bitcoind/bitcoind/src/main/java/bisq/wallets/bitcoind/BitcoinWallet.java rename to wallets/wallet/src/main/java/bisq/wallets/bitcoind/BitcoinWallet.java index 015dc290b9..a45be691d4 100644 --- a/wallets/bitcoind/bitcoind/src/main/java/bisq/wallets/bitcoind/BitcoinWallet.java +++ b/wallets/wallet/src/main/java/bisq/wallets/bitcoind/BitcoinWallet.java @@ -17,7 +17,6 @@ package bisq.wallets.bitcoind; -import bisq.common.monetary.Coin; import bisq.common.observable.collection.ObservableSet; import bisq.wallets.bitcoind.rpc.BitcoindDaemon; import bisq.wallets.bitcoind.rpc.BitcoindWallet; @@ -100,7 +99,6 @@ public List getTransactions() { List inputs = new ArrayList<>(); List outputs = new ArrayList<>(); int lockTime = 0; - Coin amount = Coin.asBtcFromValue(0); boolean incoming = true; return new Transaction(tx.getTxId(), inputs, @@ -109,7 +107,7 @@ public List getTransactions() { tx.getBlockheight(), Optional.of(new Date(tx.getTime() * 1000L)), tx.getConfirmations(), - amount, + tx.getAmount(), incoming); }) .collect(Collectors.toList()); diff --git a/wallets/bitcoind/bitcoind/src/main/java/bisq/wallets/bitcoind/BitcoinWalletService.java b/wallets/wallet/src/main/java/bisq/wallets/bitcoind/BitcoinWalletService.java similarity index 100% rename from wallets/bitcoind/bitcoind/src/main/java/bisq/wallets/bitcoind/BitcoinWalletService.java rename to wallets/wallet/src/main/java/bisq/wallets/bitcoind/BitcoinWalletService.java diff --git a/wallets/bitcoind/bitcoind/src/main/java/bisq/wallets/bitcoind/BitcoinWalletStore.java b/wallets/wallet/src/main/java/bisq/wallets/bitcoind/BitcoinWalletStore.java similarity index 100% rename from wallets/bitcoind/bitcoind/src/main/java/bisq/wallets/bitcoind/BitcoinWalletStore.java rename to wallets/wallet/src/main/java/bisq/wallets/bitcoind/BitcoinWalletStore.java diff --git a/wallets/bitcoind/bitcoind/src/main/java/bisq/wallets/bitcoind/WalletFactory.java b/wallets/wallet/src/main/java/bisq/wallets/bitcoind/WalletFactory.java similarity index 100% rename from wallets/bitcoind/bitcoind/src/main/java/bisq/wallets/bitcoind/WalletFactory.java rename to wallets/wallet/src/main/java/bisq/wallets/bitcoind/WalletFactory.java diff --git a/wallets/bitcoind/bitcoind/src/main/proto/wallets.bitcoind.proto b/wallets/wallet/src/main/proto/wallets.bitcoind.proto similarity index 100% rename from wallets/bitcoind/bitcoind/src/main/proto/wallets.bitcoind.proto rename to wallets/wallet/src/main/proto/wallets.bitcoind.proto