(
p: &Plugin<State>,
v: serde_json::Value,
)
| 152 | } |
| 153 | |
| 154 | async fn handle_htlc_inner( |
| 155 | p: &Plugin<State>, |
| 156 | v: serde_json::Value, |
| 157 | ) -> Result<serde_json::Value, anyhow::Error> { |
| 158 | if !p.state().lsps2_enabled { |
| 159 | return Ok(json_continue()); |
| 160 | } |
| 161 | |
| 162 | let req: HtlcAcceptedRequest = serde_json::from_value(v)?; |
| 163 | |
| 164 | let short_channel_id = match req.onion.short_channel_id { |
| 165 | Some(scid) => scid, |
| 166 | None => { |
| 167 | trace!("We are the destination of the HTLC, continue."); |
| 168 | return Ok(json_continue()); |
| 169 | } |
| 170 | }; |
| 171 | |
| 172 | let rpc_path = Path::new(&p.configuration().lightning_dir).join(&p.configuration().rpc_file); |
| 173 | let api = ClnApiRpc::new(rpc_path); |
| 174 | // Fixme: Use real htlc_minimum_amount. |
| 175 | let handler = HtlcAcceptedHookHandler::new(api, 1000); |
| 176 | |
| 177 | let onion = Onion { |
| 178 | short_channel_id, |
| 179 | payload: req.onion.payload, |
| 180 | }; |
| 181 | |
| 182 | let htlc = Htlc { |
| 183 | amount_msat: Msat::from_msat(req.htlc.amount_msat.msat()), |
| 184 | extra_tlvs: req.htlc.extra_tlvs.unwrap_or_default(), |
| 185 | }; |
| 186 | |
| 187 | debug!("Handle potential jit-session HTLC."); |
| 188 | let response = match handler.handle(&htlc, &onion).await { |
| 189 | Ok(dec) => { |
| 190 | log_decision(&dec); |
| 191 | decision_to_response(dec)? |
| 192 | } |
| 193 | Err(e) => { |
| 194 | // Fixme: Should we log **BROKEN** here? |
| 195 | debug!("Htlc handler failed (continuing): {:#}", e); |
| 196 | return Ok(json_continue()); |
| 197 | } |
| 198 | }; |
| 199 | |
| 200 | Ok(serde_json::to_value(&response)?) |
| 201 | } |
| 202 | |
| 203 | fn decision_to_response(decision: HtlcDecision) -> Result<serde_json::Value, anyhow::Error> { |
| 204 | Ok(match decision { |
no test coverage detected