newaddr has given us a change address. */
| 234 | |
| 235 | /* newaddr has given us a change address. */ |
| 236 | static 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 | |
| 265 | static bool resolve_all_output_amount(struct txprepare *txp, |
| 266 | struct amount_sat excess) |
nothing calls this directly
no test coverage detected