use miden_client::note::NoteMetadata as NativeNoteMetadata;
use miden_client::rpc::domain::note::CommittedNote as NativeCommittedNote;
use wasm_bindgen::prelude::*;
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)]
#[wasm_bindgen]
pub struct CommittedNote(NativeCommittedNote);
#[wasm_bindgen]
impl CommittedNote {
#[wasm_bindgen(js_name = "noteId")]
pub fn note_id(&self) -> NoteId {
(*self.0.note_id()).into()
}
#[wasm_bindgen(js_name = "noteIndex")]
pub fn note_index(&self) -> u16 {
self.0.inclusion_proof().location().block_note_tree_index()
}
#[wasm_bindgen(js_name = "inclusionPath")]
pub fn inclusion_path(&self) -> SparseMerklePath {
self.0.inclusion_proof().note_path().into()
}
#[wasm_bindgen(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().map_or_else(
|| {
NativeNoteMetadata::new(self.0.sender(), self.0.note_type())
.with_tag(self.0.tag())
.into()
},
Into::into,
)
}
#[wasm_bindgen(js_name = "fullMetadata")]
pub fn full_metadata(&self) -> Option<NoteMetadata> {
self.0.metadata().map(Into::into)
}
#[wasm_bindgen(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())
}
}