| 164 | } |
| 165 | |
| 166 | static struct command_result * |
| 167 | json_openchannel2_sign_call(struct command *cmd, |
| 168 | const char *buf, |
| 169 | const jsmntok_t *params) |
| 170 | { |
| 171 | struct channel_id cid; |
| 172 | struct wally_psbt *psbt; |
| 173 | const char *err; |
| 174 | struct out_req *req; |
| 175 | struct pending_open *open; |
| 176 | size_t count; |
| 177 | |
| 178 | err = json_scan(tmpctx, buf, params, |
| 179 | "{openchannel2_sign:" |
| 180 | "{channel_id:%,psbt:%}}", |
| 181 | JSON_SCAN(json_to_channel_id, &cid), |
| 182 | JSON_SCAN_TAL(cmd, json_to_psbt, &psbt)); |
| 183 | |
| 184 | if (err) |
| 185 | plugin_err(cmd->plugin, |
| 186 | "`openchannel2_sign` payload did not scan %s: %.*s", |
| 187 | err, json_tok_full_len(params), |
| 188 | json_tok_full(buf, params)); |
| 189 | |
| 190 | /* If we're not tracking this open, just pass through */ |
| 191 | open = find_channel_pending_open(&cid); |
| 192 | if (!open) { |
| 193 | plugin_log(cmd->plugin, LOG_DBG, |
| 194 | "nothing to sign for channel %s", |
| 195 | type_to_string(tmpctx, struct channel_id, &cid)); |
| 196 | return command_hook_cont_psbt(cmd, psbt); |
| 197 | } |
| 198 | |
| 199 | if (!psbt_has_our_input(psbt)) { |
| 200 | plugin_log(cmd->plugin, LOG_DBG, |
| 201 | "no inputs to sign for channel %s", |
| 202 | type_to_string(tmpctx, struct channel_id, &cid)); |
| 203 | return command_hook_cont_psbt(cmd, psbt); |
| 204 | } |
| 205 | |
| 206 | plugin_log(cmd->plugin, LOG_DBG, |
| 207 | "openchannel_sign PSBT is %s", |
| 208 | type_to_string(tmpctx, struct wally_psbt, psbt)); |
| 209 | |
| 210 | req = jsonrpc_request_start(cmd->plugin, cmd, |
| 211 | "signpsbt", |
| 212 | &signpsbt_done, |
| 213 | &forward_error, |
| 214 | open); |
| 215 | json_add_psbt(req->js, "psbt", psbt); |
| 216 | /* Use input markers to identify which inputs |
| 217 | * are ours, only sign those */ |
| 218 | json_array_start(req->js, "signonly"); |
| 219 | count = 0; |
| 220 | for (size_t i = 0; i < psbt->num_inputs; i++) { |
| 221 | if (psbt_input_is_ours(&psbt->inputs[i])) { |
| 222 | json_add_num(req->js, NULL, i); |
| 223 | count++; |
nothing calls this directly
no test coverage detected