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

Function newaddr_done

plugins/txprepare.c:236–263  ·  view source on GitHub ↗

newaddr has given us a change address. */

Source from the content-addressed store, hash-verified

234
235/* newaddr has given us a change address. */
236static struct command_result *newaddr_done(struct command *cmd,
237 const char *buf,
238 const jsmntok_t *result,
239 struct txprepare *txp)
240{
241 size_t num = tal_count(txp->outputs), pos;
242 const jsmntok_t *addr = json_get_member(buf, result, "bech32");
243
244 /* Insert change in random position in outputs */
245 tal_resize(&txp->outputs, num+1);
246 pos = pseudorand(num+1);
247 memmove(txp->outputs + pos + 1,
248 txp->outputs + pos,
249 sizeof(txp->outputs[0]) * (num - pos));
250
251 txp->outputs[pos].amount = txp->change_amount;
252 txp->outputs[pos].is_to_external = false;
253 if (json_to_address_scriptpubkey(txp, chainparams, buf, addr,
254 &txp->outputs[pos].script)
255 != ADDRESS_PARSE_SUCCESS) {
256 return command_fail(cmd, LIGHTNINGD,
257 "Change address '%.*s' unparsable?",
258 addr->end - addr->start,
259 buf + addr->start);
260 }
261
262 return finish_txprepare(cmd, txp);
263}
264
265static bool resolve_all_output_amount(struct txprepare *txp,
266 struct amount_sat excess)

Callers

nothing calls this directly

Calls 5

finish_txprepareFunction · 0.85
command_failFunction · 0.70
json_get_memberFunction · 0.50
pseudorandFunction · 0.50

Tested by

no test coverage detected