use js_export_macro::js_export;
use miden_client::rpc::domain::note::CommittedNote as NativeCommittedNote;
use super::account_id::AccountId;
use super::note_id::NoteId;
use super::note_inclusion_proof::NoteInclusionProof;
use super::note_metadata::NoteMetadata;
use super::note_type::NoteType;
use super::sparse_merkle_path::SparseMerklePath;
#[derive(Clone)]
#[js_export]
pub struct CommittedNote(NativeCommittedNote);
#[js_export]
impl CommittedNote {
#[js_export(js_name = "noteId")]
pub fn note_id(&self) -> NoteId {
(*self.0.note_id()).into()
}
#[js_export(js_name = "noteIndex")]
pub fn note_index(&self) -> u16 {
self.0.inclusion_proof().location().block_note_tree_index()
}
#[js_export(js_name = "inclusionPath")]
pub fn inclusion_path(&self) -> SparseMerklePath {
self.0.inclusion_proof().note_path().into()
}
#[js_export(js_name = "noteType")]
pub fn note_type(&self) -> NoteType {
self.0.note_type().into()
}
pub fn sender(&self) -> AccountId {
self.0.sender().into()
}
pub fn tag(&self) -> u32 {
self.0.tag().as_u32()
}
pub fn metadata(&self) -> NoteMetadata {
self.0.metadata().into()
}
#[js_export(js_name = "inclusionProof")]
pub fn inclusion_proof(&self) -> NoteInclusionProof {
self.0.inclusion_proof().into()
}
}
impl From<NativeCommittedNote> for CommittedNote {
fn from(native_note: NativeCommittedNote) -> Self {
CommittedNote(native_note)
}
}
impl From<&NativeCommittedNote> for CommittedNote {
fn from(native_note: &NativeCommittedNote) -> Self {
CommittedNote(native_note.clone())
}
}