forked from Qortal/qortal
Added "maximumCount" parameter to HSQLDBATRepository.getMatchingFinalATStatesQuorum() and use it to limit the number of ATs being returned in the query.
Initially set to 10 when used by the /crosschain/price/{blockchain} API, so that the price is based on the last 10 trades rather than every trade that has ever taken place.
This commit is contained in:
parent
f4520e2752
commit
8260cec713
@ -262,6 +262,7 @@ public class CrossChainResource {
|
|||||||
|
|
||||||
// We want both a minimum of 5 trades and enough trades to span at least 4 hours
|
// We want both a minimum of 5 trades and enough trades to span at least 4 hours
|
||||||
int minimumCount = 5;
|
int minimumCount = 5;
|
||||||
|
int maximumCount = 10;
|
||||||
long minimumPeriod = 4 * 60 * 60 * 1000L; // ms
|
long minimumPeriod = 4 * 60 * 60 * 1000L; // ms
|
||||||
Boolean isFinished = Boolean.TRUE;
|
Boolean isFinished = Boolean.TRUE;
|
||||||
|
|
||||||
@ -276,7 +277,7 @@ public class CrossChainResource {
|
|||||||
ACCT acct = acctInfo.getValue().get();
|
ACCT acct = acctInfo.getValue().get();
|
||||||
|
|
||||||
List<ATStateData> atStates = repository.getATRepository().getMatchingFinalATStatesQuorum(codeHash,
|
List<ATStateData> atStates = repository.getATRepository().getMatchingFinalATStatesQuorum(codeHash,
|
||||||
isFinished, acct.getModeByteOffset(), (long) AcctMode.REDEEMED.value, minimumCount, minimumPeriod);
|
isFinished, acct.getModeByteOffset(), (long) AcctMode.REDEEMED.value, minimumCount, maximumCount, minimumPeriod);
|
||||||
|
|
||||||
for (ATStateData atState : atStates) {
|
for (ATStateData atState : atStates) {
|
||||||
CrossChainTradeData crossChainTradeData = acct.populateTradeData(repository, atState);
|
CrossChainTradeData crossChainTradeData = acct.populateTradeData(repository, atState);
|
||||||
|
@ -98,7 +98,7 @@ public interface ATRepository {
|
|||||||
*/
|
*/
|
||||||
public List<ATStateData> getMatchingFinalATStatesQuorum(byte[] codeHash, Boolean isFinished,
|
public List<ATStateData> getMatchingFinalATStatesQuorum(byte[] codeHash, Boolean isFinished,
|
||||||
Integer dataByteOffset, Long expectedValue,
|
Integer dataByteOffset, Long expectedValue,
|
||||||
int minimumCount, long minimumPeriod) throws DataException;
|
int minimumCount, int maximumCount, long minimumPeriod) throws DataException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns all ATStateData for a given block height.
|
* Returns all ATStateData for a given block height.
|
||||||
|
@ -454,7 +454,7 @@ public class HSQLDBATRepository implements ATRepository {
|
|||||||
@Override
|
@Override
|
||||||
public List<ATStateData> getMatchingFinalATStatesQuorum(byte[] codeHash, Boolean isFinished,
|
public List<ATStateData> getMatchingFinalATStatesQuorum(byte[] codeHash, Boolean isFinished,
|
||||||
Integer dataByteOffset, Long expectedValue,
|
Integer dataByteOffset, Long expectedValue,
|
||||||
int minimumCount, long minimumPeriod) throws DataException {
|
int minimumCount, int maximumCount, long minimumPeriod) throws DataException {
|
||||||
// We need most recent entry first so we can use its timestamp to slice further results
|
// We need most recent entry first so we can use its timestamp to slice further results
|
||||||
List<ATStateData> mostRecentStates = this.getMatchingFinalATStates(codeHash, isFinished,
|
List<ATStateData> mostRecentStates = this.getMatchingFinalATStates(codeHash, isFinished,
|
||||||
dataByteOffset, expectedValue, null,
|
dataByteOffset, expectedValue, null,
|
||||||
@ -510,7 +510,8 @@ public class HSQLDBATRepository implements ATRepository {
|
|||||||
bindParams.add(minimumHeight);
|
bindParams.add(minimumHeight);
|
||||||
bindParams.add(minimumCount);
|
bindParams.add(minimumCount);
|
||||||
|
|
||||||
sql.append("ORDER BY FinalATStates.height DESC");
|
sql.append("ORDER BY FinalATStates.height DESC LIMIT ?");
|
||||||
|
bindParams.add(maximumCount);
|
||||||
|
|
||||||
List<ATStateData> atStates = new ArrayList<>();
|
List<ATStateData> atStates = new ArrayList<>();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user