-
Notifications
You must be signed in to change notification settings - Fork 115
refactor: enforce CLAIM note consumer via NetworkAccountTarget attachment, not NoteStorage
#2480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a242d2a
e6c81ba
8bbc6b9
bde7af3
501cbd0
31f2772
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -172,38 +172,37 @@ impl SequentialCommit for LeafData { | |
|
|
||
| /// Output note data for CLAIM note creation. | ||
| /// Contains note-specific data and can use Miden types. | ||
| /// TODO: Remove all but target_faucet_account_id | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: technically should not remove this TODO just yet. |
||
| #[derive(Clone)] | ||
| pub struct OutputNoteData { | ||
| /// P2ID note serial number (4 felts as Word) | ||
| pub output_p2id_serial_num: Word, | ||
| /// Target agg faucet account ID (2 felts: prefix and suffix) | ||
| pub target_faucet_account_id: AccountId, | ||
| /// P2ID output note tag | ||
| pub output_note_tag: NoteTag, | ||
| /// Miden claim amount (scaled-down token amount as Felt) | ||
| pub miden_claim_amount: Felt, | ||
| } | ||
|
|
||
| impl OutputNoteData { | ||
| /// Converts the output note data to a vector of field elements for note storage | ||
| /// Converts the output note data to a vector of field elements for note storage. | ||
| /// | ||
| /// Layout (8 felts = 2 words): | ||
| /// `[serial_num(4), tag(1), miden_claim_amount(1), padding(2)]` | ||
| pub fn to_elements(&self) -> Vec<Felt> { | ||
| const OUTPUT_NOTE_DATA_ELEMENT_COUNT: usize = 8; // 4 + 2 + 1 + 1 (serial_num + account_id + tag + miden_claim_amount) | ||
| const OUTPUT_NOTE_DATA_ELEMENT_COUNT: usize = 8; | ||
| let mut elements = Vec::with_capacity(OUTPUT_NOTE_DATA_ELEMENT_COUNT); | ||
|
|
||
| // P2ID note serial number (4 felts as Word) | ||
| elements.extend(self.output_p2id_serial_num); | ||
|
|
||
| // Target faucet account ID (2 felts: prefix and suffix) | ||
| elements.push(self.target_faucet_account_id.prefix().as_felt()); | ||
| elements.push(self.target_faucet_account_id.suffix()); | ||
|
|
||
| // Output note tag | ||
| elements.push(Felt::new(self.output_note_tag.as_u32() as u64)); | ||
|
|
||
| // Miden claim amount | ||
| elements.push(self.miden_claim_amount); | ||
|
|
||
| // Padding to keep 8 felts (2 words) for pipe_double_words_preimage_to_memory | ||
| elements.extend([Felt::ZERO; 2]); | ||
|
Comment on lines
+203
to
+204
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this actually doesn't have to be padded to 8 felts, (2 words) in |
||
|
|
||
| elements | ||
| } | ||
| } | ||
|
|
@@ -245,24 +244,24 @@ impl TryFrom<ClaimNoteStorage> for NoteStorage { | |
| /// | ||
| /// # Parameters | ||
| /// - `storage`: The core storage for creating the CLAIM note | ||
| /// - `target_faucet_id`: The account ID of the agglayer faucet that should consume this note. | ||
| /// Encoded as a `NetworkAccountTarget` attachment on the note metadata. | ||
| /// - `sender_account_id`: The account ID of the CLAIM note creator | ||
| /// - `rng`: Random number generator for creating the CLAIM note serial number | ||
| /// | ||
| /// # Errors | ||
| /// Returns an error if note creation fails. | ||
| pub fn create_claim_note<R: FeltRng>( | ||
| storage: ClaimNoteStorage, | ||
| target_faucet_id: AccountId, | ||
| sender_account_id: AccountId, | ||
| rng: &mut R, | ||
| ) -> Result<Note, NoteError> { | ||
| let note_storage = NoteStorage::try_from(storage.clone())?; | ||
|
|
||
| let attachment = NetworkAccountTarget::new( | ||
| storage.output_note_data.target_faucet_account_id, | ||
| NoteExecutionHint::Always, | ||
| ) | ||
| .map_err(|e| NoteError::other(e.to_string()))? | ||
| .into(); | ||
| let attachment = NetworkAccountTarget::new(target_faucet_id, NoteExecutionHint::Always) | ||
| .map_err(|e| NoteError::other(e.to_string()))? | ||
| .into(); | ||
|
|
||
| let metadata = | ||
| NoteMetadata::new(sender_account_id, NoteType::Public).with_attachment(attachment); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's wait for this PR to land as it refactors
OUTPUT_NOTE_DATA_KEYand removesoutput_p2id_serial_numOr could you rebase off of #2484