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 57 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
98 changes: 54 additions & 44 deletions src/cli/input_notes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,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},
DataStore,
Expand Down Expand Up @@ -120,7 +123,7 @@ fn list_input_notes<N: NodeRpcClient, S: Store, D: DataStore>(
filter: ClientNoteFilter,
) -> Result<(), String> {
let notes = client.get_input_notes(filter)?;
print_notes_summary(&notes);
print_notes_summary(&notes)?;
Ok(())
}

Expand Down Expand Up @@ -166,7 +169,7 @@ pub fn import_note<N: NodeRpcClient, S: Store, D: DataStore>(
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 @@ -185,7 +188,7 @@ fn show_input_note<N: NodeRpcClient, S: Store, D: DataStore>(
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 @@ -194,14 +197,17 @@ fn show_input_note<N: NodeRpcClient, S: Store, D: DataStore>(

// 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 @@ -210,34 +216,32 @@ fn show_input_note<N: NodeRpcClient, S: Store, D: DataStore>(
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 @@ -246,7 +250,7 @@ fn show_input_note<N: NodeRpcClient, S: Store, D: DataStore>(

// 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 @@ -259,22 +263,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 @@ -327,7 +340,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 @@ -342,7 +355,7 @@ mod tests {

export_note(
&client,
&committed_note.note_id().inner().to_string(),
&committed_note.id().inner().to_string(),
Some(filename_path.clone()),
)
.unwrap();
Expand All @@ -351,7 +364,7 @@ mod tests {

export_note(
&client,
&pending_note.note_id().inner().to_string(),
&pending_note.id().inner().to_string(),
Some(filename_path_pending.clone()),
)
.unwrap();
Expand Down Expand Up @@ -380,17 +393,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 @@ -431,19 +441,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 @@ -173,7 +173,7 @@ pub(crate) fn get_note_with_id_prefix<N: NodeRpcClient, S: Store, D: DataStore>(
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 @@ -182,7 +182,7 @@ pub(crate) fn get_note_with_id_prefix<N: NodeRpcClient, S: Store, D: DataStore>(
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 @@ -148,7 +148,7 @@ fn build_transaction_template<N: NodeRpcClient, S: Store, D: DataStore>(
.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 @@ -212,14 +212,14 @@ impl<N: NodeRpcClient, S: Store, D: DataStore> Client<N, S, D> {
.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 @@ -37,7 +37,7 @@ impl DataStore for SqliteDataStore {
.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