forked from Qortal/qortal
Filter failed trade after 1 attempt
This commit is contained in:
parent
db7b17e52e
commit
404c5d0300
@ -712,30 +712,16 @@ public class TradeBot implements Listener {
|
||||
}
|
||||
|
||||
try {
|
||||
List<byte[]> signatures = repository.getTransactionRepository().getSignaturesMatchingCriteria(null, null, null, Arrays.asList(Transaction.TransactionType.MESSAGE), null, null, crossChainTradeData.qortalCreatorTradeAddress, TransactionsResource.ConfirmationStatus.BOTH, null, null, null);
|
||||
if (signatures.size() < getMaxTradeOfferAttempts) {
|
||||
// Less than 3 (or user-specified number of) MESSAGE transactions relate to this trade, so assume it is ok
|
||||
validTrades.put(crossChainTradeData.qortalAtAddress, now);
|
||||
continue;
|
||||
}
|
||||
List<TransactionData> transactions = repository.getTransactionRepository().getUnconfirmedTransactions(Arrays.asList(Transaction.TransactionType.MESSAGE), null, null, null, null);
|
||||
|
||||
List<TransactionData> transactions = new ArrayList<>(signatures.size());
|
||||
for (byte[] signature : signatures) {
|
||||
transactions.add(repository.getTransactionRepository().fromSignature(signature));
|
||||
}
|
||||
transactions.sort(Transaction.getDataComparator());
|
||||
|
||||
// Get timestamp of the first MESSAGE transaction
|
||||
long firstMessageTimestamp = transactions.get(0).getTimestamp();
|
||||
|
||||
// Treat as failed if first buy attempt was more than 60 mins ago (as it's still in the OFFERING state)
|
||||
boolean isFailed = (now - firstMessageTimestamp > 60*60*1000L);
|
||||
if (isFailed) {
|
||||
failedTrades.put(crossChainTradeData.qortalAtAddress, now);
|
||||
updatedCrossChainTrades.remove(crossChainTradeData);
|
||||
}
|
||||
else {
|
||||
validTrades.put(crossChainTradeData.qortalAtAddress, now);
|
||||
for (TransactionData transactionData : transactions) {
|
||||
// Treat as failed if buy attempt was more than 60 mins ago (as it's still in the OFFERING state)
|
||||
if (transactionData.getRecipient().equals(crossChainTradeData.qortalCreatorTradeAddress) && now - transactionData.getTimestamp() > 60*60*1000L) {
|
||||
failedTrades.put(crossChainTradeData.qortalAtAddress, now);
|
||||
updatedCrossChainTrades.remove(crossChainTradeData);
|
||||
} else {
|
||||
validTrades.put(crossChainTradeData.qortalAtAddress, now);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (DataException e) {
|
||||
|
@ -75,6 +75,9 @@ public abstract class TransactionData {
|
||||
@Schema(description = "groupID for this transaction")
|
||||
protected int txGroupId;
|
||||
|
||||
@Schema(description = "recipient for this transaction")
|
||||
protected String recipient;
|
||||
|
||||
// Not always present
|
||||
@Schema(accessMode = AccessMode.READ_ONLY, hidden = true, description = "height of block containing transaction")
|
||||
protected Integer blockHeight;
|
||||
@ -105,7 +108,7 @@ public abstract class TransactionData {
|
||||
/** Constructor for use by transaction subclasses. */
|
||||
protected TransactionData(TransactionType type, BaseTransactionData baseTransactionData) {
|
||||
this.type = type;
|
||||
|
||||
this.recipient = baseTransactionData.recipient;
|
||||
this.timestamp = baseTransactionData.timestamp;
|
||||
this.txGroupId = baseTransactionData.txGroupId;
|
||||
this.reference = baseTransactionData.reference;
|
||||
@ -136,6 +139,10 @@ public abstract class TransactionData {
|
||||
return this.txGroupId;
|
||||
}
|
||||
|
||||
public String getRecipient() {
|
||||
return this.recipient;
|
||||
}
|
||||
|
||||
public void setTxGroupId(int txGroupId) {
|
||||
this.txGroupId = txGroupId;
|
||||
}
|
||||
@ -250,5 +257,4 @@ public abstract class TransactionData {
|
||||
|
||||
return Arrays.equals(this.signature, otherTransactionData.signature);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user