-
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.
add zaps.fetchZappedReceipts + examples for receipts
- Loading branch information
Showing
7 changed files
with
159 additions
and
34 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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// 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: | ||
"30782a8323b7c98b172c5a2af7206bb8283c655be6ddce11133611a03d5f1177", | ||
eventId: | ||
"d7bc29fa3c55ac525a3d5f2021211edb672b58565225dec423479a0875feea9d"); | ||
|
||
// Sort eventReceipts by amountSats in descending order | ||
receipts | ||
.sort((a, b) => (b.amountSats ?? 0).compareTo(a.amountSats ?? 0)); | ||
|
||
// Sort profileReceipts 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", | ||
); | ||
|
||
// 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
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