mirror of
https://github.com/haveno-dex/haveno.git
synced 2024-12-22 19:49:32 +00:00
fix scheduling offers with funds sent to self
This commit is contained in:
parent
8fd7f17317
commit
7d17d7d40d
2 changed files with 36 additions and 6 deletions
|
@ -1169,18 +1169,29 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
||||||
Set<MoneroTxWallet> scheduledTxs = new HashSet<MoneroTxWallet>();
|
Set<MoneroTxWallet> scheduledTxs = new HashSet<MoneroTxWallet>();
|
||||||
for (MoneroTxWallet tx : xmrWalletService.getTxs()) {
|
for (MoneroTxWallet tx : xmrWalletService.getTxs()) {
|
||||||
|
|
||||||
// skip if outputs unavailable
|
// skip if no funds available
|
||||||
if (tx.getIncomingTransfers() == null || tx.getIncomingTransfers().isEmpty()) continue;
|
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 (!isOutputsAvailable(tx)) continue;
|
||||||
if (isTxScheduledByOtherOffer(openOffers, openOffer, tx.getHash())) continue;
|
if (isTxScheduledByOtherOffer(openOffers, openOffer, tx.getHash())) continue;
|
||||||
|
|
||||||
// add scheduled tx
|
// schedule transaction if incoming tranfers to account 0
|
||||||
|
if (tx.getIncomingTransfers() != null) {
|
||||||
for (MoneroIncomingTransfer transfer : tx.getIncomingTransfers()) {
|
for (MoneroIncomingTransfer transfer : tx.getIncomingTransfers()) {
|
||||||
if (transfer.getAccountIndex() == 0) {
|
if (transfer.getAccountIndex() == 0) {
|
||||||
scheduledAmount = scheduledAmount.add(transfer.getAmount());
|
scheduledAmount = scheduledAmount.add(transfer.getAmount());
|
||||||
scheduledTxs.add(tx);
|
scheduledTxs.add(tx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// schedule transaction if funds sent to self, because they are not included in incoming transfers // TODO: fix in libraries?
|
||||||
|
if (!scheduledTxs.contains(tx)) {
|
||||||
|
if (sentToSelfAmount.compareTo(BigInteger.ZERO) > 0) {
|
||||||
|
scheduledAmount = scheduledAmount.add(sentToSelfAmount);
|
||||||
|
scheduledTxs.add(tx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// break if sufficient funds
|
// break if sufficient funds
|
||||||
if (scheduledAmount.compareTo(offerReserveAmount) >= 0) break;
|
if (scheduledAmount.compareTo(offerReserveAmount) >= 0) break;
|
||||||
|
|
|
@ -1219,10 +1219,29 @@ public class XmrWalletService extends XmrWalletBase {
|
||||||
return cachedAvailableBalance;
|
return cachedAvailableBalance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasAddress(String address) {
|
||||||
|
for (MoneroSubaddress subaddress : getSubaddresses()) {
|
||||||
|
if (subaddress.getAddress().equals(address)) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public List<MoneroSubaddress> getSubaddresses() {
|
public List<MoneroSubaddress> getSubaddresses() {
|
||||||
return cachedSubaddresses;
|
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) {
|
public List<MoneroOutputWallet> getOutputs(MoneroOutputQuery query) {
|
||||||
List<MoneroOutputWallet> filteredOutputs = new ArrayList<MoneroOutputWallet>();
|
List<MoneroOutputWallet> filteredOutputs = new ArrayList<MoneroOutputWallet>();
|
||||||
for (MoneroOutputWallet output : cachedOutputs) {
|
for (MoneroOutputWallet output : cachedOutputs) {
|
||||||
|
|
Loading…
Reference in a new issue