From 6d772b0acdabdd19f0ed66663528a9a2912eb165 Mon Sep 17 00:00:00 2001 From: sneurlax Date: Wed, 19 Jul 2023 10:50:56 -0500 Subject: [PATCH] add block endpoint --- lib/dto/ordinals/block_response.dart | 20 ++++++++++---------- lib/services/ordinals_api.dart | 6 ++++++ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/dto/ordinals/block_response.dart b/lib/dto/ordinals/block_response.dart index 365098594..a3de1ee1c 100644 --- a/lib/dto/ordinals/block_response.dart +++ b/lib/dto/ordinals/block_response.dart @@ -19,13 +19,13 @@ class BlockResponse { factory BlockResponse.fromJson(Map json) { return BlockResponse( - links: BlockLinks.fromJson(json['_links']), - hash: json['hash'], - previousBlockhash: json['previous_blockhash'], - size: json['size'], - target: json['target'], - timestamp: json['timestamp'], - weight: json['weight'], + links: BlockLinks.fromJson(json['_links'] as Map), + hash: json['hash'] as String, + previousBlockhash: json['previous_blockhash'] as String, + size: json['size'] as int, + target: json['target'] as String, + timestamp: json['timestamp'] as String, + weight: json['weight'] as int, ); } } @@ -41,8 +41,8 @@ class BlockLinks { factory BlockLinks.fromJson(Map json) { return BlockLinks( - prev: BlockLink.fromJson(json['prev']), - self: BlockLink.fromJson(json['self']), + prev: BlockLink.fromJson(json['prev'] as Map), + self: BlockLink.fromJson(json['self'] as Map), ); } } @@ -53,6 +53,6 @@ class BlockLink { BlockLink({required this.href}); factory BlockLink.fromJson(Map json) { - return BlockLink(href: json['href']); + return BlockLink(href: json['href'] as String); } } diff --git a/lib/services/ordinals_api.dart b/lib/services/ordinals_api.dart index a0586d1ec..de9740554 100644 --- a/lib/services/ordinals_api.dart +++ b/lib/services/ordinals_api.dart @@ -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/output_response.dart'; import 'package:stackwallet/dto/ordinals/address_response.dart'; +import 'package:stackwallet/dto/ordinals/block_response.dart'; class OrdinalsAPI { final String baseUrl; @@ -60,4 +61,9 @@ class OrdinalsAPI { final response = await _getResponse('/address/$address'); return AddressResponse.fromJson(response); } + + Future getBlock(int blockNumber) async { + final response = await _getResponse('/block/$blockNumber'); + return BlockResponse.fromJson(response); + } }