damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 47a74257c84c6a3868078e506cd330ff9bd97f82
parent 1b161fefd099d8df6f57d694a0becc9289c12e4a
Author: William Casarin <jb55@jb55.com>
Date:   Wed, 24 May 2023 14:56:01 -0700

nwc debugging

Diffstat:
Mdamus/Components/ZapButton.swift | 3+++
Mdamus/Models/HomeModel.swift | 15+++++++--------
Mdamus/Util/PostBox.swift | 5+++++
Mdamus/Util/WalletConnect.swift | 3++-
4 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/damus/Components/ZapButton.swift b/damus/Components/ZapButton.swift @@ -272,9 +272,12 @@ func send_zap(damus_state: DamusState, event: NostrEvent, lnurl: String, is_cust let nwc_req = nwc_pay(url: nwc_state.url, pool: damus_state.pool, post: damus_state.postbox, invoice: inv, on_flush: flusher) guard let nwc_req, case .nwc(let pzap_state) = pending_zap_state else { + print("nwc: failed to send nwc request for zapreq \(reqid.reqid)") return } + print("nwc: sending request \(nwc_req.id) zap_req_id \(reqid.reqid)") + if pzap_state.update_state(state: .postbox_pending(nwc_req)) { // we don't need to trigger a ZapsDataModel update here } diff --git a/damus/Models/HomeModel.swift b/damus/Models/HomeModel.swift @@ -132,11 +132,11 @@ class HomeModel: ObservableObject { case .nwc_request: break case .nwc_response: - handle_nwc_response(ev) + handle_nwc_response(ev, relay: relay_id) } } - func handle_nwc_response(_ ev: NostrEvent) { + func handle_nwc_response(_ ev: NostrEvent, relay: String) { Task { @MainActor in // TODO: Adapt KeychainStorage to StringCodable and instead of parsing to WalletConnectURL every time guard let nwc_str = damus_state.settings.nostr_wallet_connect, @@ -148,25 +148,24 @@ class HomeModel: ObservableObject { // since command results are not returned for ephemeral events, // remove the request from the postbox which is likely failing over and over if damus_state.postbox.remove_relayer(relay_id: nwc.relay.id, event_id: resp.req_id) { - print("nwc: got response, removed \(resp.req_id) from the postbox") + print("nwc: got response, removed \(resp.req_id) from the postbox [\(relay)]") } else { - print("nwc: \(resp.req_id) not found in the postbox, nothing to remove") - } - - if resp.response.error == nil { + print("nwc: \(resp.req_id) not found in the postbox, nothing to remove [\(relay)]") } guard let err = resp.response.error else { + print("nwc success: \(resp.response.result.debugDescription) [\(relay)]") nwc_success(state: self.damus_state, resp: resp) return } - print("nwc error: \(err)") + print("nwc error: \(resp.response)") nwc_error(zapcache: self.damus_state.zaps, evcache: self.damus_state.events, resp: resp) } } func handle_zap_event_with_zapper(profiles: Profiles, ev: NostrEvent, our_keypair: Keypair, zapper: String) { + guard let zap = Zap.from_zap_event(zap_ev: ev, zapper: zapper, our_privkey: our_keypair.privkey) else { return } diff --git a/damus/Util/PostBox.swift b/damus/Util/PostBox.swift @@ -150,6 +150,11 @@ class PostBox { relayer.attempts += 1 relayer.last_attempt = Int64(Date().timeIntervalSince1970) relayer.retry_after *= 1.5 + if let relay = pool.get_relay(relayer.relay) { + print("flushing event \(event.event.id) to \(relayer.relay)") + } else { + print("could not find relay when flushing: \(relayer.relay)") + } pool.send(.event(event.event), to: [relayer.relay], skip_ephemeral: event.skip_ephemeral) } } diff --git a/damus/Util/WalletConnect.swift b/damus/Util/WalletConnect.swift @@ -180,7 +180,7 @@ func subscribe_to_nwc(url: WalletConnectURL, pool: RelayPool) { filter.limit = 0 let sub = NostrSubscribe(filters: [filter], sub_id: "nwc") - pool.send(.subscribe(sub), to: [url.relay.id]) + pool.send(.subscribe(sub), to: [url.relay.id], skip_ephemeral: false) } @discardableResult @@ -233,6 +233,7 @@ func send_donation_zap(pool: RelayPool, postbox: PostBox, nwc: WalletConnectURL, return } + print("damus-donation donating...") nwc_pay(url: nwc, pool: pool, post: postbox, invoice: invoice, delay: nil) }