-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode-control.ts
More file actions
49 lines (44 loc) · 1.51 KB
/
Copy pathnode-control.ts
File metadata and controls
49 lines (44 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { eventIterator, oc } from "@orpc/contract";
import { z } from "zod";
import {
InvoiceBolt11ResultSchema,
InvoiceBolt12OfferResultSchema,
InvoiceCreateBolt11InputSchema,
InvoiceCreateBolt12OfferInputSchema,
NodeEventSchema,
PayoutInputSchema,
PayoutResultSchema,
} from "../schemas/node-control";
/**
* Node control contract used over a WebSocket between mdk.com (RPC client) and
* a merchant's running lightning-js node (RPC handler).
*
* The connection is initiated by the merchant function dialing OUT to mdk.com
* (Vercel does not support inbound WebSockets). mdk.com grants a single-active
* lease per appId via a DB row before the node is constructed.
*/
export const payoutContract = oc
.input(PayoutInputSchema)
.output(PayoutResultSchema);
export const invoiceCreateBolt11Contract = oc
.input(InvoiceCreateBolt11InputSchema)
.output(InvoiceBolt11ResultSchema);
export const invoiceCreateBolt12OfferContract = oc
.input(InvoiceCreateBolt12OfferInputSchema)
.output(InvoiceBolt12OfferResultSchema);
/**
* Server-pushed event stream. mdk.com calls this once per session and consumes
* the AsyncIterable for the lifetime of the connection. Single subscriber per
* session, buffered from session start, FIFO.
*/
export const nodeEventsContract = oc
.input(z.void())
.output(eventIterator(NodeEventSchema));
export const nodeControl = {
payout: payoutContract,
invoice: {
createBolt11: invoiceCreateBolt11Contract,
createBolt12Offer: invoiceCreateBolt12OfferContract,
},
events: nodeEventsContract,
};