Refactor asset handling and introduce SwapNoteStorage#2592
Refactor asset handling and introduce SwapNoteStorage#2592PoulavBhowmick03 wants to merge 2 commits into0xMiden:nextfrom
Conversation
|
I wrote it similar to |
PhilippGackstatter
left a comment
There was a problem hiding this comment.
Looks good, thanks! I left a few comments.
|
|
||
| pub fn into_recipient(self, serial_num: Word) -> NoteRecipient { | ||
| NoteRecipient::new(serial_num, SwapNote::script(), NoteStorage::from(self)) | ||
| } |
There was a problem hiding this comment.
Nit: Missing docs
| fn dummy_fungible_faucet() -> AccountId { | ||
| AccountId::dummy( | ||
| [1u8; 15], | ||
| AccountIdVersion::Version0, | ||
| AccountType::FungibleFaucet, | ||
| AccountStorageMode::Public, | ||
| ) | ||
| } | ||
|
|
||
| fn dummy_non_fungible_faucet() -> AccountId { | ||
| AccountId::dummy( | ||
| [2u8; 15], | ||
| AccountIdVersion::Version0, | ||
| AccountType::NonFungibleFaucet, | ||
| AccountStorageMode::Public, | ||
| ) | ||
| } | ||
|
|
||
| fn dummy_fungible_asset() -> Asset { | ||
| Asset::Fungible(FungibleAsset::new(dummy_fungible_faucet(), 1000).unwrap()) | ||
| } | ||
|
|
||
| fn dummy_non_fungible_asset() -> Asset { | ||
| let details = | ||
| NonFungibleAssetDetails::new(dummy_non_fungible_faucet(), vec![0xaa, 0xbb]).unwrap(); | ||
| Asset::NonFungible(NonFungibleAsset::new(&details).unwrap()) | ||
| } |
There was a problem hiding this comment.
Nit: We have constants like ACCOUNT_ID_PUBLIC_FUNGIBLE_FAUCET_2 that we can use instead of these dummies, or use AccountIdBuilder in line to create IDs (which is more concise).
| pub fn new( | ||
| payback_note_type: NoteType, | ||
| payback_tag: NoteTag, | ||
| payback_attachment: NoteAttachment, | ||
| requested_asset: Asset, | ||
| payback_recipient_digest: Word, | ||
| ) -> Self { |
There was a problem hiding this comment.
This constructor is useful for reconstructing a swap storage from raw parts and rather low-level. So, I'd rename this to from_parts.
For convenience, I'd add the following constructor
pub fn new(
sender: AccountId,
requested_asset: Asset,
payback_note_type: NoteType,
payback_attachment: NoteAttachment,
payback_serial_number: Word,
) -> Self {It would derive these things:
payback_recipient = P2idNoteStorage::new(sender).into_recipient(payback_serial_num)payback_tag = NoteTag::with_account_target(sender)
| pub struct SwapNoteStorage { | ||
| payback_note_type: NoteType, | ||
| payback_tag: NoteTag, |
There was a problem hiding this comment.
Let's also use SwapNoteStorage inside SwapNote::create and replace the existing swap note storage construction with this type.
| /// Expected number of storage items of the SWAP note. | ||
| pub const NUM_ITEMS: usize = 20; |
There was a problem hiding this comment.
Let's also redefine SwapNote::NUM_STORAGE_ITEMS = SwapNoteStorage::NUM_STORAGE_ITEMS.
Closes #2515