feat(standards): SwapNote bon builder#11
Conversation
Convert the `SwapNote` marker type into a struct built via a `bon` typestate builder (`SwapNote::builder()`), mirroring `P2idNote`. `SwapNote::into_notes` returns the outgoing SWAP note together with its payback `NoteDetails`. The "requested asset must differ from offered" check now surfaces via `NoteError::other`. Migrate the mock-chain `add_swap_note` call site. Part of 0xMiden#2283.
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 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 |
VAIBHAVJINDAL3012
left a comment
There was a problem hiding this comment.
- Check on serial number
- Check on into_notes
| let tag = Self::build_tag(self.swap_note_type, &self.offered_asset, &self.requested_asset); | ||
| let metadata = PartialNoteMetadata::new(self.sender, self.swap_note_type).with_tag(tag); | ||
| let assets = NoteAssets::new(vec![self.offered_asset]) | ||
| .expect("a single offered asset never exceeds the note asset limit"); |
There was a problem hiding this comment.
dont' use expect, check from P2ID note......
Btw why do we need this function......
| let payback_serial_number = rng.draw_word(); | ||
| let serial_number = rng.draw_word(); |
There was a problem hiding this comment.
How both serial numbers are same???
Check it corereclty
Propagate NoteAssets::new errors with ? instead of panicking via .expect(...), matching the error handling the original create used and keeping the (Note, NoteDetails) return. Also comment the builder test.
Summary
Converts
SwapNotefrom a unit marker +SwapNote::createfactory into a struct built with abontypestate builder (SwapNote::builder()), mirroring the mergedP2idNotebuilder. One of three per-note PRs splitting the standard-note builder work (Swap / Burn / Mint).SwapNote::builder()produces aSwapNote; callSwapNote::into_notes()to get the outgoing SWAPNoteplus the paybackNoteDetails.requested != offeredvalidation is preserved viaNoteError::other..generate_serial_numbers()draws the swap and payback serial numbers (payback first, preserving the previous draw order).add_swap_noteand the swap interface test.Builder-only change; no MASM or on-chain behaviour changes.
Verification
cargo clippy -p miden-standards -p miden-testing --all-targets --all-features -- -D warnings- cleannote::swap::tests::builder_produces_swap_and_payback_notesunit test; thetests/scripts/swap.rs+ faucet suites pass and re-run in CI here.