From 46cec04717c2973d8386b55b82536a8ff0e14b16 Mon Sep 17 00:00:00 2001 From: Ez3kiel Date: Thu, 1 Aug 2024 21:38:18 +0200 Subject: [PATCH] feat(daemon): GetHardForks RPC method --- README.md | 1 + lib/src/data_transfer_objects/dtos.dart | 1 + .../get_hard_forks/get_hard_forks_result.dart | 23 ++ .../get_hard_forks_result.freezed.dart | 245 ++++++++++++++++++ .../get_hard_forks_result.g.dart | 27 ++ .../repositories/daemon/daemon_constants.dart | 5 +- .../daemon/daemon_rpc_methods_extension.dart | 8 + 7 files changed, 309 insertions(+), 1 deletion(-) create mode 100644 lib/src/data_transfer_objects/get_hard_forks/get_hard_forks_result.dart create mode 100644 lib/src/data_transfer_objects/get_hard_forks/get_hard_forks_result.freezed.dart create mode 100644 lib/src/data_transfer_objects/get_hard_forks/get_hard_forks_result.g.dart diff --git a/README.md b/README.md index 6a00446..a8a0a19 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,7 @@ JSON-RPC Clients to interact with daemon and wallet API. - splitAddress - extractKeyFromAddress - getMinerWork +- getHardForks #### Wallet diff --git a/lib/src/data_transfer_objects/dtos.dart b/lib/src/data_transfer_objects/dtos.dart index f8227e4..4009120 100644 --- a/lib/src/data_transfer_objects/dtos.dart +++ b/lib/src/data_transfer_objects/dtos.dart @@ -29,6 +29,7 @@ export 'get_block_template/get_block_template_result.dart'; export 'get_blocks_at_height/get_blocks_at_height_params.dart'; export 'get_dev_fee_thresholds/get_dev_fee_threshold_result.dart'; export 'get_difficulty/get_difficulty_result.dart'; +export 'get_hard_forks/get_hard_forks_result.dart'; export 'get_info/get_info_result.dart'; export 'get_mempool_cache/get_mempool_cache_params.dart'; export 'get_mempool_cache/get_mempool_cache_result.dart'; diff --git a/lib/src/data_transfer_objects/get_hard_forks/get_hard_forks_result.dart b/lib/src/data_transfer_objects/get_hard_forks/get_hard_forks_result.dart new file mode 100644 index 0000000..803b0ff --- /dev/null +++ b/lib/src/data_transfer_objects/get_hard_forks/get_hard_forks_result.dart @@ -0,0 +1,23 @@ +// ignore_for_file: invalid_annotation_target + +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'get_hard_forks_result.freezed.dart'; + +part 'get_hard_forks_result.g.dart'; + +/// @nodoc +@freezed +class GetHardForksResult with _$GetHardForksResult { + /// @nodoc + const factory GetHardForksResult({ + @JsonKey(name: 'height') required int height, + @JsonKey(name: 'version') required int version, + @JsonKey(name: 'changelog') required String changelog, + @JsonKey(name: 'version_requirement') String? versionRequirement, + }) = _GetHardForksResult; + + /// @nodoc + factory GetHardForksResult.fromJson(Map json) => + _$GetHardForksResultFromJson(json); +} diff --git a/lib/src/data_transfer_objects/get_hard_forks/get_hard_forks_result.freezed.dart b/lib/src/data_transfer_objects/get_hard_forks/get_hard_forks_result.freezed.dart new file mode 100644 index 0000000..837bac4 --- /dev/null +++ b/lib/src/data_transfer_objects/get_hard_forks/get_hard_forks_result.freezed.dart @@ -0,0 +1,245 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'get_hard_forks_result.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); + +GetHardForksResult _$GetHardForksResultFromJson(Map json) { + return _GetHardForksResult.fromJson(json); +} + +/// @nodoc +mixin _$GetHardForksResult { + @JsonKey(name: 'height') + int get height => throw _privateConstructorUsedError; + @JsonKey(name: 'version') + int get version => throw _privateConstructorUsedError; + @JsonKey(name: 'changelog') + String get changelog => throw _privateConstructorUsedError; + @JsonKey(name: 'version_requirement') + String? get versionRequirement => throw _privateConstructorUsedError; + + /// Serializes this GetHardForksResult to a JSON map. + Map toJson() => throw _privateConstructorUsedError; + + /// Create a copy of GetHardForksResult + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $GetHardForksResultCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $GetHardForksResultCopyWith<$Res> { + factory $GetHardForksResultCopyWith( + GetHardForksResult value, $Res Function(GetHardForksResult) then) = + _$GetHardForksResultCopyWithImpl<$Res, GetHardForksResult>; + @useResult + $Res call( + {@JsonKey(name: 'height') int height, + @JsonKey(name: 'version') int version, + @JsonKey(name: 'changelog') String changelog, + @JsonKey(name: 'version_requirement') String? versionRequirement}); +} + +/// @nodoc +class _$GetHardForksResultCopyWithImpl<$Res, $Val extends GetHardForksResult> + implements $GetHardForksResultCopyWith<$Res> { + _$GetHardForksResultCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of GetHardForksResult + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? height = null, + Object? version = null, + Object? changelog = null, + Object? versionRequirement = freezed, + }) { + return _then(_value.copyWith( + height: null == height + ? _value.height + : height // ignore: cast_nullable_to_non_nullable + as int, + version: null == version + ? _value.version + : version // ignore: cast_nullable_to_non_nullable + as int, + changelog: null == changelog + ? _value.changelog + : changelog // ignore: cast_nullable_to_non_nullable + as String, + versionRequirement: freezed == versionRequirement + ? _value.versionRequirement + : versionRequirement // ignore: cast_nullable_to_non_nullable + as String?, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$GetHardForksResultImplCopyWith<$Res> + implements $GetHardForksResultCopyWith<$Res> { + factory _$$GetHardForksResultImplCopyWith(_$GetHardForksResultImpl value, + $Res Function(_$GetHardForksResultImpl) then) = + __$$GetHardForksResultImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {@JsonKey(name: 'height') int height, + @JsonKey(name: 'version') int version, + @JsonKey(name: 'changelog') String changelog, + @JsonKey(name: 'version_requirement') String? versionRequirement}); +} + +/// @nodoc +class __$$GetHardForksResultImplCopyWithImpl<$Res> + extends _$GetHardForksResultCopyWithImpl<$Res, _$GetHardForksResultImpl> + implements _$$GetHardForksResultImplCopyWith<$Res> { + __$$GetHardForksResultImplCopyWithImpl(_$GetHardForksResultImpl _value, + $Res Function(_$GetHardForksResultImpl) _then) + : super(_value, _then); + + /// Create a copy of GetHardForksResult + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? height = null, + Object? version = null, + Object? changelog = null, + Object? versionRequirement = freezed, + }) { + return _then(_$GetHardForksResultImpl( + height: null == height + ? _value.height + : height // ignore: cast_nullable_to_non_nullable + as int, + version: null == version + ? _value.version + : version // ignore: cast_nullable_to_non_nullable + as int, + changelog: null == changelog + ? _value.changelog + : changelog // ignore: cast_nullable_to_non_nullable + as String, + versionRequirement: freezed == versionRequirement + ? _value.versionRequirement + : versionRequirement // ignore: cast_nullable_to_non_nullable + as String?, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$GetHardForksResultImpl implements _GetHardForksResult { + const _$GetHardForksResultImpl( + {@JsonKey(name: 'height') required this.height, + @JsonKey(name: 'version') required this.version, + @JsonKey(name: 'changelog') required this.changelog, + @JsonKey(name: 'version_requirement') this.versionRequirement}); + + factory _$GetHardForksResultImpl.fromJson(Map json) => + _$$GetHardForksResultImplFromJson(json); + + @override + @JsonKey(name: 'height') + final int height; + @override + @JsonKey(name: 'version') + final int version; + @override + @JsonKey(name: 'changelog') + final String changelog; + @override + @JsonKey(name: 'version_requirement') + final String? versionRequirement; + + @override + String toString() { + return 'GetHardForksResult(height: $height, version: $version, changelog: $changelog, versionRequirement: $versionRequirement)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$GetHardForksResultImpl && + (identical(other.height, height) || other.height == height) && + (identical(other.version, version) || other.version == version) && + (identical(other.changelog, changelog) || + other.changelog == changelog) && + (identical(other.versionRequirement, versionRequirement) || + other.versionRequirement == versionRequirement)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => + Object.hash(runtimeType, height, version, changelog, versionRequirement); + + /// Create a copy of GetHardForksResult + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$GetHardForksResultImplCopyWith<_$GetHardForksResultImpl> get copyWith => + __$$GetHardForksResultImplCopyWithImpl<_$GetHardForksResultImpl>( + this, _$identity); + + @override + Map toJson() { + return _$$GetHardForksResultImplToJson( + this, + ); + } +} + +abstract class _GetHardForksResult implements GetHardForksResult { + const factory _GetHardForksResult( + {@JsonKey(name: 'height') required final int height, + @JsonKey(name: 'version') required final int version, + @JsonKey(name: 'changelog') required final String changelog, + @JsonKey(name: 'version_requirement') + final String? versionRequirement}) = _$GetHardForksResultImpl; + + factory _GetHardForksResult.fromJson(Map json) = + _$GetHardForksResultImpl.fromJson; + + @override + @JsonKey(name: 'height') + int get height; + @override + @JsonKey(name: 'version') + int get version; + @override + @JsonKey(name: 'changelog') + String get changelog; + @override + @JsonKey(name: 'version_requirement') + String? get versionRequirement; + + /// Create a copy of GetHardForksResult + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$GetHardForksResultImplCopyWith<_$GetHardForksResultImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/lib/src/data_transfer_objects/get_hard_forks/get_hard_forks_result.g.dart b/lib/src/data_transfer_objects/get_hard_forks/get_hard_forks_result.g.dart new file mode 100644 index 0000000..ed489a3 --- /dev/null +++ b/lib/src/data_transfer_objects/get_hard_forks/get_hard_forks_result.g.dart @@ -0,0 +1,27 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +// ignore_for_file: package_api_docs, non_constant_identifier_names + +part of 'get_hard_forks_result.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$GetHardForksResultImpl _$$GetHardForksResultImplFromJson( + Map json) => + _$GetHardForksResultImpl( + height: (json['height'] as num).toInt(), + version: (json['version'] as num).toInt(), + changelog: json['changelog'] as String, + versionRequirement: json['version_requirement'] as String?, + ); + +Map _$$GetHardForksResultImplToJson( + _$GetHardForksResultImpl instance) => + { + 'height': instance.height, + 'version': instance.version, + 'changelog': instance.changelog, + 'version_requirement': instance.versionRequirement, + }; diff --git a/lib/src/repositories/daemon/daemon_constants.dart b/lib/src/repositories/daemon/daemon_constants.dart index 2950ce4..20b1d5d 100644 --- a/lib/src/repositories/daemon/daemon_constants.dart +++ b/lib/src/repositories/daemon/daemon_constants.dart @@ -161,7 +161,10 @@ enum DaemonMethod implements XelisJsonKey { extractKeyFromAddress('extract_key_from_address'), /// Get miner Work - getMinerWork('get_miner_work'); + getMinerWork('get_miner_work'), + + /// Get hard forks + getHardForks('get_hard_forks'); /// Creates a new [DaemonMethod] instance. const DaemonMethod(this.jsonKey); diff --git a/lib/src/repositories/daemon/daemon_rpc_methods_extension.dart b/lib/src/repositories/daemon/daemon_rpc_methods_extension.dart index 493da69..ba54187 100644 --- a/lib/src/repositories/daemon/daemon_rpc_methods_extension.dart +++ b/lib/src/repositories/daemon/daemon_rpc_methods_extension.dart @@ -495,4 +495,12 @@ extension DaemonRpcMethodsExtension on DaemonClient { ); return GetMinerWorkResult.fromJson(result as Map); } + + /// Get hard forks + Future> getHardForks() async { + final result = await sendRequest(DaemonMethod.getHardForks); + return (result as List) + .map((e) => GetHardForksResult.fromJson(e as Map)) + .toList(); + } }