-
Notifications
You must be signed in to change notification settings - Fork 44
Feat: add mithril-client
CLI command for UTxO-HD ledger state snapshot conversion
#2518
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
Draft
dlachaume
wants to merge
4
commits into
main
Choose a base branch
from
dlachaume/2492/add-client-cli-command-for-utxo-hd-ledger-state-snapshot-conversion
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5cc0614
feat(client-cli): scaffold new command to convert ledger state snapshots
dlachaume 3d9aadf
feat(client-cli): implement download of Cardano node distribution to …
dlachaume 063d2c3
feat(client-cli): implement unpack of Cardano node distribution
dlachaume cc19034
[WIP]feat(client-cli): execute the `snapshot-converter` binary
dlachaume File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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
16 changes: 16 additions & 0 deletions
16
mithril-client-cli/src/commands/tools/archive_unpacker/mod.rs
This file contains hidden or 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,16 @@ | ||
mod tar_gz_unpacker; | ||
mod zip_unpacker; | ||
|
||
pub use tar_gz_unpacker::*; | ||
pub use zip_unpacker::*; | ||
|
||
use mithril_client::MithrilResult; | ||
use std::path::Path; | ||
|
||
#[cfg_attr(test, mockall::automock)] | ||
pub trait ArchiveUnpacker { | ||
fn unpack(&self, archive_path: &Path, unpack_dir: &Path) -> MithrilResult<()>; | ||
|
||
#[cfg(test)] | ||
fn as_any(&self) -> &dyn std::any::Any; | ||
} |
89 changes: 89 additions & 0 deletions
89
mithril-client-cli/src/commands/tools/archive_unpacker/tar_gz_unpacker.rs
This file contains hidden or 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 std::{fs::File, path::Path}; | ||
|
||
use anyhow::Context; | ||
use flate2::read::GzDecoder; | ||
use tar::Archive; | ||
|
||
use mithril_client::MithrilResult; | ||
|
||
use super::ArchiveUnpacker; | ||
|
||
#[derive(Debug, Eq, PartialEq)] | ||
pub struct TarGzUnpacker; | ||
|
||
impl ArchiveUnpacker for TarGzUnpacker { | ||
fn unpack(&self, archive_path: &Path, unpack_dir: &Path) -> MithrilResult<()> { | ||
let archive = File::open(archive_path) | ||
.with_context(|| format!("Could not open archive file '{}'", archive_path.display()))?; | ||
let gzip_decoder = GzDecoder::new(archive); | ||
let mut file_archive = Archive::new(gzip_decoder); | ||
file_archive.unpack(unpack_dir).with_context(|| { | ||
format!( | ||
"Could not unpack '{}' with 'Gzip' to directory '{}'", | ||
archive_path.display(), | ||
unpack_dir.display() | ||
) | ||
})?; | ||
|
||
Ok(()) | ||
} | ||
|
||
#[cfg(test)] | ||
fn as_any(&self) -> &dyn std::any::Any { | ||
self | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use std::fs::{self, File}; | ||
|
||
use flate2::{write::GzEncoder, Compression}; | ||
use tar::{Builder, Header}; | ||
|
||
use mithril_common::temp_dir_create; | ||
|
||
use super::*; | ||
|
||
#[test] | ||
fn unpack_tar_archive_extracts_all_files() { | ||
let temp_dir = temp_dir_create!(); | ||
let archive_path = temp_dir.join("archive.tar.gz"); | ||
|
||
{ | ||
let tar_gz_file = File::create(&archive_path).unwrap(); | ||
let encoder = GzEncoder::new(tar_gz_file, Compression::default()); | ||
let mut tar_builder = Builder::new(encoder); | ||
|
||
let content = b"root content"; | ||
let mut header = Header::new_gnu(); | ||
header.set_size(content.len() as u64); | ||
header.set_cksum(); | ||
tar_builder | ||
.append_data(&mut header, "root.txt", &content[..]) | ||
.unwrap(); | ||
|
||
let content = b"nested content"; | ||
let mut header = Header::new_gnu(); | ||
header.set_size(content.len() as u64); | ||
header.set_cksum(); | ||
tar_builder | ||
.append_data(&mut header, "nested/dir/nested-file.txt", &content[..]) | ||
.unwrap(); | ||
|
||
tar_builder.finish().unwrap(); | ||
} | ||
|
||
TarGzUnpacker.unpack(&archive_path, &temp_dir).unwrap(); | ||
|
||
let root_file = temp_dir.join("root.txt"); | ||
assert!(root_file.exists()); | ||
let root_file_content = fs::read_to_string(&root_file).unwrap(); | ||
assert_eq!(root_file_content, "root content"); | ||
|
||
let nested_file = temp_dir.join("nested/dir/nested-file.txt"); | ||
assert!(nested_file.exists()); | ||
let nested_file_content = fs::read_to_string(&nested_file).unwrap(); | ||
assert_eq!(nested_file_content, "nested content"); | ||
Comment on lines
+79
to
+87
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: You could use assert_dir_eq for the existence check. |
||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The workspace only specify the minimal set of shared features for reqwest since we don't want to force them on downstream library users.
For our binaries we needs a bit more: