Skip to content

Commit

Permalink
Add more conversions for NoteRecordDetails
Browse files Browse the repository at this point in the history
  • Loading branch information
tomyrd committed Jul 5, 2024
1 parent be5af12 commit 14f63dc
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 44 deletions.
30 changes: 5 additions & 25 deletions crates/rust-client/src/notes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use winter_maybe_async::{maybe_async, maybe_await};
use crate::{
errors::{ClientError, StoreError},
rpc::{NodeRpcClient, NoteDetails},
store::{InputNoteRecord, NoteFilter, NoteRecordDetails, NoteStatus, OutputNoteRecord, Store},
store::{InputNoteRecord, NoteFilter, NoteStatus, OutputNoteRecord, Store},
Client,
};

Expand Down Expand Up @@ -160,12 +160,7 @@ impl<N: NodeRpcClient, R: FeltRng, S: Store, A: TransactionAuthenticator> Client
};

// If note is not tracked, we create a new one.
let details = NoteRecordDetails::new(
node_note.nullifier().to_string(),
node_note.script().clone(),
node_note.inputs().values().to_vec(),
node_note.serial_num(),
);
let details = node_note.clone().into();

InputNoteRecord::new(
node_note.id(),
Expand Down Expand Up @@ -196,12 +191,7 @@ impl<N: NodeRpcClient, R: FeltRng, S: Store, A: TransactionAuthenticator> Client
}
},
NoteFile::NoteDetails(details, None) => {
let record_details = NoteRecordDetails::new(
details.nullifier().to_string(),
details.script().clone(),
details.inputs().values().to_vec(),
details.serial_num(),
);
let record_details = details.clone().into();

InputNoteRecord::new(
details.id(),
Expand Down Expand Up @@ -236,12 +226,7 @@ impl<N: NodeRpcClient, R: FeltRng, S: Store, A: TransactionAuthenticator> Client
info!("Ignoring note with tag {}", tag);
}

let record_details = NoteRecordDetails::new(
details.nullifier().to_string(),
details.script().clone(),
details.inputs().values().to_vec(),
details.serial_num(),
);
let record_details = details.clone().into();

InputNoteRecord::new(
details.id(),
Expand All @@ -256,12 +241,7 @@ impl<N: NodeRpcClient, R: FeltRng, S: Store, A: TransactionAuthenticator> Client
)
},
NoteFile::NoteWithProof(note, inclusion_proof) => {
let details = NoteRecordDetails::new(
note.nullifier().to_string(),
note.script().clone(),
note.inputs().values().to_vec(),
note.serial_num(),
);
let details = note.clone().into();

InputNoteRecord::new(
note.id(),
Expand Down
14 changes: 2 additions & 12 deletions crates/rust-client/src/store/note_record/input_note_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,7 @@ impl From<Note> for InputNoteRecord {
status: NoteStatus::Expected { created_at: 0 },
metadata: Some(*note.metadata()),
inclusion_proof: None,
details: NoteRecordDetails::new(
note.nullifier().to_string(),
note.script().clone(),
note.inputs().values().to_vec(),
note.serial_num(),
),
details: note.into(),
ignored: false,
imported_tag: None,
}
Expand All @@ -214,12 +209,7 @@ impl From<InputNote> for InputNoteRecord {
assets: recorded_note.note().assets().clone(),
status: NoteStatus::Expected { created_at: 0 },
metadata: Some(*recorded_note.note().metadata()),
details: NoteRecordDetails::new(
recorded_note.note().nullifier().to_string(),
recorded_note.note().script().clone(),
recorded_note.note().inputs().values().to_vec(),
recorded_note.note().serial_num(),
),
details: recorded_note.note().clone().into(),
inclusion_proof: recorded_note.proof().cloned(),
ignored: false,
imported_tag: None,
Expand Down
24 changes: 23 additions & 1 deletion crates/rust-client/src/store/note_record/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use chrono::{Local, TimeZone};
use miden_objects::{
accounts::AccountId,
assembly::{Assembler, ProgramAst},
notes::NoteScript,
notes::{Note, NoteDetails, NoteScript},
utils::{ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable},
Digest, Felt, Word,
};
Expand Down Expand Up @@ -250,3 +250,25 @@ impl Deserializable for NoteRecordDetails {
Ok(NoteRecordDetails::new(nullifier, script, inputs, serial_num))
}
}

impl From<Note> for NoteRecordDetails {
fn from(note: Note) -> Self {
Self::new(
note.nullifier().to_string(),
note.script().clone(),
note.inputs().values().to_vec(),
note.serial_num(),
)
}
}

impl From<NoteDetails> for NoteRecordDetails {
fn from(details: NoteDetails) -> Self {
Self::new(
details.nullifier().to_string(),
details.script().clone(),
details.inputs().values().to_vec(),
details.serial_num(),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,7 @@ impl From<Note> for OutputNoteRecord {
status: NoteStatus::Expected { created_at: 0 },
metadata: *note.metadata(),
inclusion_proof: None,
details: Some(NoteRecordDetails::new(
note.nullifier().to_string(),
note.script().clone(),
note.inputs().values().to_vec(),
note.serial_num(),
)),
details: Some(note.into()),
}
}
}
Expand Down

0 comments on commit 14f63dc

Please sign in to comment.