replace BigInteger.valueOf(0) with BigInteger.ZERO

This commit is contained in:
woodser 2023-12-08 07:45:22 -05:00
parent cd89b8bf15
commit 3730773006
34 changed files with 81 additions and 81 deletions

View file

@ -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");

View file

@ -94,7 +94,7 @@ public class Price extends MonetaryWrapper implements Comparable<Price> {
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() {

View file

@ -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;
}
}

View file

@ -1029,7 +1029,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
// get earliest unscheduled txs with sufficient incoming amount
List<String> scheduledTxHashes = new ArrayList<String>();
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<OpenOffer> 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<MoneroTx, BigInteger> txResult = xmrWalletService.verifyTradeTx(
offer.getId(),

View file

@ -51,7 +51,7 @@ public class MakerReserveOfferFunds extends Task<PlaceOfferModel> {
// 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);

View file

@ -102,7 +102,7 @@ public class ValidateOffer extends Task<PlaceOfferModel> {
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);
}

View file

@ -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;

View file

@ -367,7 +367,7 @@ public final class PaymentMethod implements PersistablePayload, Comparable<Payme
}
public static PaymentMethod getDummyPaymentMethod(String id) {
return new PaymentMethod(id, 0, BigInteger.valueOf(0), Arrays.asList());
return new PaymentMethod(id, 0, BigInteger.ZERO, Arrays.asList());
}
@ -417,7 +417,7 @@ public final class PaymentMethod implements PersistablePayload, Comparable<Payme
// Used for dummy entries in payment methods list (SHOW_ALL)
private PaymentMethod(String id) {
this(id, 0, BigInteger.valueOf(0), new ArrayList<String>());
this(id, 0, BigInteger.ZERO, new ArrayList<String>());
}

View file

@ -1051,7 +1051,7 @@ public abstract class DisputeManager<T extends DisputeList<Dispute>> 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) +

View file

@ -386,7 +386,7 @@ public final class ArbitrationManager extends DisputeManager<ArbitrationDisputeL
// verify payouts sum to unlocked balance within loss of precision due to conversion to centineros
BigInteger txCost = arbitratorSignedPayoutTx.getFee().add(arbitratorSignedPayoutTx.getChangeAmount()); // cost = fee + lost dust change
if (!arbitratorSignedPayoutTx.getChangeAmount().equals(BigInteger.ZERO)) log.warn("Dust left in multisig wallet for {} {}: {}", getClass().getSimpleName(), trade.getId(), arbitratorSignedPayoutTx.getChangeAmount());
if (trade.getWallet().getUnlockedBalance().subtract(actualBuyerAmount.add(actualSellerAmount).add(txCost)).compareTo(BigInteger.valueOf(0)) > 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<ArbitrationDisputeL
public static BigInteger[] getBuyerSellerPayoutTxCost(DisputeResult disputeResult, BigInteger payoutTxCost) {
boolean isBuyerWinner = disputeResult.getWinner() == Winner.BUYER;
BigInteger loserAmount = isBuyerWinner ? disputeResult.getSellerPayoutAmountBeforeCost() : disputeResult.getBuyerPayoutAmountBeforeCost();
if (loserAmount.equals(BigInteger.valueOf(0))) {
if (loserAmount.equals(BigInteger.ZERO)) {
BigInteger buyerPayoutTxFee = isBuyerWinner ? payoutTxCost : BigInteger.ZERO;
BigInteger sellerPayoutTxFee = isBuyerWinner ? BigInteger.ZERO : payoutTxCost;
return new BigInteger[] { buyerPayoutTxFee, sellerPayoutTxFee };

View file

@ -216,8 +216,8 @@ public class ClosedTradableManager implements PersistedDataHost {
public BigInteger getXmrTradeFee(Tradable tradable) {
return isMaker(tradable) ?
tradable.getOptionalMakerFee().orElse(BigInteger.valueOf(0)) :
tradable.getOptionalTakerFee().orElse(BigInteger.valueOf(0));
tradable.getOptionalMakerFee().orElse(BigInteger.ZERO) :
tradable.getOptionalTakerFee().orElse(BigInteger.ZERO);
}
public boolean isMaker(Tradable tradable) {

View file

@ -199,11 +199,11 @@ public class HavenoUtils {
}
public static BigInteger parseXmr(String input) {
if (input == null || input.length() == 0) return BigInteger.valueOf(0);
if (input == null || input.length() == 0) return BigInteger.ZERO;
try {
return xmrToAtomicUnits(new BigDecimal(ParsingUtils.parseNumberStringToDouble(input)).doubleValue());
} catch (Exception e) {
return BigInteger.valueOf(0);
return BigInteger.ZERO;
}
}
@ -247,7 +247,7 @@ public class HavenoUtils {
public static BigInteger getFeePerXmr(BigInteger feePerXmr, BigInteger amount) {
BigDecimal feePerXmrAsDecimal = feePerXmr == null ? BigDecimal.valueOf(0) : new BigDecimal(feePerXmr);
BigDecimal amountMultiplier = BigDecimal.valueOf(divide(amount == null ? BigInteger.valueOf(0) : amount, HavenoUtils.xmrToAtomicUnits(1.0)));
BigDecimal amountMultiplier = BigDecimal.valueOf(divide(amount == null ? BigInteger.ZERO : amount, HavenoUtils.xmrToAtomicUnits(1.0)));
return feePerXmrAsDecimal.multiply(amountMultiplier).toBigInteger();
}

View file

@ -1658,7 +1658,7 @@ public abstract class Trade implements Tradable, Model {
}
public BigInteger getFrozenAmount() {
BigInteger sum = BigInteger.valueOf(0);
BigInteger sum = BigInteger.ZERO;
for (String keyImage : getSelf().getReserveTxKeyImages()) {
List<MoneroOutputWallet> 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());
}

View file

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

View file

@ -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<MoneroTx, BigInteger> txResult;
try {

View file

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

View file

@ -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.

View file

@ -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<MoneroOutputWallet> 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<Trade> trades = tradeManager.getTradesStreamWithFundsLockedIn().collect(Collectors.toList());
for (Trade trade : trades) {
sum = sum.add(trade.getReservedAmount());

View file

@ -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<XmrAddressEntry> 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<XmrAddressEntry> 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) {

View file

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

View file

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

View file

@ -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(),

View file

@ -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<Tradable> 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");
}
}

View file

@ -75,7 +75,7 @@ public class WithdrawalView extends ActivatableView<VBox, Void> {
private final P2PService p2PService;
private final WalletPasswordWindow walletPasswordWindow;
private XmrBalanceListener balanceListener;
private BigInteger amount = BigInteger.valueOf(0);
private BigInteger amount = BigInteger.ZERO;
private ChangeListener<String> amountListener;
private ChangeListener<Boolean> amountFocusListener;
private ChangeListener<Toggle> feeToggleGroupListener;
@ -148,7 +148,7 @@ public class WithdrawalView extends ActivatableView<VBox, Void> {
};
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<VBox, Void> {
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<VBox, Void> {
.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<VBox, Void> {
///////////////////////////////////////////////////////////////////////////////////////////
private void reset() {
amount = BigInteger.valueOf(0);
amount = BigInteger.ZERO;
amountTextField.setText("");
amountTextField.setPromptText(Res.get("funds.withdrawal.setAmount"));

View file

@ -123,7 +123,7 @@ public class SpreadView extends ActivatableViewAndModel<GridPane, SpreadViewMode
int numberOfBuyOffers = sortedList.stream().mapToInt(item -> 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);

View file

@ -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<Offer> offers = offersByCurrencyMap.get(key);

View file

@ -121,7 +121,7 @@ public abstract class MutableOfferDataModel extends OfferDataModel {
protected boolean allowAmountUpdate = true;
private final TradeStatisticsManager tradeStatisticsManager;
private final Predicate<ObjectProperty<BigInteger>> isNonZeroAmount = (c) -> c.get() != null && c.get().compareTo(BigInteger.valueOf(0)) != 0;
private final Predicate<ObjectProperty<BigInteger>> isNonZeroAmount = (c) -> c.get() != null && c.get().compareTo(BigInteger.ZERO) != 0;
private final Predicate<ObjectProperty<Price>> isNonZeroPrice = (p) -> p.get() != null && !p.get().isZero();
private final Predicate<ObjectProperty<Volume>> 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);

View file

@ -330,7 +330,7 @@ public abstract class MutableOfferView<M extends MutableOfferViewModel<?>> 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();
}
}

View file

@ -49,7 +49,7 @@ public abstract class OfferDataModel extends ActivatableDataModel {
@Getter
protected final ObjectProperty<BigInteger> availableBalance = new SimpleObjectProperty<>();
@Getter
protected final ObjectProperty<BigInteger> missingCoin = new SimpleObjectProperty<>(BigInteger.valueOf(0));
protected final ObjectProperty<BigInteger> missingCoin = new SimpleObjectProperty<>(BigInteger.ZERO);
@Getter
protected final BooleanProperty showWalletFundedNotification = new SimpleBooleanProperty();
@Getter

View file

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

View file

@ -360,7 +360,7 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
// Called from parent as the view does not get notified when the tab is closed
public void onClose() {
BigInteger availableBalance = model.dataModel.getAvailableBalance().get();
if (availableBalance != null && availableBalance.compareTo(BigInteger.valueOf(0)) > 0 && !model.takeOfferCompleted.get() && !DevEnv.isDevMode()) {
if (availableBalance != null && availableBalance.compareTo(BigInteger.ZERO) > 0 && !model.takeOfferCompleted.get() && !DevEnv.isDevMode()) {
model.dataModel.swapTradeToSavings();
}
}

View file

@ -364,7 +364,7 @@ public class DisputeSummaryWindow extends Overlay<DisputeSummaryWindow> {
// 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<DisputeSummaryWindow> {
String sellerPayoutAddressString = contract.getSellerPayoutAddressString();
List<MoneroDestination> 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<DisputeSummaryWindow> {
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);

View file

@ -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;
}
}

View file

@ -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));
}
}