* Load a channel_hint from its JSON representation. * * @return The initialized `channel_hint` or `NULL` if we encountered a parsing * error. */
| 171 | * error. |
| 172 | */ |
| 173 | struct channel_hint *channel_hint_from_json(const tal_t *ctx, |
| 174 | const char *buffer, |
| 175 | const jsmntok_t *toks) |
| 176 | { |
| 177 | const char *ret; |
| 178 | const jsmntok_t *payload , *jhint; |
| 179 | struct channel_hint *hint = tal(ctx, struct channel_hint); |
| 180 | |
| 181 | /* Deprecated API uses "payload" */ |
| 182 | payload = json_get_member(buffer, toks, "payload"); |
| 183 | /* Modern API includes fields directly */ |
| 184 | if (!payload) { |
| 185 | jhint = json_get_member(buffer, toks, "channel_hint_update"); |
| 186 | } else { |
| 187 | jhint = json_get_member(buffer, payload, "channel_hint"); |
| 188 | } |
| 189 | ret = json_scan(ctx, buffer, jhint, |
| 190 | "{timestamp:%,scid:%,estimated_capacity_msat:%,total_capacity_msat:%,enabled:%}", |
| 191 | JSON_SCAN(json_to_u32, &hint->timestamp), |
| 192 | JSON_SCAN(json_to_short_channel_id_dir, &hint->scid), |
| 193 | JSON_SCAN(json_to_msat, &hint->estimated_capacity), |
| 194 | JSON_SCAN(json_to_msat, &hint->capacity), |
| 195 | JSON_SCAN(json_to_bool, &hint->enabled)); |
| 196 | |
| 197 | if (ret != NULL) |
| 198 | hint = tal_free(hint); |
| 199 | return hint; |
| 200 | } |
| 201 | |
| 202 | struct channel_hint_set *channel_hint_set_new(const tal_t *ctx) |
| 203 | { |
no test coverage detected