Skip to content

Commit

Permalink
cli: draft command to reconstruct consignment from YAML
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Mar 7, 2024
1 parent db84558 commit 2132a79
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use std::fs::File;
use std::path::PathBuf;
use std::str::FromStr;

use amplify::confinement::{SmallOrdMap, TinyOrdMap, TinyOrdSet, U16};
use amplify::confinement::{SmallOrdMap, TinyOrdMap, TinyOrdSet, U16 as MAX16, U32 as MAX32};
use baid58::ToBaid58;
use bp_util::{BpCommand, Config, Exec};
use bpstd::Sats;
Expand All @@ -45,7 +45,7 @@ use rgbstd::vm::RgbIsa;
use rgbstd::{AssetTag, AssignmentType, BundleId, OutputSeal, XChain, XOutputSeal};
use seals::txout::CloseMethod;
use serde_crate::{Deserialize, Serialize};
use strict_types::encoding::{FieldName, TypeName};
use strict_types::encoding::{FieldName, StrictSerialize, TypeName};
use strict_types::StrictVal;

use crate::RgbArgs;
Expand Down Expand Up @@ -247,6 +247,18 @@ pub enum Command {
dir: bool,
},

/// Reconstructs consignment from a YAML file
#[display("reconstruct")]
#[clap(hide = true)]
Reconstruct {
/// RGB file with the consignment YAML data
src: PathBuf,

/// Path for the resulting consignment file. If not given, prints the
/// consignment to STDOUT.
dst: Option<PathBuf>,
},

/// Debug-dump all stash and inventory data
#[display("dump")]
Dump {
Expand Down Expand Up @@ -559,7 +571,7 @@ impl Exec for RgbArgs {
.expect("global type doesn't match type definition");

let serialized = types
.strict_serialize_type::<U16>(&typed_val)
.strict_serialize_type::<MAX16>(&typed_val)
.expect("internal error");
// Workaround for borrow checker:
let field_name =
Expand Down Expand Up @@ -854,6 +866,17 @@ impl Exec for RgbArgs {
}
None
}
Command::Reconstruct { src, dst } => {
let file = File::open(src)?;
let transfer: Bindle<Transfer> = serde_yaml::from_reader(&file)?;
match dst {
None => println!("{transfer}"),
Some(dst) => {
transfer.strict_serialize_to_file::<MAX32>(dst)?;
}
}
None
}
Command::Dump { root_dir } => {
let runtime = self.rgb_runtime(&config)?;

Expand Down

0 comments on commit 2132a79

Please sign in to comment.