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

Function json_unreserveinputs

wallet/reservation.c:138–202  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 15

wally_tx_input_get_txidFunction · 0.85
wallet_transaction_getFunction · 0.85
tal_wally_startFunction · 0.85
tal_wally_endFunction · 0.85
wallet_utxo_getFunction · 0.85
wallet_unreserve_utxoFunction · 0.85
json_add_reservestatusFunction · 0.85
paramFunction · 0.50
command_param_failedFunction · 0.50
type_to_stringClass · 0.50
json_stream_successFunction · 0.50

Tested by

no test coverage detected