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

Function param_txout

wallet/reservation.c:933–991  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

931AUTODATA(json_command, &addpsbtinput_command);
932
933static struct command_result *param_txout(struct command *cmd,
934 const char *name,
935 const char *buffer,
936 const jsmntok_t *tok,
937 struct utxo ***utxos)
938{
939 size_t i;
940 const jsmntok_t *curr;
941
942 *utxos = tal_arr(cmd, struct utxo *, tok->size);
943
944 json_for_each_arr(i, curr, tok) {
945 struct utxo *utxo;
946 jsmntok_t txid_tok, outnum_tok;
947 struct bitcoin_outpoint outpoint;
948
949 if (!split_tok(buffer, curr, ':', &txid_tok, &outnum_tok))
950 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
951 "Could not decode the outpoint from \"%s\""
952 " The utxos should be specified as"
953 " 'txid:output_index'.",
954 json_strdup(tmpctx, buffer, curr));
955
956 if (!json_to_txid(buffer, &txid_tok, &outpoint.txid)) {
957 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
958 "Could not get a txid out of \"%s\"",
959 json_strdup(tmpctx, buffer, &txid_tok));
960 }
961 if (!json_to_number(buffer, &outnum_tok, &outpoint.n)) {
962 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
963 "Could not get a vout out of \"%s\"",
964 json_strdup(tmpctx, buffer, &outnum_tok));
965 }
966
967 utxo = wallet_utxo_get(*utxos, cmd->ld->wallet, &outpoint);
968 if (!utxo) {
969 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
970 "Unknown UTXO %s",
971 fmt_bitcoin_outpoint(tmpctx,
972 &outpoint));
973 }
974 if (utxo->status == OUTPUT_STATE_SPENT) {
975 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
976 "Already spent UTXO %s",
977 fmt_bitcoin_outpoint(tmpctx,
978 &outpoint));
979 }
980
981 (*utxos)[i] = utxo;
982 }
983
984 if (i == 0)
985 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
986 "Please specify an array of 'txid:output_index',"
987 " not \"%.*s\"",
988 tok->end - tok->start,
989 buffer + tok->start);
990 return NULL;

Callers

nothing calls this directly

Calls 7

split_tokFunction · 0.85
fmt_bitcoin_outpointFunction · 0.85
wallet_utxo_getFunction · 0.70
command_failFunction · 0.50
json_strdupFunction · 0.50
json_to_txidFunction · 0.50
json_to_numberFunction · 0.50

Tested by

no test coverage detected