Skip to content

Commit 9046d3b

Browse files
committed
fix scheduling offers with funds sent to self
1 parent 52d2e7d commit 9046d3b

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

core/src/main/java/haveno/core/offer/OpenOfferManager.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,16 +1169,24 @@ private void scheduleWithEarliestTxs(List<OpenOffer> openOffers, OpenOffer openO
11691169
Set<MoneroTxWallet> scheduledTxs = new HashSet<MoneroTxWallet>();
11701170
for (MoneroTxWallet tx : xmrWalletService.getTxs()) {
11711171

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

1177-
// add scheduled tx
1178-
for (MoneroIncomingTransfer transfer : tx.getIncomingTransfers()) {
1179-
if (transfer.getAccountIndex() == 0) {
1180-
scheduledAmount = scheduledAmount.add(transfer.getAmount());
1181-
scheduledTxs.add(tx);
1178+
// schedule transaction if funds sent to self, because they are not included in incoming transfers // TODO: fix in libraries?
1179+
if (sentToSelfAmount.compareTo(BigInteger.ZERO) > 0) {
1180+
scheduledAmount = scheduledAmount.add(sentToSelfAmount);
1181+
scheduledTxs.add(tx);
1182+
} else if (tx.getIncomingTransfers() != null) {
1183+
1184+
// schedule transaction if incoming tranfers to account 0
1185+
for (MoneroIncomingTransfer transfer : tx.getIncomingTransfers()) {
1186+
if (transfer.getAccountIndex() == 0) {
1187+
scheduledAmount = scheduledAmount.add(transfer.getAmount());
1188+
scheduledTxs.add(tx);
1189+
}
11821190
}
11831191
}
11841192

core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,10 +1219,29 @@ public BigInteger getAvailableBalance() {
12191219
return cachedAvailableBalance;
12201220
}
12211221

1222+
public boolean hasAddress(String address) {
1223+
for (MoneroSubaddress subaddress : getSubaddresses()) {
1224+
if (subaddress.getAddress().equals(address)) return true;
1225+
}
1226+
return false;
1227+
}
1228+
12221229
public List<MoneroSubaddress> getSubaddresses() {
12231230
return cachedSubaddresses;
12241231
}
12251232

1233+
public BigInteger getAmountSentToSelf(MoneroTxWallet tx) {
1234+
BigInteger sentToSelfAmount = BigInteger.ZERO;
1235+
if (tx.getOutgoingTransfer() != null && tx.getOutgoingTransfer().getDestinations() != null) {
1236+
for (MoneroDestination destination : tx.getOutgoingTransfer().getDestinations()) {
1237+
if (hasAddress(destination.getAddress())) {
1238+
sentToSelfAmount = sentToSelfAmount.add(destination.getAmount());
1239+
}
1240+
}
1241+
}
1242+
return sentToSelfAmount;
1243+
}
1244+
12261245
public List<MoneroOutputWallet> getOutputs(MoneroOutputQuery query) {
12271246
List<MoneroOutputWallet> filteredOutputs = new ArrayList<MoneroOutputWallet>();
12281247
for (MoneroOutputWallet output : cachedOutputs) {

0 commit comments

Comments
 (0)