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

Function json_unreserveinputs

wallet/reservation.c:141–214  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

139AUTODATA(json_command, &reserveinputs_command);
140
141static struct command_result *json_unreserveinputs(struct command *cmd,
142 const char *buffer,
143 const jsmntok_t *obj UNNEEDED,
144 const jsmntok_t *params)
145{
146 struct json_stream *response;
147 struct wally_psbt *psbt;
148 u32 *reserve;
149
150 if (!param_check(cmd, buffer, params,
151 p_req("psbt", param_psbt, &psbt),
152 p_opt_def("reserve", param_number, &reserve,
153 RESERVATION_DEFAULT),
154 NULL))
155 return command_param_failed();
156
157 /* We only deal with V2 internally */
158 if (!psbt_set_version(psbt, 2)) {
159 log_broken(cmd->ld->log,
160 "Unable to set version for PSBT: %s",
161 fmt_wally_psbt(tmpctx, psbt));
162 }
163
164 /* We should also add the utxo info for these inputs!
165 * (absolutely required for using this psbt in a dual-funded
166 * round) */
167 for (size_t i = 0; i < psbt->num_inputs; i++) {
168 struct bitcoin_tx *utxo_tx;
169 struct bitcoin_txid txid;
170
171 wally_psbt_input_get_txid(&psbt->inputs[i], &txid);
172 utxo_tx = wallet_transaction_get(psbt, cmd->ld->wallet,
173 &txid);
174 if (utxo_tx) {
175 tal_wally_start();
176 wally_psbt_input_set_utxo(&psbt->inputs[i],
177 utxo_tx->wtx);
178 tal_wally_end(psbt);
179 } else
180 log_broken(cmd->ld->log,
181 "No transaction found for UTXO %s",
182 fmt_bitcoin_txid(tmpctx, &txid));
183 }
184
185 if (command_check_only(cmd))
186 return command_check_done(cmd);
187
188 response = json_stream_success(cmd);
189 json_array_start(response, "reservations");
190 for (size_t i = 0; i < psbt->num_inputs; i++) {
191 struct bitcoin_outpoint outpoint;
192 struct utxo *utxo;
193 enum output_status oldstatus;
194 u32 old_res;
195
196 wally_psbt_input_get_outpoint(&psbt->inputs[i], &outpoint);
197 utxo = wallet_utxo_get(cmd, cmd->ld->wallet, &outpoint);
198 if (!utxo || utxo->status != OUTPUT_STATE_RESERVED)

Callers

nothing calls this directly

Calls 15

param_checkFunction · 0.85
psbt_set_versionFunction · 0.85
fmt_wally_psbtFunction · 0.85
wallet_transaction_getFunction · 0.85
tal_wally_startFunction · 0.85
tal_wally_endFunction · 0.85
fmt_bitcoin_txidFunction · 0.85
json_array_startFunction · 0.85
json_add_reservestatusFunction · 0.85
json_array_endFunction · 0.85

Tested by

no test coverage detected