Skip to content

Refactor asset handling and introduce SwapNoteStorage#2592

Open
PoulavBhowmick03 wants to merge 2 commits into0xMiden:nextfrom
PoulavBhowmick03:swap_note_storage
Open

Refactor asset handling and introduce SwapNoteStorage#2592
PoulavBhowmick03 wants to merge 2 commits into0xMiden:nextfrom
PoulavBhowmick03:swap_note_storage

Conversation

@PoulavBhowmick03
Copy link
Contributor

Closes #2515

@PoulavBhowmick03
Copy link
Contributor Author

I wrote it similar to P2idNoteStorage and P2ideNoteStorage and it's methods and complied to their API types.

Copy link
Contributor

@PhilippGackstatter PhilippGackstatter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks! I left a few comments.

Comment on lines +245 to +248

pub fn into_recipient(self, serial_num: Word) -> NoteRecipient {
NoteRecipient::new(serial_num, SwapNote::script(), NoteStorage::from(self))
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Missing docs

Comment on lines +352 to +378
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())
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Comment on lines +205 to +211
pub fn new(
payback_note_type: NoteType,
payback_tag: NoteTag,
payback_attachment: NoteAttachment,
requested_asset: Asset,
payback_recipient_digest: Word,
) -> Self {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Comment on lines +186 to +188
pub struct SwapNoteStorage {
payback_note_type: NoteType,
payback_tag: NoteTag,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also use SwapNoteStorage inside SwapNote::create and replace the existing swap note storage construction with this type.

Comment on lines +198 to +199
/// Expected number of storage items of the SWAP note.
pub const NUM_ITEMS: usize = 20;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also redefine SwapNote::NUM_STORAGE_ITEMS = SwapNoteStorage::NUM_STORAGE_ITEMS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add SwapNoteStorage

2 participants