stack_wallet/lib/models/isar/ordinal.dart

95 lines
2.2 KiB
Dart
Raw Normal View History

2023-07-21 23:51:04 +00:00
import 'package:isar/isar.dart';
2024-05-27 23:56:22 +00:00
import '../../db/isar/main_db.dart';
import '../../dto/ordinals/inscription_data.dart';
import 'models/isar_models.dart';
2023-07-21 23:51:04 +00:00
part 'ordinal.g.dart';
@collection
class Ordinal {
Id id = Isar.autoIncrement;
final String walletId;
2024-05-27 23:56:22 +00:00
@Index(
unique: true,
replace: true,
composite: [
CompositeIndex("utxoTXID"),
CompositeIndex("utxoVOUT"),
],
)
2023-07-21 23:51:04 +00:00
final String inscriptionId;
final int inscriptionNumber;
final String content;
// following two are used to look up the UTXO object in isar combined w/ walletId
final String utxoTXID;
final int utxoVOUT;
Ordinal({
required this.walletId,
required this.inscriptionId,
required this.inscriptionNumber,
required this.content,
required this.utxoTXID,
required this.utxoVOUT,
});
factory Ordinal.fromInscriptionData(InscriptionData data, String walletId) {
return Ordinal(
walletId: walletId,
inscriptionId: data.inscriptionId,
inscriptionNumber: data.inscriptionNumber,
content: data.content,
utxoTXID: data.output.split(':')[
0], // "output": "062f32e21aa04246b8873b5d9a929576addd0339881e1ea478b406795d6b6c47:0"
utxoVOUT: int.parse(data.output.split(':')[1]),
);
}
Ordinal copyWith({
String? walletId,
String? inscriptionId,
int? inscriptionNumber,
String? content,
String? utxoTXID,
int? utxoVOUT,
}) {
return Ordinal(
walletId: walletId ?? this.walletId,
inscriptionId: inscriptionId ?? this.inscriptionId,
inscriptionNumber: inscriptionNumber ?? this.inscriptionNumber,
content: content ?? this.content,
utxoTXID: utxoTXID ?? this.utxoTXID,
utxoVOUT: utxoVOUT ?? this.utxoVOUT,
);
}
2023-07-22 01:52:43 +00:00
UTXO? getUTXO(MainDB db) {
return db.isar.utxos
.where()
.walletIdEqualTo(walletId)
.filter()
.txidEqualTo(utxoTXID)
.and()
.voutEqualTo(utxoVOUT)
.findFirstSync();
}
2023-07-21 23:51:04 +00:00
@override
String toString() {
return 'Ordinal {'
' walletId: $walletId,'
' inscriptionId: $inscriptionId,'
' inscriptionNumber: $inscriptionNumber,'
' content: $content,'
' utxoTXID: $utxoTXID,'
' utxoVOUT: $utxoVOUT'
' }';
}
}