Skip to content

Commit 8c373d8

Browse files
committed
add support for submarine swaps
1 parent 717ca2f commit 8c373d8

14 files changed

Lines changed: 4457 additions & 1777 deletions

Cargo.lock

Lines changed: 1009 additions & 1702 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ rust-version = "1.85.0"
77
[[bin]]
88
name = "rgb-lightning-node"
99

10+
[features]
11+
default = ["electrum", "esplora"]
12+
electrum = ["rgb-lib/electrum"]
13+
esplora = ["rgb-lib/esplora"]
14+
1015
[dependencies]
1116
amplify = { version = "=4.8.1", default-features = false }
1217
anyhow = "1.0.93"
@@ -26,20 +31,18 @@ futures = "0.3"
2631
hex = { package = "hex-conservative", version = "0.3.0", default-features = false }
2732
lightning = { version = "0.2.0", path = "./rust-lightning/lightning", features = ["dnssec"] }
2833
lightning-background-processor = { version = "0.2.0", path = "./rust-lightning/lightning-background-processor" }
29-
lightning-block-sync = { version = "0.2.0", features = ["rpc-client", "tokio"] }
34+
lightning-block-sync = { version = "0.2.0", path = "./rust-lightning/lightning-block-sync", features = ["rpc-client", "tokio"] }
3035
lightning-dns-resolver = { version = "0.3.0", path = "./rust-lightning/lightning-dns-resolver" }
3136
lightning-invoice = { version = "0.34.0", features = ["std"], path = "./rust-lightning/lightning-invoice" }
3237
lightning-macros = { version = "0.2.0" }
33-
lightning-net-tokio = { version = "0.2.0" }
38+
lightning-net-tokio = { version = "0.2.0", path = "./rust-lightning/lightning-net-tokio" }
3439
lightning-persister = { version = "0.2.0", path = "./rust-lightning/lightning-persister", features = ["tokio"] }
3540
lightning-rapid-gossip-sync = { version = "0.2.0", path = "./rust-lightning/lightning-rapid-gossip-sync" }
3641
magic-crypt = "4.0.1"
3742
rand = "0.8.5"
3843
regex = { version = "1.11", default-features = false }
39-
rgb-lib = { version = "0.3.0-beta.4", features = [
40-
"electrum",
41-
"esplora",
42-
] }
44+
rgb-lib = { version = "0.3.0-beta.4", default-features = false }
45+
rgb-invoicing = "0.11.1-rc.7"
4346
scrypt = "0.11.0"
4447
serde = { version = "^1.0", features = ["derive"] }
4548
serde_json = "1.0"
@@ -69,9 +72,20 @@ tracing-test = "0.2.5"
6972
[patch.crates-io]
7073
lightning = { path = "./rust-lightning/lightning" }
7174
lightning-background-processor = { path = "./rust-lightning/lightning-background-processor"}
75+
rgb-lib = { git = "https://github.com/txalkan/rgb-lib", branch = "pr-submarine-swap" }
76+
rgb-strict-encoding = { git = "https://github.com/rgb-protocol/rgb-strict-encoding", branch = "master" }
77+
rgb-consensus = { git = "https://github.com/rgb-protocol/rgb-consensus", branch = "master" }
78+
rgb-ops = { git = "https://github.com/rgb-protocol/rgb-ops", rev = "b9d4482" }
79+
rgb-invoicing = { git = "https://github.com/rgb-protocol/rgb-ops", rev = "b9d4482" }
7280

7381
[lints.rust.unexpected_cfgs]
7482
level = "allow"
83+
check-cfg = [
84+
"cfg(c_bindings)",
85+
"cfg(fuzzing)",
86+
"cfg(ldk_bench)",
87+
"cfg(taproot)",
88+
]
7589

7690
[profile.reldebug]
7791
inherits = "release"

openapi.yaml

Lines changed: 254 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ paths:
125125
content:
126126
application/json:
127127
schema:
128-
$ref: '#/components/schemas/InvoiceCancelRequest'
128+
$ref: '#/components/schemas/CancelHodlInvoiceRequest'
129129
responses:
130130
'200':
131131
description: Successful operation
@@ -422,6 +422,63 @@ paths:
422422
application/json:
423423
schema:
424424
$ref: '#/components/schemas/GetSwapResponse'
425+
/htlcclaim:
426+
post:
427+
tags:
428+
- RGB
429+
summary: Request HTLC claim
430+
description: Validate the HTLC preimage and update the HTLC tracker entry to start claim processing.
431+
requestBody:
432+
required: true
433+
content:
434+
application/json:
435+
schema:
436+
$ref: '#/components/schemas/HtlcClaimRequest'
437+
responses:
438+
'200':
439+
description: Successful operation
440+
content:
441+
application/json:
442+
schema:
443+
$ref: '#/components/schemas/EmptyResponse'
444+
/htlcscan:
445+
post:
446+
tags:
447+
- RGB
448+
summary: Scan HTLC funding
449+
description: Scan the chain for HTLC funding UTXOs and update the tracker entry.
450+
requestBody:
451+
required: true
452+
content:
453+
application/json:
454+
schema:
455+
$ref: '#/components/schemas/HtlcScanRequest'
456+
responses:
457+
'200':
458+
description: Successful operation
459+
content:
460+
application/json:
461+
schema:
462+
$ref: '#/components/schemas/EmptyResponse'
463+
/htlctracker:
464+
post:
465+
tags:
466+
- RGB
467+
summary: Get HTLC tracker entry
468+
description: Get an HTLC tracker entry by payment hash.
469+
requestBody:
470+
required: true
471+
content:
472+
application/json:
473+
schema:
474+
$ref: '#/components/schemas/HtlcTrackerRequest'
475+
responses:
476+
'200':
477+
description: Successful operation
478+
content:
479+
application/json:
480+
schema:
481+
$ref: '#/components/schemas/HtlcTrackerResponse'
425482
/init:
426483
post:
427484
tags:
@@ -858,6 +915,25 @@ paths:
858915
application/json:
859916
schema:
860917
$ref: '#/components/schemas/RgbInvoiceResponse'
918+
/rgbinvoicehtlc:
919+
post:
920+
tags:
921+
- RGB
922+
summary: Get an RGB invoice bound to HTLC
923+
description: Get an RGB invoice that binds to an HTLC P2TR scriptPubKey for submarine swaps. This is an escrow operation where RGB assets are temporarily locked in an HTLC address that is not owned by the rgb-lib wallet. The assets will be claimed into the wallet later via `/htlcclaim` when the HTLC is spent.
924+
requestBody:
925+
required: true
926+
content:
927+
application/json:
928+
schema:
929+
$ref: '#/components/schemas/RgbInvoiceHtlcRequest'
930+
responses:
931+
'200':
932+
description: Successful operation
933+
content:
934+
application/json:
935+
schema:
936+
$ref: '#/components/schemas/RgbInvoiceHtlcResponse'
861937
/sendbtc:
862938
post:
863939
tags:
@@ -2153,6 +2229,42 @@ components:
21532229
witness:
21542230
type: boolean
21552231
example: false
2232+
RgbInvoiceHtlcRequest:
2233+
type: object
2234+
required:
2235+
- min_confirmations
2236+
- payment_hash
2237+
- user_pubkey
2238+
- csv
2239+
properties:
2240+
asset_id:
2241+
type: string
2242+
description: Optional RGB asset ID (contract ID)
2243+
example: rgb:CJkb4YZw-jRiz2sk-~PARPio-wtVYI1c-XAEYCqO-wTfvRZ8
2244+
assignment:
2245+
$ref: '#/components/schemas/Assignment'
2246+
duration_seconds:
2247+
type: integer
2248+
description: Optional invoice expiration in seconds
2249+
example: 86400
2250+
min_confirmations:
2251+
type: integer
2252+
description: Minimum confirmations required for HTLC funding UTXOs when scanning/claiming
2253+
minimum: 0
2254+
maximum: 255
2255+
example: 1
2256+
payment_hash:
2257+
type: string
2258+
description: 32-byte hex payment hash (H)
2259+
example: "9f1c3a2db36b63c6a6a71e70a37fd7f95453a32f2c9c6938b8a3e2c9e0ed6f65"
2260+
user_pubkey:
2261+
type: string
2262+
description: Compressed pubkey hex (refund key)
2263+
example: "02c1b3a2e4b0f3c2f2c0b1762a7b0b6a9c4ed9b6f7b5f2d0a1e2b3c4d5e6f7a8b9"
2264+
csv:
2265+
type: integer
2266+
description: Relative CSV timelock in blocks; added to current chain height to derive the absolute CLTV refund height
2267+
example: 144
21562268
RgbInvoiceResponse:
21572269
type: object
21582270
properties:
@@ -2168,6 +2280,147 @@ components:
21682280
batch_transfer_idx:
21692281
type: integer
21702282
example: 1
2283+
RgbInvoiceHtlcResponse:
2284+
type: object
2285+
properties:
2286+
recipient_id:
2287+
type: string
2288+
example: bcrt:utxob:cbgHUJ4e-7QyKY4U-Jsj5AZw-oI0gxZh-7fxQY2_-tFFUAZN-4CgpX
2289+
invoice:
2290+
type: string
2291+
example: rgb:~/~/~/bcrt:utxob:cbgHUJ4e-7QyKY4U-Jsj5AZw-oI0gxZh-7fxQY2_-tFFUAZN-4CgpX?expiry=1695811760&endpoints=rpc://127.0.0.1:3000/json-rpc
2292+
expiration_timestamp:
2293+
type: integer
2294+
example: 1695811760
2295+
batch_transfer_idx:
2296+
type: integer
2297+
example: 0
2298+
htlc_p2tr_script_pubkey:
2299+
type: string
2300+
description: HTLC P2TR scriptPubKey in hex format
2301+
example: "51200f0c8db753acbd17343a39c2f3f4e35e4be6da749f9e35137ab220e7b238a667"
2302+
HtlcClaimRequest:
2303+
type: object
2304+
required:
2305+
- payment_hash
2306+
- preimage
2307+
properties:
2308+
payment_hash:
2309+
type: string
2310+
description: 32-byte hex payment hash
2311+
example: "9f1c3a2db36b63c6a6a71e70a37fd7f95453a32f2c9c6938b8a3e2c9e0ed6f65"
2312+
preimage:
2313+
type: string
2314+
description: 32-byte hex preimage
2315+
example: "6f1c3a2db36b63c6a6a71e70a37fd7f95453a32f2c9c6938b8a3e2c9e0ed6f65"
2316+
HtlcScanRequest:
2317+
type: object
2318+
required:
2319+
- payment_hash
2320+
properties:
2321+
payment_hash:
2322+
type: string
2323+
description: 32-byte hex payment hash
2324+
example: "9f1c3a2db36b63c6a6a71e70a37fd7f95453a32f2c9c6938b8a3e2c9e0ed6f65"
2325+
HtlcTrackerRequest:
2326+
type: object
2327+
required:
2328+
- payment_hash
2329+
properties:
2330+
payment_hash:
2331+
type: string
2332+
description: 32-byte hex payment hash
2333+
example: "9f1c3a2db36b63c6a6a71e70a37fd7f95453a32f2c9c6938b8a3e2c9e0ed6f65"
2334+
HtlcFundingDescriptorInfo:
2335+
type: object
2336+
properties:
2337+
txid:
2338+
type: string
2339+
example: 7c2c95b9c2aa0a7d140495b664de7973b76561de833f0dd84def3efa08941664
2340+
vout:
2341+
type: integer
2342+
example: 0
2343+
value_sat:
2344+
type: integer
2345+
example: 100000
2346+
utxo_kind:
2347+
type: string
2348+
enum:
2349+
- Vanilla
2350+
- Colored
2351+
asset_id:
2352+
type: string
2353+
example: rgb:CJkb4YZw-jRiz2sk-~PARPio-wtVYI1c-XAEYCqO-wTfvRZ8
2354+
assignment:
2355+
$ref: '#/components/schemas/Assignment'
2356+
HtlcTrackerEntryInfo:
2357+
type: object
2358+
properties:
2359+
payment_hash:
2360+
type: string
2361+
example: 9f1c3a2db36b63c6a6a71e70a37fd7f95453a32f2c9c6938b8a3e2c9e0ed6f65
2362+
preimage:
2363+
type: string
2364+
example: 6f1c3a2db36b63c6a6a71e70a37fd7f95453a32f2c9c6938b8a3e2c9e0ed6f65
2365+
lp_pubkey_xonly:
2366+
type: string
2367+
example: 9b47a2dfc7d7b4a4a2c20f154fc2b8b56c5e2d47a90d0d2a6a0d37a9d9b690e1
2368+
user_pubkey_xonly:
2369+
type: string
2370+
example: 2f5b4d1d0f6e5a1c0b8f9c1c2a3b4c5d6e7f8091a2b3c4d5e6f708192a3b4c5d
2371+
lp_key_path:
2372+
type: string
2373+
example: m/86h/1h/0h/0/0
2374+
htlc_script_pubkey:
2375+
type: string
2376+
example: 51200f0c8db753acbd17343a39c2f3f4e35e4be6da749f9e35137ab220e7b238a667
2377+
recipient_id:
2378+
type: string
2379+
example: bcrt:utxob:cbgHUJ4e-7QyKY4U-Jsj5AZw-oI0gxZh-7fxQY2_-tFFUAZN-4CgpX
2380+
rgb_invoice:
2381+
type: string
2382+
example: rgb:~/~/~/bcrt:utxob:cbgHUJ4e-7QyKY4U-Jsj5AZw-oI0gxZh-7fxQY2_-tFFUAZN-4CgpX?expiry=1695811760&endpoints=rpc://127.0.0.1:3000/json-rpc
2383+
claim_tapscript_hex:
2384+
type: string
2385+
example: 20a1077fbf5d2c0a1d7b2ec7c93e3f7a1d61f0a9f7bfa8ef4a78cfa9f01f0d4cac
2386+
refund_tapscript_hex:
2387+
type: string
2388+
example: 20b1077fbf5d2c0a1d7b2ec7c93e3f7a1d61f0a9f7bfa8ef4a78cfa9f01f0d4cad
2389+
tapleaf_version:
2390+
type: integer
2391+
example: 192
2392+
control_block_hex:
2393+
type: string
2394+
example: c0ffee00
2395+
t_lock:
2396+
type: integer
2397+
example: 144
2398+
min_confirmations:
2399+
type: integer
2400+
example: 1
2401+
funding:
2402+
type: array
2403+
items:
2404+
$ref: '#/components/schemas/HtlcFundingDescriptorInfo'
2405+
status:
2406+
type: string
2407+
example: FundingDetected
2408+
asset_id:
2409+
type: string
2410+
example: rgb:CJkb4YZw-jRiz2sk-~PARPio-wtVYI1c-XAEYCqO-wTfvRZ8
2411+
assignment:
2412+
$ref: '#/components/schemas/Assignment'
2413+
btc_destination_script_hex:
2414+
type: string
2415+
example: 51200f0c8db753acbd17343a39c2f3f4e35e4be6da749f9e35137ab220e7b238a667
2416+
rgb_destination_script_hex:
2417+
type: string
2418+
example: 51200f0c8db753acbd17343a39c2f3f4e35e4be6da749f9e35137ab220e7b238a667
2419+
HtlcTrackerResponse:
2420+
type: object
2421+
properties:
2422+
entry:
2423+
$ref: '#/components/schemas/HtlcTrackerEntryInfo'
21712424
SendBtcRequest:
21722425
type: object
21732426
properties:

0 commit comments

Comments
 (0)