mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-12-23 03:49:22 +00:00
use isar ordinal model
This commit is contained in:
parent
974924de8d
commit
48109f3c49
6 changed files with 1588 additions and 42 deletions
76
lib/models/isar/ordinal.dart
Normal file
76
lib/models/isar/ordinal.dart
Normal file
|
@ -0,0 +1,76 @@
|
|||
import 'package:isar/isar.dart';
|
||||
import 'package:stackwallet/dto/ordinals/inscription_data.dart';
|
||||
|
||||
part 'ordinal.g.dart';
|
||||
|
||||
@collection
|
||||
class Ordinal {
|
||||
Id id = Isar.autoIncrement;
|
||||
|
||||
final String walletId;
|
||||
|
||||
@Index(unique: true, replace: true, composite: [
|
||||
CompositeIndex("utxoTXID"),
|
||||
CompositeIndex("utxoVOUT"),
|
||||
])
|
||||
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,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Ordinal {'
|
||||
' walletId: $walletId,'
|
||||
' inscriptionId: $inscriptionId,'
|
||||
' inscriptionNumber: $inscriptionNumber,'
|
||||
' content: $content,'
|
||||
' utxoTXID: $utxoTXID,'
|
||||
' utxoVOUT: $utxoVOUT'
|
||||
' }';
|
||||
}
|
||||
}
|
1489
lib/models/isar/ordinal.g.dart
Normal file
1489
lib/models/isar/ordinal.g.dart
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,29 +0,0 @@
|
|||
import 'package:stackwallet/dto/ordinals/inscription_data.dart';
|
||||
|
||||
class Ordinal {
|
||||
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.inscriptionId,
|
||||
required this.inscriptionNumber,
|
||||
required this.content,
|
||||
required this.utxoTXID,
|
||||
required this.utxoVOUT,
|
||||
});
|
||||
|
||||
factory Ordinal.fromInscriptionData(InscriptionData data) {
|
||||
return Ordinal(
|
||||
inscriptionId: data.inscriptionId,
|
||||
inscriptionNumber: data.inscriptionNumber,
|
||||
content: data.content,
|
||||
utxoTXID: data.output.split(':')[0], // "output": "062f32e21aa04246b8873b5d9a929576addd0339881e1ea478b406795d6b6c47:0"
|
||||
utxoVOUT: int.parse(data.output.split(':')[1]),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:stackwallet/models/ordinal.dart';
|
||||
import 'package:stackwallet/pages/ordinals/widgets/ordinal_card.dart';
|
||||
import 'package:stackwallet/widgets/loading_indicator.dart';
|
||||
|
||||
class OrdinalsList extends StatelessWidget {
|
||||
const OrdinalsList({
|
||||
|
@ -20,7 +21,7 @@ class OrdinalsList extends StatelessWidget {
|
|||
future: ordinalsFuture,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return const CircularProgressIndicator();
|
||||
return const LoadingIndicator();
|
||||
} else if (snapshot.hasError) {
|
||||
return Text('Error: ${snapshot.error}');
|
||||
} else if (snapshot.hasData) {
|
||||
|
|
|
@ -19,7 +19,7 @@ import 'package:stackwallet/models/exchange/incomplete_exchange.dart';
|
|||
import 'package:stackwallet/models/exchange/response_objects/trade.dart';
|
||||
import 'package:stackwallet/models/isar/models/contact_entry.dart';
|
||||
import 'package:stackwallet/models/isar/models/isar_models.dart';
|
||||
import 'package:stackwallet/models/ordinal.dart';
|
||||
import 'package:stackwallet/models/isar/ordinal.dart';
|
||||
import 'package:stackwallet/models/paynym/paynym_account_lite.dart';
|
||||
import 'package:stackwallet/models/send_view_auto_fill_data.dart';
|
||||
import 'package:stackwallet/pages/add_wallet_views/add_token_view/add_custom_token_view.dart';
|
||||
|
|
|
@ -4,7 +4,7 @@ import 'package:isar/isar.dart';
|
|||
import 'package:stackwallet/db/isar/main_db.dart';
|
||||
import 'package:stackwallet/dto/ordinals/inscription_data.dart';
|
||||
import 'package:stackwallet/models/isar/models/blockchain_data/utxo.dart';
|
||||
import 'package:stackwallet/models/ordinal.dart';
|
||||
import 'package:stackwallet/models/isar/ordinal.dart';
|
||||
import 'package:stackwallet/services/litescribe_api.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
|
||||
|
@ -18,12 +18,13 @@ mixin OrdinalsInterface {
|
|||
required Coin coin,
|
||||
required MainDB db,
|
||||
}) {
|
||||
print('init');
|
||||
_walletId = walletId;
|
||||
_coin = coin;
|
||||
_db = db;
|
||||
}
|
||||
final LitescribeAPI litescribeAPI = LitescribeAPI(baseUrl: 'https://litescribe.io/api');
|
||||
|
||||
final LitescribeAPI litescribeAPI =
|
||||
LitescribeAPI(baseUrl: 'https://litescribe.io/api');
|
||||
|
||||
void refreshInscriptions() async {
|
||||
List<dynamic> _inscriptions;
|
||||
|
@ -63,22 +64,26 @@ mixin OrdinalsInterface {
|
|||
return uniqueAddresses.toList();
|
||||
}
|
||||
|
||||
Future<List<InscriptionData>> getInscriptionDataFromAddress(String address) async {
|
||||
Future<List<InscriptionData>> getInscriptionDataFromAddress(
|
||||
String address) async {
|
||||
List<InscriptionData> allInscriptions = [];
|
||||
try {
|
||||
var inscriptions = await litescribeAPI.getInscriptionsByAddress(address);
|
||||
allInscriptions.addAll(inscriptions);
|
||||
} catch (e) {
|
||||
throw Exception('Error in OrdinalsInterface getInscriptionsByAddress: $e');
|
||||
throw Exception(
|
||||
'Error in OrdinalsInterface getInscriptionsByAddress: $e');
|
||||
}
|
||||
return allInscriptions;
|
||||
}
|
||||
|
||||
Future<List<InscriptionData>> getInscriptionDataFromAddresses(List<String> addresses) async {
|
||||
Future<List<InscriptionData>> getInscriptionDataFromAddresses(
|
||||
List<String> addresses) async {
|
||||
List<InscriptionData> allInscriptions = [];
|
||||
for (String address in addresses) {
|
||||
try {
|
||||
var inscriptions = await litescribeAPI.getInscriptionsByAddress(address);
|
||||
var inscriptions =
|
||||
await litescribeAPI.getInscriptionsByAddress(address);
|
||||
allInscriptions.addAll(inscriptions);
|
||||
} catch (e) {
|
||||
print("Error fetching inscriptions for address $address: $e");
|
||||
|
@ -90,7 +95,9 @@ mixin OrdinalsInterface {
|
|||
Future<List<Ordinal>> getOrdinalsFromAddress(String address) async {
|
||||
try {
|
||||
var inscriptions = await litescribeAPI.getInscriptionsByAddress(address);
|
||||
return inscriptions.map((data) => Ordinal.fromInscriptionData(data)).toList();
|
||||
return inscriptions
|
||||
.map((data) => Ordinal.fromInscriptionData(data, _walletId))
|
||||
.toList();
|
||||
} catch (e) {
|
||||
throw Exception('Error in OrdinalsInterface getOrdinalsFromAddress: $e');
|
||||
}
|
||||
|
@ -100,8 +107,10 @@ mixin OrdinalsInterface {
|
|||
List<Ordinal> allOrdinals = [];
|
||||
for (String address in addresses) {
|
||||
try {
|
||||
var inscriptions = await litescribeAPI.getInscriptionsByAddress(address);
|
||||
allOrdinals.addAll(inscriptions.map((data) => Ordinal.fromInscriptionData(data)));
|
||||
var inscriptions =
|
||||
await litescribeAPI.getInscriptionsByAddress(address);
|
||||
allOrdinals.addAll(inscriptions
|
||||
.map((data) => Ordinal.fromInscriptionData(data, _walletId)));
|
||||
} catch (e) {
|
||||
print("Error fetching inscriptions for address $address: $e");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue