Pending Zaps

A fairly large change that replaces Zaps in the codebase with "Zapping"
which is a tagged union consisting of a resolved Zap and a Pending Zap.
These are both counted as Zaps everywhere in Damus, except pending zaps
can be cancelled (most of the time).
This commit is contained in:
William Casarin
2023-05-13 21:33:34 -07:00
parent 1518a0a16c
commit 03691d0369
24 changed files with 738 additions and 179 deletions

View File

@@ -10,21 +10,46 @@ import Foundation
public struct RelayInfo: Codable {
let read: Bool?
let write: Bool?
let ephemeral: Bool?
init(read: Bool, write: Bool, ephemeral: Bool = false) {
init(read: Bool, write: Bool) {
self.read = read
self.write = write
self.ephemeral = ephemeral
}
static let rw = RelayInfo(read: true, write: true, ephemeral: false)
static let ephemeral = RelayInfo(read: true, write: true, ephemeral: true)
static let rw = RelayInfo(read: true, write: true)
}
enum RelayVariant {
case regular
case ephemeral
case nwc
}
public struct RelayDescriptor {
public let url: RelayURL
public let info: RelayInfo
let url: RelayURL
let info: RelayInfo
let variant: RelayVariant
init(url: RelayURL, info: RelayInfo, variant: RelayVariant = .regular) {
self.url = url
self.info = info
self.variant = variant
}
var ephemeral: Bool {
switch variant {
case .regular:
return false
case .ephemeral:
return true
case .nwc:
return true
}
}
static func nwc(url: RelayURL) -> RelayDescriptor {
return RelayDescriptor(url: url, info: .rw, variant: .nwc)
}
}
enum RelayFlags: Int {