2023-07-19 16:04:19 +00:00
|
|
|
import 'package:stackwallet/dto/ordinals/inscription_link.dart';
|
2023-07-19 18:03:17 +00:00
|
|
|
import 'package:stackwallet/dto/ordinals/ordinals_response.dart';
|
2023-07-19 16:04:19 +00:00
|
|
|
|
2023-07-19 18:03:17 +00:00
|
|
|
class TransactionResponse extends OrdinalsResponse<TransactionResponse> {
|
2023-07-18 21:36:26 +00:00
|
|
|
final TransactionLinks links;
|
|
|
|
final List<OutputLink> inputs;
|
|
|
|
final InscriptionLink inscription;
|
|
|
|
final List<OutputLink> outputs;
|
|
|
|
final TransactionLink self;
|
|
|
|
final String transaction;
|
|
|
|
|
|
|
|
TransactionResponse({
|
|
|
|
required this.links,
|
|
|
|
required this.inputs,
|
|
|
|
required this.inscription,
|
|
|
|
required this.outputs,
|
|
|
|
required this.self,
|
|
|
|
required this.transaction,
|
|
|
|
});
|
|
|
|
|
2023-07-19 18:03:17 +00:00
|
|
|
factory TransactionResponse.fromJson(OrdinalsResponse json) {
|
|
|
|
final data = json.data as Map<String, dynamic>;
|
|
|
|
final inputsJson = data['_links']['inputs'] as List;
|
2023-07-18 21:36:26 +00:00
|
|
|
final inputs = inputsJson
|
2023-07-19 16:04:19 +00:00
|
|
|
.map((inputJson) => OutputLink.fromJson(inputJson as Map<String, dynamic>))
|
2023-07-18 21:36:26 +00:00
|
|
|
.toList();
|
|
|
|
|
2023-07-19 18:03:17 +00:00
|
|
|
final outputsJson = data['_links']['outputs'] as List;
|
2023-07-18 21:36:26 +00:00
|
|
|
final outputs = outputsJson
|
2023-07-19 16:04:19 +00:00
|
|
|
.map((outputJson) => OutputLink.fromJson(outputJson as Map<String, dynamic>))
|
2023-07-18 21:36:26 +00:00
|
|
|
.toList();
|
|
|
|
|
|
|
|
return TransactionResponse(
|
2023-07-19 18:03:17 +00:00
|
|
|
links: TransactionLinks.fromJson(data['_links'] as Map<String, dynamic>),
|
2023-07-18 21:36:26 +00:00
|
|
|
inputs: inputs,
|
2023-07-19 18:03:17 +00:00
|
|
|
inscription: InscriptionLink.fromJson(data['_links']['inscription'] as Map<String, dynamic>),
|
2023-07-18 21:36:26 +00:00
|
|
|
outputs: outputs,
|
2023-07-19 18:03:17 +00:00
|
|
|
self: TransactionLink.fromJson(data['_links']['self'] as Map<String, dynamic>),
|
|
|
|
transaction: data['transaction'] as String,
|
2023-07-18 21:36:26 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class TransactionLinks {
|
|
|
|
final TransactionLink? block;
|
|
|
|
final InscriptionLink? inscription;
|
|
|
|
final TransactionLink? self;
|
|
|
|
|
|
|
|
TransactionLinks({
|
|
|
|
this.block,
|
|
|
|
this.inscription,
|
|
|
|
this.self,
|
|
|
|
});
|
|
|
|
|
|
|
|
factory TransactionLinks.fromJson(Map<String, dynamic> json) {
|
|
|
|
return TransactionLinks(
|
2023-07-19 18:03:17 +00:00
|
|
|
block: json['block'] != null ? TransactionLink.fromJson(json['block'] as Map<String, dynamic>) : null,
|
|
|
|
inscription: json['inscription'] != null ? InscriptionLink.fromJson(json['inscription'] as Map<String, dynamic>) : null,
|
|
|
|
self: json['self'] != null ? TransactionLink.fromJson(json['self'] as Map<String, dynamic>) : null,
|
2023-07-18 21:36:26 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class TransactionLink {
|
|
|
|
final String href;
|
|
|
|
|
|
|
|
TransactionLink({required this.href});
|
|
|
|
|
|
|
|
factory TransactionLink.fromJson(Map<String, dynamic> json) {
|
2023-07-19 16:04:19 +00:00
|
|
|
return TransactionLink(href: json['href'] as String);
|
2023-07-18 21:36:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class OutputLink {
|
|
|
|
final String href;
|
|
|
|
|
|
|
|
OutputLink({required this.href});
|
|
|
|
|
|
|
|
factory OutputLink.fromJson(Map<String, dynamic> json) {
|
2023-07-19 16:04:19 +00:00
|
|
|
return OutputLink(href: json['href'] as String);
|
2023-07-18 21:36:26 +00:00
|
|
|
}
|
|
|
|
}
|