mirror of
https://github.com/haveno-dex/haveno.git
synced 2024-12-22 19:49:32 +00:00
use more cached wallet state instead of direct queries
This commit is contained in:
parent
a5883d7bcd
commit
e96b875232
7 changed files with 18 additions and 15 deletions
|
@ -203,7 +203,7 @@ public class CreateOfferService {
|
||||||
bankId,
|
bankId,
|
||||||
acceptedBanks,
|
acceptedBanks,
|
||||||
Version.VERSION,
|
Version.VERSION,
|
||||||
xmrWalletService.getWallet().getHeight(),
|
xmrWalletService.getHeight(),
|
||||||
maxTradeLimit,
|
maxTradeLimit,
|
||||||
maxTradePeriod,
|
maxTradePeriod,
|
||||||
useAutoClose,
|
useAutoClose,
|
||||||
|
|
|
@ -472,7 +472,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
||||||
});
|
});
|
||||||
|
|
||||||
// register to process unposted offers when unlocked balance increases
|
// register to process unposted offers when unlocked balance increases
|
||||||
if (xmrWalletService.getWallet() != null) lastUnlockedBalance = xmrWalletService.getWallet().getUnlockedBalance(0);
|
if (xmrWalletService.getWallet() != null) lastUnlockedBalance = xmrWalletService.getAvailableBalance();
|
||||||
xmrWalletService.addWalletListener(new MoneroWalletListener() {
|
xmrWalletService.addWalletListener(new MoneroWalletListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onBalancesChanged(BigInteger newBalance, BigInteger newUnlockedBalance) {
|
public void onBalancesChanged(BigInteger newBalance, BigInteger newUnlockedBalance) {
|
||||||
|
@ -916,7 +916,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// handle sufficient balance
|
// handle sufficient balance
|
||||||
boolean hasSufficientBalance = xmrWalletService.getWallet().getUnlockedBalance(0).compareTo(amountNeeded) >= 0;
|
boolean hasSufficientBalance = xmrWalletService.getAvailableBalance().compareTo(amountNeeded) >= 0;
|
||||||
if (hasSufficientBalance) {
|
if (hasSufficientBalance) {
|
||||||
signAndPostOffer(openOffer, true, resultHandler, errorMessageHandler);
|
signAndPostOffer(openOffer, true, resultHandler, errorMessageHandler);
|
||||||
return;
|
return;
|
||||||
|
@ -1025,7 +1025,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
||||||
private void splitOrSchedule(List<OpenOffer> openOffers, OpenOffer openOffer, BigInteger offerReserveAmount) {
|
private void splitOrSchedule(List<OpenOffer> openOffers, OpenOffer openOffer, BigInteger offerReserveAmount) {
|
||||||
|
|
||||||
// handle sufficient available balance to split output
|
// handle sufficient available balance to split output
|
||||||
boolean sufficientAvailableBalance = xmrWalletService.getWallet().getUnlockedBalance(0).compareTo(offerReserveAmount) >= 0;
|
boolean sufficientAvailableBalance = xmrWalletService.getAvailableBalance().compareTo(offerReserveAmount) >= 0;
|
||||||
if (sufficientAvailableBalance) {
|
if (sufficientAvailableBalance) {
|
||||||
log.info("Splitting and scheduling outputs for offer {} at subaddress {}", openOffer.getShortId());
|
log.info("Splitting and scheduling outputs for offer {} at subaddress {}", openOffer.getShortId());
|
||||||
splitAndSchedule(openOffer);
|
splitAndSchedule(openOffer);
|
||||||
|
@ -1073,7 +1073,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
||||||
|
|
||||||
// check for sufficient balance - scheduled offers amount
|
// check for sufficient balance - scheduled offers amount
|
||||||
BigInteger offerReserveAmount = openOffer.getOffer().getAmountNeeded();
|
BigInteger offerReserveAmount = openOffer.getOffer().getAmountNeeded();
|
||||||
if (xmrWalletService.getWallet().getBalance(0).subtract(getScheduledAmount(openOffers)).compareTo(offerReserveAmount) < 0) {
|
if (xmrWalletService.getBalance().subtract(getScheduledAmount(openOffers)).compareTo(offerReserveAmount) < 0) {
|
||||||
throw new RuntimeException("Not enough money in Haveno wallet");
|
throw new RuntimeException("Not enough money in Haveno wallet");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1105,7 +1105,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
||||||
for (OpenOffer openOffer : openOffers) {
|
for (OpenOffer openOffer : openOffers) {
|
||||||
if (openOffer.getState() != OpenOffer.State.SCHEDULED) continue;
|
if (openOffer.getState() != OpenOffer.State.SCHEDULED) continue;
|
||||||
if (openOffer.getScheduledTxHashes() == null) continue;
|
if (openOffer.getScheduledTxHashes() == null) continue;
|
||||||
List<MoneroTxWallet> fundingTxs = xmrWalletService.getWallet().getTxs(openOffer.getScheduledTxHashes());
|
List<MoneroTxWallet> fundingTxs = xmrWalletService.getTxs(openOffer.getScheduledTxHashes());
|
||||||
for (MoneroTxWallet fundingTx : fundingTxs) {
|
for (MoneroTxWallet fundingTx : fundingTxs) {
|
||||||
if (fundingTx.getIncomingTransfers() != null) {
|
if (fundingTx.getIncomingTransfers() != null) {
|
||||||
for (MoneroIncomingTransfer transfer : fundingTx.getIncomingTransfers()) {
|
for (MoneroIncomingTransfer transfer : fundingTx.getIncomingTransfers()) {
|
||||||
|
|
|
@ -1140,6 +1140,10 @@ public class XmrWalletService {
|
||||||
xmrAddressEntryList.requestPersistence();
|
xmrAddressEntryList.requestPersistence();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getHeight() {
|
||||||
|
return walletHeight.get();
|
||||||
|
}
|
||||||
|
|
||||||
public List<MoneroTxWallet> getTxs(boolean includeFailed) {
|
public List<MoneroTxWallet> getTxs(boolean includeFailed) {
|
||||||
List<MoneroTxWallet> txs = getTxs();
|
List<MoneroTxWallet> txs = getTxs();
|
||||||
if (includeFailed) return txs;
|
if (includeFailed) return txs;
|
||||||
|
@ -1158,6 +1162,10 @@ public class XmrWalletService {
|
||||||
return cachedTxs.stream().filter(tx -> query.meetsCriteria(tx)).collect(Collectors.toList());
|
return cachedTxs.stream().filter(tx -> query.meetsCriteria(tx)).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<MoneroTxWallet> getTxs(List<String> txIds) {
|
||||||
|
return getTxs(new MoneroTxQuery().setHashes(txIds));
|
||||||
|
}
|
||||||
|
|
||||||
public MoneroTxWallet getTx(String txId) {
|
public MoneroTxWallet getTx(String txId) {
|
||||||
List<MoneroTxWallet> txs = getTxs(new MoneroTxQuery().setHash(txId));
|
List<MoneroTxWallet> txs = getTxs(new MoneroTxQuery().setHash(txId));
|
||||||
return txs.isEmpty() ? null : txs.get(0);
|
return txs.isEmpty() ? null : txs.get(0);
|
||||||
|
|
|
@ -22,7 +22,6 @@ import de.jensd.fx.fontawesome.AwesomeDude;
|
||||||
import de.jensd.fx.fontawesome.AwesomeIcon;
|
import de.jensd.fx.fontawesome.AwesomeIcon;
|
||||||
import haveno.common.util.Utilities;
|
import haveno.common.util.Utilities;
|
||||||
import haveno.core.locale.Res;
|
import haveno.core.locale.Res;
|
||||||
import haveno.core.trade.HavenoUtils;
|
|
||||||
import haveno.desktop.main.overlays.popups.Popup;
|
import haveno.desktop.main.overlays.popups.Popup;
|
||||||
import haveno.desktop.util.GUIUtil;
|
import haveno.desktop.util.GUIUtil;
|
||||||
import javafx.beans.property.ObjectProperty;
|
import javafx.beans.property.ObjectProperty;
|
||||||
|
@ -158,7 +157,6 @@ public class AddressTextField extends AnchorPane {
|
||||||
return GUIUtil.getMoneroURI(
|
return GUIUtil.getMoneroURI(
|
||||||
address.get(),
|
address.get(),
|
||||||
amount.get(),
|
amount.get(),
|
||||||
paymentLabel.get(),
|
paymentLabel.get());
|
||||||
HavenoUtils.havenoSetup.getXmrWalletService().getWallet());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1214,8 +1214,7 @@ public abstract class MutableOfferView<M extends MutableOfferViewModel<?>> exten
|
||||||
return GUIUtil.getMoneroURI(
|
return GUIUtil.getMoneroURI(
|
||||||
addressTextField.getAddress(),
|
addressTextField.getAddress(),
|
||||||
model.getDataModel().getMissingCoin().get(),
|
model.getDataModel().getMissingCoin().get(),
|
||||||
model.getPaymentLabel(),
|
model.getPaymentLabel());
|
||||||
model.dataModel.getXmrWalletService().getWallet());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addAmountPriceFields() {
|
private void addAmountPriceFields() {
|
||||||
|
|
|
@ -950,8 +950,7 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
|
||||||
return GUIUtil.getMoneroURI(
|
return GUIUtil.getMoneroURI(
|
||||||
model.dataModel.getAddressEntry().getAddressString(),
|
model.dataModel.getAddressEntry().getAddressString(),
|
||||||
model.dataModel.getMissingCoin().get(),
|
model.dataModel.getMissingCoin().get(),
|
||||||
model.getPaymentLabel(),
|
model.getPaymentLabel());
|
||||||
model.dataModel.getXmrWalletService().getWallet());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addAmountPriceFields() {
|
private void addAmountPriceFields() {
|
||||||
|
|
|
@ -95,7 +95,6 @@ import javafx.util.StringConverter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import monero.common.MoneroUtils;
|
import monero.common.MoneroUtils;
|
||||||
import monero.daemon.model.MoneroTx;
|
import monero.daemon.model.MoneroTx;
|
||||||
import monero.wallet.MoneroWallet;
|
|
||||||
import monero.wallet.model.MoneroTxConfig;
|
import monero.wallet.model.MoneroTxConfig;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bitcoinj.core.Coin;
|
import org.bitcoinj.core.Coin;
|
||||||
|
@ -686,7 +685,7 @@ public class GUIUtil {
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getMoneroURI(String address, BigInteger amount, String label, MoneroWallet wallet) {
|
public static String getMoneroURI(String address, BigInteger amount, String label) {
|
||||||
return MoneroUtils.getPaymentUri(new MoneroTxConfig()
|
return MoneroUtils.getPaymentUri(new MoneroTxConfig()
|
||||||
.setAddress(address)
|
.setAddress(address)
|
||||||
.setAmount(amount)
|
.setAmount(amount)
|
||||||
|
|
Loading…
Reference in a new issue