-
Notifications
You must be signed in to change notification settings - Fork 49
Open
Description
With the introduction of the #[note_script] attribute macro and the P2ID note script looks like:
compiler/examples/p2id-note/src/lib.rs
Lines 25 to 37 in 41926fa
| #[note_script] | |
| fn run(_arg: Word) { | |
| let inputs = note::get_inputs(); | |
| let target_account_id_prefix = inputs[0]; | |
| let target_account_id_suffix = inputs[1]; | |
| let account_id = account::get_id(); | |
| assert_eq(account_id.prefix, target_account_id_prefix); | |
| assert_eq(account_id.suffix, target_account_id_suffix); | |
| let assets = note::get_assets(); | |
| for asset in assets { | |
| receive_asset(asset); | |
| } | |
| } |
The next step up is the typed note inputs. Instead of Vec<Felt> we could return the note inputs as T given the deserialization from Vec<Felt> is implemented for T.
#[derive(Deserialize)]
struct MyNote {
account_id: AccountId,
}
#[note_script]
fn run(_arg: Word) {
let my_note = note::get_inputs_as::<MyNote>();
... or
let my_note: MyNote = note::get_inputs_as();
...
// access my_note.account_id
...
}Where AccountId implements the deserialization from Vec<Felt>. We could implement the deserialization for the Miden SDK types, but for custom types the deserialization is expected to be implemented by the user.
bobbinth and partylikeits1983
Metadata
Metadata
Assignees
Labels
No labels