Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alias offer search and other small fixes #695

Merged
merged 3 commits into from
Nov 20, 2022
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
2 changes: 1 addition & 1 deletion src/brs/Burst.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

public final class Burst {

public static final Version VERSION = Version.parse("v3.5.1");
public static final Version VERSION = Version.parse("v3.5.2-beta1");
public static final String APPLICATION = "BRS";

public static final String CONF_FOLDER = "./conf";
Expand Down
18 changes: 16 additions & 2 deletions src/brs/db/sql/SqlAliasStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
import brs.db.store.AliasStore;
import brs.db.store.DerivedTableManager;
import brs.util.Convert;

import org.jooq.Condition;
import org.jooq.DSLContext;
import org.jooq.Record;
import org.jooq.Record1;
import org.jooq.Result;
import org.jooq.SortField;

import java.util.ArrayList;
Expand Down Expand Up @@ -137,8 +141,18 @@ public Collection<Alias> getAliasesByOwner(long accountId, int from, int to) {
}

@Override
public Collection<Alias.Offer> getAliasOffers(int from, int to) {
return offerTable.getManyBy(brs.schema.Tables.ALIAS_OFFER.LATEST.eq(true), from, to);
public Collection<Alias.Offer> getAliasOffers(long account, long buyer, int from, int to) {
Condition conditions = ALIAS_OFFER.LATEST.eq(true);
if(account != 0L) {
Result<Record1<Long>> myAliases = Db.useDSLContext(ctx -> {
return ctx.select(ALIAS.ID).from(ALIAS).where(ALIAS.ACCOUNT_ID.eq(account)).fetch();
});
conditions = conditions.and(ALIAS_OFFER.ID.in(myAliases));
}
if(buyer != 0L) {
conditions = conditions.and(ALIAS_OFFER.BUYER_ID.eq(buyer));
}
return offerTable.getManyBy(conditions, from, to);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/brs/db/store/AliasStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface AliasStore {

Collection<Alias> getAliasesByOwner(long accountId, int from, int to);

Collection<Alias.Offer> getAliasOffers(int from, int to);
Collection<Alias.Offer> getAliasOffers(long account, long buyer, int from, int to);

Alias getAlias(String aliasName);
}
17 changes: 15 additions & 2 deletions src/brs/http/GetAliasesOnSale.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import brs.Alias;
import brs.BurstException;
import brs.services.AliasService;
import brs.util.Convert;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
Expand All @@ -19,7 +21,7 @@ public final class GetAliasesOnSale extends APIServlet.JsonRequestHandler {
private final AliasService aliasService;

GetAliasesOnSale(AliasService aliasService) {
super(new APITag[]{APITag.ALIASES}, FIRST_INDEX_PARAMETER, LAST_INDEX_PARAMETER);
super(new APITag[]{APITag.ALIASES}, ACCOUNT_PARAMETER, BUYER_PARAMETER, FIRST_INDEX_PARAMETER, LAST_INDEX_PARAMETER);
this.aliasService = aliasService;
}

Expand All @@ -28,9 +30,20 @@ public final class GetAliasesOnSale extends APIServlet.JsonRequestHandler {
JsonElement processRequest(HttpServletRequest req) throws BurstException {
int firstIndex = ParameterParser.getFirstIndex(req);
int lastIndex = ParameterParser.getLastIndex(req);

long account = 0L;
String accountId = Convert.emptyToNull(req.getParameter(ACCOUNT_PARAMETER));
if(accountId != null) {
account = Convert.parseUnsignedLong(accountId);
}
long buyer = 0L;
String buyerId = Convert.emptyToNull(req.getParameter(BUYER_PARAMETER));
if(buyerId != null) {
buyer = Convert.parseUnsignedLong(buyerId);
}

JsonArray aliasesJson = new JsonArray();
Collection<Alias.Offer> aliasOffers = aliasService.getAliasOffers(firstIndex, lastIndex);
Collection<Alias.Offer> aliasOffers = aliasService.getAliasOffers(account, buyer, firstIndex, lastIndex);
for(Alias.Offer offer : aliasOffers) {
Alias alias = aliasService.getAlias(offer.getId());
aliasesJson.add(JSONData.alias(alias, offer));
Expand Down
4 changes: 2 additions & 2 deletions src/brs/http/GetAssetsByName.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ JsonElement processRequest(HttpServletRequest req) throws BurstException {
}

int heightEnd = Burst.getBlockchain().getHeight();
// default is for any height
int heightStart = 0;
// default is one day window
int heightStart = heightEnd - 360;

String heightStartString = Convert.emptyToNull(req.getParameter(HEIGHT_START_PARAMETER));
if(heightStartString != null) {
Expand Down
2 changes: 1 addition & 1 deletion src/brs/services/AliasService.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface AliasService {

Collection<Alias> getAliasesByOwner(long accountId, int from, int to);

Collection<Alias.Offer> getAliasOffers(int from, int to);
Collection<Alias.Offer> getAliasOffers(long account, long buyer, int from, int to);

void addOrUpdateAlias(Transaction transaction, Attachment.MessagingAliasAssignment attachment);

Expand Down
4 changes: 2 additions & 2 deletions src/brs/services/impl/AliasServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public Collection<Alias> getAliasesByOwner(long accountId, int from, int to) {
}

@Override
public Collection<Alias.Offer> getAliasOffers(int from, int to) {
return aliasStore.getAliasOffers(from, to);
public Collection<Alias.Offer> getAliasOffers(long account, long buyer, int from, int to) {
return aliasStore.getAliasOffers(account, buyer, from, to);
}

@Override
Expand Down