Skip to content

Commit

Permalink
Merge pull request bisq-network#2803 from alvasw/wallets_remove_depen…
Browse files Browse the repository at this point in the history
…dency_to_bisq_2_coin_class

wallets: Remove dependency to Bisq 2 Coin Class
  • Loading branch information
HenrikJannsen authored Sep 11, 2024
2 parents 79beec0 + 1a213c0 commit a3df1e6
Show file tree
Hide file tree
Showing 17 changed files with 43 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 0 additions & 4 deletions wallets/bitcoind/bitcoind/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,23 @@ 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());

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());

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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -59,13 +59,21 @@ 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
public Optional<Date> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package bisq.wallets.core.model;

import bisq.common.monetary.Coin;
import lombok.EqualsAndHashCode;
import lombok.Getter;

Expand All @@ -35,7 +34,7 @@ public class Transaction {
private final int height;
private final Optional<Date> date;
private final int confirmations;
private final Coin amount;
private final long amount;
private final boolean incoming;

public Transaction(String txId,
Expand All @@ -45,7 +44,7 @@ public Transaction(String txId,
int height,
Optional<Date> date,
int confirmations,
Coin amount,
long amount,
boolean incoming) {

this.txId = txId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion wallets/elementsd/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencies {
implementation("bitcoind:core")
implementation("bitcoind:bitcoind")
implementation("bitcoind:json-rpc")
implementation("wallets:wallet")

integrationTestImplementation("bitcoind:regtest")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion wallets/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ include("electrum")
include("elementsd")

include("process")
include("wallet")

rootProject.name = "wallets"
rootProject.name = "wallets"
15 changes: 15 additions & 0 deletions wallets/wallet/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -100,7 +99,6 @@ public List<Transaction> getTransactions() {
List<TransactionInput> inputs = new ArrayList<>();
List<TransactionOutput> outputs = new ArrayList<>();
int lockTime = 0;
Coin amount = Coin.asBtcFromValue(0);
boolean incoming = true;
return new Transaction(tx.getTxId(),
inputs,
Expand All @@ -109,7 +107,7 @@ public List<Transaction> getTransactions() {
tx.getBlockheight(),
Optional.of(new Date(tx.getTime() * 1000L)),
tx.getConfirmations(),
amount,
tx.getAmount(),
incoming);
})
.collect(Collectors.toList());
Expand Down

0 comments on commit a3df1e6

Please sign in to comment.