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

Function param_outputs

plugins/txprepare.c:92–162  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90}
91
92static struct command_result *param_outputs(struct command *cmd,
93 const char *name,
94 const char *buffer,
95 const jsmntok_t *tok,
96 struct txprepare *txp)
97{
98 size_t i;
99 const jsmntok_t *t;
100
101 if (tok->type != JSMN_ARRAY) {
102 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
103 "Expected an array of outputs in the "
104 "format '[{\"txid\":0}, ...]', got \"%s\"",
105 json_strdup(tmpctx, buffer, tok));
106 }
107
108 txp->outputs = tal_arr(txp, struct tx_output, tok->size);
109 txp->output_total = AMOUNT_SAT(0);
110 txp->all_output_idx = -1;
111
112 /* We assume < 253 inputs, and if we're wrong, the fee
113 * difference is trivial. */
114 txp->weight = bitcoin_tx_core_weight(1, tal_count(txp->outputs));
115
116 json_for_each_arr(i, t, tok) {
117 enum address_parse_result res;
118 struct tx_output *out = &txp->outputs[i];
119
120 /* We assume these are accounted for elsewhere */
121 out->is_to_external = false;
122
123 /* output format: {destination: amount} */
124 if (t->type != JSMN_OBJECT)
125 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
126 "The output format must be "
127 "{destination: amount}");
128 res = json_to_address_scriptpubkey(cmd,
129 chainparams,
130 buffer, &t[1],
131 &out->script);
132 if (res == ADDRESS_PARSE_UNRECOGNIZED)
133 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
134 "Could not parse destination address");
135 else if (res == ADDRESS_PARSE_WRONG_NETWORK)
136 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
137 "Destination address is not on network %s",
138 chainparams->network_name);
139
140 if (!json_to_sat_or_all(buffer, &t[2], &out->amount))
141 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
142 "'%.*s' is a invalid satoshi amount",
143 t[2].end - t[2].start,
144 buffer + t[2].start);
145
146 if (amount_sat_eq(out->amount, AMOUNT_SAT(-1ULL))) {
147 if (txp->all_output_idx != -1)
148 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
149 "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