You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The goal is to try to compile the following code to the MASM below and see what parts we are missing:
use miden::{
account,
asset::Asset,
note::Recipient,
tx,};#[miden_account]pubstructMyWallet;#[miden_account]implMyWallet{pubfnrecieve_asset(&mutself,asset:Asset){
account::add_asset(asset);}pubfnsend_asset(&mutself,asset:Asset,recipient:Recipient){
account::remove_asset(asset);
tx::create_note(asset, recipient);}}
The above code is expected to be compiled close to the following (manually written) code:
use.miden::sat::account
use.miden::sat::tx
#! Adds the provided asset to the current account.
export.receive_asset
exec.account::add_asset
padw swapw dropw
end
#! Creates a note which sends the specified asset out of the current account
#! to the specified recipient.
export.send_asset.1
exec.account::remove_asset
# => [ASSET, tag, RECIPIENT, ...]
# insert 8 ZEROs into the stack right after recipient; we temporarily store one of the
# elements of ASSET in memory to make stack manipulation easier
push.0 swap loc_store.0 padw push.0.0.0 swapdw loc_load.0
# => [ASSET, tag, RECIPIENT, ZERO, ZERO, ...]
exec.tx::create_note
# => [note_ptr, ZERO, ZERO, ...]
end
The things to check are:
Mark the MyWallet struct as a Miden account (export marker trait in WIT vs. doc comment attribute). Keep in mind that helper methods exported in the account are to be execd in notes/tx scripts.
Try to define the Asset as a resource in WIT;
EDIT: updated to reflect the switch to WIT.
The text was updated successfully, but these errors were encountered:
Not sure how it might affect things, but a potentially better code on the Rust side for this would be:
use miden::{
account,
asset::Asset,
note::Recipient,
tx,};#[miden_account]pubstructMyWallet;#[miden_account]implMyWallet{pubfnrecieve_asset(&mutself,asset:Asset){
account::add_asset(asset);}pubfnsend_asset(&mutself,asset:Asset,recipient:Recipient){let asset = account::remove_asset(asset);// this line is different
tx::create_note(asset, recipient);}}
This is semantically different from the version in the original post only if Asset is not Copy. So, I guess one question we should settle on is whether Asset should be Copy on the Rust side. My initial thinking is that probably it should not be, but I also haven't thought through the implications.
Following the discussion at #28 (comment)
The goal is to try to compile the following code to the MASM below and see what parts we are missing:
The above code is expected to be compiled close to the following (manually written) code:
The things to check are:
MyWallet
struct as a Miden account (export marker trait in WIT vs. doc comment attribute). Keep in mind that helper methods exported in the account are to beexec
d in notes/tx scripts.Asset
as a resource in WIT;EDIT: updated to reflect the switch to WIT.
The text was updated successfully, but these errors were encountered: