mirror of
git://jb55.com/damus
synced 2024-09-19 11:43:44 +00:00
zaps/refactor: use guard instead of if block
not a fan of unncessary nesting
This commit is contained in:
parent
87992f4bb9
commit
83ef50586a
@ -1246,14 +1246,9 @@ enum ProcessZapResult {
|
|||||||
func get_zap_target_pubkey(ev: NostrEvent, events: EventCache) -> String? {
|
func get_zap_target_pubkey(ev: NostrEvent, events: EventCache) -> String? {
|
||||||
let etags = ev.referenced_ids
|
let etags = ev.referenced_ids
|
||||||
|
|
||||||
if let etag = etags.first {
|
guard let etag = etags.first else {
|
||||||
// ensure that there is only 1 etag to stop fake note zap attacks
|
// no etags, ptag-only case
|
||||||
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 {
|
|
||||||
let ptags = ev.referenced_pubkeys
|
let ptags = ev.referenced_pubkeys
|
||||||
|
|
||||||
// ensure that there is only 1 ptag to stop fake profile zap attacks
|
// 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
|
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) {
|
func process_zap_event(damus_state: DamusState, ev: NostrEvent, completion: @escaping (ProcessZapResult) -> Void) {
|
||||||
|
Loading…
Reference in New Issue
Block a user