Skip to content

Commit

Permalink
add bolt12
Browse files Browse the repository at this point in the history
  • Loading branch information
223880 committed Jul 18, 2024
1 parent 607e42c commit 1ba5ebc
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
- [ ] RBF
- [ ] Full RBF
- [ ] API
- [x] BOLT12 (Dart compatible) [WIP]
- [x] BOLT12 (Dart compatible)
- [x] BOLT11
- [ ] Mutinynet
- [ ] Bitcoin Knots
Expand Down
62 changes: 61 additions & 1 deletion lib/lightning/bolt12_service.dart
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');
}
}
}

0 comments on commit 1ba5ebc

Please sign in to comment.