Add silent payments scan label support - #11
Conversation
Support BIP329 spscan records in Label and LabelRef, and add import options to ignore unsupported record types. This keeps existing parsing strictness configurable per callsite while preserving compatibility.
📝 WalkthroughWalkthroughAdds a new ChangesSilent Payments Scan Label & Parse Options
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant Labels
participant parse_label_line
participant LabelType
Caller->>Labels: try_from_str_with_options(labels, options)
loop for each line
Labels->>parse_label_line: parse_label_line(line, options)
alt ignore_unknown_types enabled
parse_label_line->>LabelType: parse type field only
LabelType-->>parse_label_line: type value
parse_label_line-->>Labels: None (skip) if unknown type
end
parse_label_line-->>Labels: Some(Label) if known type
end
Labels-->>Caller: Labels collection
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Greptile SummaryThis PR adds support for silent payments scan labels and configurable import strictness. The main changes are:
Confidence Score: 4/5The changed flow looks mergeable after a small cleanup to
src/lib.rs Important Files Changed
Reviews (1): Last reviewed commit: "Add silent payments scan label support" | Re-trigger Greptile |
| #[derive(Clone, Debug, Serialize, Deserialize, Hash, PartialEq, Eq, PartialOrd, Ord)] | ||
| pub struct SilentPaymentsScanRecord { | ||
| #[serde(rename = "ref")] | ||
| pub ref_: String, |
There was a problem hiding this comment.
When an import contains {"type":"spscan","ref":"not-a-valid-scan-key"}, serde accepts it as a normal SilentPaymentsScanRecord because ref_ is just a String. That invalid ref then reaches Label::ref_(), map keys, and export output as if it were a valid silent payments scan key expression, so downstream wallets only see the failure later when they try to decode or use it.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/label.rs (1)
219-224: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winKeep
is_known_label_typein sync with enum variantsThe hardcoded type list in
is_known_label_typemust manually stay in sync with the#[serde(rename = "...")]attributes on bothLabelandParsedLabelLine. If a new record type is added to either enum but omitted here,ignore_unknown_typeswould silently skip records of that type during imports — a subtle data-loss bug.Consider adding a test that iterates all known type strings and verifies they deserialize successfully as both
LabelandParsedLabelLine, or at minimum a comment near both sites flagging the coupling.🧪 Suggested sync test
#[test] fn known_label_types_match_enum_variants() { let known_types = ["tx", "addr", "pubkey", "input", "output", "xpub", "spscan"]; for ty in known_types { assert!(is_known_label_type(ty), "{ty} should be known"); // Verify each known type round-trips through the enum's serde rename let minimal = format!(r#"{{"type":"{ty}"}}"#); let _: Result<LabelType, _> = serde_json::from_str(&minimal); } }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/label.rs` around lines 219 - 224, Keep is_known_label_type synchronized with the serde-renamed variants on Label and ParsedLabelLine: update the hardcoded matches list whenever either enum gains a new record type, and add a test around is_known_label_type/serde deserialization to verify every known type string still parses for both enums so ignore_unknown_types cannot silently drop new records.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/label.rs`:
- Around line 219-224: Keep is_known_label_type synchronized with the
serde-renamed variants on Label and ParsedLabelLine: update the hardcoded
matches list whenever either enum gains a new record type, and add a test around
is_known_label_type/serde deserialization to verify every known type string
still parses for both enums so ignore_unknown_types cannot silently drop new
records.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 56efe526-d0a0-4953-bf2d-7aa7b995f0bb
📒 Files selected for processing (5)
CHANGELOG.mdsrc/from.rssrc/label.rssrc/lib.rstests/data/test_vector.jsonl
Support BIP329 spscan records in Label and LabelRef, and add import options to ignore unsupported record types.
This keeps existing parsing strictness configurable per callsite while preserving compatibility.
Summary by CodeRabbit