WIP Check for zaps, send zap receipt on incoming zap tx
This commit is contained in:
parent
b36baf26eb
commit
e27c64b5f1
@ -7,6 +7,12 @@ class WebhooksController < ApplicationController
|
|||||||
def lndhub
|
def lndhub
|
||||||
@user = User.find_by!(ln_account: @payload[:user_login])
|
@user = User.find_by!(ln_account: @payload[:user_login])
|
||||||
|
|
||||||
|
if @zap_request = fetch_nostr_event_from_description
|
||||||
|
NostrManager::PublishZapReceipt.call(
|
||||||
|
user: @user, zap_request: @zap_request
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
send_notifications
|
send_notifications
|
||||||
|
|
||||||
head :ok
|
head :ok
|
||||||
@ -21,12 +27,17 @@ class WebhooksController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def process_payload
|
def process_payload
|
||||||
begin
|
|
||||||
@payload = JSON.parse(request.body.read, symbolize_names: true)
|
@payload = JSON.parse(request.body.read, symbolize_names: true)
|
||||||
head :no_content and return unless @payload[:type] == "incoming"
|
head :no_content and return unless @payload[:type] == "incoming"
|
||||||
rescue
|
rescue
|
||||||
head :unprocessable_entity and return
|
head :unprocessable_entity and return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def fetch_nostr_event_from_description
|
||||||
|
memo_json = JSON.parse(@payload[:memo])
|
||||||
|
Nostr::Event.new(**memo_json.to_h.symbolize_keys)
|
||||||
|
rescue
|
||||||
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def send_notifications
|
def send_notifications
|
||||||
|
10
app/services/nostr_manager/publish_zap_receipt.rb
Normal file
10
app/services/nostr_manager/publish_zap_receipt.rb
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
module NostrManager
|
||||||
|
class PublishZapReceipt < NostrManagerService
|
||||||
|
def initialize(user:, zap_request:)
|
||||||
|
@user, @zap_request = user, zap_request
|
||||||
|
end
|
||||||
|
|
||||||
|
def call
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
19
spec/fixtures/lndhub/incoming-zap.json
vendored
Normal file
19
spec/fixtures/lndhub/incoming-zap.json
vendored
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"id": 58,
|
||||||
|
"type": "incoming",
|
||||||
|
"user_login": "123456abcdef",
|
||||||
|
"amount": 21000,
|
||||||
|
"fee": 0,
|
||||||
|
"memo": "{\"id\":\"3cf02d7f0ccd9711c25098fc50b3a7ab880326e4e51cc8c7a7b59f147cff4fff\",\"sig\":\"e9e9bb2bac4267a107ab5c3368f504b4f11b8e3b5ae875a1d63c74d6934138d2521dc35815b6f534fc5d803cbf633736d871886368bb8f92c4ad3837a68a06f2\",\"pubkey\":\"730b43e6f62c2ab22710b046e481802c8ac1108ed2cb9c21dff808d57ba24b6c\",\"created_at\":1712487443,\"kind\":9734,\"tags\":[[\"relays\",\"wss://nostr.kosmos.org\",\"wss://relay.example.com\"],[\"p\",\"07e188a1ff87ce171d517b8ed2bb7a31b1d3453a0db3b15379ec07b724d232f3\"]],\"content\":\"\"}",
|
||||||
|
"description_hash": "b1a9910724bc9c1b03b4eba2e2d78ac69a8ac7b244e6ff6d4e7391bf6893f26a",
|
||||||
|
"payment_request": "lnbc1u1p3mull3pp5qw4x46ew6kjknudypyjsg8maw935tr5kkuz7t6h7pugp3pt4msyqhp5zp40yd97a028sgr9x4yxq5d57gft6vwja58e8cl0eea4uasr6apscqzpgxqyz5vqsp53m2n8h6yeflgukv5fhwm802kur6un9w8nvycl7auk67w5g2u008q9qyyssqml8rfmxyvp32qd5939qx7uu0w6ppjuujlpwsrz28m9u0dzp799hz5j72w0xm8pg97hd4hdvwh9zxaw2hewnnmzewvc550f9y3qsfaegphmk0mu",
|
||||||
|
"destination_pubkey_hex": "024cd3be18617f39cf645851e3ba63f51fc13f0bb09e3bb25e6fd4de556486d946",
|
||||||
|
"r_hash": "03aa6aeb2ed5a569f1a40925041f7d7163458e96b705e5eafe0f10188575dc08",
|
||||||
|
"preimage": "3539663535656537343331663432653165396430623966633664656664646563",
|
||||||
|
"keysend": false,
|
||||||
|
"state": "settled",
|
||||||
|
"created_at": "2023-01-11T09:22:57.546364Z",
|
||||||
|
"expires_at": "2023-01-12T09:22:57.547209Z",
|
||||||
|
"updated_at": "2023-01-11T09:22:58.046236131Z",
|
||||||
|
"settled_at": "2023-01-11T09:22:58.046232174Z"
|
||||||
|
}
|
@ -53,9 +53,7 @@ RSpec.describe "Webhooks", type: :request do
|
|||||||
let(:user) { create :user, ln_account: "123456abcdef" }
|
let(:user) { create :user, ln_account: "123456abcdef" }
|
||||||
let(:payload) { JSON.parse(File.read(File.expand_path("../fixtures/lndhub/incoming.json", File.dirname(__FILE__)))) }
|
let(:payload) { JSON.parse(File.read(File.expand_path("../fixtures/lndhub/incoming.json", File.dirname(__FILE__)))) }
|
||||||
|
|
||||||
before do
|
before { user.save! } #FIXME this should not be necessary
|
||||||
user.save! #FIXME this should not be necessary
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns a 200 status" do
|
it "returns a 200 status" do
|
||||||
post "/webhooks/lndhub", params: payload.to_json
|
post "/webhooks/lndhub", params: payload.to_json
|
||||||
@ -63,9 +61,15 @@ RSpec.describe "Webhooks", type: :request do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "does not send notifications by default" do
|
it "does not send notifications by default" do
|
||||||
|
post "/webhooks/lndhub", params: payload.to_json
|
||||||
expect(enqueued_jobs.size).to eq(0)
|
expect(enqueued_jobs.size).to eq(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "does not send a zap receipt" do
|
||||||
|
expect(NostrManager::PublishZapReceipt).not_to receive(:call)
|
||||||
|
post "/webhooks/lndhub", params: payload.to_json
|
||||||
|
end
|
||||||
|
|
||||||
context "notification preference set to 'xmpp'" do
|
context "notification preference set to 'xmpp'" do
|
||||||
before do
|
before do
|
||||||
Setting.xmpp_notifications_from_address = "botka@kosmos.org"
|
Setting.xmpp_notifications_from_address = "botka@kosmos.org"
|
||||||
@ -103,5 +107,22 @@ RSpec.describe "Webhooks", type: :request do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "Valid payload for zap transaction" do
|
||||||
|
let(:user) { create :user, ln_account: "123456abcdef" }
|
||||||
|
let(:payload) { JSON.parse(File.read(File.expand_path("../fixtures/lndhub/incoming-zap.json", File.dirname(__FILE__)))) }
|
||||||
|
|
||||||
|
before { user.save! } #FIXME this should not be necessary
|
||||||
|
|
||||||
|
it "returns a 200 status" do
|
||||||
|
post "/webhooks/lndhub", params: payload.to_json
|
||||||
|
expect(response).to have_http_status(:ok)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "sends a zap receipt" do
|
||||||
|
expect(NostrManager::PublishZapReceipt).to receive(:call)
|
||||||
|
post "/webhooks/lndhub", params: payload.to_json
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user