1
0
mirror of git://jb55.com/damus synced 2024-09-18 19:23:49 +00:00

zaps/refactor: use guard instead of if block

not a fan of unncessary nesting
This commit is contained in:
William Casarin 2023-07-09 07:44:33 -07:00
parent 87992f4bb9
commit 83ef50586a

View File

@ -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) {