|
| 1 | +#include "config.h" |
| 2 | +#include <plugins/askrene/datastore_wire.h> |
| 3 | +#include <wire/wire.h> |
| 4 | + |
| 5 | +/* FIXME: Generate this! */ |
| 6 | + |
| 7 | +/* Helper to append bool to data, and return value */ |
| 8 | +static bool towire_bool_val(u8 **pptr, bool v) |
| 9 | +{ |
| 10 | + towire_bool(pptr, v); |
| 11 | + return v; |
| 12 | +} |
| 13 | + |
| 14 | +static void towire_short_channel_id_dir(u8 **pptr, const struct short_channel_id_dir *scidd) |
| 15 | +{ |
| 16 | + towire_short_channel_id(pptr, scidd->scid); |
| 17 | + towire_u8(pptr, scidd->dir); |
| 18 | +} |
| 19 | + |
| 20 | +static void fromwire_short_channel_id_dir(const u8 **cursor, size_t *max, |
| 21 | + struct short_channel_id_dir *scidd) |
| 22 | +{ |
| 23 | + scidd->scid = fromwire_short_channel_id(cursor, max); |
| 24 | + scidd->dir = fromwire_u8(cursor, max); |
| 25 | +} |
| 26 | + |
| 27 | +static struct amount_msat *fromwire_opt_amount_msat(const tal_t *ctx, |
| 28 | + const u8 **cursor, size_t *len) |
| 29 | +{ |
| 30 | + struct amount_msat *msat; |
| 31 | + |
| 32 | + if (!fromwire_bool(cursor, len)) |
| 33 | + return NULL; |
| 34 | + msat = tal(ctx, struct amount_msat); |
| 35 | + *msat = fromwire_amount_msat(cursor, len); |
| 36 | + return msat; |
| 37 | +} |
| 38 | + |
| 39 | +static u32 *fromwire_opt_u32(const tal_t *ctx, const u8 **cursor, size_t *len) |
| 40 | +{ |
| 41 | + u32 *v; |
| 42 | + |
| 43 | + if (!fromwire_bool(cursor, len)) |
| 44 | + return NULL; |
| 45 | + v = tal(ctx, u32); |
| 46 | + *v = fromwire_u32(cursor, len); |
| 47 | + return v; |
| 48 | +} |
| 49 | + |
| 50 | +static u16 *fromwire_opt_u16(const tal_t *ctx, const u8 **cursor, size_t *len) |
| 51 | +{ |
| 52 | + u16 *v; |
| 53 | + |
| 54 | + if (!fromwire_bool(cursor, len)) |
| 55 | + return NULL; |
| 56 | + v = tal(ctx, u16); |
| 57 | + *v = fromwire_u16(cursor, len); |
| 58 | + return v; |
| 59 | +} |
| 60 | + |
| 61 | +static bool *fromwire_opt_bool(const tal_t *ctx, const u8 **cursor, size_t *len) |
| 62 | +{ |
| 63 | + bool *v; |
| 64 | + |
| 65 | + if (!fromwire_bool(cursor, len)) |
| 66 | + return NULL; |
| 67 | + v = tal(ctx, bool); |
| 68 | + *v = fromwire_bool(cursor, len); |
| 69 | + return v; |
| 70 | +} |
| 71 | + |
| 72 | +static const char *fromwire_opt_wirestring(const tal_t *ctx, |
| 73 | + const u8 **cursor, size_t *len) |
| 74 | +{ |
| 75 | + if (!fromwire_bool(cursor, len)) |
| 76 | + return NULL; |
| 77 | + return fromwire_wirestring(ctx, cursor, len); |
| 78 | +} |
| 79 | + |
| 80 | +static void towire_opt_u32(u8 **p, const u32 *v) |
| 81 | +{ |
| 82 | + if (towire_bool_val(p, v != NULL)) |
| 83 | + towire_u32(p, *v); |
| 84 | +} |
| 85 | + |
| 86 | +static void towire_opt_u16(u8 **p, const u16 *v) |
| 87 | +{ |
| 88 | + if (towire_bool_val(p, v != NULL)) |
| 89 | + towire_u16(p, *v); |
| 90 | +} |
| 91 | + |
| 92 | +static void towire_opt_bool(u8 **p, const bool *v) |
| 93 | +{ |
| 94 | + if (towire_bool_val(p, v != NULL)) |
| 95 | + towire_bool(p, *v); |
| 96 | +} |
| 97 | + |
| 98 | +static void towire_opt_amount_msat(u8 **p, const struct amount_msat *v) |
| 99 | +{ |
| 100 | + if (towire_bool_val(p, v != NULL)) |
| 101 | + towire_amount_msat(p, *v); |
| 102 | +} |
| 103 | + |
| 104 | +static void towire_opt_wirestring(u8 **p, const char *v) |
| 105 | +{ |
| 106 | + if (towire_bool_val(p, v != NULL)) |
| 107 | + towire_wirestring(p, v); |
| 108 | +} |
| 109 | + |
| 110 | +bool fromwire_dstore_channel(const u8 **cursor, size_t *len, |
| 111 | + struct node_id *n1, |
| 112 | + struct node_id *n2, |
| 113 | + struct short_channel_id *scid, |
| 114 | + struct amount_msat *capacity) |
| 115 | +{ |
| 116 | + if (fromwire_u16(cursor, len) != DSTORE_CHANNEL) { |
| 117 | + fromwire_fail(cursor, len); |
| 118 | + return false; |
| 119 | + } |
| 120 | + fromwire_node_id(cursor, len, n1); |
| 121 | + fromwire_node_id(cursor, len, n2); |
| 122 | + *scid = fromwire_short_channel_id(cursor, len); |
| 123 | + *capacity = fromwire_amount_msat(cursor, len); |
| 124 | + |
| 125 | + return *cursor != NULL; |
| 126 | +} |
| 127 | + |
| 128 | +void towire_dstore_channel(u8 **data, |
| 129 | + const struct node_id *n1, |
| 130 | + const struct node_id *n2, |
| 131 | + struct short_channel_id scid, |
| 132 | + struct amount_msat capacity) |
| 133 | +{ |
| 134 | + towire_u16(data, DSTORE_CHANNEL); |
| 135 | + towire_node_id(data, n1); |
| 136 | + towire_node_id(data, n2); |
| 137 | + towire_short_channel_id(data, scid); |
| 138 | + towire_amount_msat(data, capacity); |
| 139 | +} |
| 140 | + |
| 141 | +bool fromwire_dstore_channel_update(const tal_t *ctx, |
| 142 | + const u8 **cursor, size_t *len, |
| 143 | + struct short_channel_id_dir *scidd, |
| 144 | + bool **enabled, |
| 145 | + struct amount_msat **htlc_min, |
| 146 | + struct amount_msat **htlc_max, |
| 147 | + struct amount_msat **base_fee, |
| 148 | + u32 **proportional_fee, |
| 149 | + u16 **delay) |
| 150 | +{ |
| 151 | + if (fromwire_u16(cursor, len) != DSTORE_CHANNEL_UPDATE) { |
| 152 | + fromwire_fail(cursor, len); |
| 153 | + return false; |
| 154 | + } |
| 155 | + |
| 156 | + fromwire_short_channel_id_dir(cursor, len, scidd); |
| 157 | + *enabled = fromwire_opt_bool(ctx, cursor, len); |
| 158 | + *htlc_min = fromwire_opt_amount_msat(ctx, cursor, len); |
| 159 | + *htlc_max = fromwire_opt_amount_msat(ctx, cursor, len); |
| 160 | + *base_fee = fromwire_opt_amount_msat(ctx, cursor, len); |
| 161 | + *proportional_fee = fromwire_opt_u32(ctx, cursor, len); |
| 162 | + *delay = fromwire_opt_u16(ctx, cursor, len); |
| 163 | + |
| 164 | + return *cursor != NULL; |
| 165 | +} |
| 166 | + |
| 167 | +void towire_dstore_channel_update(u8 **data, |
| 168 | + const struct short_channel_id_dir *scidd, |
| 169 | + const bool *enabled, |
| 170 | + const struct amount_msat *htlc_min, |
| 171 | + const struct amount_msat *htlc_max, |
| 172 | + const struct amount_msat *base_fee, |
| 173 | + const u32 *proportional_fee, |
| 174 | + const u16 *delay) |
| 175 | +{ |
| 176 | + towire_u16(data, DSTORE_CHANNEL_UPDATE); |
| 177 | + towire_short_channel_id_dir(data, scidd); |
| 178 | + towire_opt_bool(data, enabled); |
| 179 | + towire_opt_amount_msat(data, htlc_min); |
| 180 | + towire_opt_amount_msat(data, htlc_max); |
| 181 | + towire_opt_amount_msat(data, base_fee); |
| 182 | + towire_opt_u32(data, proportional_fee); |
| 183 | + towire_opt_u16(data, delay); |
| 184 | +} |
| 185 | + |
| 186 | +bool fromwire_dstore_channel_constraint(const tal_t *ctx, |
| 187 | + const u8 **cursor, size_t *len, |
| 188 | + struct short_channel_id_dir *scidd, |
| 189 | + u64 *timestamp, |
| 190 | + struct amount_msat **min, |
| 191 | + struct amount_msat **max) |
| 192 | +{ |
| 193 | + if (fromwire_u16(cursor, len) != DSTORE_CHANNEL_CONSTRAINT) { |
| 194 | + fromwire_fail(cursor, len); |
| 195 | + return false; |
| 196 | + } |
| 197 | + |
| 198 | + fromwire_short_channel_id_dir(cursor, len, scidd); |
| 199 | + *timestamp = fromwire_u64(cursor, len); |
| 200 | + *min = fromwire_opt_amount_msat(ctx, cursor, len); |
| 201 | + *max = fromwire_opt_amount_msat(ctx, cursor, len); |
| 202 | + |
| 203 | + return *cursor != NULL; |
| 204 | +} |
| 205 | + |
| 206 | +void towire_dstore_channel_constraint(u8 **data, |
| 207 | + const struct short_channel_id_dir *scidd, |
| 208 | + u64 timestamp, |
| 209 | + const struct amount_msat *min, |
| 210 | + const struct amount_msat *max) |
| 211 | +{ |
| 212 | + towire_u16(data, DSTORE_CHANNEL_CONSTRAINT); |
| 213 | + towire_short_channel_id_dir(data, scidd); |
| 214 | + towire_u64(data, timestamp); |
| 215 | + towire_opt_amount_msat(data, min); |
| 216 | + towire_opt_amount_msat(data, max); |
| 217 | +} |
| 218 | + |
| 219 | +bool fromwire_dstore_channel_bias(const tal_t *ctx, |
| 220 | + const u8 **cursor, size_t *len, |
| 221 | + struct short_channel_id_dir *scidd, |
| 222 | + s8 *bias_factor, |
| 223 | + const char **description) |
| 224 | +{ |
| 225 | + if (fromwire_u16(cursor, len) != DSTORE_CHANNEL_BIAS) { |
| 226 | + fromwire_fail(cursor, len); |
| 227 | + return false; |
| 228 | + } |
| 229 | + |
| 230 | + fromwire_short_channel_id_dir(cursor, len, scidd); |
| 231 | + *bias_factor = fromwire_s8(cursor, len); |
| 232 | + *description = fromwire_opt_wirestring(ctx, cursor, len); |
| 233 | + |
| 234 | + return *cursor != NULL; |
| 235 | +} |
| 236 | + |
| 237 | +void towire_dstore_channel_bias(u8 **data, |
| 238 | + const struct short_channel_id_dir *scidd, |
| 239 | + s8 bias_factor, |
| 240 | + const char *description) |
| 241 | +{ |
| 242 | + towire_u16(data, DSTORE_CHANNEL_BIAS); |
| 243 | + towire_short_channel_id_dir(data, scidd); |
| 244 | + towire_s8(data, bias_factor); |
| 245 | + towire_opt_wirestring(data, description); |
| 246 | +} |
| 247 | + |
| 248 | +bool fromwire_dstore_channel_bias_v2(const tal_t *ctx, |
| 249 | + const u8 **cursor, size_t *len, |
| 250 | + struct short_channel_id_dir *scidd, |
| 251 | + s8 *bias_factor, |
| 252 | + const char **description, |
| 253 | + u64 *timestamp) |
| 254 | +{ |
| 255 | + if (fromwire_u16(cursor, len) != DSTORE_CHANNEL_BIAS_V2) { |
| 256 | + fromwire_fail(cursor, len); |
| 257 | + return false; |
| 258 | + } |
| 259 | + |
| 260 | + fromwire_short_channel_id_dir(cursor, len, scidd); |
| 261 | + *bias_factor = fromwire_s8(cursor, len); |
| 262 | + *description = fromwire_opt_wirestring(ctx, cursor, len); |
| 263 | + *timestamp = fromwire_u64(cursor, len); |
| 264 | + |
| 265 | + return *cursor != NULL; |
| 266 | +} |
| 267 | + |
| 268 | +void towire_dstore_channel_bias_v2(u8 **data, |
| 269 | + const struct short_channel_id_dir *scidd, |
| 270 | + s8 bias_factor, |
| 271 | + const char *description, |
| 272 | + u64 timestamp) |
| 273 | +{ |
| 274 | + towire_u16(data, DSTORE_CHANNEL_BIAS_V2); |
| 275 | + towire_short_channel_id_dir(data, scidd); |
| 276 | + towire_s8(data, bias_factor); |
| 277 | + towire_opt_wirestring(data, description); |
| 278 | + towire_u64(data, timestamp); |
| 279 | +} |
| 280 | + |
| 281 | +bool fromwire_dstore_node_bias(const tal_t *ctx, |
| 282 | + const u8 **cursor, size_t *len, |
| 283 | + struct node_id *node, |
| 284 | + const char **description, |
| 285 | + s8 *in_bias, s8 *out_bias, |
| 286 | + u64 *timestamp) |
| 287 | +{ |
| 288 | + if (fromwire_u16(cursor, len) != DSTORE_NODE_BIAS) { |
| 289 | + fromwire_fail(cursor, len); |
| 290 | + return false; |
| 291 | + } |
| 292 | + |
| 293 | + fromwire_node_id(cursor, len, node); |
| 294 | + *in_bias = fromwire_s8(cursor, len); |
| 295 | + *out_bias = fromwire_s8(cursor, len); |
| 296 | + *description = fromwire_opt_wirestring(ctx, cursor, len); |
| 297 | + *timestamp = fromwire_u64(cursor, len); |
| 298 | + |
| 299 | + return *cursor != NULL; |
| 300 | +} |
| 301 | + |
| 302 | +void towire_dstore_node_bias(u8 **data, |
| 303 | + const struct node_id *node, |
| 304 | + const char *description, |
| 305 | + s8 in_bias, s8 out_bias, |
| 306 | + u64 timestamp) |
| 307 | +{ |
| 308 | + towire_u16(data, DSTORE_NODE_BIAS); |
| 309 | + towire_node_id(data, node); |
| 310 | + towire_s8(data, in_bias); |
| 311 | + towire_s8(data, out_bias); |
| 312 | + towire_opt_wirestring(data, description); |
| 313 | + towire_u64(data, timestamp); |
| 314 | +} |
| 315 | + |
| 316 | +bool fromwire_dstore_disabled_node(const u8 **cursor, size_t *len, |
| 317 | + struct node_id *node) |
| 318 | +{ |
| 319 | + if (fromwire_u16(cursor, len) != DSTORE_DISABLED_NODE) { |
| 320 | + fromwire_fail(cursor, len); |
| 321 | + return false; |
| 322 | + } |
| 323 | + |
| 324 | + fromwire_node_id(cursor, len, node); |
| 325 | + return *cursor != NULL; |
| 326 | +} |
| 327 | + |
| 328 | +void towire_dstore_disabled_node(u8 **data, const struct node_id *node) |
| 329 | +{ |
| 330 | + towire_u16(data, DSTORE_DISABLED_NODE); |
| 331 | + towire_node_id(data, node); |
| 332 | +} |
0 commit comments