diff --git a/lib/models/isar/models/blockchain_data/utxo.dart b/lib/models/isar/models/blockchain_data/utxo.dart index 2cadf9e5d..4bea68d72 100644 --- a/lib/models/isar/models/blockchain_data/utxo.dart +++ b/lib/models/isar/models/blockchain_data/utxo.dart @@ -27,7 +27,10 @@ class UTXO { @Index() late final String walletId; - @Index(unique: true, replace: true, composite: [CompositeIndex("walletId")]) + @Index(unique: true, replace: true, composite: [ + CompositeIndex("walletId"), + CompositeIndex("vout"), + ]) late final String txid; late final int vout; diff --git a/lib/models/isar/models/blockchain_data/utxo.g.dart b/lib/models/isar/models/blockchain_data/utxo.g.dart index ef078911d..14f5f26c3 100644 --- a/lib/models/isar/models/blockchain_data/utxo.g.dart +++ b/lib/models/isar/models/blockchain_data/utxo.g.dart @@ -102,9 +102,9 @@ const UTXOSchema = CollectionSchema( ) ], ), - r'txid_walletId': IndexSchema( - id: -2771771174176035985, - name: r'txid_walletId', + r'txid_walletId_vout': IndexSchema( + id: -2984264099359759359, + name: r'txid_walletId_vout', unique: true, replace: true, properties: [ @@ -117,6 +117,11 @@ const UTXOSchema = CollectionSchema( name: r'walletId', type: IndexType.hash, caseSensitive: true, + ), + IndexPropertySchema( + name: r'vout', + type: IndexType.value, + caseSensitive: false, ) ], ), @@ -275,89 +280,91 @@ void _uTXOAttach(IsarCollection col, Id id, UTXO object) { } extension UTXOByIndex on IsarCollection { - Future getByTxidWalletId(String txid, String walletId) { - return getByIndex(r'txid_walletId', [txid, walletId]); + Future getByTxidWalletIdVout(String txid, String walletId, int vout) { + return getByIndex(r'txid_walletId_vout', [txid, walletId, vout]); } - UTXO? getByTxidWalletIdSync(String txid, String walletId) { - return getByIndexSync(r'txid_walletId', [txid, walletId]); + UTXO? getByTxidWalletIdVoutSync(String txid, String walletId, int vout) { + return getByIndexSync(r'txid_walletId_vout', [txid, walletId, vout]); } - Future deleteByTxidWalletId(String txid, String walletId) { - return deleteByIndex(r'txid_walletId', [txid, walletId]); + Future deleteByTxidWalletIdVout( + String txid, String walletId, int vout) { + return deleteByIndex(r'txid_walletId_vout', [txid, walletId, vout]); } - bool deleteByTxidWalletIdSync(String txid, String walletId) { - return deleteByIndexSync(r'txid_walletId', [txid, walletId]); + bool deleteByTxidWalletIdVoutSync(String txid, String walletId, int vout) { + return deleteByIndexSync(r'txid_walletId_vout', [txid, walletId, vout]); } - Future> getAllByTxidWalletId( - List txidValues, List walletIdValues) { + Future> getAllByTxidWalletIdVout(List txidValues, + List walletIdValues, List voutValues) { final len = txidValues.length; - assert(walletIdValues.length == len, + assert(walletIdValues.length == len && voutValues.length == len, 'All index values must have the same length'); final values = >[]; for (var i = 0; i < len; i++) { - values.add([txidValues[i], walletIdValues[i]]); + values.add([txidValues[i], walletIdValues[i], voutValues[i]]); } - return getAllByIndex(r'txid_walletId', values); + return getAllByIndex(r'txid_walletId_vout', values); } - List getAllByTxidWalletIdSync( - List txidValues, List walletIdValues) { + List getAllByTxidWalletIdVoutSync(List txidValues, + List walletIdValues, List voutValues) { final len = txidValues.length; - assert(walletIdValues.length == len, + assert(walletIdValues.length == len && voutValues.length == len, 'All index values must have the same length'); final values = >[]; for (var i = 0; i < len; i++) { - values.add([txidValues[i], walletIdValues[i]]); + values.add([txidValues[i], walletIdValues[i], voutValues[i]]); } - return getAllByIndexSync(r'txid_walletId', values); + return getAllByIndexSync(r'txid_walletId_vout', values); } - Future deleteAllByTxidWalletId( - List txidValues, List walletIdValues) { + Future deleteAllByTxidWalletIdVout(List txidValues, + List walletIdValues, List voutValues) { final len = txidValues.length; - assert(walletIdValues.length == len, + assert(walletIdValues.length == len && voutValues.length == len, 'All index values must have the same length'); final values = >[]; for (var i = 0; i < len; i++) { - values.add([txidValues[i], walletIdValues[i]]); + values.add([txidValues[i], walletIdValues[i], voutValues[i]]); } - return deleteAllByIndex(r'txid_walletId', values); + return deleteAllByIndex(r'txid_walletId_vout', values); } - int deleteAllByTxidWalletIdSync( - List txidValues, List walletIdValues) { + int deleteAllByTxidWalletIdVoutSync(List txidValues, + List walletIdValues, List voutValues) { final len = txidValues.length; - assert(walletIdValues.length == len, + assert(walletIdValues.length == len && voutValues.length == len, 'All index values must have the same length'); final values = >[]; for (var i = 0; i < len; i++) { - values.add([txidValues[i], walletIdValues[i]]); + values.add([txidValues[i], walletIdValues[i], voutValues[i]]); } - return deleteAllByIndexSync(r'txid_walletId', values); + return deleteAllByIndexSync(r'txid_walletId_vout', values); } - Future putByTxidWalletId(UTXO object) { - return putByIndex(r'txid_walletId', object); + Future putByTxidWalletIdVout(UTXO object) { + return putByIndex(r'txid_walletId_vout', object); } - Id putByTxidWalletIdSync(UTXO object, {bool saveLinks = true}) { - return putByIndexSync(r'txid_walletId', object, saveLinks: saveLinks); + Id putByTxidWalletIdVoutSync(UTXO object, {bool saveLinks = true}) { + return putByIndexSync(r'txid_walletId_vout', object, saveLinks: saveLinks); } - Future> putAllByTxidWalletId(List objects) { - return putAllByIndex(r'txid_walletId', objects); + Future> putAllByTxidWalletIdVout(List objects) { + return putAllByIndex(r'txid_walletId_vout', objects); } - List putAllByTxidWalletIdSync(List objects, + List putAllByTxidWalletIdVoutSync(List objects, {bool saveLinks = true}) { - return putAllByIndexSync(r'txid_walletId', objects, saveLinks: saveLinks); + return putAllByIndexSync(r'txid_walletId_vout', objects, + saveLinks: saveLinks); } } @@ -487,29 +494,29 @@ extension UTXOQueryWhere on QueryBuilder { }); } - QueryBuilder txidEqualToAnyWalletId( + QueryBuilder txidEqualToAnyWalletIdVout( String txid) { return QueryBuilder.apply(this, (query) { return query.addWhereClause(IndexWhereClause.equalTo( - indexName: r'txid_walletId', + indexName: r'txid_walletId_vout', value: [txid], )); }); } - QueryBuilder txidNotEqualToAnyWalletId( + QueryBuilder txidNotEqualToAnyWalletIdVout( String txid) { return QueryBuilder.apply(this, (query) { if (query.whereSort == Sort.asc) { return query .addWhereClause(IndexWhereClause.between( - indexName: r'txid_walletId', + indexName: r'txid_walletId_vout', lower: [], upper: [txid], includeUpper: false, )) .addWhereClause(IndexWhereClause.between( - indexName: r'txid_walletId', + indexName: r'txid_walletId_vout', lower: [txid], includeLower: false, upper: [], @@ -517,13 +524,13 @@ extension UTXOQueryWhere on QueryBuilder { } else { return query .addWhereClause(IndexWhereClause.between( - indexName: r'txid_walletId', + indexName: r'txid_walletId_vout', lower: [txid], includeLower: false, upper: [], )) .addWhereClause(IndexWhereClause.between( - indexName: r'txid_walletId', + indexName: r'txid_walletId_vout', lower: [], upper: [txid], includeUpper: false, @@ -532,29 +539,29 @@ extension UTXOQueryWhere on QueryBuilder { }); } - QueryBuilder txidWalletIdEqualTo( + QueryBuilder txidWalletIdEqualToAnyVout( String txid, String walletId) { return QueryBuilder.apply(this, (query) { return query.addWhereClause(IndexWhereClause.equalTo( - indexName: r'txid_walletId', + indexName: r'txid_walletId_vout', value: [txid, walletId], )); }); } - QueryBuilder txidEqualToWalletIdNotEqualTo( - String txid, String walletId) { + QueryBuilder + txidEqualToWalletIdNotEqualToAnyVout(String txid, String walletId) { return QueryBuilder.apply(this, (query) { if (query.whereSort == Sort.asc) { return query .addWhereClause(IndexWhereClause.between( - indexName: r'txid_walletId', + indexName: r'txid_walletId_vout', lower: [txid], upper: [txid, walletId], includeUpper: false, )) .addWhereClause(IndexWhereClause.between( - indexName: r'txid_walletId', + indexName: r'txid_walletId_vout', lower: [txid, walletId], includeLower: false, upper: [txid], @@ -562,13 +569,13 @@ extension UTXOQueryWhere on QueryBuilder { } else { return query .addWhereClause(IndexWhereClause.between( - indexName: r'txid_walletId', + indexName: r'txid_walletId_vout', lower: [txid, walletId], includeLower: false, upper: [txid], )) .addWhereClause(IndexWhereClause.between( - indexName: r'txid_walletId', + indexName: r'txid_walletId_vout', lower: [txid], upper: [txid, walletId], includeUpper: false, @@ -577,6 +584,103 @@ extension UTXOQueryWhere on QueryBuilder { }); } + QueryBuilder txidWalletIdVoutEqualTo( + String txid, String walletId, int vout) { + return QueryBuilder.apply(this, (query) { + return query.addWhereClause(IndexWhereClause.equalTo( + indexName: r'txid_walletId_vout', + value: [txid, walletId, vout], + )); + }); + } + + QueryBuilder txidWalletIdEqualToVoutNotEqualTo( + String txid, String walletId, int vout) { + return QueryBuilder.apply(this, (query) { + if (query.whereSort == Sort.asc) { + return query + .addWhereClause(IndexWhereClause.between( + indexName: r'txid_walletId_vout', + lower: [txid, walletId], + upper: [txid, walletId, vout], + includeUpper: false, + )) + .addWhereClause(IndexWhereClause.between( + indexName: r'txid_walletId_vout', + lower: [txid, walletId, vout], + includeLower: false, + upper: [txid, walletId], + )); + } else { + return query + .addWhereClause(IndexWhereClause.between( + indexName: r'txid_walletId_vout', + lower: [txid, walletId, vout], + includeLower: false, + upper: [txid, walletId], + )) + .addWhereClause(IndexWhereClause.between( + indexName: r'txid_walletId_vout', + lower: [txid, walletId], + upper: [txid, walletId, vout], + includeUpper: false, + )); + } + }); + } + + QueryBuilder + txidWalletIdEqualToVoutGreaterThan( + String txid, + String walletId, + int vout, { + bool include = false, + }) { + return QueryBuilder.apply(this, (query) { + return query.addWhereClause(IndexWhereClause.between( + indexName: r'txid_walletId_vout', + lower: [txid, walletId, vout], + includeLower: include, + upper: [txid, walletId], + )); + }); + } + + QueryBuilder txidWalletIdEqualToVoutLessThan( + String txid, + String walletId, + int vout, { + bool include = false, + }) { + return QueryBuilder.apply(this, (query) { + return query.addWhereClause(IndexWhereClause.between( + indexName: r'txid_walletId_vout', + lower: [txid, walletId], + upper: [txid, walletId, vout], + includeUpper: include, + )); + }); + } + + QueryBuilder txidWalletIdEqualToVoutBetween( + String txid, + String walletId, + int lowerVout, + int upperVout, { + bool includeLower = true, + bool includeUpper = true, + }) { + return QueryBuilder.apply(this, (query) { + return query.addWhereClause(IndexWhereClause.between( + indexName: r'txid_walletId_vout', + lower: [txid, walletId, lowerVout], + includeLower: includeLower, + upper: [txid, walletId, upperVout], + includeUpper: includeUpper, + )); + }); + } + QueryBuilder isBlockedEqualTo(bool isBlocked) { return QueryBuilder.apply(this, (query) { return query.addWhereClause(IndexWhereClause.equalTo(