Skip to content

Commit

Permalink
overwrite dupe mappings in DB if height is higher
Browse files Browse the repository at this point in the history
clean up all existing dupes on DB
b284
  • Loading branch information
MIPPL committed Sep 13, 2020
1 parent fa1646c commit a3410a9
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 22 deletions.
Binary file modified .idea/caches/build_file_checksums.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 283
versionName "283"
versionCode 284
versionName "284"
multiDexEnabled true

// Similar to other properties in the defaultConfig block,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,27 +84,46 @@ public BetMappingEntity putTransaction(Context app, String iso, BetMappingEntity
try {
database = openDatabase();
BetMappingEntity transactionEntity1 = getTxByHash(app,iso, transactionEntity.getTxHash());
if (transactionEntity1==null) {
ContentValues values = new ContentValues();
values.put(BRSQLiteHelper.BMTX_COLUMN_ID, transactionEntity.getTxHash());
values.put(BRSQLiteHelper.BMTX_TYPE, transactionEntity.getType().getNumber());
values.put(BRSQLiteHelper.BMTX_VERSION, transactionEntity.getVersion());
values.put(BRSQLiteHelper.BMTX_BLOCK_HEIGHT, transactionEntity.getBlockheight());
values.put(BRSQLiteHelper.BMTX_ISO, iso.toUpperCase());
values.put(BRSQLiteHelper.BMTX_TIMESTAMP, transactionEntity.getTimestamp());
values.put(BRSQLiteHelper.BMTX_NAMESPACEID, transactionEntity.getNamespaceID().getNumber());
values.put(BRSQLiteHelper.BMTX_MAPPINGID, transactionEntity.getMappingID());
values.put(BRSQLiteHelper.BMTX_STRING, transactionEntity.getDescription());
values.put(BRSQLiteHelper.BMTX_TIMESTAMP, transactionEntity.getTimestamp());

database.beginTransaction();
database.insert(BRSQLiteHelper.BMTX_TABLE_NAME, null, values);
cursor = database.query(BRSQLiteHelper.BMTX_TABLE_NAME,
allColumns, null, null, null, null, null);
cursor.moveToFirst();
transactionEntity1 = cursorToTransaction(app, iso.toUpperCase(), cursor);

database.setTransactionSuccessful();
if (transactionEntity1==null) {
transactionEntity1 = getMappingById(app, iso, transactionEntity.getNamespaceID(), transactionEntity.getMappingID());
if (transactionEntity1==null) { // not dupe, insert
ContentValues values = new ContentValues();
values.put(BRSQLiteHelper.BMTX_COLUMN_ID, transactionEntity.getTxHash());
values.put(BRSQLiteHelper.BMTX_TYPE, transactionEntity.getType().getNumber());
values.put(BRSQLiteHelper.BMTX_VERSION, transactionEntity.getVersion());
values.put(BRSQLiteHelper.BMTX_BLOCK_HEIGHT, transactionEntity.getBlockheight());
values.put(BRSQLiteHelper.BMTX_ISO, iso.toUpperCase());
values.put(BRSQLiteHelper.BMTX_NAMESPACEID, transactionEntity.getNamespaceID().getNumber());
values.put(BRSQLiteHelper.BMTX_MAPPINGID, transactionEntity.getMappingID());
values.put(BRSQLiteHelper.BMTX_STRING, transactionEntity.getDescription());
values.put(BRSQLiteHelper.BMTX_TIMESTAMP, transactionEntity.getTimestamp());

database.beginTransaction();
database.insert(BRSQLiteHelper.BMTX_TABLE_NAME, null, values);
database.setTransactionSuccessful();
/* don´t use the return actually, let´s make it faster
cursor = database.query(BRSQLiteHelper.BMTX_TABLE_NAME,
allColumns, null, null, null, null, null);
cursor.moveToFirst();
transactionEntity1 = cursorToTransaction(app, iso.toUpperCase(), cursor);
*/
}
else { // duplicate, update only
if (transactionEntity.getBlockheight() > transactionEntity1.getBlockheight()) {
ContentValues values = new ContentValues();
values.put(BRSQLiteHelper.BMTX_COLUMN_ID, transactionEntity.getTxHash());
values.put(BRSQLiteHelper.BMTX_BLOCK_HEIGHT, transactionEntity.getBlockheight());
values.put(BRSQLiteHelper.BMTX_STRING, transactionEntity.getDescription());
values.put(BRSQLiteHelper.BMTX_TIMESTAMP, transactionEntity.getTimestamp());

database.beginTransaction();
database.update(BRSQLiteHelper.BMTX_TABLE_NAME, values, BRSQLiteHelper.BMTX_NAMESPACEID + "=? AND " + BRSQLiteHelper.BMTX_MAPPINGID + "=?",
new String[]{String.valueOf(transactionEntity.getNamespaceID().getNumber()), String.valueOf(transactionEntity.getMappingID())});
database.setTransactionSuccessful();
}
}
}
return transactionEntity1;
} catch (Exception ex) {
Expand Down Expand Up @@ -144,6 +163,27 @@ else if (cursor.getCount()>1) { // should not happen, delete all and insert
return mappingEntity;
}

public BetMappingEntity getMappingById(Context app, String iso, BetMappingEntity.MappingNamespaceType namespace, long mappingId) {
Cursor cursor = null;
BetMappingEntity mappingEntity = null;
try {
database = openDatabase();
cursor = database.query(BRSQLiteHelper.BMTX_TABLE_NAME, allColumns,
BRSQLiteHelper.BMTX_NAMESPACEID + "=? AND " + BRSQLiteHelper.BMTX_MAPPINGID + "=? AND " + BRSQLiteHelper.TX_ISO + "=?",
new String[]{ String.valueOf( namespace.getNumber() ), String.valueOf( mappingId ), iso.toUpperCase()},null,null,null);
if (cursor.getCount()==1) {
cursor.moveToFirst();
mappingEntity = cursorToTransaction(app, iso.toUpperCase(), cursor);
}
cursor.close();
} finally {
closeDatabase();
if (cursor != null) cursor.close();
}
return mappingEntity;
}


public void deleteAllTransactions(Context app, String iso) {
try {
database = openDatabase();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ protected void CleanChainBugs(Context app) {
bm.deleteTxByHash(app,"wgr", "e4e3a4f782569fa3bf0135297942c8a1c791ec869ca036bf530ab95633d17815");

// duplicate mappings
bm.deleteDuplicateMappings(app, BetMappingEntity.MappingNamespaceType.TEAM_NAME.getNumber());
bm.deleteDuplicateMappings(app, BetMappingEntity.MappingNamespaceType.ROUNDS.getNumber());
bm.deleteDuplicateMappings(app, BetMappingEntity.MappingNamespaceType.SPORT.getNumber());
bm.deleteDuplicateMappings(app, BetMappingEntity.MappingNamespaceType.TOURNAMENT.getNumber());
}
Expand Down

0 comments on commit a3410a9

Please sign in to comment.