-
Notifications
You must be signed in to change notification settings - Fork 3
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
44 changed files
with
1,583 additions
and
115 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,7 @@ android { | |
} | ||
|
||
defaultConfig { | ||
minSdkVersion 23 | ||
minSdkVersion 21 | ||
} | ||
|
||
dependencies { | ||
|
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
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,11 @@ | ||
# running the examples | ||
|
||
For zapping example `zap.dart` you need a `nostr+walletconnect://...` uri from your NWC wallet service provider. | ||
|
||
see https://github.com/getAlby/awesome-nwc for more info how to get a wallet supporting NWC | ||
|
||
`NWC_URI=nostr+walletconnect://.... dart zap.dart` | ||
|
||
for more logging | ||
|
||
`NWC_URI=nostr+walletconnect://.... dart --enable-asserts zap.dart` |
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,32 @@ | ||
// ignore_for_file: avoid_print | ||
|
||
import 'package:ndk/ndk.dart'; | ||
|
||
void main() async { | ||
final ndk = Ndk.defaultConfig(); | ||
|
||
print("fetching zap receipts for single event "); | ||
final receipts = await ndk.zaps.fetchZappedReceipts( | ||
pubKey: | ||
"787338757fc25d65cd929394d5e7713cf43638e8d259e8dcf5c73b834eb851f2", | ||
eventId: | ||
"906a0c5920b59e5754d0df5164bfea2a8d48ce5d73beaa1e854b3e6725e3288a").toList(); | ||
|
||
// Sort eventReceipts by amountSats in descending order | ||
receipts | ||
.sort((a, b) => (b.amountSats ?? 0).compareTo(a.amountSats ?? 0)); | ||
|
||
int eventSum = 0; | ||
for (var receipt in receipts) { | ||
String? sender; | ||
if (receipt.sender!=null) { | ||
Metadata? metadata = await ndk.metadata.loadMetadata(receipt.sender!); | ||
sender = metadata?.name; | ||
} | ||
print("${sender!=null?"from ${sender} ":""} ${receipt.amountSats} sats ${receipt.comment}"); | ||
eventSum += receipt.amountSats ?? 0; | ||
} | ||
print("${receipts.length} receipts, total of $eventSum sats"); | ||
|
||
await ndk.destroy(); | ||
} |
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,30 @@ | ||
// ignore_for_file: avoid_print | ||
|
||
import 'package:ndk/ndk.dart'; | ||
|
||
void main() async { | ||
final ndk = Ndk.defaultConfig(); | ||
|
||
print("fetching zap receipts for profile "); | ||
final profileReceipts = await ndk.zaps.fetchZappedReceipts( | ||
pubKey: "30782a8323b7c98b172c5a2af7206bb8283c655be6ddce11133611a03d5f1177", | ||
).toList(); | ||
|
||
// Sort profileReceipts by amountSats in descending order | ||
profileReceipts | ||
.sort((a, b) => (b.amountSats ?? 0).compareTo(a.amountSats ?? 0)); | ||
|
||
int profileSum = 0; | ||
for (var receipt in profileReceipts) { | ||
String? sender; | ||
if (receipt.sender!=null) { | ||
Metadata? metadata = await ndk.metadata.loadMetadata(receipt.sender!); | ||
sender = metadata?.name; | ||
} | ||
print("${sender!=null?"from ${sender} ":""} ${receipt.amountSats} sats ${receipt.comment}"); | ||
profileSum += receipt.amountSats ?? 0; | ||
} | ||
print("${profileReceipts.length} receipts, total of $profileSum sats"); | ||
|
||
await ndk.destroy(); | ||
} |
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,53 @@ | ||
// ignore_for_file: avoid_print | ||
|
||
import 'dart:io'; | ||
|
||
import 'package:ndk/domain_layer/usecases/zaps/zap_receipt.dart'; | ||
import 'package:ndk/domain_layer/usecases/zaps/zaps.dart'; | ||
import 'package:ndk/ndk.dart'; | ||
import 'package:ndk/shared/nips/nip01/bip340.dart'; | ||
import 'package:ndk/shared/nips/nip01/key_pair.dart'; | ||
|
||
void main() async { | ||
// We use an empty bootstrap relay list, | ||
// since NWC will provide the relay we connect to so we don't need default relays | ||
final ndk = Ndk(NdkConfig( | ||
eventVerifier: Bip340EventVerifier(), | ||
cache: MemCacheManager(), | ||
logLevel: Logger.logLevels.trace)); | ||
|
||
// You need an NWC_URI env var or to replace with your NWC uri connection | ||
final nwcUri = Platform.environment['NWC_URI']!; | ||
final connection = await ndk.nwc.connect(nwcUri); | ||
KeyPair key = Bip340.generatePrivateKey(); | ||
final amount = 21; | ||
final lnurl = "opensats@vlt.ge"; | ||
final comment = "enjoy this zap from NDK"; | ||
|
||
ZapResponse response = await ndk.zaps.zap( | ||
nwcConnection: connection, | ||
lnurl: lnurl, | ||
comment: comment, | ||
amountSats: amount, | ||
fetchZapReceipt: true, | ||
signer: Bip340EventSigner(privateKey: key.privateKey, publicKey: key.publicKey), | ||
relays: ["wss://relay.damus.io"], | ||
pubKey: "787338757fc25d65cd929394d5e7713cf43638e8d259e8dcf5c73b834eb851f2", | ||
eventId: "906a0c5920b59e5754d0df5164bfea2a8d48ce5d73beaa1e854b3e6725e3288a" | ||
); | ||
|
||
if (response.payInvoiceResponse!=null && response.payInvoiceResponse!.preimage.isNotEmpty) { | ||
print("Payed $amount to $lnurl, preimage = ${response.payInvoiceResponse! | ||
.preimage}"); | ||
|
||
print("Waiting for Zap Receipt..."); | ||
ZapReceipt? receipt = await response.zapReceipt; | ||
if (receipt!=null) { | ||
print("Receipt : $receipt"); | ||
} else { | ||
print("No Receipt"); | ||
} | ||
} | ||
|
||
await ndk.destroy(); | ||
} |
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
36 changes: 36 additions & 0 deletions
36
packages/ndk/lib/data_layer/repositories/lnurl_http_impl.dart
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,36 @@ | ||
import 'package:ndk/domain_layer/repositories/lnurl_transport.dart'; | ||
import 'package:ndk/domain_layer/usecases/lnurl/lnurl_response.dart'; | ||
|
||
import '../../domain_layer/repositories/nip_05_repo.dart'; | ||
import '../../shared/logger/logger.dart'; | ||
import '../data_sources/http_request.dart'; | ||
|
||
/// implementation of the [Nip05Repository] interface with http | ||
class LnurlTransportHttpImpl implements LnurlTransport { | ||
final HttpRequestDS httpDS; | ||
|
||
/// constructor | ||
LnurlTransportHttpImpl(this.httpDS); | ||
|
||
@override | ||
Future<LnurlResponse?> requestLnurlResponse(String lnurl) async { | ||
try { | ||
final response = await httpDS.jsonRequest(lnurl); | ||
return LnurlResponse.fromJson(response); | ||
} catch (e) { | ||
Logger.log.w(e); | ||
return null; | ||
} | ||
} | ||
|
||
@override | ||
Future<Map<String,dynamic>?> fetchInvoice(String callbacklink) async { | ||
try { | ||
return await httpDS.jsonRequest(callbacklink); | ||
} catch (e) { | ||
Logger.log.d(e); | ||
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
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
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
11 changes: 11 additions & 0 deletions
11
packages/ndk/lib/domain_layer/repositories/lnurl_transport.dart
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,11 @@ | ||
import 'package:ndk/domain_layer/usecases/lnurl/lnurl_response.dart'; | ||
import 'package:ndk/ndk.dart'; | ||
|
||
/// transport to get the lnurl response | ||
abstract class LnurlTransport { | ||
/// network request to get theLnurl response and invoices | ||
Future<LnurlResponse?> requestLnurlResponse(String lnurl); | ||
|
||
/// fetch an invoice from lnurl callback endpoint | ||
Future<Map<String,dynamic>?> fetchInvoice(String callbacklink); | ||
} |
Oops, something went wrong.