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

Add batch to preview command #2752

Merged
merged 17 commits into from
Nov 27, 2023
102 changes: 76 additions & 26 deletions src/subcommand/preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,24 @@ use {super::*, fee_rate::FeeRate};
pub(crate) struct Preview {
#[command(flatten)]
server: super::server::Server,
inscriptions: Vec<PathBuf>,
#[arg(
num_args = 0..,
long,
help = "Inscribe inscriptions defined in <BATCHES>."
)]
batches: Option<Vec<PathBuf>>,
#[arg(num_args = 0.., long, help = "Inscribe contents of <FILES>.")]
files: Option<Vec<PathBuf>>,
}

#[derive(Debug, Parser)]
pub(crate) struct Batch {
batch_files: Vec<PathBuf>,
}

#[derive(Debug, Parser)]
pub(crate) struct File {
files: Vec<PathBuf>,
}

struct KillOnDrop(process::Child);
Expand Down Expand Up @@ -74,33 +91,66 @@ impl Preview {

rpc_client.generate_to_address(101, &address)?;

for file in self.inscriptions {
Arguments {
options: options.clone(),
subcommand: Subcommand::Wallet(super::wallet::Wallet::Inscribe(
super::wallet::inscribe::Inscribe {
batch: None,
cbor_metadata: None,
commit_fee_rate: None,
compress: false,
destination: None,
dry_run: false,
fee_rate: FeeRate::try_from(1.0).unwrap(),
file: Some(file),
json_metadata: None,
metaprotocol: None,
no_backup: true,
no_limit: false,
parent: None,
postage: Some(TransactionBuilder::TARGET_POSTAGE),
reinscribe: false,
satpoint: None,
},
)),
if let Some(files) = self.files {
for file in files {
Arguments {
options: options.clone(),
subcommand: Subcommand::Wallet(super::wallet::Wallet::Inscribe(
super::wallet::inscribe::Inscribe {
batch: None,
cbor_metadata: None,
commit_fee_rate: None,
compress: false,
destination: None,
dry_run: false,
fee_rate: FeeRate::try_from(1.0).unwrap(),
file: Some(file),
json_metadata: None,
metaprotocol: None,
no_backup: true,
no_limit: false,
parent: None,
postage: Some(TransactionBuilder::TARGET_POSTAGE),
reinscribe: false,
satpoint: None,
},
)),
}
.run()?;

rpc_client.generate_to_address(1, &address)?;
}
.run()?;
}

rpc_client.generate_to_address(1, &address)?;
if let Some(batches) = self.batches {
for batch in batches {
Arguments {
options: options.clone(),
subcommand: Subcommand::Wallet(super::wallet::Wallet::Inscribe(
super::wallet::inscribe::Inscribe {
batch: Some(batch),
cbor_metadata: None,
commit_fee_rate: None,
compress: false,
destination: None,
dry_run: false,
fee_rate: FeeRate::try_from(1.0).unwrap(),
file: None,
json_metadata: None,
metaprotocol: None,
no_backup: true,
no_limit: false,
parent: None,
postage: Some(TransactionBuilder::TARGET_POSTAGE),
reinscribe: false,
satpoint: None,
},
)),
}
.run()?;

rpc_client.generate_to_address(1, &address)?;
}
}

rpc_client.generate_to_address(1, &address)?;
Expand Down
2 changes: 1 addition & 1 deletion src/subcommand/wallet/inscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub(crate) struct ParentInfo {
pub(crate) struct Inscribe {
#[arg(
long,
help = "Inscribe a multiple inscriptions defines in a yaml <BATCH_FILE>.",
help = "Inscribe multiple inscriptions defined in a yaml <BATCH_FILE>.",
conflicts_with_all = &[
"cbor_metadata", "destination", "file", "json_metadata", "metaprotocol", "parent", "postage", "reinscribe", "satpoint"
]
Expand Down
41 changes: 17 additions & 24 deletions tests/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,22 @@ fn preview() {
.unwrap()
.port();

let examples = fs::read_dir("examples")
.unwrap()
.map(|entry| {
entry
.unwrap()
.path()
.canonicalize()
.unwrap()
.to_str()
.unwrap()
.into()
})
.filter(|example| example != "examples/av1.mp4")
.collect::<Vec<String>>();

let mut args = vec![
"preview".to_string(),
"--http-port".to_string(),
port.to_string(),
];
args.extend(examples.clone());

let builder = CommandBuilder::new(args);
let builder = CommandBuilder::new(format!(
"preview --http-port {port} --files alert.html inscription.txt --batches batch_1.yaml batch_2.yaml"
))
.write("inscription.txt", "Hello World")
.write("alert.html", "<script>alert('LFG!')</script>")
.write("poem.txt", "Sphinx of black quartz, judge my vow.")
.write("tulip.png", [0; 555])
.write("meow.wav", [0; 2048])
.write(
"batch_1.yaml",
"mode: shared-output\ninscriptions:\n- file: poem.txt\n- file: tulip.png\n",
)
.write(
"batch_2.yaml",
"mode: shared-output\ninscriptions:\n- file: meow.wav\n",
);

let _child = KillOnDrop(builder.command().spawn().unwrap());

Expand All @@ -67,6 +60,6 @@ fn preview() {
.unwrap()
.text()
.unwrap(),
format!(".*(<a href=/inscription/.*){{{}}}.*", examples.len())
format!(".*(<a href=/inscription/.*){{{}}}.*", 5)
);
}
Loading