mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-26 04:05:53 +00:00
add convenience method, remove ord-litecoin API file, cast dynamic->int
This commit is contained in:
parent
af30826e9e
commit
39eaa937fc
3 changed files with 7 additions and 90 deletions
|
@ -44,7 +44,7 @@ class LitescribeAPI {
|
||||||
// Check if the number of returned inscriptions equals the limit
|
// Check if the number of returned inscriptions equals the limit
|
||||||
final list = response.data['result']['list'];
|
final list = response.data['result']['list'];
|
||||||
final int total = response.data['result']['total'] as int;
|
final int total = response.data['result']['total'] as int;
|
||||||
final int currentSize = list.length;
|
final int currentSize = list.length as int;
|
||||||
|
|
||||||
if (currentSize == size && currentSize < total) {
|
if (currentSize == size && currentSize < total) {
|
||||||
// If the number of returned inscriptions equals the limit and there are more inscriptions available,
|
// If the number of returned inscriptions equals the limit and there are more inscriptions available,
|
||||||
|
|
|
@ -43,6 +43,12 @@ mixin OrdinalsInterface {
|
||||||
// TODO save inscriptions to isar which gets watched by a FutureBuilder/StreamBuilder
|
// TODO save inscriptions to isar which gets watched by a FutureBuilder/StreamBuilder
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<List<InscriptionData>> getInscriptions() async {
|
||||||
|
final utxos = await _db.getUTXOs(_walletId).findAll();
|
||||||
|
final uniqueAddresses = getUniqueAddressesFromUTXOs(utxos);
|
||||||
|
return await getInscriptionsFromAddresses(uniqueAddresses);
|
||||||
|
}
|
||||||
|
|
||||||
List<String> getUniqueAddressesFromUTXOs(List<UTXO> utxos) {
|
List<String> getUniqueAddressesFromUTXOs(List<UTXO> utxos) {
|
||||||
final Set<String> uniqueAddresses = <String>{};
|
final Set<String> uniqueAddresses = <String>{};
|
||||||
for (var utxo in utxos) {
|
for (var utxo in utxos) {
|
||||||
|
|
|
@ -1,89 +0,0 @@
|
||||||
import 'dart:convert';
|
|
||||||
import 'package:http/http.dart' as http;
|
|
||||||
|
|
||||||
import 'package:stackwallet/dto/ordinals/ordinals_response.dart';
|
|
||||||
import 'package:stackwallet/dto/ordinals/feed_response.dart';
|
|
||||||
import 'package:stackwallet/dto/ordinals/inscription_response.dart';
|
|
||||||
import 'package:stackwallet/dto/ordinals/sat_response.dart';
|
|
||||||
import 'package:stackwallet/dto/ordinals/transaction_response.dart';
|
|
||||||
import 'package:stackwallet/dto/ordinals/output_response.dart';
|
|
||||||
import 'package:stackwallet/dto/ordinals/address_response.dart';
|
|
||||||
import 'package:stackwallet/dto/ordinals/block_response.dart';
|
|
||||||
import 'package:stackwallet/dto/ordinals/content_response.dart';
|
|
||||||
import 'package:stackwallet/dto/ordinals/preview_response.dart';
|
|
||||||
|
|
||||||
class OrdinalsAPI {
|
|
||||||
static final OrdinalsAPI _instance = OrdinalsAPI._internal();
|
|
||||||
|
|
||||||
factory OrdinalsAPI({required String baseUrl}) {
|
|
||||||
_instance.baseUrl = baseUrl;
|
|
||||||
return _instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
OrdinalsAPI._internal();
|
|
||||||
|
|
||||||
late String baseUrl;
|
|
||||||
|
|
||||||
Future<OrdinalsResponse> _getResponse(String endpoint) async {
|
|
||||||
final response = await http.get(Uri.parse('$baseUrl$endpoint'));
|
|
||||||
if (response.statusCode == 200) {
|
|
||||||
return OrdinalsResponse(data: _validateJson(response.body));
|
|
||||||
} else {
|
|
||||||
throw Exception('Failed to load data');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, dynamic> _validateJson(String responseBody) {
|
|
||||||
final parsed = jsonDecode(responseBody);
|
|
||||||
if (parsed is Map<String, dynamic>) {
|
|
||||||
return parsed;
|
|
||||||
} else {
|
|
||||||
throw const FormatException('Invalid JSON format');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<FeedResponse> getLatestInscriptions() async {
|
|
||||||
final response = await _getResponse('/feed');
|
|
||||||
return FeedResponse.fromJson(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<InscriptionResponse> getInscriptionDetails(String inscriptionId) async {
|
|
||||||
final response = await _getResponse('/inscription/$inscriptionId');
|
|
||||||
return InscriptionResponse.fromJson(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<SatResponse> getSatDetails(int satNumber) async {
|
|
||||||
final response = await _getResponse('/sat/$satNumber');
|
|
||||||
return SatResponse.fromJson(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<TransactionResponse> getTransaction(String transactionId) async {
|
|
||||||
final response = await _getResponse('/tx/$transactionId');
|
|
||||||
return TransactionResponse.fromJson(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<OutputResponse> getTransactionOutputs(String transactionId) async {
|
|
||||||
final response = await _getResponse('/output/$transactionId');
|
|
||||||
return OutputResponse.fromJson(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<AddressResponse> getInscriptionsByAddress(String address) async {
|
|
||||||
final response = await _getResponse('/address/$address');
|
|
||||||
return AddressResponse.fromJson(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<BlockResponse> getBlock(String blockHash) async {
|
|
||||||
final response = await _getResponse('/block/$blockHash');
|
|
||||||
return BlockResponse.fromJson(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<ContentResponse> getInscriptionContent(String inscriptionId) async {
|
|
||||||
final response = await _getResponse('/content/$inscriptionId');
|
|
||||||
return ContentResponse.fromJson(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<PreviewResponse> getInscriptionPreview(String inscriptionId) async {
|
|
||||||
final response = await _getResponse('/preview/$inscriptionId');
|
|
||||||
return PreviewResponse.fromJson(response);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue