add block endpoint

This commit is contained in:
sneurlax 2023-07-19 10:50:56 -05:00
parent f972c34dc4
commit 6d772b0acd
2 changed files with 16 additions and 10 deletions

View file

@ -19,13 +19,13 @@ class BlockResponse {
factory BlockResponse.fromJson(Map<String, dynamic> json) { factory BlockResponse.fromJson(Map<String, dynamic> json) {
return BlockResponse( return BlockResponse(
links: BlockLinks.fromJson(json['_links']), links: BlockLinks.fromJson(json['_links'] as Map<String, dynamic>),
hash: json['hash'], hash: json['hash'] as String,
previousBlockhash: json['previous_blockhash'], previousBlockhash: json['previous_blockhash'] as String,
size: json['size'], size: json['size'] as int,
target: json['target'], target: json['target'] as String,
timestamp: json['timestamp'], timestamp: json['timestamp'] as String,
weight: json['weight'], weight: json['weight'] as int,
); );
} }
} }
@ -41,8 +41,8 @@ class BlockLinks {
factory BlockLinks.fromJson(Map<String, dynamic> json) { factory BlockLinks.fromJson(Map<String, dynamic> json) {
return BlockLinks( return BlockLinks(
prev: BlockLink.fromJson(json['prev']), prev: BlockLink.fromJson(json['prev'] as Map<String, dynamic>),
self: BlockLink.fromJson(json['self']), self: BlockLink.fromJson(json['self'] as Map<String, dynamic>),
); );
} }
} }
@ -53,6 +53,6 @@ class BlockLink {
BlockLink({required this.href}); BlockLink({required this.href});
factory BlockLink.fromJson(Map<String, dynamic> json) { factory BlockLink.fromJson(Map<String, dynamic> json) {
return BlockLink(href: json['href']); return BlockLink(href: json['href'] as String);
} }
} }

View file

@ -7,6 +7,7 @@ import 'package:stackwallet/dto/ordinals/sat_response.dart';
import 'package:stackwallet/dto/ordinals/transaction_response.dart'; import 'package:stackwallet/dto/ordinals/transaction_response.dart';
import 'package:stackwallet/dto/ordinals/output_response.dart'; import 'package:stackwallet/dto/ordinals/output_response.dart';
import 'package:stackwallet/dto/ordinals/address_response.dart'; import 'package:stackwallet/dto/ordinals/address_response.dart';
import 'package:stackwallet/dto/ordinals/block_response.dart';
class OrdinalsAPI { class OrdinalsAPI {
final String baseUrl; final String baseUrl;
@ -60,4 +61,9 @@ class OrdinalsAPI {
final response = await _getResponse('/address/$address'); final response = await _getResponse('/address/$address');
return AddressResponse.fromJson(response); return AddressResponse.fromJson(response);
} }
Future<BlockResponse> getBlock(int blockNumber) async {
final response = await _getResponse('/block/$blockNumber');
return BlockResponse.fromJson(response);
}
} }