utxo bugfix

This commit is contained in:
julian 2023-03-07 08:07:04 -06:00
parent 8f80b6976f
commit 2ccf6bfc71
2 changed files with 162 additions and 55 deletions

View file

@ -27,7 +27,10 @@ class UTXO {
@Index() @Index()
late final String walletId; 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 String txid;
late final int vout; late final int vout;

View file

@ -102,9 +102,9 @@ const UTXOSchema = CollectionSchema(
) )
], ],
), ),
r'txid_walletId': IndexSchema( r'txid_walletId_vout': IndexSchema(
id: -2771771174176035985, id: -2984264099359759359,
name: r'txid_walletId', name: r'txid_walletId_vout',
unique: true, unique: true,
replace: true, replace: true,
properties: [ properties: [
@ -117,6 +117,11 @@ const UTXOSchema = CollectionSchema(
name: r'walletId', name: r'walletId',
type: IndexType.hash, type: IndexType.hash,
caseSensitive: true, caseSensitive: true,
),
IndexPropertySchema(
name: r'vout',
type: IndexType.value,
caseSensitive: false,
) )
], ],
), ),
@ -275,89 +280,91 @@ void _uTXOAttach(IsarCollection<dynamic> col, Id id, UTXO object) {
} }
extension UTXOByIndex on IsarCollection<UTXO> { extension UTXOByIndex on IsarCollection<UTXO> {
Future<UTXO?> getByTxidWalletId(String txid, String walletId) { Future<UTXO?> getByTxidWalletIdVout(String txid, String walletId, int vout) {
return getByIndex(r'txid_walletId', [txid, walletId]); return getByIndex(r'txid_walletId_vout', [txid, walletId, vout]);
} }
UTXO? getByTxidWalletIdSync(String txid, String walletId) { UTXO? getByTxidWalletIdVoutSync(String txid, String walletId, int vout) {
return getByIndexSync(r'txid_walletId', [txid, walletId]); return getByIndexSync(r'txid_walletId_vout', [txid, walletId, vout]);
} }
Future<bool> deleteByTxidWalletId(String txid, String walletId) { Future<bool> deleteByTxidWalletIdVout(
return deleteByIndex(r'txid_walletId', [txid, walletId]); String txid, String walletId, int vout) {
return deleteByIndex(r'txid_walletId_vout', [txid, walletId, vout]);
} }
bool deleteByTxidWalletIdSync(String txid, String walletId) { bool deleteByTxidWalletIdVoutSync(String txid, String walletId, int vout) {
return deleteByIndexSync(r'txid_walletId', [txid, walletId]); return deleteByIndexSync(r'txid_walletId_vout', [txid, walletId, vout]);
} }
Future<List<UTXO?>> getAllByTxidWalletId( Future<List<UTXO?>> getAllByTxidWalletIdVout(List<String> txidValues,
List<String> txidValues, List<String> walletIdValues) { List<String> walletIdValues, List<int> voutValues) {
final len = txidValues.length; final len = txidValues.length;
assert(walletIdValues.length == len, assert(walletIdValues.length == len && voutValues.length == len,
'All index values must have the same length'); 'All index values must have the same length');
final values = <List<dynamic>>[]; final values = <List<dynamic>>[];
for (var i = 0; i < len; i++) { 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<UTXO?> getAllByTxidWalletIdSync( List<UTXO?> getAllByTxidWalletIdVoutSync(List<String> txidValues,
List<String> txidValues, List<String> walletIdValues) { List<String> walletIdValues, List<int> voutValues) {
final len = txidValues.length; final len = txidValues.length;
assert(walletIdValues.length == len, assert(walletIdValues.length == len && voutValues.length == len,
'All index values must have the same length'); 'All index values must have the same length');
final values = <List<dynamic>>[]; final values = <List<dynamic>>[];
for (var i = 0; i < len; i++) { 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<int> deleteAllByTxidWalletId( Future<int> deleteAllByTxidWalletIdVout(List<String> txidValues,
List<String> txidValues, List<String> walletIdValues) { List<String> walletIdValues, List<int> voutValues) {
final len = txidValues.length; final len = txidValues.length;
assert(walletIdValues.length == len, assert(walletIdValues.length == len && voutValues.length == len,
'All index values must have the same length'); 'All index values must have the same length');
final values = <List<dynamic>>[]; final values = <List<dynamic>>[];
for (var i = 0; i < len; i++) { 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( int deleteAllByTxidWalletIdVoutSync(List<String> txidValues,
List<String> txidValues, List<String> walletIdValues) { List<String> walletIdValues, List<int> voutValues) {
final len = txidValues.length; final len = txidValues.length;
assert(walletIdValues.length == len, assert(walletIdValues.length == len && voutValues.length == len,
'All index values must have the same length'); 'All index values must have the same length');
final values = <List<dynamic>>[]; final values = <List<dynamic>>[];
for (var i = 0; i < len; i++) { 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<Id> putByTxidWalletId(UTXO object) { Future<Id> putByTxidWalletIdVout(UTXO object) {
return putByIndex(r'txid_walletId', object); return putByIndex(r'txid_walletId_vout', object);
} }
Id putByTxidWalletIdSync(UTXO object, {bool saveLinks = true}) { Id putByTxidWalletIdVoutSync(UTXO object, {bool saveLinks = true}) {
return putByIndexSync(r'txid_walletId', object, saveLinks: saveLinks); return putByIndexSync(r'txid_walletId_vout', object, saveLinks: saveLinks);
} }
Future<List<Id>> putAllByTxidWalletId(List<UTXO> objects) { Future<List<Id>> putAllByTxidWalletIdVout(List<UTXO> objects) {
return putAllByIndex(r'txid_walletId', objects); return putAllByIndex(r'txid_walletId_vout', objects);
} }
List<Id> putAllByTxidWalletIdSync(List<UTXO> objects, List<Id> putAllByTxidWalletIdVoutSync(List<UTXO> objects,
{bool saveLinks = true}) { {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<UTXO, UTXO, QWhereClause> {
}); });
} }
QueryBuilder<UTXO, UTXO, QAfterWhereClause> txidEqualToAnyWalletId( QueryBuilder<UTXO, UTXO, QAfterWhereClause> txidEqualToAnyWalletIdVout(
String txid) { String txid) {
return QueryBuilder.apply(this, (query) { return QueryBuilder.apply(this, (query) {
return query.addWhereClause(IndexWhereClause.equalTo( return query.addWhereClause(IndexWhereClause.equalTo(
indexName: r'txid_walletId', indexName: r'txid_walletId_vout',
value: [txid], value: [txid],
)); ));
}); });
} }
QueryBuilder<UTXO, UTXO, QAfterWhereClause> txidNotEqualToAnyWalletId( QueryBuilder<UTXO, UTXO, QAfterWhereClause> txidNotEqualToAnyWalletIdVout(
String txid) { String txid) {
return QueryBuilder.apply(this, (query) { return QueryBuilder.apply(this, (query) {
if (query.whereSort == Sort.asc) { if (query.whereSort == Sort.asc) {
return query return query
.addWhereClause(IndexWhereClause.between( .addWhereClause(IndexWhereClause.between(
indexName: r'txid_walletId', indexName: r'txid_walletId_vout',
lower: [], lower: [],
upper: [txid], upper: [txid],
includeUpper: false, includeUpper: false,
)) ))
.addWhereClause(IndexWhereClause.between( .addWhereClause(IndexWhereClause.between(
indexName: r'txid_walletId', indexName: r'txid_walletId_vout',
lower: [txid], lower: [txid],
includeLower: false, includeLower: false,
upper: [], upper: [],
@ -517,13 +524,13 @@ extension UTXOQueryWhere on QueryBuilder<UTXO, UTXO, QWhereClause> {
} else { } else {
return query return query
.addWhereClause(IndexWhereClause.between( .addWhereClause(IndexWhereClause.between(
indexName: r'txid_walletId', indexName: r'txid_walletId_vout',
lower: [txid], lower: [txid],
includeLower: false, includeLower: false,
upper: [], upper: [],
)) ))
.addWhereClause(IndexWhereClause.between( .addWhereClause(IndexWhereClause.between(
indexName: r'txid_walletId', indexName: r'txid_walletId_vout',
lower: [], lower: [],
upper: [txid], upper: [txid],
includeUpper: false, includeUpper: false,
@ -532,29 +539,29 @@ extension UTXOQueryWhere on QueryBuilder<UTXO, UTXO, QWhereClause> {
}); });
} }
QueryBuilder<UTXO, UTXO, QAfterWhereClause> txidWalletIdEqualTo( QueryBuilder<UTXO, UTXO, QAfterWhereClause> txidWalletIdEqualToAnyVout(
String txid, String walletId) { String txid, String walletId) {
return QueryBuilder.apply(this, (query) { return QueryBuilder.apply(this, (query) {
return query.addWhereClause(IndexWhereClause.equalTo( return query.addWhereClause(IndexWhereClause.equalTo(
indexName: r'txid_walletId', indexName: r'txid_walletId_vout',
value: [txid, walletId], value: [txid, walletId],
)); ));
}); });
} }
QueryBuilder<UTXO, UTXO, QAfterWhereClause> txidEqualToWalletIdNotEqualTo( QueryBuilder<UTXO, UTXO, QAfterWhereClause>
String txid, String walletId) { txidEqualToWalletIdNotEqualToAnyVout(String txid, String walletId) {
return QueryBuilder.apply(this, (query) { return QueryBuilder.apply(this, (query) {
if (query.whereSort == Sort.asc) { if (query.whereSort == Sort.asc) {
return query return query
.addWhereClause(IndexWhereClause.between( .addWhereClause(IndexWhereClause.between(
indexName: r'txid_walletId', indexName: r'txid_walletId_vout',
lower: [txid], lower: [txid],
upper: [txid, walletId], upper: [txid, walletId],
includeUpper: false, includeUpper: false,
)) ))
.addWhereClause(IndexWhereClause.between( .addWhereClause(IndexWhereClause.between(
indexName: r'txid_walletId', indexName: r'txid_walletId_vout',
lower: [txid, walletId], lower: [txid, walletId],
includeLower: false, includeLower: false,
upper: [txid], upper: [txid],
@ -562,13 +569,13 @@ extension UTXOQueryWhere on QueryBuilder<UTXO, UTXO, QWhereClause> {
} else { } else {
return query return query
.addWhereClause(IndexWhereClause.between( .addWhereClause(IndexWhereClause.between(
indexName: r'txid_walletId', indexName: r'txid_walletId_vout',
lower: [txid, walletId], lower: [txid, walletId],
includeLower: false, includeLower: false,
upper: [txid], upper: [txid],
)) ))
.addWhereClause(IndexWhereClause.between( .addWhereClause(IndexWhereClause.between(
indexName: r'txid_walletId', indexName: r'txid_walletId_vout',
lower: [txid], lower: [txid],
upper: [txid, walletId], upper: [txid, walletId],
includeUpper: false, includeUpper: false,
@ -577,6 +584,103 @@ extension UTXOQueryWhere on QueryBuilder<UTXO, UTXO, QWhereClause> {
}); });
} }
QueryBuilder<UTXO, UTXO, QAfterWhereClause> 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<UTXO, UTXO, QAfterWhereClause> 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<UTXO, UTXO, QAfterWhereClause>
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<UTXO, UTXO, QAfterWhereClause> 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<UTXO, UTXO, QAfterWhereClause> 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<UTXO, UTXO, QAfterWhereClause> isBlockedEqualTo(bool isBlocked) { QueryBuilder<UTXO, UTXO, QAfterWhereClause> isBlockedEqualTo(bool isBlocked) {
return QueryBuilder.apply(this, (query) { return QueryBuilder.apply(this, (query) {
return query.addWhereClause(IndexWhereClause.equalTo( return query.addWhereClause(IndexWhereClause.equalTo(