nwc: fix bug where private nwc zaps weren't getting tracked properly

It was using the wrapper zap request id instead of the inner id. Fix
this type error by creating a ZapRequestId wrapper that makes sure it
uses the proper request id.
This commit is contained in:
William Casarin
2023-05-14 10:48:44 -07:00
parent e472e559a5
commit b1fee253b4
6 changed files with 80 additions and 21 deletions

View File

@@ -234,7 +234,8 @@ func nwc_error(zapcache: Zaps, evcache: EventCache, resp: FullWalletResponse) {
}
// remove the pending zap if there was an error
remove_zap(reqid: pzap.request.ev.id, zapcache: zapcache, evcache: evcache)
let reqid = ZapRequestId(from_pending: pzap)
remove_zap(reqid: reqid, zapcache: zapcache, evcache: evcache)
return
}
}

View File

@@ -105,10 +105,10 @@ class PendingZap {
let type: ZapType
private(set) var state: PendingZapState
init(amount_msat: Int64, target: ZapTarget, request: ZapRequest, type: ZapType, state: PendingZapState) {
init(amount_msat: Int64, target: ZapTarget, request: MakeZapRequest, type: ZapType, state: PendingZapState) {
self.amount_msat = amount_msat
self.target = target
self.request = request
self.request = request.private_inner_request
self.type = type
self.state = state
}
@@ -125,6 +125,21 @@ class PendingZap {
}
}
struct ZapRequestId: Equatable {
let reqid: String
init(from_zap: Zapping) {
self.reqid = from_zap.request.id
}
init(from_makezap: MakeZapRequest) {
self.reqid = from_makezap.private_inner_request.ev.id
}
init(from_pending: PendingZap) {
self.reqid = from_pending.request.ev.id
}
}
enum Zapping {
case zap(Zap)

View File

@@ -91,9 +91,9 @@ class Zaps {
}
}
func remove_zap(reqid: String, zapcache: Zaps, evcache: EventCache) {
guard let zap = zapcache.remove_zap(reqid: reqid) else {
func remove_zap(reqid: ZapRequestId, zapcache: Zaps, evcache: EventCache) {
guard let zap = zapcache.remove_zap(reqid: reqid.reqid) else {
return
}
evcache.get_cache_data(zap.target.id).zaps_model.remove(reqid: reqid)
evcache.get_cache_data(zap.target.id).zaps_model.remove(reqid: reqid.reqid)
}