Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: split input output note register structs #199

Merged
merged 63 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
e86d00e
split input notes
mFragaBA Jan 29, 2024
550ba44
make enum for notes tables
mFragaBA Jan 30, 2024
6cf5d30
rename recipients variable and add more NoteTable uses
mFragaBA Jan 30, 2024
3cd914e
Merge branch 'main' of github.com:0xPolygonMiden/miden-client into mF…
mFragaBA Jan 30, 2024
0d548d9
run fmt
mFragaBA Jan 30, 2024
e589a31
Merge branch 'main' of github.com:0xPolygonMiden/miden-client into mF…
mFragaBA Jan 31, 2024
b65fbd5
change to_string for to_hex
mFragaBA Jan 31, 2024
e9336db
correct nullable fields and reorder fields
mFragaBA Jan 31, 2024
3c8567d
remove unnecesarry note filter
mFragaBA Jan 31, 2024
3fa58c7
remove unnecessary commit_height field
mFragaBA Jan 31, 2024
bf46c0a
move related rows into metadata row for notes
mFragaBA Jan 31, 2024
3ca4b43
Merge branch 'main' of github.com:0xPolygonMiden/miden-client into mF…
mFragaBA Feb 1, 2024
287a8e0
Merge branch 'main' of github.com:0xPolygonMiden/miden-client into mF…
mFragaBA Feb 1, 2024
73b5bbc
remove dbg statements
mFragaBA Feb 2, 2024
d4485d2
switch to_string for to_hex
mFragaBA Feb 2, 2024
b01acf2
Revert "move related rows into metadata row for notes"
mFragaBA Feb 2, 2024
d91569c
Merge branch 'main' of github.com:0xPolygonMiden/miden-client into mF…
mFragaBA Feb 5, 2024
91cbe66
restore filtering by pending notes
mFragaBA Feb 6, 2024
c7f98d1
Merge branch 'main' of github.com:0xPolygonMiden/miden-client into mF…
mFragaBA Feb 7, 2024
1e021ce
Merge branch 'main' of github.com:0xPolygonMiden/miden-client into mF…
mFragaBA Feb 9, 2024
dcfe797
Merge branch 'main' of github.com:0xPolygonMiden/miden-client into mF…
mFragaBA Feb 14, 2024
e43d379
store grouped json fields
mFragaBA Feb 14, 2024
c2d7dc9
add json fields with serialization/deserialization
mFragaBA Feb 14, 2024
d5e1dd3
remove dbg calls and set nullable/non-nullable cols accordingly
mFragaBA Feb 15, 2024
bc49e8c
Merge branch 'main' of github.com:0xPolygonMiden/miden-client into mF…
mFragaBA Feb 15, 2024
ed8e965
Merge branch 'mFragaBA-split-input-notes-table' of github.com:0xPolyg…
mFragaBA Feb 15, 2024
8686b66
apply clippy suggestion
mFragaBA Feb 15, 2024
2f94ba7
add helper functions to work with json values returned as strings
mFragaBA Feb 15, 2024
21ae1d6
add documentation for handling json with sqlite
mFragaBA Feb 15, 2024
6bf494d
fix incorrect function use to fetch output notes
mFragaBA Feb 15, 2024
a71a440
ignore doc tests
mFragaBA Feb 15, 2024
85c7920
Merge branch 'main' of github.com:0xPolygonMiden/miden-client into mF…
mFragaBA Feb 19, 2024
1e42962
Merge branch 'mFragaBA-split-input-notes-table' of github.com:0xPolyg…
mFragaBA Feb 19, 2024
8b56c81
Merge branch 'main' of github.com:0xPolygonMiden/miden-client into mF…
mFragaBA Feb 19, 2024
d4748a6
add json validity constraints
mFragaBA Feb 20, 2024
6d49ce4
use structs to represent json columns
mFragaBA Feb 21, 2024
338ab42
remove dbg statements
mFragaBA Feb 23, 2024
6f471ba
use propper serialization
mFragaBA Feb 23, 2024
f62fe42
Merge branch 'main' of github.com:0xPolygonMiden/miden-client into mF…
mFragaBA Feb 23, 2024
ea8be86
Merge branch 'main' of github.com:0xPolygonMiden/miden-client into mF…
mFragaBA Feb 29, 2024
8238815
use existing NoteMetadata instead of NoteRecordMetadata
mFragaBA Mar 1, 2024
added2b
also remove NoteRecordInclusionProof and use NoteInclusionProof instead
mFragaBA Mar 1, 2024
e1fc26b
Merge branch 'main' of github.com:0xPolygonMiden/miden-client into mF…
mFragaBA Mar 1, 2024
bdbea53
add implementations for output notes
mFragaBA Mar 4, 2024
47fda21
change input note record struct
mFragaBA Mar 4, 2024
66cafb2
Fix test failures
mFragaBA Mar 4, 2024
15fd102
update doc comments
mFragaBA Mar 5, 2024
051fa0a
cleanup struct
mFragaBA Mar 5, 2024
8cae5d3
remove dbg statements
mFragaBA Mar 5, 2024
36235ee
Merge branch 'main' of github.com:0xPolygonMiden/miden-client into mF…
mFragaBA Mar 5, 2024
a1cb379
Merge branch 'mFragaBA-serialize-fields-as-json' of github.com:0xPoly…
mFragaBA Mar 5, 2024
eec0161
Merge branch 'main' of github.com:0xPolygonMiden/miden-client into mF…
mFragaBA Mar 5, 2024
85ec9f2
Merge branch 'mFragaBA-serialize-fields-as-json' of github.com:0xPoly…
mFragaBA Mar 5, 2024
0a1554b
Merge branch 'main' of github.com:0xPolygonMiden/miden-client into mF…
mFragaBA Mar 6, 2024
6f8ccb7
Merge branch 'mFragaBA-serialize-fields-as-json' of github.com:0xPoly…
mFragaBA Mar 11, 2024
e3a6c1f
fix serialization for output notes
mFragaBA Mar 11, 2024
b5574b1
Merge branch 'main' of github.com:0xPolygonMiden/miden-client into mF…
mFragaBA Mar 13, 2024
1c6ea50
change from to tryfrom for notestatus
mFragaBA Mar 14, 2024
21fc72e
move note record structs to its own module
mFragaBA Mar 14, 2024
cff949d
remove todo comment
mFragaBA Mar 14, 2024
ac94858
remove quotes from note status
mFragaBA Mar 14, 2024
f20798d
Merge branch 'main' of github.com:0xPolygonMiden/miden-client into mF…
mFragaBA Mar 14, 2024
a7d4636
Merge branch 'main' of github.com:0xPolygonMiden/miden-client into mF…
mFragaBA Mar 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 52 additions & 44 deletions src/cli/input_notes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ use miden_client::{
client::rpc::NodeRpcClient,
store::{InputNoteRecord, NoteFilter as ClientNoteFilter, Store},
};
use miden_objects::{notes::NoteId, Digest};
use miden_objects::{
notes::{NoteId, NoteInputs, NoteScript},
Digest,
};
use miden_tx::utils::{Deserializable, Serializable};

use super::{Client, Parser};
Expand Down Expand Up @@ -119,7 +122,7 @@ fn list_input_notes<N: NodeRpcClient, S: Store>(
filter: ClientNoteFilter,
) -> Result<(), String> {
let notes = client.get_input_notes(filter)?;
print_notes_summary(&notes);
print_notes_summary(&notes)?;
Ok(())
}

Expand Down Expand Up @@ -164,7 +167,7 @@ pub fn import_note<N: NodeRpcClient, S: Store>(
let input_note_record =
InputNoteRecord::read_from_bytes(&contents).map_err(|err| err.to_string())?;

let note_id = input_note_record.note().id();
let note_id = input_note_record.id();
client.import_input_note(input_note_record)?;

Ok(note_id)
Expand All @@ -183,7 +186,7 @@ fn show_input_note<N: NodeRpcClient, S: Store>(
get_note_with_id_prefix(&client, &note_id).map_err(|err| err.to_string())?;

// print note summary
print_notes_summary(core::iter::once(&input_note_record));
print_notes_summary(core::iter::once(&input_note_record))?;

let mut table = Table::new();
table
Expand All @@ -192,14 +195,17 @@ fn show_input_note<N: NodeRpcClient, S: Store>(

// print note script
if show_script {
let script = NoteScript::read_from_bytes(input_note_record.details().script())
.map_err(|err| format!("Failed to parse the note record's program AST: {}", err))?;

table
.add_row(vec![
Cell::new("Note Script hash").add_attribute(Attribute::Bold),
Cell::new(input_note_record.note().script().hash()),
Cell::new(script.hash()),
])
.add_row(vec![
Cell::new("Note Script code").add_attribute(Attribute::Bold),
Cell::new(input_note_record.note().script().code()),
Cell::new(script.code()),
]);
};

Expand All @@ -208,32 +214,29 @@ fn show_input_note<N: NodeRpcClient, S: Store>(
table
.add_row(vec![
Cell::new("Note Vault hash").add_attribute(Attribute::Bold),
Cell::new(input_note_record.note().assets().commitment()),
Cell::new(input_note_record.assets().commitment()),
])
.add_row(vec![Cell::new("Note Vault").add_attribute(Attribute::Bold)]);

input_note_record.note().assets().iter().for_each(|asset| {
input_note_record.assets().iter().for_each(|asset| {
table.add_row(vec![Cell::new(format!("{:?}", asset))]);
})
};

if show_inputs {
let inputs = NoteInputs::read_from_bytes(input_note_record.details().inputs())
.map_err(|err| format!("Failed to parse the note record's inputs: {}", err))?;

table
.add_row(vec![
Cell::new("Note Inputs hash").add_attribute(Attribute::Bold),
Cell::new(input_note_record.note().inputs().commitment()),
Cell::new(inputs.commitment()),
])
.add_row(vec![Cell::new("Note Inputs").add_attribute(Attribute::Bold)]);
input_note_record
.note()
.inputs()
.values()
.iter()
.enumerate()
.for_each(|(idx, input)| {
table
.add_row(vec![Cell::new(idx).add_attribute(Attribute::Bold), Cell::new(input)]);
});

inputs.values().iter().enumerate().for_each(|(idx, input)| {
table.add_row(vec![Cell::new(idx).add_attribute(Attribute::Bold), Cell::new(input)]);
});
};

println!("{table}");
Expand All @@ -242,7 +245,7 @@ fn show_input_note<N: NodeRpcClient, S: Store>(

// HELPERS
// ================================================================================================
fn print_notes_summary<'a, I>(notes: I)
fn print_notes_summary<'a, I>(notes: I) -> Result<(), String>
where
I: IntoIterator<Item = &'a InputNoteRecord>,
{
Expand All @@ -255,22 +258,31 @@ where
"Commit Height",
]);

notes.into_iter().for_each(|input_note_record| {
for input_note_record in notes {
let commit_height = input_note_record
.inclusion_proof()
.map(|proof| proof.origin().block_num.to_string())
.unwrap_or("-".to_string());

let script = NoteScript::read_from_bytes(input_note_record.details().script())
.map_err(|err| format!("Failed to parse the note record's program AST: {}", err))?;

let inputs = NoteInputs::read_from_bytes(input_note_record.details().inputs())
.map_err(|err| format!("Failed to parse the note record's inputs: {}", err))?;

table.add_row(vec![
input_note_record.note().id().inner().to_string(),
input_note_record.note().script().hash().to_string(),
input_note_record.note().assets().commitment().to_string(),
input_note_record.note().inputs().commitment().to_string(),
Digest::new(input_note_record.note().serial_num()).to_string(),
input_note_record.id().inner().to_string(),
script.hash().to_string(),
input_note_record.assets().commitment().to_string(),
inputs.commitment().to_string(),
Digest::new(input_note_record.details().serial_num()).to_string(),
commit_height,
]);
});
}

println!("{table}");

Ok(())
}

// TESTS
Expand Down Expand Up @@ -319,7 +331,7 @@ mod tests {
let (_, commited_notes, _, _) = mock_full_chain_mmr_and_notes(consumed_notes);

let committed_note: InputNoteRecord = commited_notes.first().unwrap().clone().into();
let pending_note = InputNoteRecord::new(created_notes.first().unwrap().clone(), None);
let pending_note = InputNoteRecord::from(created_notes.first().unwrap().clone());

client.import_input_note(committed_note.clone()).unwrap();
client.import_input_note(pending_note.clone()).unwrap();
Expand All @@ -332,18 +344,14 @@ mod tests {
let mut filename_path_pending = temp_dir();
filename_path_pending.push("test_import_pending");

export_note(
&client,
&committed_note.note_id().inner().to_string(),
Some(filename_path.clone()),
)
.unwrap();
export_note(&client, &committed_note.id().inner().to_string(), Some(filename_path.clone()))
.unwrap();

assert!(filename_path.exists());

export_note(
&client,
&pending_note.note_id().inner().to_string(),
&pending_note.id().inner().to_string(),
Some(filename_path_pending.clone()),
)
.unwrap();
Expand All @@ -368,14 +376,14 @@ mod tests {

import_note(&mut client, filename_path).unwrap();
let imported_note_record: InputNoteRecord =
client.get_input_note(committed_note.note().id()).unwrap();
client.get_input_note(committed_note.id()).unwrap();

assert_eq!(committed_note.note().id(), imported_note_record.note().id());
assert_eq!(committed_note.id(), imported_note_record.id());

import_note(&mut client, filename_path_pending).unwrap();
let imported_pending_note_record = client.get_input_note(pending_note.note().id()).unwrap();
let imported_pending_note_record = client.get_input_note(pending_note.id()).unwrap();

assert_eq!(imported_pending_note_record.note().id(), pending_note.note().id());
assert_eq!(imported_pending_note_record.id(), pending_note.id());
}

#[tokio::test]
Expand Down Expand Up @@ -410,19 +418,19 @@ mod tests {
let (_, notes, _, _) = mock_full_chain_mmr_and_notes(consumed_notes);

let committed_note: InputNoteRecord = notes.first().unwrap().clone().into();
let pending_note = InputNoteRecord::new(created_notes.first().unwrap().clone(), None);
let pending_note = InputNoteRecord::from(created_notes.first().unwrap().clone());

client.import_input_note(committed_note.clone()).unwrap();
client.import_input_note(pending_note.clone()).unwrap();
assert!(pending_note.inclusion_proof().is_none());
assert!(committed_note.inclusion_proof().is_some());

// Check that we can fetch Both notes
let note = get_note_with_id_prefix(&client, &committed_note.note_id().to_hex()).unwrap();
assert_eq!(note.note_id(), committed_note.note_id());
let note = get_note_with_id_prefix(&client, &committed_note.id().to_hex()).unwrap();
assert_eq!(note.id(), committed_note.id());

let note = get_note_with_id_prefix(&client, &pending_note.note_id().to_hex()).unwrap();
assert_eq!(note.note_id(), pending_note.note_id());
let note = get_note_with_id_prefix(&client, &pending_note.id().to_hex()).unwrap();
assert_eq!(note.id(), pending_note.id());

// Check that we get an error if many match
let note_id_with_many_matches = "0x";
Expand Down
4 changes: 2 additions & 2 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ pub(crate) fn get_note_with_id_prefix<N: NodeRpcClient, S: Store>(
NoteIdPrefixFetchError::NoMatch(note_id_prefix.to_string())
})?
.into_iter()
.filter(|note_record| note_record.note_id().to_hex().starts_with(note_id_prefix))
.filter(|note_record| note_record.id().to_hex().starts_with(note_id_prefix))
.collect::<Vec<_>>();

if input_note_records.is_empty() {
Expand All @@ -160,7 +160,7 @@ pub(crate) fn get_note_with_id_prefix<N: NodeRpcClient, S: Store>(
if input_note_records.len() > 1 {
let input_note_record_ids = input_note_records
.iter()
.map(|input_note_record| input_note_record.note_id())
.map(|input_note_record| input_note_record.id())
.collect::<Vec<_>>();
tracing::error!(
"Multiple notes found for the prefix {}: {:?}",
Expand Down
2 changes: 1 addition & 1 deletion src/cli/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ fn build_transaction_template<N: NodeRpcClient, S: Store>(
.iter()
.map(|note_id| {
get_note_with_id_prefix(client, note_id)
.map(|note_record| note_record.note_id())
.map(|note_record| note_record.id())
.map_err(|err| err.to_string())
})
.collect::<Result<Vec<NoteId>, _>>()?;
Expand Down
4 changes: 2 additions & 2 deletions src/client/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,14 @@ impl<N: NodeRpcClient, S: Store> Client<N, S> {
.store
.get_input_notes(NoteFilter::Pending)?
.iter()
.map(|n| n.note().id())
.map(|n| n.id())
.collect();

let pending_output_notes: Vec<NoteId> = self
.store
.get_output_notes(NoteFilter::Pending)?
.iter()
.map(|n| n.note().id())
.map(|n| n.id())
.collect();

let mut pending_notes = [pending_input_notes, pending_output_notes].concat();
Expand Down
2 changes: 1 addition & 1 deletion src/store/data_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl<S: Store> DataStore for ClientDataStore<S> {
.store
.get_input_notes(NoteFilter::Committed)?
.iter()
.map(|note_record| note_record.note_id())
.map(|note_record| note_record.id())
.collect::<Vec<_>>();

for note_id in notes {
Expand Down
Loading
Loading