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 reinscribe option to batch file #3220

Merged
merged 7 commits into from
Mar 5, 2024
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 @@ -13,6 +13,9 @@ parent: 6ac5cacb768794f4fd7a78bf00f2074891fce68bd65c4ff36e77177237aacacai0
# postage for each inscription:
postage: 12345

# allow reinscribing
reinscribe: true

# sat to inscribe on, can only be used with `same-sat`:
# sat: 5000000000

Expand Down
7 changes: 6 additions & 1 deletion src/subcommand/wallet/inscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ impl Inscribe {
let inscriptions;
let mode;
let parent_info;
let reinscribe;
let reveal_satpoints;

let satpoint = match (self.file, self.batch) {
Expand Down Expand Up @@ -115,6 +116,8 @@ impl Inscribe {

mode = Mode::SeparateOutputs;

reinscribe = self.reinscribe;

reveal_satpoints = Vec::new();

destinations = vec![match self.destination.clone() {
Expand Down Expand Up @@ -148,6 +151,8 @@ impl Inscribe {

mode = batchfile.mode;

reinscribe = batchfile.reinscribe;

if let Some(sat) = batchfile.sat {
Some(wallet.find_sat_in_outputs(sat)?)
} else {
Expand All @@ -167,7 +172,7 @@ impl Inscribe {
no_limit: self.no_limit,
parent_info,
postages,
reinscribe: self.reinscribe,
reinscribe,
reveal_fee_rate: self.fee_rate,
reveal_satpoints,
satpoint,
Expand Down
2 changes: 2 additions & 0 deletions src/wallet/inscribe/batch_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ pub struct Batchfile {
pub(crate) mode: Mode,
pub(crate) parent: Option<InscriptionId>,
pub(crate) postage: Option<u64>,
#[serde(default)]
pub(crate) reinscribe: bool,
pub(crate) sat: Option<Sat>,
pub(crate) satpoint: Option<SatPoint>,
}
Expand Down
98 changes: 98 additions & 0 deletions tests/wallet/inscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1754,6 +1754,104 @@ fn batch_same_sat_with_parent() {
);
}

#[test]
fn batch_same_sat_with_satpoint_and_reinscription() {
let bitcoin_rpc_server = test_bitcoincore_rpc::spawn();

let ord_rpc_server = TestServer::spawn_with_server_args(&bitcoin_rpc_server, &[], &[]);

create_wallet(&bitcoin_rpc_server, &ord_rpc_server);

bitcoin_rpc_server.mine_blocks(1);

let output = CommandBuilder::new("wallet inscribe --fee-rate 5.0 --file parent.png")
.write("parent.png", [1; 520])
.bitcoin_rpc_server(&bitcoin_rpc_server)
.ord_rpc_server(&ord_rpc_server)
.run_and_deserialize_output::<Inscribe>();

bitcoin_rpc_server.mine_blocks(1);

let inscription_id = output.inscriptions[0].id;
let satpoint = output.inscriptions[0].location;

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!("mode: same-sat\nsatpoint: {}\ninscriptions:\n- file: inscription.txt\n- file: tulip.png\n- file: meow.wav\n", satpoint)
)
.bitcoin_rpc_server(&bitcoin_rpc_server)
.ord_rpc_server(&ord_rpc_server)
.expected_exit_code(1)
.stderr_regex(".*error: sat at .*:0:0 already inscribed.*")
.run_and_extract_stdout();

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!("mode: same-sat\nsatpoint: {}\nreinscribe: true\ninscriptions:\n- file: inscription.txt\n- file: tulip.png\n- file: meow.wav\n", satpoint)
)
.bitcoin_rpc_server(&bitcoin_rpc_server)
.ord_rpc_server(&ord_rpc_server)
.run_and_deserialize_output::<Inscribe>();

assert_eq!(
output.inscriptions[0].location,
output.inscriptions[1].location
);
assert_eq!(
output.inscriptions[1].location,
output.inscriptions[2].location
);

bitcoin_rpc_server.mine_blocks(1);

let outpoint = output.inscriptions[0].location.outpoint;

ord_rpc_server.assert_response_regex(
format!("/inscription/{}", inscription_id),
format!(
r".*<dt>location</dt>.*<dd class=monospace>{}:0</dd>.*",
outpoint
),
);

ord_rpc_server.assert_response_regex(
format!("/inscription/{}", output.inscriptions[0].id),
format!(
r".*<dt>location</dt>.*<dd class=monospace>{}:0</dd>.*",
outpoint
),
);

ord_rpc_server.assert_response_regex(
format!("/inscription/{}", output.inscriptions[1].id),
format!(
r".*<dt>location</dt>.*<dd class=monospace>{}:0</dd>.*",
outpoint
),
);

ord_rpc_server.assert_response_regex(
format!("/inscription/{}", output.inscriptions[2].id),
format!(
r".*<dt>location</dt>.*<dd class=monospace>{}:0</dd>.*",
outpoint
),
);

ord_rpc_server.assert_response_regex(
format!("/output/{}", output.inscriptions[0].location.outpoint),
format!(r".*<a href=/inscription/{}>.*</a>.*<a href=/inscription/{}>.*</a>.*<a href=/inscription/{}>.*</a>.*<a href=/inscription/{}>.*</a>.*", inscription_id, output.inscriptions[0].id, output.inscriptions[1].id, output.inscriptions[2].id),
);
}

#[test]
fn inscribe_with_sat_arg() {
let bitcoin_rpc_server = test_bitcoincore_rpc::spawn();
Expand Down
Loading