mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-22 02:24:30 +00:00
WIP _db not initialized, refresh on ordinals view for poc
This commit is contained in:
parent
06c433ff85
commit
4db0328c73
6 changed files with 93 additions and 85 deletions
|
@ -1,4 +1,5 @@
|
|||
import 'package:stackwallet/dto/ordinals/litescribe_response.dart';
|
||||
import 'package:stackwallet/dto/ordinals/inscription_data.dart';
|
||||
|
||||
class AddressInscriptionResponse extends LitescribeResponse<AddressInscriptionResponse> {
|
||||
final int status;
|
||||
|
@ -21,7 +22,7 @@ class AddressInscriptionResponse extends LitescribeResponse<AddressInscriptionRe
|
|||
}
|
||||
|
||||
class AddressInscriptionResult {
|
||||
final List<AddressInscription> list;
|
||||
final List<InscriptionData> list;
|
||||
final int total;
|
||||
|
||||
AddressInscriptionResult({
|
||||
|
@ -31,61 +32,8 @@ class AddressInscriptionResult {
|
|||
|
||||
factory AddressInscriptionResult.fromJson(Map<String, dynamic> json) {
|
||||
return AddressInscriptionResult(
|
||||
list: (json['list'] as List).map((item) => AddressInscription.fromJson(item as Map<String, dynamic>)).toList(),
|
||||
list: (json['list'] as List).map((item) => InscriptionData.fromJson(item as Map<String, dynamic>)).toList(),
|
||||
total: json['total'] as int,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class AddressInscription {
|
||||
final String inscriptionId;
|
||||
final int inscriptionNumber;
|
||||
final String address;
|
||||
final String preview;
|
||||
final String content;
|
||||
final int contentLength;
|
||||
final String contentType;
|
||||
final String contentBody;
|
||||
final int timestamp;
|
||||
final String genesisTransaction;
|
||||
final String location;
|
||||
final String output;
|
||||
final int outputValue;
|
||||
final int offset;
|
||||
|
||||
AddressInscription({
|
||||
required this.inscriptionId,
|
||||
required this.inscriptionNumber,
|
||||
required this.address,
|
||||
required this.preview,
|
||||
required this.content,
|
||||
required this.contentLength,
|
||||
required this.contentType,
|
||||
required this.contentBody,
|
||||
required this.timestamp,
|
||||
required this.genesisTransaction,
|
||||
required this.location,
|
||||
required this.output,
|
||||
required this.outputValue,
|
||||
required this.offset,
|
||||
});
|
||||
|
||||
factory AddressInscription.fromJson(Map<String, dynamic> json) {
|
||||
return AddressInscription(
|
||||
inscriptionId: json['inscriptionId'] as String,
|
||||
inscriptionNumber: json['inscriptionNumber'] as int,
|
||||
address: json['address'] as String,
|
||||
preview: json['preview'] as String,
|
||||
content: json['content'] as String,
|
||||
contentLength: json['contentLength'] as int,
|
||||
contentType: json['contentType'] as String,
|
||||
contentBody: json['contentBody'] as String,
|
||||
timestamp: json['timestamp'] as int,
|
||||
genesisTransaction: json['genesisTransaction'] as String,
|
||||
location: json['location'] as String,
|
||||
output: json['output'] as String,
|
||||
outputValue: json['outputValue'] as int,
|
||||
offset: json['offset'] as int,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
53
lib/dto/ordinals/inscription_data.dart
Normal file
53
lib/dto/ordinals/inscription_data.dart
Normal file
|
@ -0,0 +1,53 @@
|
|||
// inscription data from litescribe /address/inscriptions endpoint
|
||||
class InscriptionData {
|
||||
final String inscriptionId;
|
||||
final int inscriptionNumber;
|
||||
final String address;
|
||||
final String preview;
|
||||
final String content;
|
||||
final int contentLength;
|
||||
final String contentType;
|
||||
final String contentBody;
|
||||
final int timestamp;
|
||||
final String genesisTransaction;
|
||||
final String location;
|
||||
final String output;
|
||||
final int outputValue;
|
||||
final int offset;
|
||||
|
||||
InscriptionData({
|
||||
required this.inscriptionId,
|
||||
required this.inscriptionNumber,
|
||||
required this.address,
|
||||
required this.preview,
|
||||
required this.content,
|
||||
required this.contentLength,
|
||||
required this.contentType,
|
||||
required this.contentBody,
|
||||
required this.timestamp,
|
||||
required this.genesisTransaction,
|
||||
required this.location,
|
||||
required this.output,
|
||||
required this.outputValue,
|
||||
required this.offset,
|
||||
});
|
||||
|
||||
factory InscriptionData.fromJson(Map<String, dynamic> json) {
|
||||
return InscriptionData(
|
||||
inscriptionId: json['inscriptionId'] as String,
|
||||
inscriptionNumber: json['inscriptionNumber'] as int,
|
||||
address: json['address'] as String,
|
||||
preview: json['preview'] as String,
|
||||
content: json['content'] as String,
|
||||
contentLength: json['contentLength'] as int,
|
||||
contentType: json['contentType'] as String,
|
||||
contentBody: json['contentBody'] as String,
|
||||
timestamp: json['timestamp'] as int,
|
||||
genesisTransaction: json['genesisTransaction'] as String,
|
||||
location: json['location'] as String,
|
||||
output: json['output'] as String,
|
||||
outputValue: json['outputValue'] as int,
|
||||
offset: json['offset'] as int,
|
||||
);
|
||||
}
|
||||
}
|
|
@ -14,8 +14,9 @@ import 'package:flutter_svg/svg.dart';
|
|||
import 'package:stackwallet/models/ordinal.dart';
|
||||
import 'package:stackwallet/pages/ordinals/ordinals_filter_view.dart';
|
||||
import 'package:stackwallet/pages/ordinals/widgets/ordinals_list.dart';
|
||||
import 'package:stackwallet/services/litescribe_api.dart';
|
||||
import 'package:stackwallet/services/ordinals_api.dart';
|
||||
import 'package:stackwallet/providers/global/wallets_provider.dart';
|
||||
// import 'package:stackwallet/services/litescribe_api.dart';
|
||||
// import 'package:stackwallet/services/ordinals_api.dart';
|
||||
import 'package:stackwallet/services/mixins/ordinals_interface.dart';
|
||||
import 'package:stackwallet/themes/stack_colors.dart';
|
||||
import 'package:stackwallet/utilities/assets.dart';
|
||||
|
@ -28,6 +29,7 @@ import 'package:stackwallet/widgets/icon_widgets/x_icon.dart';
|
|||
import 'package:stackwallet/widgets/stack_text_field.dart';
|
||||
import 'package:stackwallet/widgets/textfield_icon_button.dart';
|
||||
|
||||
|
||||
class OrdinalsView extends ConsumerStatefulWidget {
|
||||
const OrdinalsView({
|
||||
super.key,
|
||||
|
|
|
@ -136,6 +136,7 @@ class LitecoinWallet extends CoinServiceAPI
|
|||
_secureStore = secureStore;
|
||||
initCache(walletId, coin);
|
||||
initWalletDB(mockableOverride: mockableOverride);
|
||||
initOrdinalsInterface(walletId:walletId, coin: coin, db: db);
|
||||
initCoinControlInterface(
|
||||
walletId: walletId,
|
||||
walletName: walletName,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import 'package:stackwallet/dto/ordinals/address_inscription_response.dart';
|
||||
import 'package:stackwallet/dto/ordinals/inscription_data.dart';
|
||||
import 'package:stackwallet/dto/ordinals/litescribe_response.dart';
|
||||
|
||||
class LitescribeAPI {
|
||||
|
@ -34,7 +34,7 @@ class LitescribeAPI {
|
|||
}
|
||||
}
|
||||
|
||||
Future<AddressInscriptionResponse> getInscriptionsByAddress(String address, {int cursor = 0, int size = 1000}) async {
|
||||
Future<List<InscriptionData>> getInscriptionsByAddress(String address, {int cursor = 0, int size = 1000}) async {
|
||||
// size param determines how many inscriptions are returned per response
|
||||
// default of 1000 is used to cover most addresses (I assume)
|
||||
// if the total number of inscriptions at the address exceeds the length of the list of inscriptions returned, another call with a higher size is made
|
||||
|
@ -42,7 +42,7 @@ class LitescribeAPI {
|
|||
final response = await _getResponse('/address/inscriptions?address=$address&cursor=$cursor&size=$size');
|
||||
|
||||
// Check if the number of returned inscriptions equals the limit
|
||||
final list = response.data['result']['list'] as List<dynamic>;
|
||||
final list = response.data['result']['list'] as List<InscriptionData>;
|
||||
final int total = response.data['result']['total'] as int;
|
||||
final int currentSize = list.length;
|
||||
|
||||
|
@ -54,7 +54,7 @@ class LitescribeAPI {
|
|||
// TODO test logic with smaller size "pagination"
|
||||
} else {
|
||||
try {
|
||||
return AddressInscriptionResponse.fromJson(response.data as Map<String, dynamic>);
|
||||
return list;
|
||||
} catch (e) {
|
||||
throw const FormatException('LitescribeAPI getInscriptionsByAddress exception: AddressInscriptionResponse.fromJson failure');
|
||||
}
|
||||
|
|
|
@ -15,8 +15,8 @@ import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
|||
// import 'package:stackwallet/dto/ordinals/preview_response.dart';
|
||||
// import 'package:stackwallet/services/ordinals_api.dart';
|
||||
|
||||
import 'package:stackwallet/dto/ordinals/address_inscription_response.dart'; // verbose due to Litescribe being the 2nd API
|
||||
import 'package:stackwallet/services/litescribe_api.dart';
|
||||
import 'package:stackwallet/dto/ordinals/inscription_data.dart';
|
||||
|
||||
|
||||
mixin OrdinalsInterface {
|
||||
|
@ -29,39 +29,29 @@ 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');
|
||||
|
||||
Future<List<AddressInscription>> getInscriptionsByAddress(String address) async {
|
||||
try {
|
||||
var response = await litescribeAPI.getInscriptionsByAddress(address);
|
||||
print("Found ${response.result.total} inscription${response.result.total > 1 ? 's' : ''} at address $address"); // TODO disable (POC)
|
||||
return response.result.list;
|
||||
} catch (e) {
|
||||
throw Exception('Error in OrdinalsInterface getInscriptionsByAddress: $e');
|
||||
}
|
||||
}
|
||||
// Future<List<InscriptionData>> getInscriptionsByAddress(String address) async {
|
||||
// try {
|
||||
// var response = await litescribeAPI.getInscriptionsByAddress(address);
|
||||
// // print("Found ${response.result.total} inscription${response.result.total > 1 ? 's' : ''} at address $address"); // TODO disable (POC)
|
||||
// return response.result.list;
|
||||
// } catch (e) {
|
||||
// throw Exception('Error in OrdinalsInterface getInscriptionsByAddress: $e');
|
||||
// }
|
||||
// }
|
||||
|
||||
void refreshInscriptions() async {
|
||||
List<dynamic> _inscriptions;
|
||||
final utxos = await _db.getUTXOs(_walletId).findAll();
|
||||
final uniqueAddresses = getUniqueAddressesFromUTXOs(utxos);
|
||||
for (String address in uniqueAddresses) {
|
||||
// TODO fetch all inscriptions from all addresses
|
||||
// TODO save those inscriptions to isar, which a StreamBuilder will be "subscribed"-to
|
||||
}
|
||||
// TODO get all inscriptions at all addresses in wallet
|
||||
var inscriptions = await getInscriptionsByAddress('ltc1qk4e8hdq5w6rvk5xvkxajjak78v45pkul8a2cg9');
|
||||
for (var inscription in inscriptions) {
|
||||
print(inscription);
|
||||
print(inscription.address);
|
||||
print(inscription.content);
|
||||
print(inscription.inscriptionId);
|
||||
print(inscription.inscriptionNumber);
|
||||
}
|
||||
_inscriptions = await getAllInscriptionsFromAddresses(uniqueAddresses);
|
||||
// TODO save inscriptions to isar which gets watched by a StreamBuilder
|
||||
}
|
||||
|
||||
List<String> getUniqueAddressesFromUTXOs(List<UTXO> utxos) {
|
||||
|
@ -74,7 +64,21 @@ mixin OrdinalsInterface {
|
|||
return uniqueAddresses.toList();
|
||||
}
|
||||
|
||||
/* // ord-litecoin interface
|
||||
Future<List<InscriptionData>> getAllInscriptionsFromAddresses(List<String> addresses) async {
|
||||
List<InscriptionData> allInscriptions = [];
|
||||
for (String address in addresses) {
|
||||
try {
|
||||
var inscriptions = await litescribeAPI.getInscriptionsByAddress(address);
|
||||
print("Found ${inscriptions.length} inscription${inscriptions.length > 1 ? 's' : ''} at address $address");
|
||||
allInscriptions.addAll(inscriptions);
|
||||
} catch (e) {
|
||||
print("Error fetching inscriptions for address $address: $e");
|
||||
}
|
||||
}
|
||||
return allInscriptions;
|
||||
}
|
||||
|
||||
/* // ord-litecoin interface
|
||||
final OrdinalsAPI ordinalsAPI = OrdinalsAPI(baseUrl: 'https://ord-litecoin.stackwallet.com');
|
||||
|
||||
Future<FeedResponse> fetchLatestInscriptions() async {
|
||||
|
|
Loading…
Reference in a new issue