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

Support for YAML export for consignments and stash dumps #31

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
47 changes: 25 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ required-features = ["cli"]
amplify = { workspace = true }
baid58 = { workspace = true }
strict_types = { workspace = true, features = ["serde"] }
commit_verify = "0.10.5"
commit_verify = { version = "0.10.5", features = ["serde"] }
bp-core = { version = "0.10.11", features = ["serde"] }
rgb-std = { workspace = true }
rgb-wallet = { workspace = true }
rgb-std = { workspace = true, features = ["serde"] }
rgb-wallet = { workspace = true, features = ["serde"] }
rgb-persist-fs = { version = "0.10.0", path = "fs" }
bitcoin = { version = "0.30.1", features = ["serde"] }
electrum-client = { version = "0.17.0", optional = true }
Expand All @@ -63,6 +63,8 @@ clap = { version = "4.1.8", features = ["derive", "env"], optional = true }
shellexpand = { version = "3.0.0", optional = true }
serde = "1.0.159"
serde_yaml = "0.9.19"
serde_json = "1.0.107"
toml = "0.8.2"

[features]
default = ["electrum", "log"]
Expand All @@ -72,3 +74,7 @@ cli = ["clap", "shellexpand", "log", "electrum"]

[package.metadata.docs.rs]
features = [ "all" ]

[patch.crates-io]
rgb-core = { git = "https://github.com/RGB-WG/rgb-core", branch = "fix/vm-serde" }
rgb-std = { git = "https://github.com/RGB-WG/rgb-wallet", branch = "master" }
48 changes: 24 additions & 24 deletions src/bin/rgb/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
// TODO: For now, serde implementation doesn't work for consignments due to
// some of the keys which can't be serialized to strings. Once this fixed,
// allow this inspect formats option
/*
#[derive(ValueEnum, Copy, Clone, Eq, PartialEq, Hash, Debug, Display, Default)]
#[display(lowercase)]
pub enum InspectFormat {
Expand All @@ -54,7 +53,6 @@
Debug,
Contractum,
}
*/

#[derive(Subcommand, Clone, PartialEq, Eq, Debug, Display)]
#[display(lowercase)]
Expand Down Expand Up @@ -179,9 +177,10 @@
/// Inspects any RGB data file.
#[display("inspect")]
Inspect {
// #[clap(short, long, default_value = "yaml")]
// /// Format used for data inspection
// format: InspectFormat,
#[clap(short, long, default_value = "yaml")]
/// Format used for data inspection
format: InspectFormat,

Check warning on line 182 in src/bin/rgb/command.rs

View check run for this annotation

Codecov / codecov/patch

src/bin/rgb/command.rs#L182

Added line #L182 was not covered by tests

/// RGB file to inspect.
file: PathBuf,
},
Expand Down Expand Up @@ -579,12 +578,12 @@
);
eprintln!("Stash data are updated.");
}
Command::Inspect { file } => {
Command::Inspect { file, format } => {

Check warning on line 581 in src/bin/rgb/command.rs

View check run for this annotation

Codecov / codecov/patch

src/bin/rgb/command.rs#L581

Added line #L581 was not covered by tests
let bindle = UniversalBindle::load(file)?;
// TODO: For now, serde implementation doesn't work for consignments due to
// some of the keys which can't be serialized to strings. Once this fixed,
// allow this inspect formats option
/* let s = match format {
let s = match format {

Check warning on line 586 in src/bin/rgb/command.rs

View check run for this annotation

Codecov / codecov/patch

src/bin/rgb/command.rs#L586

Added line #L586 was not covered by tests
InspectFormat::Yaml => {
serde_yaml::to_string(&bindle).expect("unable to present as YAML")
}
Expand All @@ -598,8 +597,6 @@
InspectFormat::Contractum => todo!("contractum representation"),
};
println!("{s}");
*/
println!("{bindle:#?}");
}
Command::Dump { root_dir } => {
fs::remove_dir_all(&root_dir).ok();
Expand All @@ -615,52 +612,55 @@
// Stash
for id in runtime.schema_ids()? {
fs::write(
format!("{root_dir}/stash/schemata/{id}.debug"),
format!("{:#?}", runtime.schema(id)?),
format!("{root_dir}/stash/schemata/{id}.yaml"),
serde_yaml::to_string(runtime.schema(id)?)?,

Check warning on line 616 in src/bin/rgb/command.rs

View check run for this annotation

Codecov / codecov/patch

src/bin/rgb/command.rs#L615-L616

Added lines #L615 - L616 were not covered by tests
)?;
}
for (id, name) in runtime.ifaces()? {
fs::write(
format!("{root_dir}/stash/ifaces/{id}.{name}.debug"),
format!("{:#?}", runtime.iface_by_id(id)?),
format!("{root_dir}/stash/ifaces/{id}.{name}.yaml"),
serde_yaml::to_string(runtime.iface_by_id(id)?)?,

Check warning on line 622 in src/bin/rgb/command.rs

View check run for this annotation

Codecov / codecov/patch

src/bin/rgb/command.rs#L621-L622

Added lines #L621 - L622 were not covered by tests
)?;
}
for id in runtime.contract_ids()? {
fs::write(
format!("{root_dir}/stash/geneses/{id}.debug"),
format!("{:#?}", runtime.genesis(id)?),
format!("{root_dir}/stash/geneses/{id}.yaml"),
serde_yaml::to_string(runtime.genesis(id)?)?,

Check warning on line 628 in src/bin/rgb/command.rs

View check run for this annotation

Codecov / codecov/patch

src/bin/rgb/command.rs#L627-L628

Added lines #L627 - L628 were not covered by tests
)?;
for (no, suppl) in runtime.contract_suppl(id).into_iter().flatten().enumerate()
{
fs::write(
format!("{root_dir}/stash/geneses/{id}.suppl.{no:03}.debug"),
format!("{:#?}", suppl),
format!("{root_dir}/stash/geneses/{id}.suppl.{no:03}.yaml"),
serde_yaml::to_string(suppl)?,

Check warning on line 634 in src/bin/rgb/command.rs

View check run for this annotation

Codecov / codecov/patch

src/bin/rgb/command.rs#L633-L634

Added lines #L633 - L634 were not covered by tests
)?;
}
}
for id in runtime.bundle_ids()? {
fs::write(
format!("{root_dir}/stash/bundles/{id}.debug"),
format!("{:#?}", runtime.bundle(id)?),
format!("{root_dir}/stash/bundles/{id}.yaml"),
serde_yaml::to_string(runtime.bundle(id)?)?,

Check warning on line 641 in src/bin/rgb/command.rs

View check run for this annotation

Codecov / codecov/patch

src/bin/rgb/command.rs#L640-L641

Added lines #L640 - L641 were not covered by tests
)?;
}
for id in runtime.anchor_ids()? {
fs::write(
format!("{root_dir}/stash/anchors/{id}.debug"),
format!("{:#?}", runtime.anchor(id)?),
format!("{root_dir}/stash/anchors/{id}.yaml"),
serde_yaml::to_string(runtime.anchor(id)?)?,

Check warning on line 647 in src/bin/rgb/command.rs

View check run for this annotation

Codecov / codecov/patch

src/bin/rgb/command.rs#L646-L647

Added lines #L646 - L647 were not covered by tests
)?;
}
for id in runtime.extension_ids()? {
fs::write(
format!("{root_dir}/stash/extensions/{id}.debug"),
format!("{:#?}", runtime.extension(id)?),
format!("{root_dir}/stash/extensions/{id}.yaml"),
serde_yaml::to_string(runtime.extension(id)?)?,

Check warning on line 653 in src/bin/rgb/command.rs

View check run for this annotation

Codecov / codecov/patch

src/bin/rgb/command.rs#L652-L653

Added lines #L652 - L653 were not covered by tests
)?;
}
// TODO: Add sigs debugging

// State
for (id, history) in runtime.debug_history() {
fs::write(format!("{root_dir}/state/{id}.debug"), format!("{:#?}", history))?;
fs::write(
format!("{root_dir}/state/{id}.yaml"),
serde_yaml::to_string(history)?,
)?;

Check warning on line 663 in src/bin/rgb/command.rs

View check run for this annotation

Codecov / codecov/patch

src/bin/rgb/command.rs#L661-L663

Added lines #L661 - L663 were not covered by tests
}

// Index
Expand Down
Loading