cake_wallet/cw_bitcoin/lib/electrum_worker/methods/connection.dart

78 lines
1.9 KiB
Dart
Raw Normal View History

2024-10-31 14:39:02 +00:00
part of 'methods.dart';
class ElectrumWorkerConnectionRequest implements ElectrumWorkerRequest {
ElectrumWorkerConnectionRequest({
required this.uri,
required this.network,
2024-11-16 17:53:00 +00:00
required this.useSSL,
this.id,
});
2024-10-31 14:39:02 +00:00
final Uri uri;
2024-11-16 17:53:00 +00:00
final bool useSSL;
final BasedUtxoNetwork network;
final int? id;
2024-10-31 14:39:02 +00:00
@override
final String method = ElectrumWorkerMethods.connect.method;
@override
factory ElectrumWorkerConnectionRequest.fromJson(Map<String, dynamic> json) {
return ElectrumWorkerConnectionRequest(
uri: Uri.parse(json['uri'] as String),
network: BasedUtxoNetwork.values.firstWhere(
(e) => e.toString() == json['network'] as String,
),
2024-11-16 17:53:00 +00:00
useSSL: json['useSSL'] as bool,
id: json['id'] as int?,
);
2024-10-31 14:39:02 +00:00
}
@override
Map<String, dynamic> toJson() {
return {
'method': method,
'uri': uri.toString(),
'network': network.toString(),
2024-11-16 17:53:00 +00:00
'useSSL': useSSL,
};
2024-10-31 14:39:02 +00:00
}
}
class ElectrumWorkerConnectionError extends ElectrumWorkerErrorResponse {
ElectrumWorkerConnectionError({
required super.error,
super.id,
}) : super();
2024-10-31 14:39:02 +00:00
@override
String get method => ElectrumWorkerMethods.connect.method;
}
class ElectrumWorkerConnectionResponse extends ElectrumWorkerResponse<ConnectionStatus, String> {
ElectrumWorkerConnectionResponse({
required ConnectionStatus status,
super.error,
super.id,
}) : super(
2024-10-31 14:39:02 +00:00
result: status,
method: ElectrumWorkerMethods.connect.method,
);
@override
String resultJson(result) {
return result.toString();
}
@override
factory ElectrumWorkerConnectionResponse.fromJson(Map<String, dynamic> json) {
return ElectrumWorkerConnectionResponse(
status: ConnectionStatus.values.firstWhere(
(e) => e.toString() == json['result'] as String,
),
error: json['error'] as String?,
id: json['id'] as int?,
2024-10-31 14:39:02 +00:00
);
}
}