Skip to content

Commit

Permalink
add filter by event id, support duplicate event creation txs, b 250
Browse files Browse the repository at this point in the history
  • Loading branch information
MIPPL committed Nov 16, 2019
1 parent 96fab49 commit 70abbc3
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 10 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
Binary file modified .idea/caches/gradle_models.ser
Binary file not shown.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId = 'com.wagerrwallet'
minSdkVersion 23
targetSdkVersion 28
versionCode 249
versionName "249"
versionCode 250
versionName "250"
multiDexEnabled true

// Similar to other properties in the defaultConfig block,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class TxUiHolder {
private int txSize;
public TxMetaData metaData;
private BetEntity betEntity;
private BetResultEntity betResultEntity;
private String teamSearchDescription;

private TxUiHolder() {
Expand All @@ -77,12 +78,16 @@ public TxUiHolder(long timeStamp, int blockHeight, byte[] hash, String txReverse
this.txSize = txSize;
this.isCoinbase = isCoinbase;
betEntity = null;
betResultEntity = null;
this.teamSearchDescription = "";
}

public BetEntity getBetEntity() { return betEntity;}
public void setBetEntity( BetEntity be ) { betEntity=be; }

public BetResultEntity getBetResultEntity() { return betResultEntity;}
public void setBetResultEntity( BetResultEntity br ) { betResultEntity=br; }

public int getBlockHeight() {
return blockHeight;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@ public void filter(final long[] switches, boolean bNotify, String query) {
// team match
boolean matchesTeam = item.getTxHomeTeam().toLowerCase().contains(lowerQuery)
|| item.getTxAwayTeam().toLowerCase().contains(lowerQuery);
if ( matchesTeam ) {
boolean matchesEventId = Utils.isInteger(lowerQuery) && item.getEventID()==Integer.parseInt(lowerQuery);

if ( matchesTeam || matchesEventId ) {
if (switchesON == 0) {
filteredList.add(item);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ else if (confirms == 3)
BetResultTxDataStore brds = BetResultTxDataStore.getInstance(mContext);
BetResultEntity br = brds.getByBlockHeight(mContext, wallet.getIso(mContext), item.getBlockHeight() - 1);
if (br != null) {
item.setBetResultEntity( br );
eventID = br.getEventID();
EventTxUiHolder ev = BetEventTxDataStore.getInstance(mContext).getTransactionByEventId(mContext, "wgr", eventID);
if (ev != null) {
Expand Down Expand Up @@ -406,11 +407,14 @@ private void filter(final String query, final boolean[] switches, final boolean[
item = backUpFeed.get(i);
boolean matchesHash = item.getTxHashHexReversed() != null && item.getTxHashHexReversed().toLowerCase().contains(lowerQuery);
boolean matchesAddress = item.getToRecipient(wallet, false).toLowerCase().contains(lowerQuery) || item.getToRecipient(wallet, true).toLowerCase().contains(lowerQuery);
boolean matchesMemo = item.metaData != null && item.metaData.comment != null && item.metaData.comment.toLowerCase().contains(lowerQuery);
//boolean matchesMemo = item.metaData != null && item.metaData.comment != null && item.metaData.comment.toLowerCase().contains(lowerQuery);
// team match
boolean matchesTeam = !item.getTeamSearchDescription().isEmpty() && item.getTeamSearchDescription().toLowerCase().contains(lowerQuery);
boolean matchesEventId = Utils.isInteger(lowerQuery) &&
((item.getBetEntity()!=null) && item.getBetEntity().getEventID()==Integer.parseInt(lowerQuery) // bets
|| (item.getBetResultEntity()!=null) && item.getBetResultEntity().getEventID()==Integer.parseInt(lowerQuery) ); // payouts

if (matchesHash || matchesAddress || matchesMemo || matchesTeam ) {
if (matchesHash || matchesAddress || matchesTeam || matchesEventId) {
if (switchesON == 0) {
filteredList.add(item);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,13 @@ public BetEventEntity putTransaction(Context app, String iso, BetEventEntity tra
try {
database = openDatabase();
BetEventEntity transactionEntity1 = getTxByHash(app,iso, transactionEntity.getTxHash());
BetEventEntity transactionEntity2 = getByEventIdLowerHeight(app,iso, transactionEntity.getEventID(), transactionEntity.getBlockheight());
if (transactionEntity1==null) {
ContentValues values = new ContentValues();

values.put(BRSQLiteHelper.BETX_COLUMN_ID, transactionEntity.getTxHash());
values.put(BRSQLiteHelper.BETX_TYPE, transactionEntity.getType().getNumber());
values.put(BRSQLiteHelper.BETX_VERSION, transactionEntity.getVersion());
values.put(BRSQLiteHelper.BETX_EVENTID, transactionEntity.getEventID());
values.put(BRSQLiteHelper.BETX_EVENT_TIMESTAMP, transactionEntity.getEventTimestamp());
values.put(BRSQLiteHelper.BETX_SPORT, transactionEntity.getSportID());
values.put(BRSQLiteHelper.BETX_TOURNAMENT, transactionEntity.getTournamentID());
Expand All @@ -124,7 +125,18 @@ public BetEventEntity putTransaction(Context app, String iso, BetEventEntity tra
values.put(BRSQLiteHelper.BETX_ISO, iso.toUpperCase());

database.beginTransaction();
database.insert(BRSQLiteHelper.BETX_TABLE_NAME, null, values);

// request, we may receive correction txs
if (transactionEntity2!=null) {
database.update(BRSQLiteHelper.BETX_TABLE_NAME, values, BRSQLiteHelper.BETX_EVENTID + "=? AND " + BRSQLiteHelper.TX_ISO + "=?",
new String[]{String.valueOf(transactionEntity.getEventID()), iso.toUpperCase()} );
}
else {
values.put(BRSQLiteHelper.BETX_EVENTID, transactionEntity.getEventID());
database.insert(BRSQLiteHelper.BETX_TABLE_NAME, null, values);
}


cursor = database.query(BRSQLiteHelper.BETX_TABLE_NAME,
allColumns, BRSQLiteHelper.BETX_EVENTID + "=? AND " + BRSQLiteHelper.TX_ISO + "=?",
new String[]{String.valueOf(transactionEntity.getEventID()), iso.toUpperCase()}, null, null, null);
Expand Down Expand Up @@ -265,16 +277,16 @@ public boolean updateTotalsMarket(Context app, String iso, BetEventEntity transa
return ret;
}

public BetEventEntity getById(Context app, String iso, int eventID) {
public BetEventEntity getByEventIdLowerHeight(Context app, String iso, long eventID, long blockHeight) {
Cursor cursor = null;
BetEventEntity transactionEntity1 = null;
try {
int r=0;
database = openDatabase();

cursor = database.query(BRSQLiteHelper.BETX_TABLE_NAME,
allColumns, BRSQLiteHelper.BETX_EVENTID + "=? AND " + BRSQLiteHelper.TX_ISO + "=?",
new String[]{ String.valueOf(eventID), iso.toUpperCase()},null,null,null);
allColumns, BRSQLiteHelper.BETX_EVENTID + "=? AND " + BRSQLiteHelper.TX_ISO + "=? AND " + BRSQLiteHelper.TX_BLOCK_HEIGHT + "<?" ,
new String[]{ String.valueOf(eventID), iso.toUpperCase(), String.valueOf(blockHeight) },null,null,null);
if (cursor.getCount()==1) {
cursor.moveToFirst();
transactionEntity1 = cursorToTransaction(app, iso.toUpperCase(), cursor);
Expand Down
24 changes: 24 additions & 0 deletions app/src/main/java/com/wagerrwallet/tools/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,28 @@ public static String reverseHex(String hex) {
return result.reverse().toString();
}

// 20 times faster than try..parseint..catch alternative
public static boolean isInteger(String str) {
if (str == null) {
return false;
}
int length = str.length();
if (length == 0) {
return false;
}
int i = 0;
if (str.charAt(0) == '-') {
if (length == 1) {
return false;
}
i = 1;
}
for (; i < length; i++) {
char c = str.charAt(i);
if (c < '0' || c > '9') {
return false;
}
}
return true;
}
}

0 comments on commit 70abbc3

Please sign in to comment.