# Fiber HTLC Cross-Chain Building ## Metadata **Status**:: #x **Zettel**:: #zettel/fleeting **Created**:: [[2024-03-29]] **Parent**:: [[Fiber HTLC Cross-Chain Pitch]] ## Synopsis - 提供 RPC 进行支付 - 参考 [SendPaymentV2 | Lightning Labs API Reference](https://lightning.engineering/api-docs/api/lnd/router/send-payment-v2) - 提供 RPC 提交 HTLC 的 preimage - 参考 [SettleInvoice | Lightning Labs API Reference](https://lightning.engineering/api-docs/api/lnd/invoices/settle-invoice) - 提供按 payment hash 订阅 sending HTLC 状态的接口,并能获得最终得到的 preimage。 - 参考 [TrackPayments | Lightning Labs API Reference](https://lightning.engineering/api-docs/api/lnd/router/track-payments) - 通过 add_index / settle_index 可以保证重启后不会漏消息 - 提供按 payment hash 订阅 receiving HTLC 状态的接口 - 参考 [SubscribeInvoices | Lightning Labs API Reference](https://lightning.engineering/api-docs/api/lnd/lightning/subscribe-invoices) - 先订阅,然后用 [LookupInvoice | Lightning Labs API Reference](https://lightning.engineering/api-docs/api/lnd/lightning/lookup-invoice) 查询一遍可以保证重启后不会漏消息 - [Add an option to subscribe to every Hold Invoice at once · Issue #3120 · lightningnetwork/lnd (github.com)](https://github.com/lightningnetwork/lnd/issues/3120) - 使用 SubscribeSingleInvoice 代替 - 其它 RPC - SubscribeHtlcEvents: ❌ no events for accepted Htlcs - HtlcInterceptor: ❌ only for HTLC forwarding ## Tasks - [x] Send BTC via cchub - [x] Add RPC method to submit the BTC invoice req string and generate a BTC payment order. - [x] Pay the BTC invoice when accepting CKB HTLC. Add an RPC method to simulate it. - [x] Subscribe to lnd payment events to get the preimage and settle the CKB HTLC - [x] Receive BTC via cchub - [x] Add RPC method to submit the CKB node info and generate a BTC receipt order. - Use SHA256 to generate preimage and hash - preimage: c05991f9fcecc4fc4e1057893d9436d3ce9a611999fb2fe18a3e67fcaa5b1e0f - hash: 23fba099e5289e8ffbfd3a4e74949382761a1d2043e9cb31ff413d35bf8fa00b - invoice: lnbcrt5u1pnp3a9wpp56dff2rveklruf2xffywg4yqy5gcner4sw7av9m03vqs7tvw59zrsdqqcqzzsxqyz5vqsp5kc6c7vh5k3rzq5ku746tdm3fxq8jwfsw58thp7pnwc4t0m84pjxq9qyyssqwv725dts3aqm0pywncff33kpejgcqmjg8e097jk74caz45k2ysypj60rrum0mt0gey74kl63y9zpms8ffxaushpyzh7ys25m5appafsph36x88 - [x] Subscribe to lnd invoice events. - [x] Lnd does not notify accepted event - [x] Pay the CKB node when accepting BTC HTLC for hold invoices. Add an RPC method to simulate it. - Use lndcli to settle the hodl invoice ## Libraries [contribsys/faktory: Language-agnostic persistent background job server (github.com)](https://github.com/contribsys/faktory)