diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index d998d28ab..96da86b20 100644 Binary files a/.idea/caches/build_file_checksums.ser and b/.idea/caches/build_file_checksums.ser differ diff --git a/app/build.gradle b/app/build.gradle index c55880ff4..7bb99e3ae 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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, diff --git a/app/src/main/java/com/wagerrwallet/tools/sqlite/BetMappingTxDataStore.java b/app/src/main/java/com/wagerrwallet/tools/sqlite/BetMappingTxDataStore.java index 78ace887c..80e75c65b 100644 --- a/app/src/main/java/com/wagerrwallet/tools/sqlite/BetMappingTxDataStore.java +++ b/app/src/main/java/com/wagerrwallet/tools/sqlite/BetMappingTxDataStore.java @@ -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) { @@ -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(); diff --git a/app/src/main/java/com/wagerrwallet/wallet/wallets/wagerr/WalletWagerrManager.java b/app/src/main/java/com/wagerrwallet/wallet/wallets/wagerr/WalletWagerrManager.java index 474db6bdf..aec865ba9 100644 --- a/app/src/main/java/com/wagerrwallet/wallet/wallets/wagerr/WalletWagerrManager.java +++ b/app/src/main/java/com/wagerrwallet/wallet/wallets/wagerr/WalletWagerrManager.java @@ -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()); }