askrene added DSTORE_CHANNEL_BIAS_V2 (convertable) and * DSTORE_NODE_BIAS (not convertable) */
| 47 | /* askrene added DSTORE_CHANNEL_BIAS_V2 (convertable) and |
| 48 | * DSTORE_NODE_BIAS (not convertable) */ |
| 49 | static const char *convert_layer_data(const tal_t *ctx, |
| 50 | const char *layername, |
| 51 | const u8 *data_in, |
| 52 | const u8 **data_out) |
| 53 | { |
| 54 | size_t len = tal_bytelen(data_in); |
| 55 | struct node_id n; |
| 56 | struct short_channel_id scid; |
| 57 | struct amount_msat msat, *msat_ptr; |
| 58 | struct short_channel_id_dir scidd; |
| 59 | bool *bool_ptr; |
| 60 | u64 timestamp; |
| 61 | u32 *u32_ptr; |
| 62 | u16 *u16_ptr; |
| 63 | s8 bias; |
| 64 | const char *string; |
| 65 | u8 *out = tal_arr(ctx, u8, 0); |
| 66 | |
| 67 | /* Unfortunately, there are no explicit lengths, so we have |
| 68 | * to read all records even if we don't care about them. */ |
| 69 | while (len != 0) { |
| 70 | enum dstore_layer_type type; |
| 71 | const u8 *olddata = data_in; |
| 72 | type = fromwire_peektypen(data_in, len); |
| 73 | |
| 74 | switch (type) { |
| 75 | /* These are all simply digested and copied */ |
| 76 | case DSTORE_CHANNEL: |
| 77 | if (fromwire_dstore_channel(&data_in, &len, |
| 78 | &n, &n, &scid, &msat)) |
| 79 | copy_data(&out, data_in, olddata - data_in); |
| 80 | continue; |
| 81 | case DSTORE_CHANNEL_UPDATE: |
| 82 | if (fromwire_dstore_channel_update(tmpctx, &data_in, &len, |
| 83 | &scidd, &bool_ptr, |
| 84 | &msat_ptr, &msat_ptr, &msat_ptr, |
| 85 | &u32_ptr, &u16_ptr)) |
| 86 | copy_data(&out, data_in, olddata - data_in); |
| 87 | continue; |
| 88 | case DSTORE_CHANNEL_CONSTRAINT: |
| 89 | if (fromwire_dstore_channel_constraint(tmpctx, &data_in, &len, |
| 90 | &scidd, ×tamp, |
| 91 | &msat_ptr, &msat_ptr)) |
| 92 | copy_data(&out, data_in, olddata - data_in); |
| 93 | continue; |
| 94 | case DSTORE_CHANNEL_BIAS: |
| 95 | if (fromwire_dstore_channel_bias(tmpctx, &data_in, &len, |
| 96 | &scidd, &bias, |
| 97 | &string)) |
| 98 | copy_data(&out, data_in, olddata - data_in); |
| 99 | continue; |
| 100 | case DSTORE_DISABLED_NODE: |
| 101 | if (fromwire_dstore_disabled_node(&data_in, &len, &n)) |
| 102 | copy_data(&out, data_in, olddata - data_in); |
| 103 | continue; |
| 104 | |
| 105 | /* Convert back, lose timestamp */ |
| 106 | case DSTORE_CHANNEL_BIAS_V2: |
no test coverage detected