MCPcopy Create free account
hub / github.com/ElementsProject/lightning / handle_buy

Method handle_buy

plugins/lsps-plugin/src/core/lsps2/handler.rs:350–391  ·  view source on GitHub ↗
(
        &self,
        peer_id: PublicKey,
        request: Lsps2BuyRequest,
    )

Source from the content-addressed store, hash-verified

348 }
349
350 async fn handle_buy(
351 &self,
352 peer_id: PublicKey,
353 request: Lsps2BuyRequest,
354 ) -> core::result::Result<Lsps2BuyResponse, RpcError> {
355 let fee_params = request.opening_fee_params;
356
357 // FIXME: In the future we should replace the \`None\` with a meaningful
358 // value that reflects the inbound capacity for this node from the
359 // public network for a better pre-condition check on the payment_size.
360 fee_params.validate(&self.promise_secret, request.payment_size_msat, None)?;
361
362 // Generate a tmp scid to identify jit channel request in htlc.
363 let blockheight = self
364 .api
365 .get_blockheight()
366 .await
367 .map_err(|_| RpcError::internal_error("internal error"))?;
368
369 // FIXME: Future task: Check that we don't conflict with any jit scid we
370 // already handed out -> Check datastore entries.
371 let jit_scid = ShortChannelId::from(generate_jit_scid(blockheight));
372
373 let ok = self
374 .api
375 .store_buy_request(&jit_scid, &peer_id, &fee_params, &request.payment_size_msat)
376 .await
377 .map_err(|_| RpcError::internal_error("internal error"))?;
378
379 if !ok {
380 return Err(RpcError::internal_error("internal error"))?;
381 }
382
383 Ok(Lsps2BuyResponse {
384 jit_channel_scid: jit_scid,
385 // We can make this configurable if necessary.
386 lsp_cltv_expiry_delta: DEFAULT_CLTV_EXPIRY_DELTA,
387 // We can implement the other mode later on as we might have to do
388 // some additional work on core-lightning to enable this.
389 client_trusts_lsp: false,
390 })
391 }
392}
393
394fn generate_jit_scid(best_blockheigt: u32) -> u64 {

Calls 4

generate_jit_scidFunction · 0.85
validateMethod · 0.80
get_blockheightMethod · 0.45
store_buy_requestMethod · 0.45

Tested by

no test coverage detected