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.
feat: Added wasm consumable notes + improved note models (0xPolygonMi…
…den#561) * feat: Added wasm consumable notes + improved note models * improved tests + cleaned up model constructors * cleanup
- Loading branch information
1 parent
29a6082
commit b1c79f4
Showing
15 changed files
with
589 additions
and
248 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
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,89 @@ | ||
use miden_client::{ | ||
notes::{NoteConsumability as NativeNoteConsumability, NoteRelevance}, | ||
store::InputNoteRecord as NativeInputNoteRecord, | ||
}; | ||
use wasm_bindgen::prelude::*; | ||
|
||
use super::{account_id::AccountId, input_note_record::InputNoteRecord}; | ||
|
||
#[derive(Clone)] | ||
#[wasm_bindgen] | ||
pub struct ConsumableNoteRecord { | ||
input_note_record: InputNoteRecord, | ||
note_consumability: Vec<NoteConsumability>, | ||
} | ||
|
||
#[derive(Clone, Copy)] | ||
#[wasm_bindgen] | ||
pub struct NoteConsumability { | ||
account_id: AccountId, | ||
|
||
// The block number after which the note can be consumed, | ||
// if None then the note can be consumed immediately | ||
consumable_after_block: Option<u32>, | ||
} | ||
|
||
#[wasm_bindgen] | ||
impl NoteConsumability { | ||
pub(crate) fn new( | ||
account_id: AccountId, | ||
consumable_after_block: Option<u32>, | ||
) -> NoteConsumability { | ||
NoteConsumability { account_id, consumable_after_block } | ||
} | ||
|
||
pub fn account_id(&self) -> AccountId { | ||
self.account_id | ||
} | ||
|
||
pub fn consumable_after_block(&self) -> Option<u32> { | ||
self.consumable_after_block | ||
} | ||
} | ||
|
||
#[wasm_bindgen] | ||
impl ConsumableNoteRecord { | ||
#[wasm_bindgen(constructor)] | ||
pub fn new( | ||
input_note_record: InputNoteRecord, | ||
note_consumability: Vec<NoteConsumability>, | ||
) -> ConsumableNoteRecord { | ||
ConsumableNoteRecord { input_note_record, note_consumability } | ||
} | ||
|
||
pub fn input_note_record(&self) -> InputNoteRecord { | ||
self.input_note_record.clone() | ||
} | ||
|
||
pub fn note_consumability(&self) -> Vec<NoteConsumability> { | ||
self.note_consumability.clone() | ||
} | ||
} | ||
|
||
// CONVERSIONS | ||
// ================================================================================================ | ||
impl From<(NativeInputNoteRecord, Vec<NativeNoteConsumability>)> for ConsumableNoteRecord { | ||
fn from( | ||
(input_note_record, note_consumability): ( | ||
NativeInputNoteRecord, | ||
Vec<NativeNoteConsumability>, | ||
), | ||
) -> Self { | ||
ConsumableNoteRecord::new( | ||
input_note_record.into(), | ||
note_consumability.into_iter().map(|c| c.into()).collect(), | ||
) | ||
} | ||
} | ||
|
||
impl From<NativeNoteConsumability> for NoteConsumability { | ||
fn from(note_consumability: NativeNoteConsumability) -> Self { | ||
NoteConsumability::new( | ||
note_consumability.0.into(), | ||
match note_consumability.1 { | ||
NoteRelevance::After(block) => Some(block), | ||
NoteRelevance::Always => None, | ||
}, | ||
) | ||
} | ||
} |
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
Oops, something went wrong.