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

Function json_reserveinputs

wallet/reservation.c:80–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78}
79
80static struct command_result *json_reserveinputs(struct command *cmd,
81 const char *buffer,
82 const jsmntok_t *obj UNNEEDED,
83 const jsmntok_t *params)
84{
85 struct json_stream *response;
86 struct wally_psbt *psbt;
87 struct utxo **utxos = tal_arr(cmd, struct utxo *, 0);
88 bool *exclusive;
89 u32 *reserve, current_height;
90
91 if (!param(cmd, buffer, params,
92 p_req("psbt", param_psbt, &psbt),
93 p_opt_def("exclusive", param_bool, &exclusive, true),
94 p_opt_def("reserve", param_number, &reserve,
95 RESERVATION_DEFAULT),
96 NULL))
97 return command_param_failed();
98
99 current_height = get_block_height(cmd->ld->topology);
100 for (size_t i = 0; i < psbt->tx->num_inputs; i++) {
101 struct bitcoin_outpoint outpoint;
102 struct utxo *utxo;
103
104 wally_tx_input_get_outpoint(&psbt->tx->inputs[i], &outpoint);
105 utxo = wallet_utxo_get(cmd, cmd->ld->wallet, &outpoint);
106 if (!utxo)
107 continue;
108 if (*exclusive && utxo_is_reserved(utxo, current_height)) {
109 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
110 "%s already reserved",
111 type_to_string(tmpctx,
112 struct bitcoin_outpoint,
113 &utxo->outpoint));
114 }
115 if (utxo->status == OUTPUT_STATE_SPENT)
116 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
117 "%s already spent",
118 type_to_string(tmpctx,
119 struct bitcoin_outpoint,
120 &utxo->outpoint));
121 tal_arr_expand(&utxos, utxo);
122 }
123
124 response = json_stream_success(cmd);
125 reserve_and_report(response, cmd->ld->wallet, current_height, *reserve, utxos);
126 return command_success(cmd, response);
127}
128
129static const struct json_command reserveinputs_command = {
130 "reserveinputs",

Callers

nothing calls this directly

Calls 11

wallet_utxo_getFunction · 0.85
utxo_is_reservedFunction · 0.85
reserve_and_reportFunction · 0.85
paramFunction · 0.50
command_param_failedFunction · 0.50
get_block_heightFunction · 0.50
command_failFunction · 0.50
type_to_stringClass · 0.50
json_stream_successFunction · 0.50
command_successFunction · 0.50

Tested by

no test coverage detected