Commit cab6d7d
fix(dashcore): make OutPoint serde tolerant of ContentDeserializer's HR-quirk (#708)
* fix(dashcore): make `OutPoint` serde survive ContentDeserializer replays
`OutPoint`'s `Deserialize` impl branched on `is_human_readable()` and used
two unrelated visitors — a string-only `StringVisitor` for HR and a
struct-only `StructVisitor` for non-HR. Serde's `ContentDeserializer`
(used internally for `#[serde(tag = "...")]`, `flatten`, and untagged
enums) always reports `is_human_readable() == true` regardless of the
upstream format, so a value originally produced as a non-HR struct could
be replayed into the HR branch as a map and fail with
`invalid type: map, expected an OutPoint`.
Fix the `serde_struct_human_string_impl!` macro to use a single visitor
that accepts all three input shapes (`visit_str`, `visit_seq`,
`visit_map`) and use `deserialize_any` in the HR branch so the actual
content shape is picked up regardless of what `is_human_readable`
reports. The non-HR branch keeps `deserialize_struct` so bincode
(which doesn't support `deserialize_any`) still works. The serialize
side is unchanged.
The trade-off: raw JSON now also accepts the struct/seq forms in
addition to the canonical \`\"txid:vout\"\` string form, and tolerates
unknown fields in the struct form. This is intentional and required —
internally-tagged enums replay the entire buffered content (including
the tag field) when resolving each variant, so \`visit_map\` must accept
unknown fields. Canonical JSON output is unchanged because the
serialize side still emits the string form.
Add a regression test that round-trips an \`OutPoint\` through an
internally-tagged enum via \`serde_json::Value\` (forcing the
\`ContentDeserializer\` path) and through bincode.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix(test): drop bincode round-trip from OutPoint serde regression test
The dev-dependency on `bincode` doesn't enable the `serde` feature, so
`bincode::serde::encode_to_vec` is not in scope. The non-human-readable
struct path is already exercised by the existing dashcore test suite
which uses bincode extensively, so the regression test only needs to
lock in the `ContentDeserializer` behavior — kept the JSON-via-tagged-
enum and string-form assertions.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* test(dashcore): restore bincode side of OutPoint serde tagged-enum test
Adding `features = ["serde"]` to the bincode dev-dep so the regression
test can exercise the symmetric non-human-readable struct path through
the tagged enum, not just the human-readable JSON path. Reword the
macro doc comment so it frames the underlying issue as
serde's `ContentDeserializer` HR-quirk rather than implying a bug
specific to dashcore — the same sharp edge bites every custom
`Deserialize` that uses `is_human_readable()` for shape dispatch and
the upstream stance is "accept any shape, don't branch".
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* test(dashcore): use plain OutPoint bincode round-trip instead of tagged
A bincode round-trip *via* a `#[serde(tag = ...)]` enum can't work — serde
internally-tagged dispatch buffers content by calling `deserialize_any`
on the upstream deserializer, and bincode is not self-describing
(`Serde(AnyNotSupported)`). That limitation is orthogonal to the bug
this PR fixes — the original failing case in dashpay/platform routes
through `platform_value::Value`, which *does* support `deserialize_any`.
Replace the bogus bincode-tagged-enum assertion with a plain `OutPoint`
bincode round-trip, which still locks the non-human-readable struct
path (`visit_seq`).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix(test): drop needless borrow flagged by clippy
`bincode::serde::encode_to_vec` takes the value by `Serialize` bound and
`OutPoint` is `Copy`, so the `&raw` borrow is redundant
(`clippy::needless_borrows_for_generic_args`).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* review: add map-form regression test and reject duplicate fields
Address CodeRabbit review feedback on the OutPoint serde fix:
1. Add a test that hand-builds the JSON object/map shape of `OutPoint`
inside a `#[serde(tag = ...)]` enum and deserializes from it. This
is the exact shape the original bug exhibited downstream — serde
serialized as a map (because the upstream format was non-human-
readable), then the tagged enum replayed through `ContentDeserializer`
into the HR branch where the old string-only visitor errored. The
`serde_json::to_value` round-trip was only exercising the visit_str
path through `ContentDeserializer` because canonical OutPoint HR
serialization is a string.
2. Reject duplicate field keys in `serde_struct_human_string_impl!`'s
`visit_map`. Previously a duplicate silently kept the last value;
now it errors with `duplicate field` like serde's derive. Add a
test covering this — parse from a raw JSON string (not `json!`)
because `Value::Object` deduplicates on construction.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 56fe09d commit cab6d7d
2 files changed
Lines changed: 224 additions & 105 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
337 | 337 | | |
338 | 338 | | |
339 | 339 | | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
340 | 447 | | |
341 | 448 | | |
342 | 449 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
358 | 358 | | |
359 | 359 | | |
360 | 360 | | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
361 | 375 | | |
362 | 376 | | |
363 | 377 | | |
364 | 378 | | |
365 | 379 | | |
366 | 380 | | |
367 | 381 | | |
368 | | - | |
369 | | - | |
370 | | - | |
371 | | - | |
372 | | - | |
373 | | - | |
374 | | - | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
375 | 385 | | |
376 | | - | |
377 | | - | |
378 | | - | |
| 386 | + | |
| 387 | + | |
379 | 388 | | |
380 | | - | |
381 | | - | |
382 | | - | |
383 | | - | |
384 | | - | |
385 | | - | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
386 | 392 | | |
| 393 | + | |
| 394 | + | |
387 | 395 | | |
388 | 396 | | |
389 | | - | |
390 | | - | |
391 | | - | |
392 | | - | |
393 | | - | |
394 | | - | |
395 | | - | |
396 | | - | |
397 | | - | |
398 | | - | |
399 | | - | |
400 | | - | |
401 | | - | |
402 | | - | |
403 | | - | |
404 | | - | |
405 | | - | |
406 | | - | |
407 | | - | |
408 | | - | |
409 | | - | |
410 | | - | |
411 | | - | |
412 | | - | |
413 | | - | |
414 | | - | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
415 | 406 | | |
416 | 407 | | |
| 408 | + | |
417 | 409 | | |
418 | | - | |
419 | | - | |
420 | | - | |
421 | | - | |
422 | | - | |
423 | | - | |
424 | | - | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
425 | 416 | | |
| 417 | + | |
426 | 418 | | |
427 | | - | |
428 | | - | |
429 | | - | |
430 | | - | |
| 419 | + | |
431 | 420 | | |
432 | | - | |
433 | | - | |
434 | | - | |
| 421 | + | |
| 422 | + | |
435 | 423 | | |
436 | | - | |
437 | | - | |
438 | | - | |
439 | | - | |
440 | | - | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
441 | 427 | | |
442 | | - | |
443 | | - | |
444 | | - | |
445 | | - | |
446 | | - | |
447 | | - | |
448 | | - | |
449 | | - | |
450 | | - | |
451 | | - | |
452 | | - | |
453 | | - | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
454 | 434 | | |
455 | | - | |
456 | | - | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
457 | 456 | | |
458 | | - | |
459 | | - | |
460 | | - | |
461 | | - | |
462 | | - | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
463 | 462 | | |
464 | | - | |
| 463 | + | |
465 | 464 | | |
466 | | - | |
467 | | - | |
468 | | - | |
469 | | - | |
470 | | - | |
471 | | - | |
472 | | - | |
473 | | - | |
474 | | - | |
475 | | - | |
476 | | - | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
477 | 469 | | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
478 | 479 | | |
| 480 | + | |
479 | 481 | | |
480 | | - | |
481 | | - | |
482 | | - | |
483 | | - | |
484 | | - | |
485 | | - | |
486 | | - | |
487 | | - | |
488 | | - | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
489 | 486 | | |
| 487 | + | |
490 | 488 | | |
491 | | - | |
492 | | - | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
493 | 494 | | |
494 | | - | |
| 495 | + | |
| 496 | + | |
495 | 497 | | |
496 | | - | |
| 498 | + | |
497 | 499 | | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
498 | 510 | | |
499 | 511 | | |
500 | 512 | | |
| |||
0 commit comments