forked from 0xPolygonMiden/miden-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9029693
commit 1c90071
Showing
19 changed files
with
968 additions
and
748 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use miden_client::store::InputNoteRecord as NativeInputNoteRecord; | ||
use wasm_bindgen::prelude::*; | ||
|
||
use super::{note_details::NoteDetails, note_id::NoteId, note_state::NoteState}; | ||
|
||
#[derive(Clone)] | ||
#[wasm_bindgen] | ||
pub struct InputNoteRecord(NativeInputNoteRecord); | ||
|
||
#[wasm_bindgen] | ||
impl InputNoteRecord { | ||
pub fn id(&self) -> NoteId { | ||
self.0.id().into() | ||
} | ||
|
||
pub fn state(&self) -> NoteState { | ||
self.0.state().into() | ||
} | ||
|
||
pub fn details(&self) -> NoteDetails { | ||
self.0.details().into() | ||
} | ||
} | ||
|
||
// CONVERSIONS | ||
// ================================================================================================ | ||
|
||
impl From<NativeInputNoteRecord> for InputNoteRecord { | ||
fn from(native_note: NativeInputNoteRecord) -> Self { | ||
InputNoteRecord(native_note) | ||
} | ||
} | ||
|
||
impl From<&NativeInputNoteRecord> for InputNoteRecord { | ||
fn from(native_note: &NativeInputNoteRecord) -> Self { | ||
InputNoteRecord(native_note.clone()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
use miden_client::store::NoteFilter as NativeNoteFilter; | ||
use wasm_bindgen::prelude::*; | ||
|
||
use super::note_id::NoteId; | ||
|
||
// TODO: Add nullfiier support | ||
|
||
#[derive(Clone)] | ||
#[wasm_bindgen] | ||
pub struct NoteFilter { | ||
note_type: NoteFilterTypes, | ||
note_ids: Option<Vec<NoteId>>, | ||
} | ||
|
||
#[wasm_bindgen] | ||
impl NoteFilter { | ||
#[wasm_bindgen(constructor)] | ||
pub fn new(note_type: NoteFilterTypes, note_ids: Option<Vec<NoteId>>) -> NoteFilter { | ||
NoteFilter { note_type, note_ids } | ||
} | ||
} | ||
|
||
#[derive(Clone)] | ||
#[wasm_bindgen] | ||
pub enum NoteFilterTypes { | ||
All, | ||
Consumed, | ||
Committed, | ||
Expected, | ||
Processing, | ||
Ignored, | ||
List, | ||
Unique, | ||
Nullifiers, | ||
Unverified, | ||
} | ||
|
||
// CONVERSIONS | ||
// ================================================================================================ | ||
|
||
impl From<NoteFilter> for NativeNoteFilter { | ||
fn from(filter: NoteFilter) -> Self { | ||
match filter.note_type { | ||
NoteFilterTypes::All => NativeNoteFilter::All, | ||
NoteFilterTypes::Consumed => NativeNoteFilter::Consumed, | ||
NoteFilterTypes::Committed => NativeNoteFilter::Committed, | ||
NoteFilterTypes::Expected => NativeNoteFilter::Expected, | ||
NoteFilterTypes::Processing => NativeNoteFilter::Processing, | ||
NoteFilterTypes::Ignored => NativeNoteFilter::Ignored, | ||
NoteFilterTypes::List => { | ||
let note_ids = | ||
filter.note_ids.unwrap_or_else(|| panic!("Note IDs required for List filter")); | ||
NativeNoteFilter::List(note_ids.iter().map(|note| note.into()).collect()) | ||
}, | ||
NoteFilterTypes::Unique => { | ||
let note_ids = | ||
filter.note_ids.unwrap_or_else(|| panic!("Note ID required for Unique filter")); | ||
|
||
if note_ids.len() != 1 { | ||
panic!("Only one Note ID can be provided"); | ||
} | ||
|
||
NativeNoteFilter::Unique(note_ids.first().unwrap().into()) | ||
}, | ||
NoteFilterTypes::Nullifiers => NativeNoteFilter::Nullifiers(vec![]), | ||
NoteFilterTypes::Unverified => NativeNoteFilter::Unverified, | ||
} | ||
} | ||
} | ||
|
||
impl From<&NoteFilter> for NativeNoteFilter { | ||
fn from(filter: &NoteFilter) -> Self { | ||
match filter.note_type { | ||
NoteFilterTypes::All => NativeNoteFilter::All, | ||
NoteFilterTypes::Consumed => NativeNoteFilter::Consumed, | ||
NoteFilterTypes::Committed => NativeNoteFilter::Committed, | ||
NoteFilterTypes::Expected => NativeNoteFilter::Expected, | ||
NoteFilterTypes::Processing => NativeNoteFilter::Processing, | ||
NoteFilterTypes::Ignored => NativeNoteFilter::Ignored, | ||
NoteFilterTypes::List => { | ||
let note_ids = filter | ||
.note_ids | ||
.clone() | ||
.unwrap_or_else(|| panic!("Note IDs required for List filter")); | ||
NativeNoteFilter::List(note_ids.iter().map(|note| note.into()).collect()) | ||
}, | ||
NoteFilterTypes::Unique => { | ||
let note_ids = filter | ||
.note_ids | ||
.clone() | ||
.unwrap_or_else(|| panic!("Note ID required for Unique filter")); | ||
|
||
if note_ids.len() != 1 { | ||
panic!("Only one Note ID can be provided"); | ||
} | ||
|
||
NativeNoteFilter::Unique(note_ids.first().unwrap().into()) | ||
}, | ||
NoteFilterTypes::Nullifiers => NativeNoteFilter::Nullifiers(vec![]), | ||
NoteFilterTypes::Unverified => NativeNoteFilter::Unverified, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use miden_client::store::NoteState as NativeNoteState; | ||
use wasm_bindgen::prelude::*; | ||
|
||
#[derive(Clone)] | ||
#[wasm_bindgen] | ||
pub enum NoteState { | ||
Expected, | ||
Unverified, | ||
Committed, | ||
Invalid, | ||
ProcessingAuthenticated, | ||
ProcessingUnauthenticated, | ||
ConsumedAuthenticatedLocal, | ||
ConsumedUnauthenticatedLocal, | ||
ConsumedExternal, | ||
} | ||
|
||
// CONVERSIONS | ||
// ================================================================================================ | ||
|
||
impl From<NativeNoteState> for NoteState { | ||
fn from(native_note: NativeNoteState) -> Self { | ||
match native_note { | ||
NativeNoteState::Expected(_) => NoteState::Expected, | ||
NativeNoteState::Unverified(_) => NoteState::Unverified, | ||
NativeNoteState::Committed(_) => NoteState::Committed, | ||
NativeNoteState::Invalid(_) => NoteState::Invalid, | ||
NativeNoteState::ProcessingAuthenticated(_) => NoteState::ProcessingAuthenticated, | ||
NativeNoteState::ProcessingUnauthenticated(_) => NoteState::ProcessingUnauthenticated, | ||
NativeNoteState::ConsumedAuthenticatedLocal(_) => NoteState::ConsumedAuthenticatedLocal, | ||
NativeNoteState::ConsumedUnauthenticatedLocal(_) => { | ||
NoteState::ConsumedUnauthenticatedLocal | ||
}, | ||
NativeNoteState::ConsumedExternal(_) => NoteState::ConsumedExternal, | ||
} | ||
} | ||
} | ||
|
||
impl From<&NativeNoteState> for NoteState { | ||
fn from(native_note: &NativeNoteState) -> Self { | ||
match native_note { | ||
NativeNoteState::Expected(_) => NoteState::Expected, | ||
NativeNoteState::Unverified(_) => NoteState::Unverified, | ||
NativeNoteState::Committed(_) => NoteState::Committed, | ||
NativeNoteState::Invalid(_) => NoteState::Invalid, | ||
NativeNoteState::ProcessingAuthenticated(_) => NoteState::ProcessingAuthenticated, | ||
NativeNoteState::ProcessingUnauthenticated(_) => NoteState::ProcessingUnauthenticated, | ||
NativeNoteState::ConsumedAuthenticatedLocal(_) => NoteState::ConsumedAuthenticatedLocal, | ||
NativeNoteState::ConsumedUnauthenticatedLocal(_) => { | ||
NoteState::ConsumedUnauthenticatedLocal | ||
}, | ||
NativeNoteState::ConsumedExternal(_) => NoteState::ConsumedExternal, | ||
} | ||
} | ||
} |
Oops, something went wrong.