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) {
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<String, dynamic>),
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<String, dynamic> json) {
return BlockLinks(
prev: BlockLink.fromJson(json['prev']),
self: BlockLink.fromJson(json['self']),
prev: BlockLink.fromJson(json['prev'] as Map<String, dynamic>),
self: BlockLink.fromJson(json['self'] as Map<String, dynamic>),
);
}
}
@ -53,6 +53,6 @@ class BlockLink {
BlockLink({required this.href});
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/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<BlockResponse> getBlock(int blockNumber) async {
final response = await _getResponse('/block/$blockNumber');
return BlockResponse.fromJson(response);
}
}