-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
223880
committed
Jul 18, 2024
1 parent
607e42c
commit 1ba5ebc
Showing
2 changed files
with
62 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 |
---|---|---|
@@ -1 +1,61 @@ | ||
// TODO implementation | ||
import 'dart:convert'; | ||
import 'package:http/http.dart' as http; | ||
|
||
class Bolt12Service { | ||
final String baseUrl; | ||
|
||
Bolt12Service(this.baseUrl); | ||
|
||
Future<String> generateInvoice({ | ||
required int satoshis, | ||
required String description, | ||
required int expiry, | ||
required String payeeNodeKey, | ||
required String payeeNodeAddress, | ||
required String payeeNodeAlias, | ||
required String payeeNodePubkey, | ||
required String onionMessage, | ||
required String payeeBase64, | ||
required String jsonEncode, | ||
required String jsonDecode, | ||
}) async { | ||
final response = await http.post( | ||
Uri.parse('$baseUrl/generate_invoice'), | ||
headers: {'Content-Type': 'application/json'}, | ||
body: jsonEncode({ | ||
'satoshis': satoshis, | ||
'description': description, | ||
'expiry': expiry, | ||
'payeeNodeKey': payeeNodeKey, | ||
'onionMessage': onionMessage, | ||
'payeeBase64': payeeBase64, | ||
'payeeNodeAddress': payeeNodeAddress, | ||
'payeeNodeAlias': payeeNodeAlias, | ||
'payeeNodePubkey': payeeNodePubkey, | ||
'jsonEncode': jsonEncode, | ||
'jsonDecode': jsonDecode, | ||
'bolt12': ' | ||
}), | ||
); | ||
if (response.statusCode == 200) { | ||
return jsonDecode(response.body)['invoice']; | ||
} else { | ||
throw Exception('Failed to generate invoice'); | ||
} | ||
} | ||
Future<Map<String, dynamic>> decodeInvoice(String bolt12Invoice) async { | ||
final response = await http.post( | ||
Uri.parse('$baseUrl/decode_invoice'), | ||
headers: {'Content-Type': 'application/json'}, | ||
body: jsonEncode({'invoice': bolt12Invoice}), | ||
); | ||
if (response.statusCode == 200) { | ||
return jsonDecode(response.body); | ||
} else { | ||
throw Exception('Failed to decode invoice'); | ||
} | ||
} | ||
} |