|
8 | 8 | #include <common/json_stream.h> |
9 | 9 | #include <common/memleak.h> |
10 | 10 | #include <common/type_to_string.h> |
| 11 | +#include <errno.h> |
11 | 12 | #include <plugins/libplugin-pay.h> |
12 | 13 | #include <sodium.h> |
13 | 14 |
|
@@ -161,29 +162,65 @@ REGISTER_PAYMENT_MODIFIER(check_preapprovekeysend, void *, NULL, |
161 | 162 | * End of check_preapprovekeysend modifier |
162 | 163 | *****************************************************************************/ |
163 | 164 |
|
| 165 | +/* Deprecated: comma-separated string containing integers */ |
| 166 | +static bool json_accumulate_uintarr(const char *buffer, |
| 167 | + const jsmntok_t *tok, |
| 168 | + u64 **dest) |
| 169 | +{ |
| 170 | + char *str = json_strdup(NULL, buffer, tok); |
| 171 | + char *endp, **elements = tal_strsplit(str, str, ",", STR_NO_EMPTY); |
| 172 | + unsigned long long l; |
| 173 | + u64 u; |
| 174 | + for (int i = 0; elements[i] != NULL; i++) { |
| 175 | + /* This is how the manpage says to do it. Yech. */ |
| 176 | + errno = 0; |
| 177 | + l = strtoull(elements[i], &endp, 0); |
| 178 | + if (*endp || !str[0]) |
| 179 | + return false; |
| 180 | + u = l; |
| 181 | + if (errno || u != l) |
| 182 | + return false; |
| 183 | + tal_arr_expand(dest, u); |
| 184 | + } |
| 185 | + tal_free(str); |
| 186 | + return NULL; |
| 187 | +} |
| 188 | + |
| 189 | +/* values_int is a JSON array of u64s */ |
| 190 | +static bool jsonarr_accumulate_u64(const char *buffer, |
| 191 | + const jsmntok_t *tok, |
| 192 | + u64 **dest) |
| 193 | +{ |
| 194 | + const jsmntok_t *t; |
| 195 | + size_t i, n; |
| 196 | + |
| 197 | + if (tok->type != JSMN_ARRAY) |
| 198 | + return false; |
| 199 | + n = tal_count(*dest); |
| 200 | + tal_resize(dest, n + tok->size); |
| 201 | + json_for_each_arr(i, t, tok) { |
| 202 | + if (!json_to_u64(buffer, t, &(*dest)[n + i])) |
| 203 | + return false; |
| 204 | + } |
| 205 | + return true; |
| 206 | +} |
| 207 | + |
164 | 208 | static const char *init(struct plugin *p, const char *buf UNUSED, |
165 | 209 | const jsmntok_t *config UNUSED) |
166 | 210 | { |
167 | | - const jsmntok_t *maxdelay, *extratlvs, *ctok; |
168 | | - const char *cbuf; |
169 | | - |
170 | 211 | rpc_scan(p, "getinfo", take(json_out_obj(NULL, NULL, NULL)), "{id:%}", |
171 | 212 | JSON_SCAN(json_to_node_id, &my_id)); |
172 | 213 |
|
173 | | - ctok = |
174 | | - jsonrpc_request_sync(tmpctx, p, "listconfigs", |
175 | | - take(json_out_obj(NULL, NULL, NULL)), &cbuf); |
176 | | - /* `accept-htlc-tlv-types` may be missing if not set in the |
177 | | - * config */ |
178 | | - maxdelay = json_get_member(cbuf, ctok, "max-locktime-blocks"); |
179 | | - extratlvs = json_get_member(cbuf, ctok, "accept-htlc-tlv-types"); |
180 | 214 | accepted_extra_tlvs = notleak(tal_arr(NULL, u64, 0)); |
181 | | - |
182 | | - assert(maxdelay != NULL); |
183 | | - json_to_number(cbuf, maxdelay, &maxdelay_default); |
184 | | - |
185 | | - if (extratlvs != NULL) |
186 | | - json_to_uintarr(cbuf, extratlvs, &accepted_extra_tlvs); |
| 215 | + /* accept-htlc-tlv-types deprecated in v23.08, but still grab it! */ |
| 216 | + rpc_scan(p, "listconfigs", take(json_out_obj(NULL, NULL, NULL)), |
| 217 | + "{configs:{" |
| 218 | + "max-locktime-blocks:{value_int:%}," |
| 219 | + "accept-htlc-tlv-types?:{value_str:%}," |
| 220 | + "accept-htlc-tlv-type:{values_int:%}}}", |
| 221 | + JSON_SCAN(json_to_u32, &maxdelay_default), |
| 222 | + JSON_SCAN(json_accumulate_uintarr, &accepted_extra_tlvs), |
| 223 | + JSON_SCAN(jsonarr_accumulate_u64, &accepted_extra_tlvs)); |
187 | 224 |
|
188 | 225 | return NULL; |
189 | 226 | } |
|
0 commit comments