Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions core/src/main/java/haveno/core/offer/OpenOfferManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -1169,16 +1169,24 @@ private void scheduleWithEarliestTxs(List<OpenOffer> openOffers, OpenOffer openO
Set<MoneroTxWallet> scheduledTxs = new HashSet<MoneroTxWallet>();
for (MoneroTxWallet tx : xmrWalletService.getTxs()) {

// skip if outputs unavailable
if (tx.getIncomingTransfers() == null || tx.getIncomingTransfers().isEmpty()) continue;
// skip if no funds available
BigInteger sentToSelfAmount = xmrWalletService.getAmountSentToSelf(tx); // amount sent to self always shows 0, so compute from destinations manually
if (sentToSelfAmount.equals(BigInteger.ZERO) && (tx.getIncomingTransfers() == null || tx.getIncomingTransfers().isEmpty())) continue;
if (!isOutputsAvailable(tx)) continue;
if (isTxScheduledByOtherOffer(openOffers, openOffer, tx.getHash())) continue;

// add scheduled tx
for (MoneroIncomingTransfer transfer : tx.getIncomingTransfers()) {
if (transfer.getAccountIndex() == 0) {
scheduledAmount = scheduledAmount.add(transfer.getAmount());
scheduledTxs.add(tx);
// schedule transaction if funds sent to self, because they are not included in incoming transfers // TODO: fix in libraries?
if (sentToSelfAmount.compareTo(BigInteger.ZERO) > 0) {
scheduledAmount = scheduledAmount.add(sentToSelfAmount);
scheduledTxs.add(tx);
} else if (tx.getIncomingTransfers() != null) {

// schedule transaction if incoming tranfers to account 0
for (MoneroIncomingTransfer transfer : tx.getIncomingTransfers()) {
if (transfer.getAccountIndex() == 0) {
scheduledAmount = scheduledAmount.add(transfer.getAmount());
scheduledTxs.add(tx);
}
}
}

Expand Down
19 changes: 19 additions & 0 deletions core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java
Original file line number Diff line number Diff line change
Expand Up @@ -1219,10 +1219,29 @@ public BigInteger getAvailableBalance() {
return cachedAvailableBalance;
}

public boolean hasAddress(String address) {
for (MoneroSubaddress subaddress : getSubaddresses()) {
if (subaddress.getAddress().equals(address)) return true;
}
return false;
}

public List<MoneroSubaddress> getSubaddresses() {
return cachedSubaddresses;
}

public BigInteger getAmountSentToSelf(MoneroTxWallet tx) {
BigInteger sentToSelfAmount = BigInteger.ZERO;
if (tx.getOutgoingTransfer() != null && tx.getOutgoingTransfer().getDestinations() != null) {
for (MoneroDestination destination : tx.getOutgoingTransfer().getDestinations()) {
if (hasAddress(destination.getAddress())) {
sentToSelfAmount = sentToSelfAmount.add(destination.getAmount());
}
}
}
return sentToSelfAmount;
}

public List<MoneroOutputWallet> getOutputs(MoneroOutputQuery query) {
List<MoneroOutputWallet> filteredOutputs = new ArrayList<MoneroOutputWallet>();
for (MoneroOutputWallet output : cachedOutputs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ void onPlaceOffer(Offer offer, Runnable resultHandler) {

dataModel.onPlaceOffer(offer, transaction -> {
resultHandler.run();
placeOfferCompleted.set(true);
if (!createOfferCanceled) placeOfferCompleted.set(true);
errorMessage.set(null);
}, errMessage -> {
createOfferRequested = false;
Expand Down
Loading