diff --git a/core/src/main/java/haveno/core/api/CoreDisputesService.java b/core/src/main/java/haveno/core/api/CoreDisputesService.java index a72e85ff8e..20c4ae4886 100644 --- a/core/src/main/java/haveno/core/api/CoreDisputesService.java +++ b/core/src/main/java/haveno/core/api/CoreDisputesService.java @@ -218,12 +218,12 @@ public class CoreDisputesService { disputeResult.setSellerPayoutAmountBeforeCost(sellerSecurityDeposit); } else if (payout == DisputePayout.BUYER_GETS_ALL) { disputeResult.setBuyerPayoutAmountBeforeCost(tradeAmount.add(buyerSecurityDeposit).add(sellerSecurityDeposit)); // TODO (woodser): apply min payout to incentivize loser? (see post v1.1.7) - disputeResult.setSellerPayoutAmountBeforeCost(BigInteger.valueOf(0)); + disputeResult.setSellerPayoutAmountBeforeCost(BigInteger.ZERO); } else if (payout == DisputePayout.SELLER_GETS_TRADE_AMOUNT) { disputeResult.setBuyerPayoutAmountBeforeCost(buyerSecurityDeposit); disputeResult.setSellerPayoutAmountBeforeCost(tradeAmount.add(sellerSecurityDeposit)); } else if (payout == DisputePayout.SELLER_GETS_ALL) { - disputeResult.setBuyerPayoutAmountBeforeCost(BigInteger.valueOf(0)); + disputeResult.setBuyerPayoutAmountBeforeCost(BigInteger.ZERO); disputeResult.setSellerPayoutAmountBeforeCost(tradeAmount.add(sellerSecurityDeposit).add(buyerSecurityDeposit)); } else if (payout == DisputePayout.CUSTOM) { if (customWinnerAmount > trade.getWallet().getBalance().longValueExact()) throw new RuntimeException("Winner payout is more than the trade wallet's balance"); diff --git a/core/src/main/java/haveno/core/monetary/Price.java b/core/src/main/java/haveno/core/monetary/Price.java index bfea2dbd17..95fcd4f8b6 100644 --- a/core/src/main/java/haveno/core/monetary/Price.java +++ b/core/src/main/java/haveno/core/monetary/Price.java @@ -94,7 +94,7 @@ public class Price extends MonetaryWrapper implements Comparable { else if (monetary instanceof CryptoMoney && this.monetary instanceof CryptoMoney) return HavenoUtils.coinToAtomicUnits(new CryptoExchangeRate((CryptoMoney) this.monetary).cryptoToCoin((CryptoMoney) monetary)); else - return BigInteger.valueOf(0); + return BigInteger.ZERO; } public String getCurrencyCode() { diff --git a/core/src/main/java/haveno/core/offer/OfferUtil.java b/core/src/main/java/haveno/core/offer/OfferUtil.java index 6eca9ab42f..857efbf3ec 100644 --- a/core/src/main/java/haveno/core/offer/OfferUtil.java +++ b/core/src/main/java/haveno/core/offer/OfferUtil.java @@ -143,9 +143,9 @@ public class OfferUtil { public BigInteger getBalanceShortage(BigInteger cost, BigInteger balance) { if (cost != null) { BigInteger shortage = cost.subtract(balance); - return shortage.compareTo(BigInteger.valueOf(0)) < 0 ? BigInteger.valueOf(0) : shortage; + return shortage.compareTo(BigInteger.ZERO) < 0 ? BigInteger.ZERO : shortage; } else { - return BigInteger.valueOf(0); + return BigInteger.ZERO; } } diff --git a/core/src/main/java/haveno/core/offer/OpenOfferManager.java b/core/src/main/java/haveno/core/offer/OpenOfferManager.java index 802132e83d..987158bfbe 100644 --- a/core/src/main/java/haveno/core/offer/OpenOfferManager.java +++ b/core/src/main/java/haveno/core/offer/OpenOfferManager.java @@ -1029,7 +1029,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe // get earliest unscheduled txs with sufficient incoming amount List scheduledTxHashes = new ArrayList(); - BigInteger scheduledAmount = BigInteger.valueOf(0); + BigInteger scheduledAmount = BigInteger.ZERO; for (MoneroTxWallet lockedTx : lockedTxs) { if (isTxScheduled(openOffers, lockedTx.getHash())) continue; if (lockedTx.getIncomingTransfers() == null || lockedTx.getIncomingTransfers().isEmpty()) continue; @@ -1048,7 +1048,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe } private BigInteger getScheduledAmount(List openOffers) { - BigInteger scheduledAmount = BigInteger.valueOf(0); + BigInteger scheduledAmount = BigInteger.ZERO; for (OpenOffer openOffer : openOffers) { if (openOffer.getState() != OpenOffer.State.SCHEDULED) continue; if (openOffer.getScheduledTxHashes() == null) continue; @@ -1178,7 +1178,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe } // verify maker's reserve tx (double spend, trade fee, trade amount, mining fee) - BigInteger sendAmount = offer.getDirection() == OfferDirection.BUY ? BigInteger.valueOf(0) : offer.getAmount(); + BigInteger sendAmount = offer.getDirection() == OfferDirection.BUY ? BigInteger.ZERO : offer.getAmount(); BigInteger securityDeposit = offer.getDirection() == OfferDirection.BUY ? offer.getMaxBuyerSecurityDeposit() : offer.getMaxSellerSecurityDeposit(); Tuple2 txResult = xmrWalletService.verifyTradeTx( offer.getId(), diff --git a/core/src/main/java/haveno/core/offer/placeoffer/tasks/MakerReserveOfferFunds.java b/core/src/main/java/haveno/core/offer/placeoffer/tasks/MakerReserveOfferFunds.java index f766fcce51..51887920aa 100644 --- a/core/src/main/java/haveno/core/offer/placeoffer/tasks/MakerReserveOfferFunds.java +++ b/core/src/main/java/haveno/core/offer/placeoffer/tasks/MakerReserveOfferFunds.java @@ -51,7 +51,7 @@ public class MakerReserveOfferFunds extends Task { // create reserve tx BigInteger makerFee = offer.getMakerFee(); - BigInteger sendAmount = offer.getDirection() == OfferDirection.BUY ? BigInteger.valueOf(0) : offer.getAmount(); + BigInteger sendAmount = offer.getDirection() == OfferDirection.BUY ? BigInteger.ZERO : offer.getAmount(); BigInteger securityDeposit = offer.getDirection() == OfferDirection.BUY ? offer.getMaxBuyerSecurityDeposit() : offer.getMaxSellerSecurityDeposit(); String returnAddress = model.getXmrWalletService().getOrCreateAddressEntry(offer.getId(), XmrAddressEntry.Context.TRADE_PAYOUT).getAddressString(); XmrAddressEntry fundingEntry = model.getXmrWalletService().getAddressEntry(offer.getId(), XmrAddressEntry.Context.OFFER_FUNDING).orElse(null); diff --git a/core/src/main/java/haveno/core/offer/placeoffer/tasks/ValidateOffer.java b/core/src/main/java/haveno/core/offer/placeoffer/tasks/ValidateOffer.java index 5ff2bba0be..dfad9a0818 100644 --- a/core/src/main/java/haveno/core/offer/placeoffer/tasks/ValidateOffer.java +++ b/core/src/main/java/haveno/core/offer/placeoffer/tasks/ValidateOffer.java @@ -102,7 +102,7 @@ public class ValidateOffer extends Task { public static void checkBINotNullOrZero(BigInteger value, String name) { checkNotNull(value, name + " is null"); - checkArgument(value.compareTo(BigInteger.valueOf(0)) > 0, + checkArgument(value.compareTo(BigInteger.ZERO) > 0, name + " must be positive. " + name + "=" + value); } diff --git a/core/src/main/java/haveno/core/offer/takeoffer/TakeOfferModel.java b/core/src/main/java/haveno/core/offer/takeoffer/TakeOfferModel.java index 838ac1e32d..dff0b25743 100644 --- a/core/src/main/java/haveno/core/offer/takeoffer/TakeOfferModel.java +++ b/core/src/main/java/haveno/core/offer/takeoffer/TakeOfferModel.java @@ -66,7 +66,7 @@ public class TakeOfferModel implements Model { @Getter private BigInteger totalToPay; @Getter - private BigInteger missingCoin = BigInteger.valueOf(0); + private BigInteger missingCoin = BigInteger.ZERO; @Getter private BigInteger totalAvailableBalance; @Getter @@ -156,7 +156,7 @@ public class TakeOfferModel implements Model { @NotNull public BigInteger getFundsNeededForTrade() { // If taking a buy offer, taker needs to reserve the offer.amt too. - return securityDeposit.add(offer.isBuyOffer() ? amount : BigInteger.valueOf(0)); + return securityDeposit.add(offer.isBuyOffer() ? amount : BigInteger.ZERO); } private void validateModelInputs() { @@ -173,7 +173,7 @@ public class TakeOfferModel implements Model { this.amount = null; this.availableBalance = null; this.isXmrWalletFunded = false; - this.missingCoin = BigInteger.valueOf(0); + this.missingCoin = BigInteger.ZERO; this.offer = null; this.paymentAccount = null; this.securityDeposit = null; diff --git a/core/src/main/java/haveno/core/payment/payload/PaymentMethod.java b/core/src/main/java/haveno/core/payment/payload/PaymentMethod.java index efe853ac88..342d36212b 100644 --- a/core/src/main/java/haveno/core/payment/payload/PaymentMethod.java +++ b/core/src/main/java/haveno/core/payment/payload/PaymentMethod.java @@ -367,7 +367,7 @@ public final class PaymentMethod implements PersistablePayload, Comparable()); + this(id, 0, BigInteger.ZERO, new ArrayList()); } diff --git a/core/src/main/java/haveno/core/support/dispute/DisputeManager.java b/core/src/main/java/haveno/core/support/dispute/DisputeManager.java index 95ad78d628..ba23f41e15 100644 --- a/core/src/main/java/haveno/core/support/dispute/DisputeManager.java +++ b/core/src/main/java/haveno/core/support/dispute/DisputeManager.java @@ -1051,7 +1051,7 @@ public abstract class DisputeManager> extends Sup String optionTradeDetails; // We don't translate those strings (yet) as it is only displayed to mediators/arbitrators. String headline; - if (potentialGain.compareTo(BigInteger.valueOf(0)) > 0) { + if (potentialGain.compareTo(BigInteger.ZERO) > 0) { headline = "This might be a potential option trade!"; optionTradeDetails = "\nBTC amount calculated with price at dispute opening: " + HavenoUtils.formatXmr(potentialAmountAtDisputeOpening, true) + "\nMax loss of security deposit is: " + HavenoUtils.formatXmr(maxLossSecDeposit, true) + diff --git a/core/src/main/java/haveno/core/support/dispute/arbitration/ArbitrationManager.java b/core/src/main/java/haveno/core/support/dispute/arbitration/ArbitrationManager.java index fc7197da4c..f20675f461 100644 --- a/core/src/main/java/haveno/core/support/dispute/arbitration/ArbitrationManager.java +++ b/core/src/main/java/haveno/core/support/dispute/arbitration/ArbitrationManager.java @@ -386,7 +386,7 @@ public final class ArbitrationManager extends DisputeManager 0) { + if (trade.getWallet().getUnlockedBalance().subtract(actualBuyerAmount.add(actualSellerAmount).add(txCost)).compareTo(BigInteger.ZERO) > 0) { throw new RuntimeException("The dispute payout amounts do not sum to the wallet's unlocked balance while verifying the dispute payout tx, unlocked balance=" + trade.getWallet().getUnlockedBalance() + " vs sum payout amount=" + actualBuyerAmount.add(actualSellerAmount) + ", buyer payout=" + actualBuyerAmount + ", seller payout=" + actualSellerAmount); } @@ -452,7 +452,7 @@ public final class ArbitrationManager extends DisputeManager outputs = xmrWalletService.getWallet().getOutputs(new MoneroOutputQuery().setIsFrozen(true).setIsSpent(false).setKeyImage(new MoneroKeyImage(keyImage))); // TODO: will this check tx pool? avoid if (!outputs.isEmpty()) sum = sum.add(outputs.get(0).getAmount()); @@ -1667,7 +1667,7 @@ public abstract class Trade implements Tradable, Model { } public BigInteger getReservedAmount() { - if (isArbitrator() || !isDepositsPublished() || isPayoutPublished()) return BigInteger.valueOf(0); + if (isArbitrator() || !isDepositsPublished() || isPayoutPublished()) return BigInteger.ZERO; return isBuyer() ? getBuyer().getSecurityDeposit() : getAmount().add(getSeller().getSecurityDeposit()); } diff --git a/core/src/main/java/haveno/core/trade/protocol/tasks/ArbitratorProcessDepositRequest.java b/core/src/main/java/haveno/core/trade/protocol/tasks/ArbitratorProcessDepositRequest.java index 1ea81453fc..4ae7aafab8 100644 --- a/core/src/main/java/haveno/core/trade/protocol/tasks/ArbitratorProcessDepositRequest.java +++ b/core/src/main/java/haveno/core/trade/protocol/tasks/ArbitratorProcessDepositRequest.java @@ -80,7 +80,7 @@ public class ArbitratorProcessDepositRequest extends TradeTask { boolean isFromTaker = trader == trade.getTaker(); boolean isFromBuyer = trader == trade.getBuyer(); BigInteger tradeFee = isFromTaker ? trade.getTakerFee() : trade.getMakerFee(); - BigInteger sendAmount = isFromBuyer ? BigInteger.valueOf(0) : trade.getAmount(); + BigInteger sendAmount = isFromBuyer ? BigInteger.ZERO : trade.getAmount(); BigInteger securityDeposit = isFromBuyer ? trade.getBuyerSecurityDepositBeforeMiningFee() : trade.getSellerSecurityDepositBeforeMiningFee(); String depositAddress = processModel.getMultisigAddress(); diff --git a/core/src/main/java/haveno/core/trade/protocol/tasks/ArbitratorProcessReserveTx.java b/core/src/main/java/haveno/core/trade/protocol/tasks/ArbitratorProcessReserveTx.java index cb13af6783..aa2df99097 100644 --- a/core/src/main/java/haveno/core/trade/protocol/tasks/ArbitratorProcessReserveTx.java +++ b/core/src/main/java/haveno/core/trade/protocol/tasks/ArbitratorProcessReserveTx.java @@ -55,7 +55,7 @@ public class ArbitratorProcessReserveTx extends TradeTask { // process reserve tx with expected values BigInteger tradeFee = isFromMaker ? trade.getMakerFee() : trade.getTakerFee(); - BigInteger sendAmount = isFromBuyer ? BigInteger.valueOf(0) : isFromMaker ? offer.getAmount() : trade.getAmount(); // maker reserve tx is for offer amount + BigInteger sendAmount = isFromBuyer ? BigInteger.ZERO : isFromMaker ? offer.getAmount() : trade.getAmount(); // maker reserve tx is for offer amount BigInteger securityDeposit = isFromMaker ? isFromBuyer ? offer.getMaxBuyerSecurityDeposit() : offer.getMaxSellerSecurityDeposit() : isFromBuyer ? trade.getBuyerSecurityDepositBeforeMiningFee() : trade.getSellerSecurityDepositBeforeMiningFee(); Tuple2 txResult; try { diff --git a/core/src/main/java/haveno/core/trade/protocol/tasks/TakerReserveTradeFunds.java b/core/src/main/java/haveno/core/trade/protocol/tasks/TakerReserveTradeFunds.java index 727472182c..78daef5145 100644 --- a/core/src/main/java/haveno/core/trade/protocol/tasks/TakerReserveTradeFunds.java +++ b/core/src/main/java/haveno/core/trade/protocol/tasks/TakerReserveTradeFunds.java @@ -41,7 +41,7 @@ public class TakerReserveTradeFunds extends TradeTask { // create reserve tx BigInteger takerFee = trade.getTakerFee(); - BigInteger sendAmount = trade.getOffer().getDirection() == OfferDirection.BUY ? trade.getAmount() : BigInteger.valueOf(0); + BigInteger sendAmount = trade.getOffer().getDirection() == OfferDirection.BUY ? trade.getAmount() : BigInteger.ZERO; BigInteger securityDeposit = trade.getOffer().getDirection() == OfferDirection.BUY ? trade.getSellerSecurityDepositBeforeMiningFee() : trade.getBuyerSecurityDepositBeforeMiningFee(); String returnAddress = model.getXmrWalletService().getOrCreateAddressEntry(trade.getOffer().getId(), XmrAddressEntry.Context.TRADE_PAYOUT).getAddressString(); MoneroTxWallet reserveTx = model.getXmrWalletService().createReserveTx(takerFee, sendAmount, securityDeposit, returnAddress, false, null); diff --git a/core/src/main/java/haveno/core/util/coin/CoinUtil.java b/core/src/main/java/haveno/core/util/coin/CoinUtil.java index b339337590..65c8e4ec37 100644 --- a/core/src/main/java/haveno/core/util/coin/CoinUtil.java +++ b/core/src/main/java/haveno/core/util/coin/CoinUtil.java @@ -62,7 +62,7 @@ public class CoinUtil { * @return The percentage value as double (e.g. 1% is 0.01) */ public static double getAsPercentPerBtc(BigInteger part, BigInteger total) { - return MathUtils.roundDouble(HavenoUtils.divide(part == null ? BigInteger.valueOf(0) : part, total == null ? BigInteger.valueOf(1) : total), 4); + return MathUtils.roundDouble(HavenoUtils.divide(part == null ? BigInteger.ZERO : part, total == null ? BigInteger.valueOf(1) : total), 4); } /** @@ -71,7 +71,7 @@ public class CoinUtil { * @return The percentage as atomic units (e.g. 1% of 1 BTC is 0.01 BTC) */ public static BigInteger getPercentOfAmount(double percent, BigInteger amount) { - if (amount == null) amount = BigInteger.valueOf(0); + if (amount == null) amount = BigInteger.ZERO; return BigDecimal.valueOf(percent).multiply(new BigDecimal(amount)).setScale(8, RoundingMode.DOWN).toBigInteger(); } @@ -134,7 +134,7 @@ public class CoinUtil { // 10 EUR in case of HalCash. Volume smallestUnitForVolume = Volume.parse(String.valueOf(factor), price.getCurrencyCode()); if (smallestUnitForVolume.getValue() <= 0) - return BigInteger.valueOf(0); + return BigInteger.ZERO; BigInteger smallestUnitForAmount = price.getAmountByVolume(smallestUnitForVolume); long minTradeAmount = Restrictions.getMinTradeAmount().longValueExact(); @@ -152,7 +152,7 @@ public class CoinUtil { ? getAdjustedVolumeUnit(price.getVolumeByAmount(smallestUnitForAmount), factor) : getAdjustedVolumeUnit(price.getVolumeByAmount(amount), factor); if (volume.getValue() <= 0) - return BigInteger.valueOf(0); + return BigInteger.ZERO; // From that adjusted volume we calculate back the amount. It might be a bit different as // the amount used as input before due rounding. diff --git a/core/src/main/java/haveno/core/xmr/Balances.java b/core/src/main/java/haveno/core/xmr/Balances.java index 1e3a99e4a7..e6662e479c 100644 --- a/core/src/main/java/haveno/core/xmr/Balances.java +++ b/core/src/main/java/haveno/core/xmr/Balances.java @@ -101,12 +101,12 @@ public class Balances { // TODO (woodser): converting to long should generally be avoided since can lose precision, but in practice these amounts are below max value private void updateAvailableBalance() { - availableBalance.set(xmrWalletService.getWallet() == null ? BigInteger.valueOf(0) : xmrWalletService.getWallet().getUnlockedBalance(0)); + availableBalance.set(xmrWalletService.getWallet() == null ? BigInteger.ZERO : xmrWalletService.getWallet().getUnlockedBalance(0)); } private void updatePendingBalance() { - BigInteger balance = xmrWalletService.getWallet() == null ? BigInteger.valueOf(0) : xmrWalletService.getWallet().getBalance(0); - BigInteger unlockedBalance = xmrWalletService.getWallet() == null ? BigInteger.valueOf(0) : xmrWalletService.getWallet().getUnlockedBalance(0); + BigInteger balance = xmrWalletService.getWallet() == null ? BigInteger.ZERO : xmrWalletService.getWallet().getBalance(0); + BigInteger unlockedBalance = xmrWalletService.getWallet() == null ? BigInteger.ZERO : xmrWalletService.getWallet().getUnlockedBalance(0); BigInteger pendingBalanceSum = balance.subtract(unlockedBalance); // add frozen trade balances - reserved amounts @@ -122,7 +122,7 @@ public class Balances { } private void updateReservedOfferBalance() { - BigInteger sum = BigInteger.valueOf(0); + BigInteger sum = BigInteger.ZERO; if (xmrWalletService.getWallet() != null) { List frozenOutputs = xmrWalletService.getWallet().getOutputs(new MoneroOutputQuery().setIsFrozen(true).setIsSpent(false)); for (MoneroOutputWallet frozenOutput : frozenOutputs) sum = sum.add(frozenOutput.getAmount()); @@ -138,7 +138,7 @@ public class Balances { } private void updateReservedTradeBalance() { - BigInteger sum = BigInteger.valueOf(0); + BigInteger sum = BigInteger.ZERO; List trades = tradeManager.getTradesStreamWithFundsLockedIn().collect(Collectors.toList()); for (Trade trade : trades) { sum = sum.add(trade.getReservedAmount()); diff --git a/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java b/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java index 138377f879..aaeb8f693f 100644 --- a/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java +++ b/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java @@ -424,7 +424,7 @@ public class XmrWalletService { // create deposit tx String multisigAddress = trade.getProcessModel().getMultisigAddress(); BigInteger tradeFee = trade instanceof MakerTrade ? trade.getOffer().getMakerFee() : trade.getTakerFee(); - BigInteger sendAmount = trade instanceof BuyerTrade ? BigInteger.valueOf(0) : trade.getAmount(); + BigInteger sendAmount = trade instanceof BuyerTrade ? BigInteger.ZERO : trade.getAmount(); BigInteger securityDeposit = trade instanceof BuyerTrade ? trade.getBuyerSecurityDepositBeforeMiningFee() : trade.getSellerSecurityDepositBeforeMiningFee(); long time = System.currentTimeMillis(); log.info("Creating deposit tx with multisig address={}", multisigAddress); @@ -449,7 +449,7 @@ public class XmrWalletService { subaddressIndices.addAll(subaddressIndicesWithExactInput); } if (preferredSubaddressIndex != null) { - if (wallet.getBalance(0, preferredSubaddressIndex).compareTo(BigInteger.valueOf(0)) > 0) { + if (wallet.getBalance(0, preferredSubaddressIndex).compareTo(BigInteger.ZERO) > 0) { subaddressIndices.add(0, preferredSubaddressIndex); // try preferred subaddress first if funded } else if (reserveExactAmount) { subaddressIndices.add(preferredSubaddressIndex); // otherwise only try preferred subaddress if using exact output @@ -532,7 +532,7 @@ public class XmrWalletService { } // verify unlock height - if (!BigInteger.valueOf(0).equals(tx.getUnlockTime())) throw new RuntimeException("Unlock height must be 0"); + if (!BigInteger.ZERO.equals(tx.getUnlockTime())) throw new RuntimeException("Unlock height must be 0"); // verify miner fee BigInteger feeEstimate = getElevatedFeeEstimate(tx.getWeight()); @@ -603,7 +603,7 @@ public class XmrWalletService { // round up to multiple of quantization mask BigInteger[] quotientAndRemainder = baseFee.divideAndRemainder(qmask); BigInteger feeEstimate = qmask.multiply(quotientAndRemainder[0]); - if (quotientAndRemainder[1].compareTo(BigInteger.valueOf(0)) > 0) feeEstimate = feeEstimate.add(qmask); + if (quotientAndRemainder[1].compareTo(BigInteger.ZERO) > 0) feeEstimate = feeEstimate.add(qmask); return feeEstimate; } @@ -1105,7 +1105,7 @@ public class XmrWalletService { } public List getFundedAvailableAddressEntries() { - return getAvailableAddressEntries().stream().filter(addressEntry -> getBalanceForSubaddress(addressEntry.getSubaddressIndex()).compareTo(BigInteger.valueOf(0)) > 0).collect(Collectors.toList()); + return getAvailableAddressEntries().stream().filter(addressEntry -> getBalanceForSubaddress(addressEntry.getSubaddressIndex()).compareTo(BigInteger.ZERO) > 0).collect(Collectors.toList()); } public List getAddressEntryListAsImmutableList() { @@ -1147,7 +1147,7 @@ public class XmrWalletService { //if (tx.getTransfers(new MoneroTransferQuery().setSubaddressIndex(subaddressIndex)).isEmpty()) continue; // TODO monero-project: transfers are occluded by transfers from/to same account, so this will return unused when used numUnspentOutputs += tx.isConfirmed() ? tx.getOutputsWallet(new MoneroOutputQuery().setAccountIndex(0).setSubaddressIndex(subaddressIndex)).size() : 1; // TODO: monero-project does not provide outputs for unconfirmed txs } - boolean positiveBalance = wallet.getBalance(0, subaddressIndex).compareTo(BigInteger.valueOf(0)) > 0; + boolean positiveBalance = wallet.getBalance(0, subaddressIndex).compareTo(BigInteger.ZERO) > 0; if (positiveBalance && numUnspentOutputs == 0) return 1; // outputs do not appear until confirmed and internal transfers are occluded, so report 1 if positive balance return numUnspentOutputs; } @@ -1228,7 +1228,7 @@ public class XmrWalletService { available = Stream.concat(available, getAddressEntries(XmrAddressEntry.Context.ARBITRATOR).stream()); available = Stream.concat(available, getAddressEntries(XmrAddressEntry.Context.OFFER_FUNDING).stream().filter(entry -> !tradeManager.getOpenOfferManager().getOpenOfferById(entry.getOfferId()).isPresent())); available = Stream.concat(available, getAddressEntries(XmrAddressEntry.Context.TRADE_PAYOUT).stream().filter(entry -> tradeManager.getTrade(entry.getOfferId()) == null || tradeManager.getTrade(entry.getOfferId()).isPayoutUnlocked())); - return available.filter(addressEntry -> getBalanceForSubaddress(addressEntry.getSubaddressIndex()).compareTo(BigInteger.valueOf(0)) > 0); + return available.filter(addressEntry -> getBalanceForSubaddress(addressEntry.getSubaddressIndex()).compareTo(BigInteger.ZERO) > 0); } public void addWalletListener(MoneroWalletListenerI listener) { diff --git a/core/src/test/java/haveno/core/account/sign/SignedWitnessServiceTest.java b/core/src/test/java/haveno/core/account/sign/SignedWitnessServiceTest.java index 40c991ed1f..a84c1645e3 100644 --- a/core/src/test/java/haveno/core/account/sign/SignedWitnessServiceTest.java +++ b/core/src/test/java/haveno/core/account/sign/SignedWitnessServiceTest.java @@ -353,7 +353,7 @@ public class SignedWitnessServiceTest { when(keyRing.getSignatureKeyPair()).thenReturn(signerKeyPair); AccountAgeWitness accountAgeWitness = new AccountAgeWitness(account1DataHash, accountCreationTime); - signedWitnessService.signAndPublishAccountAgeWitness(BigInteger.valueOf(0), accountAgeWitness, peerKeyPair.getPublic()); + signedWitnessService.signAndPublishAccountAgeWitness(BigInteger.ZERO, accountAgeWitness, peerKeyPair.getPublic()); verify(p2pService, never()).addPersistableNetworkPayload(any(PersistableNetworkPayload.class), anyBoolean()); } diff --git a/core/src/test/java/haveno/core/util/coin/CoinUtilTest.java b/core/src/test/java/haveno/core/util/coin/CoinUtilTest.java index 2981958018..a27c7ac15e 100644 --- a/core/src/test/java/haveno/core/util/coin/CoinUtilTest.java +++ b/core/src/test/java/haveno/core/util/coin/CoinUtilTest.java @@ -71,7 +71,7 @@ public class CoinUtilTest { try { CoinUtil.getAdjustedAmount( - BigInteger.valueOf(0), + BigInteger.ZERO, Price.valueOf("USD", 1000_0000), HavenoUtils.xmrToAtomicUnits(0.2).longValueExact(), 1); diff --git a/desktop/src/main/java/haveno/desktop/components/AddressTextField.java b/desktop/src/main/java/haveno/desktop/components/AddressTextField.java index 94faa4153e..1e68775932 100644 --- a/desktop/src/main/java/haveno/desktop/components/AddressTextField.java +++ b/desktop/src/main/java/haveno/desktop/components/AddressTextField.java @@ -151,9 +151,9 @@ public class AddressTextField extends AnchorPane { /////////////////////////////////////////////////////////////////////////////////////////// private String getMoneroURI() { - if (amount.get().compareTo(BigInteger.valueOf(0)) < 0) { + if (amount.get().compareTo(BigInteger.ZERO) < 0) { log.warn("Amount must not be negative"); - setAmount(BigInteger.valueOf(0)); + setAmount(BigInteger.ZERO); } return GUIUtil.getMoneroURI( address.get(), diff --git a/desktop/src/main/java/haveno/desktop/main/funds/transactions/TransactionsListItem.java b/desktop/src/main/java/haveno/desktop/main/funds/transactions/TransactionsListItem.java index 8bf772ba1c..c0fcfedbba 100644 --- a/desktop/src/main/java/haveno/desktop/main/funds/transactions/TransactionsListItem.java +++ b/desktop/src/main/java/haveno/desktop/main/funds/transactions/TransactionsListItem.java @@ -53,7 +53,7 @@ class TransactionsListItem { private String direction = ""; private boolean received; private boolean detailsAvailable; - private BigInteger amount = BigInteger.valueOf(0); + private BigInteger amount = BigInteger.ZERO; private String memo = ""; private long confirmations = 0; @Getter @@ -88,8 +88,8 @@ class TransactionsListItem { Optional optionalTradable = Optional.ofNullable(transactionAwareTradable) .map(TransactionAwareTradable::asTradable); - BigInteger valueSentToMe = tx.getIncomingAmount() == null ? BigInteger.valueOf(0) : tx.getIncomingAmount(); - BigInteger valueSentFromMe = tx.getOutgoingAmount() == null ? BigInteger.valueOf(0) : tx.getOutgoingAmount(); + BigInteger valueSentToMe = tx.getIncomingAmount() == null ? BigInteger.ZERO : tx.getIncomingAmount(); + BigInteger valueSentFromMe = tx.getOutgoingAmount() == null ? BigInteger.ZERO : tx.getOutgoingAmount(); if (tx.getTransfers().get(0).isIncoming()) { addressString = ((MoneroIncomingTransfer) tx.getTransfers().get(0)).getAddress(); @@ -99,7 +99,7 @@ class TransactionsListItem { else addressString = "unavailable"; } - if (valueSentFromMe.compareTo(BigInteger.valueOf(0)) == 0) { + if (valueSentFromMe.compareTo(BigInteger.ZERO) == 0) { amount = valueSentToMe; direction = Res.get("funds.tx.direction.receivedWith"); received = true; @@ -125,13 +125,13 @@ class TransactionsListItem { } else if (trade.getPayoutTxId() != null && trade.getPayoutTxId().equals(txId)) { details = Res.get("funds.tx.multiSigPayout", tradeId); - if (amount.compareTo(BigInteger.valueOf(0)) == 0) { + if (amount.compareTo(BigInteger.ZERO) == 0) { initialTxConfidenceVisibility = false; } } else { Trade.DisputeState disputeState = trade.getDisputeState(); if (disputeState == Trade.DisputeState.DISPUTE_CLOSED) { - if (valueSentToMe.compareTo(BigInteger.valueOf(0)) > 0) { + if (valueSentToMe.compareTo(BigInteger.ZERO) > 0) { details = Res.get("funds.tx.disputePayout", tradeId); } else { details = Res.get("funds.tx.disputeLost", tradeId); @@ -139,7 +139,7 @@ class TransactionsListItem { } else if (disputeState == Trade.DisputeState.REFUND_REQUEST_CLOSED || disputeState == Trade.DisputeState.REFUND_REQUESTED || disputeState == Trade.DisputeState.REFUND_REQUEST_STARTED_BY_PEER) { - if (valueSentToMe.compareTo(BigInteger.valueOf(0)) > 0) { + if (valueSentToMe.compareTo(BigInteger.ZERO) > 0) { details = Res.get("funds.tx.refund", tradeId); } else { // We have spent the deposit tx outputs to the Haveno donation address to enable @@ -147,7 +147,7 @@ class TransactionsListItem { // already when funding the deposit tx we show 0 BTC as amount. // Confirmation is not known from the BitcoinJ side (not 100% clear why) as no funds // left our wallet nor we received funds. So we set indicator invisible. - amount = BigInteger.valueOf(0); + amount = BigInteger.ZERO; details = Res.get("funds.tx.collateralForRefund", tradeId); initialTxConfidenceVisibility = false; } @@ -157,7 +157,7 @@ class TransactionsListItem { } } } else { - if (amount.compareTo(BigInteger.valueOf(0)) == 0) { + if (amount.compareTo(BigInteger.ZERO) == 0) { details = Res.get("funds.tx.noFundsFromDispute"); } } diff --git a/desktop/src/main/java/haveno/desktop/main/funds/withdrawal/WithdrawalView.java b/desktop/src/main/java/haveno/desktop/main/funds/withdrawal/WithdrawalView.java index 9b09e8c963..daa027ca85 100644 --- a/desktop/src/main/java/haveno/desktop/main/funds/withdrawal/WithdrawalView.java +++ b/desktop/src/main/java/haveno/desktop/main/funds/withdrawal/WithdrawalView.java @@ -75,7 +75,7 @@ public class WithdrawalView extends ActivatableView { private final P2PService p2PService; private final WalletPasswordWindow walletPasswordWindow; private XmrBalanceListener balanceListener; - private BigInteger amount = BigInteger.valueOf(0); + private BigInteger amount = BigInteger.ZERO; private ChangeListener amountListener; private ChangeListener amountFocusListener; private ChangeListener feeToggleGroupListener; @@ -148,7 +148,7 @@ public class WithdrawalView extends ActivatableView { }; amountFocusListener = (observable, oldValue, newValue) -> { if (oldValue && !newValue) { - if (amount.compareTo(BigInteger.valueOf(0)) > 0) + if (amount.compareTo(BigInteger.ZERO) > 0) amountTextField.setText(HavenoUtils.formatXmr(amount)); else amountTextField.setText(""); @@ -200,7 +200,7 @@ public class WithdrawalView extends ActivatableView { final String withdrawToAddress = withdrawToTextField.getText(); // create tx - if (amount.compareTo(BigInteger.valueOf(0)) <= 0) throw new RuntimeException(Res.get("portfolio.pending.step5_buyer.amountTooLow")); + if (amount.compareTo(BigInteger.ZERO) <= 0) throw new RuntimeException(Res.get("portfolio.pending.step5_buyer.amountTooLow")); MoneroTxWallet tx = xmrWalletService.getWallet().createTx(new MoneroTxConfig() .setAccountIndex(0) .setAmount(amount) @@ -262,7 +262,7 @@ public class WithdrawalView extends ActivatableView { .filter(Trade::isPayoutPublished) .forEach(trade -> xmrWalletService.getAddressEntry(trade.getId(), XmrAddressEntry.Context.TRADE_PAYOUT) .ifPresent(addressEntry -> { - if (xmrWalletService.getBalanceForAddress(addressEntry.getAddressString()).compareTo(BigInteger.valueOf(0)) == 0) + if (xmrWalletService.getBalanceForAddress(addressEntry.getAddressString()).compareTo(BigInteger.ZERO) == 0) tradeManager.onTradeCompleted(trade); })); } catch (Exception e) { @@ -276,7 +276,7 @@ public class WithdrawalView extends ActivatableView { /////////////////////////////////////////////////////////////////////////////////////////// private void reset() { - amount = BigInteger.valueOf(0); + amount = BigInteger.ZERO; amountTextField.setText(""); amountTextField.setPromptText(Res.get("funds.withdrawal.setAmount")); diff --git a/desktop/src/main/java/haveno/desktop/main/market/spread/SpreadView.java b/desktop/src/main/java/haveno/desktop/main/market/spread/SpreadView.java index 7a680a68c2..1324142f99 100644 --- a/desktop/src/main/java/haveno/desktop/main/market/spread/SpreadView.java +++ b/desktop/src/main/java/haveno/desktop/main/market/spread/SpreadView.java @@ -123,7 +123,7 @@ public class SpreadView extends ActivatableViewAndModel item.numberOfBuyOffers).sum(); int numberOfSellOffers = sortedList.stream().mapToInt(item -> item.numberOfSellOffers).sum(); - BigInteger totalAmount = BigInteger.valueOf(0); + BigInteger totalAmount = BigInteger.ZERO; for (SpreadItem item : sortedList) totalAmount = totalAmount.add(item.totalAmount); String total = HavenoUtils.formatXmr(totalAmount); diff --git a/desktop/src/main/java/haveno/desktop/main/market/spread/SpreadViewModel.java b/desktop/src/main/java/haveno/desktop/main/market/spread/SpreadViewModel.java index 3529cb94c4..00002880e7 100644 --- a/desktop/src/main/java/haveno/desktop/main/market/spread/SpreadViewModel.java +++ b/desktop/src/main/java/haveno/desktop/main/market/spread/SpreadViewModel.java @@ -129,7 +129,7 @@ class SpreadViewModel extends ActivatableViewModel { } spreadItems.clear(); - BigInteger totalAmount = BigInteger.valueOf(0); + BigInteger totalAmount = BigInteger.ZERO; for (String key : offersByCurrencyMap.keySet()) { List offers = offersByCurrencyMap.get(key); diff --git a/desktop/src/main/java/haveno/desktop/main/offer/MutableOfferDataModel.java b/desktop/src/main/java/haveno/desktop/main/offer/MutableOfferDataModel.java index eaaa08de4d..2c1e3a3b59 100644 --- a/desktop/src/main/java/haveno/desktop/main/offer/MutableOfferDataModel.java +++ b/desktop/src/main/java/haveno/desktop/main/offer/MutableOfferDataModel.java @@ -121,7 +121,7 @@ public abstract class MutableOfferDataModel extends OfferDataModel { protected boolean allowAmountUpdate = true; private final TradeStatisticsManager tradeStatisticsManager; - private final Predicate> isNonZeroAmount = (c) -> c.get() != null && c.get().compareTo(BigInteger.valueOf(0)) != 0; + private final Predicate> isNonZeroAmount = (c) -> c.get() != null && c.get().compareTo(BigInteger.ZERO) != 0; private final Predicate> isNonZeroPrice = (p) -> p.get() != null && !p.get().isZero(); private final Predicate> isNonZeroVolume = (v) -> v.get() != null && !v.get().isZero(); @Getter @@ -642,7 +642,7 @@ public abstract class MutableOfferDataModel extends OfferDataModel { private BigInteger getSellerSecurityDeposit() { BigInteger amount = this.amount.get(); if (amount == null) - amount = BigInteger.valueOf(0); + amount = BigInteger.ZERO; BigInteger percentOfAmount = CoinUtil.getPercentOfAmount( createOfferService.getSellerSecurityDepositAsDouble(buyerSecurityDepositPct.get()), amount); diff --git a/desktop/src/main/java/haveno/desktop/main/offer/MutableOfferView.java b/desktop/src/main/java/haveno/desktop/main/offer/MutableOfferView.java index f7313adabf..25a95fcad2 100644 --- a/desktop/src/main/java/haveno/desktop/main/offer/MutableOfferView.java +++ b/desktop/src/main/java/haveno/desktop/main/offer/MutableOfferView.java @@ -330,7 +330,7 @@ public abstract class MutableOfferView> exten // called from parent as the view does not get notified when the tab is closed public void onClose() { // we use model.placeOfferCompleted to not react on close which was triggered by a successful placeOffer - if (model.getDataModel().getBalance().get().compareTo(BigInteger.valueOf(0)) > 0 && !model.placeOfferCompleted.get()) { + if (model.getDataModel().getBalance().get().compareTo(BigInteger.ZERO) > 0 && !model.placeOfferCompleted.get()) { model.getDataModel().swapTradeToSavings(); } } diff --git a/desktop/src/main/java/haveno/desktop/main/offer/OfferDataModel.java b/desktop/src/main/java/haveno/desktop/main/offer/OfferDataModel.java index ea507ee59a..d530ea521c 100644 --- a/desktop/src/main/java/haveno/desktop/main/offer/OfferDataModel.java +++ b/desktop/src/main/java/haveno/desktop/main/offer/OfferDataModel.java @@ -49,7 +49,7 @@ public abstract class OfferDataModel extends ActivatableDataModel { @Getter protected final ObjectProperty availableBalance = new SimpleObjectProperty<>(); @Getter - protected final ObjectProperty missingCoin = new SimpleObjectProperty<>(BigInteger.valueOf(0)); + protected final ObjectProperty missingCoin = new SimpleObjectProperty<>(BigInteger.ZERO); @Getter protected final BooleanProperty showWalletFundedNotification = new SimpleBooleanProperty(); @Getter diff --git a/desktop/src/main/java/haveno/desktop/main/offer/takeoffer/TakeOfferDataModel.java b/desktop/src/main/java/haveno/desktop/main/offer/takeoffer/TakeOfferDataModel.java index bba1117b37..5acbec9ee8 100644 --- a/desktop/src/main/java/haveno/desktop/main/offer/takeoffer/TakeOfferDataModel.java +++ b/desktop/src/main/java/haveno/desktop/main/offer/takeoffer/TakeOfferDataModel.java @@ -353,7 +353,7 @@ class TakeOfferDataModel extends OfferDataModel { void calculateVolume() { if (tradePrice != null && offer != null && amount.get() != null && - amount.get().compareTo(BigInteger.valueOf(0)) != 0) { + amount.get().compareTo(BigInteger.ZERO) != 0) { Volume volumeByAmount = tradePrice.getVolumeByAmount(amount.get()); volumeByAmount = VolumeUtil.getAdjustedVolume(volumeByAmount, offer.getPaymentMethod().getId()); diff --git a/desktop/src/main/java/haveno/desktop/main/offer/takeoffer/TakeOfferView.java b/desktop/src/main/java/haveno/desktop/main/offer/takeoffer/TakeOfferView.java index 5b257f51cc..38828f70b2 100644 --- a/desktop/src/main/java/haveno/desktop/main/offer/takeoffer/TakeOfferView.java +++ b/desktop/src/main/java/haveno/desktop/main/offer/takeoffer/TakeOfferView.java @@ -360,7 +360,7 @@ public class TakeOfferView extends ActivatableViewAndModel 0 && !model.takeOfferCompleted.get() && !DevEnv.isDevMode()) { + if (availableBalance != null && availableBalance.compareTo(BigInteger.ZERO) > 0 && !model.takeOfferCompleted.get() && !DevEnv.isDevMode()) { model.dataModel.swapTradeToSavings(); } } diff --git a/desktop/src/main/java/haveno/desktop/main/overlays/windows/DisputeSummaryWindow.java b/desktop/src/main/java/haveno/desktop/main/overlays/windows/DisputeSummaryWindow.java index a325e3b27e..a85b3bab07 100644 --- a/desktop/src/main/java/haveno/desktop/main/overlays/windows/DisputeSummaryWindow.java +++ b/desktop/src/main/java/haveno/desktop/main/overlays/windows/DisputeSummaryWindow.java @@ -364,7 +364,7 @@ public class DisputeSummaryWindow extends Overlay { // be made return totalAmount.compareTo(available) <= 0; } else { - if (totalAmount.compareTo(BigInteger.valueOf(0)) <= 0) { + if (totalAmount.compareTo(BigInteger.ZERO) <= 0) { return false; } return totalAmount.compareTo(available) == 0; @@ -612,23 +612,23 @@ public class DisputeSummaryWindow extends Overlay { String sellerPayoutAddressString = contract.getSellerPayoutAddressString(); List destinations = payoutTx.getOutgoingTransfer().getDestinations(); boolean buyerFirst = destinations.get(0).getAddress().equals(buyerPayoutAddressString); - BigInteger buyerPayoutAmount = buyerFirst ? destinations.get(0).getAmount() : destinations.size() == 2 ? destinations.get(1).getAmount() : BigInteger.valueOf(0); - BigInteger sellerPayoutAmount = buyerFirst ? (destinations.size() == 2 ? destinations.get(1).getAmount() : BigInteger.valueOf(0)) : destinations.get(0).getAmount(); + BigInteger buyerPayoutAmount = buyerFirst ? destinations.get(0).getAmount() : destinations.size() == 2 ? destinations.get(1).getAmount() : BigInteger.ZERO; + BigInteger sellerPayoutAmount = buyerFirst ? (destinations.size() == 2 ? destinations.get(1).getAmount() : BigInteger.ZERO) : destinations.get(0).getAmount(); String buyerDetails = ""; - if (buyerPayoutAmount.compareTo(BigInteger.valueOf(0)) > 0) { + if (buyerPayoutAmount.compareTo(BigInteger.ZERO) > 0) { buyerDetails = Res.get("disputeSummaryWindow.close.txDetails.buyer", HavenoUtils.formatXmr(buyerPayoutAmount, true), buyerPayoutAddressString); } String sellerDetails = ""; - if (sellerPayoutAmount.compareTo(BigInteger.valueOf(0)) > 0) { + if (sellerPayoutAmount.compareTo(BigInteger.ZERO) > 0) { sellerDetails = Res.get("disputeSummaryWindow.close.txDetails.seller", HavenoUtils.formatXmr(sellerPayoutAmount, true), sellerPayoutAddressString); } BigInteger outputAmount = buyerPayoutAmount.add(sellerPayoutAmount).add(payoutTx.getFee()); - if (outputAmount.compareTo(BigInteger.valueOf(0)) > 0) { + if (outputAmount.compareTo(BigInteger.ZERO) > 0) { new Popup().width(900) .headLine(Res.get("disputeSummaryWindow.close.txDetails.headline")) .confirmation(Res.get("disputeSummaryWindow.close.txDetails", @@ -728,13 +728,13 @@ public class DisputeSummaryWindow extends Overlay { sellerPayoutAmount.equals(sellerSecurityDeposit)) { buyerGetsTradeAmountRadioButton.setSelected(true); } else if (buyerPayoutAmount.equals(tradeAmount.add(buyerSecurityDeposit).add(sellerSecurityDeposit)) && - sellerPayoutAmount.equals(BigInteger.valueOf(0))) { + sellerPayoutAmount.equals(BigInteger.ZERO)) { buyerGetsAllRadioButton.setSelected(true); } else if (sellerPayoutAmount.equals(tradeAmount.add(sellerSecurityDeposit)) && buyerPayoutAmount.equals(buyerSecurityDeposit)) { sellerGetsTradeAmountRadioButton.setSelected(true); } else if (sellerPayoutAmount.equals(tradeAmount.add(buyerSecurityDeposit).add(sellerSecurityDeposit)) - && buyerPayoutAmount.equals(BigInteger.valueOf(0))) { + && buyerPayoutAmount.equals(BigInteger.ZERO)) { sellerGetsAllRadioButton.setSelected(true); } else { customRadioButton.setSelected(true); diff --git a/desktop/src/main/java/haveno/desktop/main/portfolio/pendingtrades/PendingTradesDataModel.java b/desktop/src/main/java/haveno/desktop/main/portfolio/pendingtrades/PendingTradesDataModel.java index 5c1acd4754..5ca5cf0fd0 100644 --- a/desktop/src/main/java/haveno/desktop/main/portfolio/pendingtrades/PendingTradesDataModel.java +++ b/desktop/src/main/java/haveno/desktop/main/portfolio/pendingtrades/PendingTradesDataModel.java @@ -276,14 +276,14 @@ public class PendingTradesDataModel extends ActivatableDataModel { return offer.getMakerFee(); } else { log.error("offer is null"); - return BigInteger.valueOf(0); + return BigInteger.ZERO; } } else { return trade.getTakerFee(); } } else { log.error("Trade is null at getTotalFees"); - return BigInteger.valueOf(0); + return BigInteger.ZERO; } } diff --git a/desktop/src/test/java/haveno/desktop/util/GUIUtilTest.java b/desktop/src/test/java/haveno/desktop/util/GUIUtilTest.java index e568d20aff..26714798da 100644 --- a/desktop/src/test/java/haveno/desktop/util/GUIUtilTest.java +++ b/desktop/src/test/java/haveno/desktop/util/GUIUtilTest.java @@ -127,6 +127,6 @@ public class GUIUtilTest { BigInteger fee = BigInteger.valueOf(100000000L); assertEquals(" (0.01% of trade amount)", - GUIUtil.getPercentageOfTradeAmount(fee, HavenoUtils.xmrToAtomicUnits(1.0), BigInteger.valueOf(0))); + GUIUtil.getPercentageOfTradeAmount(fee, HavenoUtils.xmrToAtomicUnits(1.0), BigInteger.ZERO)); } }