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

Move postage into batch file #2705

Merged
merged 5 commits into from
Nov 20, 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
3 changes: 3 additions & 0 deletions batch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ mode: separate-outputs
# parent inscription:
parent: 6ac5cacb768794f4fd7a78bf00f2074891fce68bd65c4ff36e77177237aacacai0

# postage for each inscription:
postage: 12345

# inscriptions to inscribe
#
# each inscription has the following fields:
Expand Down
17 changes: 13 additions & 4 deletions src/subcommand/wallet/inscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub(crate) struct Inscribe {
long,
help = "Inscribe a multiple inscriptions defines in a yaml <BATCH_FILE>.",
conflicts_with_all = &[
"file", "destination", "cbor_metadata", "json_metadata", "satpoint", "reinscribe", "metaprotocol", "parent"
"cbor_metadata", "destination", "file", "json_metadata", "metaprotocol", "parent", "postage", "reinscribe", "satpoint"
]
)]
pub(crate) batch: Option<PathBuf>,
Expand Down Expand Up @@ -123,8 +123,7 @@ impl Inscribe {

let chain = options.chain();

let postage = self.postage.unwrap_or(TransactionBuilder::TARGET_POSTAGE);

let postage;
let destinations;
let inscriptions;
let mode;
Expand All @@ -133,6 +132,9 @@ impl Inscribe {
match (self.file, self.batch) {
(Some(file), None) => {
parent_info = Inscribe::get_parent_info(self.parent, &index, &utxos, &client, chain)?;

postage = self.postage.unwrap_or(TransactionBuilder::TARGET_POSTAGE);
raphjaph marked this conversation as resolved.
Show resolved Hide resolved

inscriptions = vec![Inscription::from_file(
chain,
file,
Expand All @@ -142,7 +144,9 @@ impl Inscribe {
metadata,
self.compress,
)?];

mode = Mode::SeparateOutputs;

destinations = vec![match self.destination.clone() {
Some(destination) => destination.require_network(chain.network())?,
None => get_change_address(&client, chain)?,
Expand All @@ -153,6 +157,11 @@ impl Inscribe {

parent_info = Inscribe::get_parent_info(batchfile.parent, &index, &utxos, &client, chain)?;

postage = batchfile
.postage
.map(Amount::from_sat)
.unwrap_or(TransactionBuilder::TARGET_POSTAGE);

inscriptions = batchfile.inscriptions(
chain,
parent_info.as_ref().map(|info| info.tx_out.value),
Expand Down Expand Up @@ -797,7 +806,7 @@ inscriptions:
}
],
parent: Some(parent),
mode: Mode::SeparateOutputs,
..Default::default()
}
);
}
Expand Down
6 changes: 4 additions & 2 deletions src/subcommand/wallet/inscribe/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,9 @@ impl Batch {
}
}

#[derive(PartialEq, Debug, Copy, Clone, Serialize, Deserialize)]
#[derive(PartialEq, Debug, Copy, Clone, Serialize, Deserialize, Default)]
pub(crate) enum Mode {
#[default]
#[serde(rename = "separate-outputs")]
SeparateOutputs,
#[serde(rename = "shared-output")]
Expand Down Expand Up @@ -547,12 +548,13 @@ impl BatchEntry {
}
}

#[derive(Deserialize, PartialEq, Debug, Clone)]
#[derive(Deserialize, PartialEq, Debug, Clone, Default)]
#[serde(deny_unknown_fields)]
pub(crate) struct Batchfile {
pub(crate) inscriptions: Vec<BatchEntry>,
pub(crate) mode: Mode,
pub(crate) parent: Option<InscriptionId>,
pub(crate) postage: Option<u64>,
}

impl Batchfile {
Expand Down
8 changes: 4 additions & 4 deletions tests/wallet/inscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1014,13 +1014,13 @@ fn batch_in_same_output_with_non_default_postage() {

create_wallet(&rpc_server);

let output = CommandBuilder::new("wallet inscribe --fee-rate 1 --batch batch.yaml --postage 777sat")
let output = CommandBuilder::new("wallet inscribe --fee-rate 1 --batch batch.yaml")
.write("inscription.txt", "Hello World")
.write("tulip.png", [0; 555])
.write("meow.wav", [0; 2048])
.write(
"batch.yaml",
"mode: shared-output\ninscriptions:\n- file: inscription.txt\n- file: tulip.png\n- file: meow.wav\n"
"mode: shared-output\npostage: 777\ninscriptions:\n- file: inscription.txt\n- file: tulip.png\n- file: meow.wav\n"
)
.rpc_server(&rpc_server)
.run_and_deserialize_output::<Inscribe>();
Expand Down Expand Up @@ -1168,13 +1168,13 @@ fn batch_in_separate_outputs_with_parent_and_non_default_postage() {

let parent_id = parent_output.inscriptions[0].id;

let output = CommandBuilder::new("wallet inscribe --fee-rate 1 --batch batch.yaml --postage 777sat")
let output = CommandBuilder::new("wallet inscribe --fee-rate 1 --batch batch.yaml")
.write("inscription.txt", "Hello World")
.write("tulip.png", [0; 555])
.write("meow.wav", [0; 2048])
.write(
"batch.yaml",
format!("parent: {parent_id}\nmode: separate-outputs\ninscriptions:\n- file: inscription.txt\n- file: tulip.png\n- file: meow.wav\n")
format!("parent: {parent_id}\nmode: separate-outputs\npostage: 777\ninscriptions:\n- file: inscription.txt\n- file: tulip.png\n- file: meow.wav\n")
)
.rpc_server(&rpc_server)
.run_and_deserialize_output::<Inscribe>();
Expand Down