| 90 | } |
| 91 | |
| 92 | static 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" |
nothing calls this directly
no test coverage detected