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

Function param_outputs

plugins/txprepare.c:56–126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54}
55
56static struct command_result *param_outputs(struct command *cmd,
57 const char *name,
58 const char *buffer,
59 const jsmntok_t *tok,
60 struct txprepare *txp)
61{
62 size_t i;
63 const jsmntok_t *t;
64
65 if (tok->type != JSMN_ARRAY) {
66 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
67 "Expected an array of outputs in the "
68 "format '[{\"txid\":0}, ...]', got \"%s\"",
69 json_strdup(tmpctx, buffer, tok));
70 }
71
72 txp->outputs = tal_arr(txp, struct tx_output, tok->size);
73 txp->output_total = AMOUNT_SAT(0);
74 txp->all_output_idx = -1;
75
76 /* We assume < 253 inputs, and if we're wrong, the fee
77 * difference is trivial. */
78 txp->weight = bitcoin_tx_core_weight(1, tal_count(txp->outputs));
79
80 json_for_each_arr(i, t, tok) {
81 enum address_parse_result res;
82 struct tx_output *out = &txp->outputs[i];
83
84 /* We assume these are accounted for elsewhere */
85 out->is_to_external = false;
86
87 /* output format: {destination: amount} */
88 if (t->type != JSMN_OBJECT)
89 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
90 "The output format must be "
91 "{destination: amount}");
92 res = json_to_address_scriptpubkey(cmd,
93 chainparams,
94 buffer, &t[1],
95 &out->script);
96 if (res == ADDRESS_PARSE_UNRECOGNIZED)
97 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
98 "Could not parse destination address");
99 else if (res == ADDRESS_PARSE_WRONG_NETWORK)
100 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
101 "Destination address is not on network %s",
102 chainparams->network_name);
103
104 if (!json_to_sat_or_all(buffer, &t[2], &out->amount))
105 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
106 "'%.*s' is a invalid satoshi amount",
107 t[2].end - t[2].start,
108 buffer + t[2].start);
109
110 if (amount_sat_eq(out->amount, AMOUNT_SAT(-1ULL))) {
111 if (txp->all_output_idx != -1)
112 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
113 "Cannot use 'all' in"

Callers

nothing calls this directly

Calls 9

bitcoin_tx_core_weightFunction · 0.85
json_to_sat_or_allFunction · 0.85
bitcoin_tx_output_weightFunction · 0.85
tal_bytelenFunction · 0.85
command_failFunction · 0.70
json_strdupFunction · 0.50
amount_sat_eqFunction · 0.50
amount_sat_addFunction · 0.50

Tested by

no test coverage detected