-
Notifications
You must be signed in to change notification settings - Fork 9
feat(pubkeys): add unbanning support #161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
packages/komodo_defi_rpc_methods/lib/src/rpc_methods/wallet/unban_pubkeys.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| import 'package:equatable/equatable.dart'; | ||
| import 'package:komodo_defi_rpc_methods/src/internal_exports.dart'; | ||
| import 'package:komodo_defi_types/komodo_defi_type_utils.dart'; | ||
|
|
||
| /// Determines how pubkeys should be unbanned | ||
| enum UnbanType { | ||
| all, | ||
| few; | ||
|
|
||
| @override | ||
| String toString() => switch (this) { | ||
| UnbanType.all => 'All', | ||
| UnbanType.few => 'Few', | ||
| }; | ||
|
|
||
| static UnbanType parse(String value) { | ||
| final lowerValue = value.toLowerCase(); | ||
| if (lowerValue == 'all') { | ||
| return UnbanType.all; | ||
| } else if (lowerValue == 'few') { | ||
| return UnbanType.few; | ||
| } else { | ||
| throw ArgumentError( | ||
| 'Invalid UnbanType value: $value. Expected "all" or "few".', | ||
| ); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Parameter for [UnbanPubkeysRequest] | ||
| class UnbanBy extends Equatable { | ||
| const UnbanBy.all() : type = UnbanType.all, data = null; | ||
| const UnbanBy.few(this.data) : type = UnbanType.few; | ||
|
|
||
| final UnbanType type; | ||
| final List<String>? data; | ||
|
|
||
| JsonMap toJson() => {'type': type.toString(), if (data != null) 'data': data}; | ||
|
|
||
| @override | ||
| List<Object?> get props => [type, data]; | ||
| } | ||
|
|
||
| class UnbanPubkeysRequest | ||
| extends BaseRequest<UnbanPubkeysResponse, GeneralErrorResponse> { | ||
| UnbanPubkeysRequest({required String rpcPass, required this.unbanBy}) | ||
| : super(method: 'unban_pubkeys', rpcPass: rpcPass, mmrpc: null); | ||
|
CharlVS marked this conversation as resolved.
|
||
|
|
||
| final UnbanBy unbanBy; | ||
|
|
||
| @override | ||
| JsonMap toJson() => {...super.toJson(), 'unban_by': unbanBy.toJson()}; | ||
|
|
||
| @override | ||
| UnbanPubkeysResponse parse(JsonMap json) => UnbanPubkeysResponse.parse(json); | ||
| } | ||
|
|
||
| class UnbanPubkeysResponse extends BaseResponse { | ||
| UnbanPubkeysResponse({required super.mmrpc, required this.result}); | ||
|
|
||
| factory UnbanPubkeysResponse.parse(JsonMap json) => UnbanPubkeysResponse( | ||
| mmrpc: json.valueOrNull<String>('mmrpc'), | ||
| result: UnbanPubkeysResult.fromJson(json.value<JsonMap>('result')), | ||
| ); | ||
|
|
||
| final UnbanPubkeysResult result; | ||
|
|
||
| @override | ||
| JsonMap toJson() => {'mmrpc': mmrpc, 'result': result.toJson()}; | ||
| } | ||
|
|
||
| class UnbanPubkeysResult extends Equatable { | ||
| const UnbanPubkeysResult({ | ||
| required this.stillBanned, | ||
| required this.unbanned, | ||
| required this.wereNotBanned, | ||
| }); | ||
|
|
||
| factory UnbanPubkeysResult.fromJson(JsonMap json) { | ||
| final still = json.valueOrNull<JsonMap>('still_banned') ?? {}; | ||
| final unbanned = json.valueOrNull<JsonMap>('unbanned') ?? {}; | ||
| return UnbanPubkeysResult( | ||
| stillBanned: still.map( | ||
| (k, v) => MapEntry(k, BannedPubkeyInfo.fromJson(v as JsonMap)), | ||
| ), | ||
| unbanned: unbanned.map( | ||
| (k, v) => MapEntry(k, BannedPubkeyInfo.fromJson(v as JsonMap)), | ||
| ), | ||
| wereNotBanned: | ||
| (json.valueOrNull<List<dynamic>>('were_not_banned') ?? []) | ||
| .cast<String>(), | ||
| ); | ||
| } | ||
|
|
||
| final Map<String, BannedPubkeyInfo> stillBanned; | ||
| final Map<String, BannedPubkeyInfo> unbanned; | ||
| final List<String> wereNotBanned; | ||
|
|
||
| JsonMap toJson() => { | ||
| 'still_banned': stillBanned.map((k, v) => MapEntry(k, v.toJson())), | ||
| 'unbanned': unbanned.map((k, v) => MapEntry(k, v.toJson())), | ||
| 'were_not_banned': wereNotBanned, | ||
| }; | ||
|
|
||
| @override | ||
| List<Object?> get props => [stillBanned, unbanned, wereNotBanned]; | ||
| } | ||
|
|
||
| class BannedPubkeyInfo extends Equatable { | ||
| const BannedPubkeyInfo({required this.type, required this.reason}); | ||
|
|
||
| factory BannedPubkeyInfo.fromJson(JsonMap json) => BannedPubkeyInfo( | ||
| type: json.value<String>('type'), | ||
| reason: json.value<String>('reason'), | ||
| ); | ||
|
|
||
| final String type; | ||
| final String reason; | ||
|
|
||
| JsonMap toJson() => {'type': type, 'reason': reason}; | ||
|
|
||
| @override | ||
| List<Object?> get props => [type, reason]; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| export 'package:komodo_defi_rpc_methods/komodo_defi_rpc_methods.dart' | ||
| show AddressFormat, BalanceInfo; | ||
| show AddressFormat, BalanceInfo, UnbanBy, UnbanPubkeysResult, BannedPubkeyInfo; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.