Skip to content

Commit fc537b4

Browse files
committed
add support for submarine swaps
1 parent 17ea616 commit fc537b4

14 files changed

Lines changed: 4456 additions & 1770 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: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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:
@@ -856,6 +913,25 @@ paths:
856913
application/json:
857914
schema:
858915
$ref: '#/components/schemas/RgbInvoiceResponse'
916+
/rgbinvoicehtlc:
917+
post:
918+
tags:
919+
- RGB
920+
summary: Get an RGB invoice bound to HTLC
921+
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.
922+
requestBody:
923+
required: true
924+
content:
925+
application/json:
926+
schema:
927+
$ref: '#/components/schemas/RgbInvoiceHtlcRequest'
928+
responses:
929+
'200':
930+
description: Successful operation
931+
content:
932+
application/json:
933+
schema:
934+
$ref: '#/components/schemas/RgbInvoiceHtlcResponse'
859935
/sendbtc:
860936
post:
861937
tags:
@@ -2158,6 +2234,42 @@ components:
21582234
witness:
21592235
type: boolean
21602236
example: false
2237+
RgbInvoiceHtlcRequest:
2238+
type: object
2239+
required:
2240+
- min_confirmations
2241+
- payment_hash
2242+
- user_pubkey
2243+
- csv
2244+
properties:
2245+
asset_id:
2246+
type: string
2247+
description: Optional RGB asset ID (contract ID)
2248+
example: rgb:CJkb4YZw-jRiz2sk-~PARPio-wtVYI1c-XAEYCqO-wTfvRZ8
2249+
assignment:
2250+
$ref: '#/components/schemas/Assignment'
2251+
duration_seconds:
2252+
type: integer
2253+
description: Optional invoice expiration in seconds
2254+
example: 86400
2255+
min_confirmations:
2256+
type: integer
2257+
description: Minimum confirmations required for HTLC funding UTXOs when scanning/claiming
2258+
minimum: 0
2259+
maximum: 255
2260+
example: 1
2261+
payment_hash:
2262+
type: string
2263+
description: 32-byte hex payment hash (H)
2264+
example: "9f1c3a2db36b63c6a6a71e70a37fd7f95453a32f2c9c6938b8a3e2c9e0ed6f65"
2265+
user_pubkey:
2266+
type: string
2267+
description: Compressed pubkey hex (refund key)
2268+
example: "02c1b3a2e4b0f3c2f2c0b1762a7b0b6a9c4ed9b6f7b5f2d0a1e2b3c4d5e6f7a8b9"
2269+
csv:
2270+
type: integer
2271+
description: Relative CSV timelock in blocks; added to current chain height to derive the absolute CLTV refund height
2272+
example: 144
21612273
RgbInvoiceResponse:
21622274
type: object
21632275
properties:
@@ -2173,6 +2285,147 @@ components:
21732285
batch_transfer_idx:
21742286
type: integer
21752287
example: 1
2288+
RgbInvoiceHtlcResponse:
2289+
type: object
2290+
properties:
2291+
recipient_id:
2292+
type: string
2293+
example: bcrt:utxob:cbgHUJ4e-7QyKY4U-Jsj5AZw-oI0gxZh-7fxQY2_-tFFUAZN-4CgpX
2294+
invoice:
2295+
type: string
2296+
example: rgb:~/~/~/bcrt:utxob:cbgHUJ4e-7QyKY4U-Jsj5AZw-oI0gxZh-7fxQY2_-tFFUAZN-4CgpX?expiry=1695811760&endpoints=rpc://127.0.0.1:3000/json-rpc
2297+
expiration_timestamp:
2298+
type: integer
2299+
example: 1695811760
2300+
batch_transfer_idx:
2301+
type: integer
2302+
example: 0
2303+
htlc_p2tr_script_pubkey:
2304+
type: string
2305+
description: HTLC P2TR scriptPubKey in hex format
2306+
example: "51200f0c8db753acbd17343a39c2f3f4e35e4be6da749f9e35137ab220e7b238a667"
2307+
HtlcClaimRequest:
2308+
type: object
2309+
required:
2310+
- payment_hash
2311+
- preimage
2312+
properties:
2313+
payment_hash:
2314+
type: string
2315+
description: 32-byte hex payment hash
2316+
example: "9f1c3a2db36b63c6a6a71e70a37fd7f95453a32f2c9c6938b8a3e2c9e0ed6f65"
2317+
preimage:
2318+
type: string
2319+
description: 32-byte hex preimage
2320+
example: "6f1c3a2db36b63c6a6a71e70a37fd7f95453a32f2c9c6938b8a3e2c9e0ed6f65"
2321+
HtlcScanRequest:
2322+
type: object
2323+
required:
2324+
- payment_hash
2325+
properties:
2326+
payment_hash:
2327+
type: string
2328+
description: 32-byte hex payment hash
2329+
example: "9f1c3a2db36b63c6a6a71e70a37fd7f95453a32f2c9c6938b8a3e2c9e0ed6f65"
2330+
HtlcTrackerRequest:
2331+
type: object
2332+
required:
2333+
- payment_hash
2334+
properties:
2335+
payment_hash:
2336+
type: string
2337+
description: 32-byte hex payment hash
2338+
example: "9f1c3a2db36b63c6a6a71e70a37fd7f95453a32f2c9c6938b8a3e2c9e0ed6f65"
2339+
HtlcFundingDescriptorInfo:
2340+
type: object
2341+
properties:
2342+
txid:
2343+
type: string
2344+
example: 7c2c95b9c2aa0a7d140495b664de7973b76561de833f0dd84def3efa08941664
2345+
vout:
2346+
type: integer
2347+
example: 0
2348+
value_sat:
2349+
type: integer
2350+
example: 100000
2351+
utxo_kind:
2352+
type: string
2353+
enum:
2354+
- Vanilla
2355+
- Colored
2356+
asset_id:
2357+
type: string
2358+
example: rgb:CJkb4YZw-jRiz2sk-~PARPio-wtVYI1c-XAEYCqO-wTfvRZ8
2359+
assignment:
2360+
$ref: '#/components/schemas/Assignment'
2361+
HtlcTrackerEntryInfo:
2362+
type: object
2363+
properties:
2364+
payment_hash:
2365+
type: string
2366+
example: 9f1c3a2db36b63c6a6a71e70a37fd7f95453a32f2c9c6938b8a3e2c9e0ed6f65
2367+
preimage:
2368+
type: string
2369+
example: 6f1c3a2db36b63c6a6a71e70a37fd7f95453a32f2c9c6938b8a3e2c9e0ed6f65
2370+
lp_pubkey_xonly:
2371+
type: string
2372+
example: 9b47a2dfc7d7b4a4a2c20f154fc2b8b56c5e2d47a90d0d2a6a0d37a9d9b690e1
2373+
user_pubkey_xonly:
2374+
type: string
2375+
example: 2f5b4d1d0f6e5a1c0b8f9c1c2a3b4c5d6e7f8091a2b3c4d5e6f708192a3b4c5d
2376+
lp_key_path:
2377+
type: string
2378+
example: m/86h/1h/0h/0/0
2379+
htlc_script_pubkey:
2380+
type: string
2381+
example: 51200f0c8db753acbd17343a39c2f3f4e35e4be6da749f9e35137ab220e7b238a667
2382+
recipient_id:
2383+
type: string
2384+
example: bcrt:utxob:cbgHUJ4e-7QyKY4U-Jsj5AZw-oI0gxZh-7fxQY2_-tFFUAZN-4CgpX
2385+
rgb_invoice:
2386+
type: string
2387+
example: rgb:~/~/~/bcrt:utxob:cbgHUJ4e-7QyKY4U-Jsj5AZw-oI0gxZh-7fxQY2_-tFFUAZN-4CgpX?expiry=1695811760&endpoints=rpc://127.0.0.1:3000/json-rpc
2388+
claim_tapscript_hex:
2389+
type: string
2390+
example: 20a1077fbf5d2c0a1d7b2ec7c93e3f7a1d61f0a9f7bfa8ef4a78cfa9f01f0d4cac
2391+
refund_tapscript_hex:
2392+
type: string
2393+
example: 20b1077fbf5d2c0a1d7b2ec7c93e3f7a1d61f0a9f7bfa8ef4a78cfa9f01f0d4cad
2394+
tapleaf_version:
2395+
type: integer
2396+
example: 192
2397+
control_block_hex:
2398+
type: string
2399+
example: c0ffee00
2400+
t_lock:
2401+
type: integer
2402+
example: 144
2403+
min_confirmations:
2404+
type: integer
2405+
example: 1
2406+
funding:
2407+
type: array
2408+
items:
2409+
$ref: '#/components/schemas/HtlcFundingDescriptorInfo'
2410+
status:
2411+
type: string
2412+
example: FundingDetected
2413+
asset_id:
2414+
type: string
2415+
example: rgb:CJkb4YZw-jRiz2sk-~PARPio-wtVYI1c-XAEYCqO-wTfvRZ8
2416+
assignment:
2417+
$ref: '#/components/schemas/Assignment'
2418+
btc_destination_script_hex:
2419+
type: string
2420+
example: 51200f0c8db753acbd17343a39c2f3f4e35e4be6da749f9e35137ab220e7b238a667
2421+
rgb_destination_script_hex:
2422+
type: string
2423+
example: 51200f0c8db753acbd17343a39c2f3f4e35e4be6da749f9e35137ab220e7b238a667
2424+
HtlcTrackerResponse:
2425+
type: object
2426+
properties:
2427+
entry:
2428+
$ref: '#/components/schemas/HtlcTrackerEntryInfo'
21762429
SendBtcRequest:
21772430
type: object
21782431
properties:

0 commit comments

Comments
 (0)