commit 83ef50586a905f6eb8723df9025ec4e38d530acf
parent 87992f4bb92ddfd1d53906ffc52ce90d1c26f855
Author: William Casarin <jb55@jb55.com>
Date: Sun, 9 Jul 2023 07:44:33 -0700
zaps/refactor: use guard instead of if block
not a fan of unncessary nesting
Diffstat:
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/damus/Models/HomeModel.swift b/damus/Models/HomeModel.swift
@@ -1246,14 +1246,9 @@ enum ProcessZapResult {
func get_zap_target_pubkey(ev: NostrEvent, events: EventCache) -> String? {
let etags = ev.referenced_ids
- if let etag = etags.first {
- // ensure that there is only 1 etag to stop fake note zap attacks
- guard etags.count == 1 else {
- return nil
- }
- // we can't trust the p tag on note zaps because they can be faked
- return events.lookup(etag.id)?.pubkey
- } else {
+ guard let etag = etags.first else {
+ // no etags, ptag-only case
+
let ptags = ev.referenced_pubkeys
// ensure that there is only 1 ptag to stop fake profile zap attacks
@@ -1263,6 +1258,16 @@ func get_zap_target_pubkey(ev: NostrEvent, events: EventCache) -> String? {
return ptags.first?.id
}
+
+ // we have an e-tag
+
+ // ensure that there is only 1 etag to stop fake note zap attacks
+ guard etags.count == 1 else {
+ return nil
+ }
+
+ // we can't trust the p tag on note zaps because they can be faked
+ return events.lookup(etag.id)?.pubkey
}
func process_zap_event(damus_state: DamusState, ev: NostrEvent, completion: @escaping (ProcessZapResult) -> Void) {