mirror of
https://github.com/haveno-dex/haveno.git
synced 2024-12-22 11:39:29 +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,
|
||||
acceptedBanks,
|
||||
Version.VERSION,
|
||||
xmrWalletService.getWallet().getHeight(),
|
||||
xmrWalletService.getHeight(),
|
||||
maxTradeLimit,
|
||||
maxTradePeriod,
|
||||
useAutoClose,
|
||||
|
|
|
@ -472,7 +472,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
|||
});
|
||||
|
||||
// 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() {
|
||||
@Override
|
||||
public void onBalancesChanged(BigInteger newBalance, BigInteger newUnlockedBalance) {
|
||||
|
@ -916,7 +916,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
|||
} else {
|
||||
|
||||
// handle sufficient balance
|
||||
boolean hasSufficientBalance = xmrWalletService.getWallet().getUnlockedBalance(0).compareTo(amountNeeded) >= 0;
|
||||
boolean hasSufficientBalance = xmrWalletService.getAvailableBalance().compareTo(amountNeeded) >= 0;
|
||||
if (hasSufficientBalance) {
|
||||
signAndPostOffer(openOffer, true, resultHandler, errorMessageHandler);
|
||||
return;
|
||||
|
@ -1025,7 +1025,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
|||
private void splitOrSchedule(List<OpenOffer> openOffers, OpenOffer openOffer, BigInteger offerReserveAmount) {
|
||||
|
||||
// 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) {
|
||||
log.info("Splitting and scheduling outputs for offer {} at subaddress {}", openOffer.getShortId());
|
||||
splitAndSchedule(openOffer);
|
||||
|
@ -1073,7 +1073,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
|||
|
||||
// check for sufficient balance - scheduled offers amount
|
||||
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");
|
||||
}
|
||||
|
||||
|
@ -1105,7 +1105,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
|||
for (OpenOffer openOffer : openOffers) {
|
||||
if (openOffer.getState() != OpenOffer.State.SCHEDULED) 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) {
|
||||
if (fundingTx.getIncomingTransfers() != null) {
|
||||
for (MoneroIncomingTransfer transfer : fundingTx.getIncomingTransfers()) {
|
||||
|
|
|
@ -1140,6 +1140,10 @@ public class XmrWalletService {
|
|||
xmrAddressEntryList.requestPersistence();
|
||||
}
|
||||
|
||||
public long getHeight() {
|
||||
return walletHeight.get();
|
||||
}
|
||||
|
||||
public List<MoneroTxWallet> getTxs(boolean includeFailed) {
|
||||
List<MoneroTxWallet> txs = getTxs();
|
||||
if (includeFailed) return txs;
|
||||
|
@ -1158,6 +1162,10 @@ public class XmrWalletService {
|
|||
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) {
|
||||
List<MoneroTxWallet> txs = getTxs(new MoneroTxQuery().setHash(txId));
|
||||
return txs.isEmpty() ? null : txs.get(0);
|
||||
|
|
|
@ -22,7 +22,6 @@ import de.jensd.fx.fontawesome.AwesomeDude;
|
|||
import de.jensd.fx.fontawesome.AwesomeIcon;
|
||||
import haveno.common.util.Utilities;
|
||||
import haveno.core.locale.Res;
|
||||
import haveno.core.trade.HavenoUtils;
|
||||
import haveno.desktop.main.overlays.popups.Popup;
|
||||
import haveno.desktop.util.GUIUtil;
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
|
@ -158,7 +157,6 @@ public class AddressTextField extends AnchorPane {
|
|||
return GUIUtil.getMoneroURI(
|
||||
address.get(),
|
||||
amount.get(),
|
||||
paymentLabel.get(),
|
||||
HavenoUtils.havenoSetup.getXmrWalletService().getWallet());
|
||||
paymentLabel.get());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1214,8 +1214,7 @@ public abstract class MutableOfferView<M extends MutableOfferViewModel<?>> exten
|
|||
return GUIUtil.getMoneroURI(
|
||||
addressTextField.getAddress(),
|
||||
model.getDataModel().getMissingCoin().get(),
|
||||
model.getPaymentLabel(),
|
||||
model.dataModel.getXmrWalletService().getWallet());
|
||||
model.getPaymentLabel());
|
||||
}
|
||||
|
||||
private void addAmountPriceFields() {
|
||||
|
|
|
@ -950,8 +950,7 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
|
|||
return GUIUtil.getMoneroURI(
|
||||
model.dataModel.getAddressEntry().getAddressString(),
|
||||
model.dataModel.getMissingCoin().get(),
|
||||
model.getPaymentLabel(),
|
||||
model.dataModel.getXmrWalletService().getWallet());
|
||||
model.getPaymentLabel());
|
||||
}
|
||||
|
||||
private void addAmountPriceFields() {
|
||||
|
|
|
@ -95,7 +95,6 @@ import javafx.util.StringConverter;
|
|||
import lombok.extern.slf4j.Slf4j;
|
||||
import monero.common.MoneroUtils;
|
||||
import monero.daemon.model.MoneroTx;
|
||||
import monero.wallet.MoneroWallet;
|
||||
import monero.wallet.model.MoneroTxConfig;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bitcoinj.core.Coin;
|
||||
|
@ -686,7 +685,7 @@ public class GUIUtil {
|
|||
.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()
|
||||
.setAddress(address)
|
||||
.setAmount(amount)
|
||||
|
|
Loading…
Reference in a new issue