This repository has been archived by the owner on Apr 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
116 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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,28 @@ | ||
import 'package:cashu_dart/src/model/response/get_keys.dart'; | ||
import 'package:cashu_dart/src/utils/request.dart'; | ||
|
||
/// Class that handles Cashu Mint API. | ||
class CashuMint { | ||
/// Takes [String] url as a parameter | ||
CashuMint({ | ||
required this.url, | ||
}); | ||
|
||
final String url; | ||
|
||
Future<GetKeysResponse?> getKeys({ | ||
String? keysetId, | ||
}) async { | ||
var endpoint = '$url/v1/keys'; | ||
|
||
if (keysetId != null) { | ||
endpoint = '$endpoint/$keysetId'; | ||
} | ||
|
||
final requestedData = await request(endpoint, 'GET', null); | ||
|
||
final respon = | ||
requestedData != null ? GetKeysResponse.fromJson(requestedData) : null; | ||
return respon; | ||
} | ||
} |
This file contains 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,37 @@ | ||
import 'package:cashu_dart/src/model/types.dart'; | ||
|
||
class GetKeysResponse { | ||
GetKeysResponse({ | ||
required this.keysets, | ||
}); | ||
|
||
final List<KeySet> keysets; | ||
|
||
factory GetKeysResponse.fromJson(Map<String, dynamic> json) { | ||
return GetKeysResponse( | ||
keysets: List<KeySet>.from( | ||
json['keysets'].map((x) => KeySet.fromJson(x)), | ||
), | ||
); | ||
} | ||
} | ||
|
||
class KeySet { | ||
KeySet({ | ||
required this.id, | ||
required this.unit, | ||
required this.keys, | ||
}); | ||
|
||
final String id; | ||
final String unit; | ||
final MintKeys keys; | ||
|
||
factory KeySet.fromJson(Map<String, dynamic> json) { | ||
return KeySet( | ||
id: json['id'] as String, | ||
unit: json['unit'] as String, | ||
keys: Map<String, String>.from(json['keys'] as Map<String, dynamic>), | ||
); | ||
} | ||
} |
This file contains 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,39 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:dio/dio.dart'; | ||
|
||
Future<Map<String, dynamic>?> request( | ||
String url, | ||
String method, | ||
String? body, | ||
) async { | ||
if (method == 'GET') { | ||
return await _getRequest(url); | ||
} else if (method == 'POST') { | ||
return await _postRequest(url, body); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
Future<Map<String, dynamic>?> _getRequest(String url) async { | ||
final dio = Dio(); | ||
final response = await dio.get<Map<String, dynamic>>(url); | ||
|
||
if (response.statusCode == HttpStatus.ok) { | ||
return response.data; | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
Future<Map<String, dynamic>?> _postRequest(String url, String? body) async { | ||
final dio = Dio(); | ||
final response = await dio.post<Map<String, dynamic>>(url, data: body); | ||
|
||
if (response.statusCode == HttpStatus.ok) { | ||
return response.data; | ||
} else { | ||
return null; | ||
} | ||
} |
This file contains 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,9 @@ | ||
import 'package:cashu_dart/src/mint.dart'; | ||
|
||
class CashuWallet { | ||
CashuWallet({ | ||
required this.cashuMint, | ||
}); | ||
|
||
final CashuMint cashuMint; | ||
} |
This file contains 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