-
Notifications
You must be signed in to change notification settings - Fork 54
/
metadata.rs
48 lines (42 loc) · 1.31 KB
/
metadata.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use super::{AccountId, Felt, Word};
/// Represents metadata associated with a note. This includes the sender, tag, and number of assets.
/// - sender is the account which created the note.
/// - tag is a tag which can be used to identify the target account for the note.
/// - num_assets is the number of assets in the note.
#[derive(Debug, Eq, PartialEq)]
pub struct NoteMetadata {
sender: AccountId,
tag: Felt,
num_assets: Felt,
}
impl NoteMetadata {
/// Returns a new note metadata object created with the specified parameters.
pub fn new(sender: AccountId, tag: Felt, num_assets: Felt) -> Self {
Self {
sender,
tag,
num_assets,
}
}
/// Returns the account which created the note.
pub fn sender(&self) -> AccountId {
self.sender
}
/// Returns the tag associated with the note.
pub fn tag(&self) -> Felt {
self.tag
}
/// Returns the number of assets in the note.
pub fn num_assets(&self) -> Felt {
self.num_assets
}
}
impl From<&NoteMetadata> for Word {
fn from(metadata: &NoteMetadata) -> Self {
let mut elements = Word::default();
elements[0] = metadata.num_assets;
elements[1] = metadata.tag;
elements[2] = metadata.sender.into();
elements
}
}