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

Function main

plugins/lsps-plugin/src/service.rs:65–135  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

63
64#[tokio::main]
65async fn main() -> Result<(), anyhow::Error> {
66 if let Some(plugin) = cln_plugin::Builder::new(tokio::io::stdin(), tokio::io::stdout())
67 .option(OPTION_ENABLED)
68 .option(OPTION_PROMISE_SECRET)
69 // FIXME: Temporarily disabled lsp feature to please test cases, this is
70 // ok as the feature is optional per spec.
71 // We need to ensure that `connectd` only starts after all plugins have
72 // been initialized.
73 // .featurebits(
74 // cln_plugin::FeatureBitsKind::Node,
75 // util::feature_bit_to_hex(LSP_FEATURE_BIT),
76 // )
77 // .featurebits(
78 // cln_plugin::FeatureBitsKind::Init,
79 // util::feature_bit_to_hex(LSP_FEATURE_BIT),
80 // )
81 .hook_from_builder(
82 HookBuilder::new("custommsg", service_custommsg_hook)
83 .filters(vec![HookFilter::Int(i64::from(LSPS0_MESSAGE_TYPE))]),
84 )
85 .hook("htlc_accepted", on_htlc_accepted)
86 .configure()
87 .await?
88 {
89 let rpc_path =
90 Path::new(&plugin.configuration().lightning_dir).join(&plugin.configuration().rpc_file);
91
92 if plugin.option(&OPTION_ENABLED)? {
93 log::debug!("lsps2-service enabled");
94 if let Some(secret_hex) = plugin.option(&OPTION_PROMISE_SECRET)? {
95 let secret_hex = secret_hex.trim().to_lowercase();
96
97 let decoded_bytes = match hex::decode(&secret_hex) {
98 Ok(bytes) => bytes,
99 Err(_) => {
100 return plugin
101 .disable(&format!(
102 "Invalid hex string for promise secret: {}",
103 secret_hex
104 ))
105 .await;
106 }
107 };
108
109 let secret: [u8; 32] = match decoded_bytes.try_into() {
110 Ok(array) => array,
111 Err(vec) => {
112 return plugin
113 .disable(&format!(
114 "Promise secret must be exactly 32 bytes, got {}",
115 vec.len()
116 ))
117 .await;
118 }
119 };
120
121 let state = State::new(rpc_path, &secret);
122 let plugin = plugin.start(state).await?;

Callers

nothing calls this directly

Calls 10

configureMethod · 0.80
hook_from_builderMethod · 0.80
optionMethod · 0.80
filtersMethod · 0.80
joinMethod · 0.80
configurationMethod · 0.80
disableMethod · 0.80
decodeFunction · 0.50
hookMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected