use miden::protocol::active_note
use miden::standards::wallets::basic as basic_wallet
use miden::standards::note::note_creator
# ERRORS
# =================================================================================================
# PASS_THROUGH script expects exactly 14 note storage items
const ERR_PASS_THROUGH_WRONG_NUMBER_OF_STORAGE_ITEMS="wrong number of storage items"
#! PASS_THROUGH script:
#! Creates a note consumable by pass-through, containing the same asset.
#!
#! Requires that the account exposes:
#! - miden::standards::note::note_creator::create_note procedure.
#! - miden::standards::wallets::basic::move_asset_to_note procedure.
#!
#! Inputs: []
#! Outputs: []
#!
#! Note storage is assumed to be as follows:
#! - ASSET_KEY
#! - ASSET_VALUE
#! - RECIPIENT
#! - [note_type, tag]
@note_script
pub proc main
# drop note arguments
dropw
# store note storage into memory starting at address 0
push.0 exec.active_note::get_storage
# => [num_storage_items, storage_ptr]
# make sure the number of storage items is 14
eq.14 assert.err=ERR_PASS_THROUGH_WRONG_NUMBER_OF_STORAGE_ITEMS
# => [storage_ptr]
drop
# => []
# move the incoming note's assets into the account vault so they can be
# moved into the output note from the account context
exec.basic_wallet::move_note_assets_to_account
# => []
# pad the stack for the create_note call
padw padw push.0.0
# => [pad(10)]
# load RECIPIENT
padw mem_loadw_le.8
# => [RECIPIENT, pad(10)]
# load note_type and tag from memory
mem_load.12 mem_load.13
# => [tag, note_type, RECIPIENT, pad(10)]
# create a note using storage (note creation must originate from the account context)
call.note_creator::create_note
# => [note_idx, pad(15)]
# keep note_idx, drop 8 pad elements above it
movdn.8 dropw dropw
# => [note_idx, pad(7)]
# load ASSET_VALUE and ASSET_KEY
padw mem_loadw_le.4
# => [ASSET_VALUE, note_idx, pad(7)]
padw mem_loadw_le.0
# => [ASSET_KEY, ASSET_VALUE, note_idx, pad(7)]
# move the asset from the account vault into the created note
call.basic_wallet::move_asset_to_note
# => [pad(16)]
# clean stack
dropw dropw dropw dropw
# => []
end