| 204 | } |
| 205 | |
| 206 | struct descriptions *init_descriptions(const tal_t *ctx, |
| 207 | struct command *init_cmd) |
| 208 | { |
| 209 | struct descriptions *descriptions = tal(ctx, struct descriptions); |
| 210 | struct json_out *params; |
| 211 | const jsmntok_t *result, *datastore, *t; |
| 212 | size_t i; |
| 213 | const char *buf; |
| 214 | |
| 215 | descriptions->by_utxo = tal(descriptions, struct utxo_desc_htable); |
| 216 | utxo_desc_htable_init(descriptions->by_utxo); |
| 217 | memleak_add_helper(descriptions->by_utxo, memleak_scan_utxo_desc_htable); |
| 218 | |
| 219 | descriptions->by_payment_hash = tal(descriptions, struct payment_hash_desc_htable); |
| 220 | payment_hash_desc_htable_init(descriptions->by_payment_hash); |
| 221 | memleak_add_helper(descriptions->by_payment_hash, memleak_scan_payment_hash_desc_htable); |
| 222 | |
| 223 | /* Load everything under "bookkeeper/description/utxo" */ |
| 224 | params = json_out_new(tmpctx); |
| 225 | json_out_start(params, NULL, '{'); |
| 226 | json_out_start(params, "key", '['); |
| 227 | json_out_addstr(params, NULL, "bookkeeper"); |
| 228 | json_out_addstr(params, NULL, "description"); |
| 229 | json_out_addstr(params, NULL, "utxo"); |
| 230 | json_out_end(params, ']'); |
| 231 | json_out_end(params, '}'); |
| 232 | |
| 233 | result = jsonrpc_request_sync(tmpctx, init_cmd, |
| 234 | "listdatastore", |
| 235 | params, &buf); |
| 236 | |
| 237 | datastore = json_get_member(buf, result, "datastore"); |
| 238 | json_for_each_arr(i, t, datastore) { |
| 239 | const jsmntok_t *keytok, *hextok; |
| 240 | const char *desc_str; |
| 241 | struct bitcoin_outpoint outp; |
| 242 | |
| 243 | keytok = json_get_member(buf, t, "key"); |
| 244 | if (keytok->size != 4) |
| 245 | continue; |
| 246 | |
| 247 | /* ["bookkeeper", "description", "utxo", <key>] */ |
| 248 | hextok = json_get_member(buf, t, "hex"); |
| 249 | desc_str = json_cstr_from_hex(tmpctx, buf, hextok); |
| 250 | if (!json_to_outpoint(buf, keytok + 4, &outp)) { |
| 251 | plugin_log(init_cmd->plugin, LOG_BROKEN, |
| 252 | "Invalid outpoint desc for %.*s", |
| 253 | json_tok_full_len(keytok), |
| 254 | json_tok_full(buf, keytok)); |
| 255 | continue; |
| 256 | } |
| 257 | new_utxo_description(descriptions, &outp, take(desc_str)); |
| 258 | } |
| 259 | |
| 260 | /* Load everything under "bookkeeper/description/payment" */ |
| 261 | params = json_out_new(tmpctx); |
| 262 | json_out_start(params, NULL, '{'); |
| 263 | json_out_start(params, "key", '['); |
no test coverage detected