From c3c20b8225152e0bcb552a1f7c271dbfc0f9a76f Mon Sep 17 00:00:00 2001 From: raphjaph Date: Thu, 1 Dec 2022 23:22:35 +0100 Subject: [PATCH 1/2] refuse to reinscribe sats --- src/subcommand/wallet/inscribe.rs | 7 +++++++ tests/wallet.rs | 29 +++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/subcommand/wallet/inscribe.rs b/src/subcommand/wallet/inscribe.rs index 3dc81aa62a..7ed42acafa 100644 --- a/src/subcommand/wallet/inscribe.rs +++ b/src/subcommand/wallet/inscribe.rs @@ -33,6 +33,13 @@ impl Inscribe { let inscription_satpoints = index.get_inscription_satpoints()?; + if inscription_satpoints.contains(&self.satpoint) { + return Err(anyhow!( + "sat at {} already inscribed", + self.satpoint + )); + } + let commit_tx_change = get_change_addresses(&options, 2)?; let reveal_tx_destination = get_change_addresses(&options, 1)?[0].clone(); diff --git a/tests/wallet.rs b/tests/wallet.rs index 2b455825db..9d8f2b96bb 100644 --- a/tests/wallet.rs +++ b/tests/wallet.rs @@ -385,3 +385,32 @@ fn send_does_not_use_inscribed_sats_as_cardinal_utxos() { .expected_stderr("error: wallet does not contain enough cardinal UTXOs, please add additional funds to wallet.\n") .run(); } + +#[test] +fn refuse_to_reinscribe_sats() { + let rpc_server = test_bitcoincore_rpc::spawn_with(Network::Regtest, "ord"); + + let txid = rpc_server.mine_blocks_with_subsidy(1, 800)[0].txdata[0].txid(); + let stdout = CommandBuilder::new(format!( + "--chain regtest wallet inscribe --satpoint {txid}:0:0 --file degenerate.png" + )) + .write("degenerate.png", [1; 100]) + .rpc_server(&rpc_server) + .stdout_regex("commit\t[[:xdigit:]]{64}\nreveal\t[[:xdigit:]]{64}\n") + .run(); + + let first_inscription_id = stdout.split("reveal\t").collect::>()[1].trim(); + + rpc_server.mine_blocks_with_subsidy(1, 100)[0].txdata[0].txid(); + + CommandBuilder::new(format!( + "--chain regtest wallet inscribe --satpoint {first_inscription_id}:0:0 --file hello.txt" + )) + .write("hello.txt", "HELLOWORLD") + .rpc_server(&rpc_server) + .expected_exit_code(1) + .expected_stderr(format!( + "error: sat at {first_inscription_id}:0:0 already inscribed\n" + )) + .run(); +} From 5249bfdc9ba74edb3c7ad06686396442953a51ce Mon Sep 17 00:00:00 2001 From: raphjaph Date: Thu, 1 Dec 2022 23:28:50 +0100 Subject: [PATCH 2/2] rebase --- src/subcommand/wallet/inscribe.rs | 5 +---- tests/wallet.rs | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/subcommand/wallet/inscribe.rs b/src/subcommand/wallet/inscribe.rs index 7ed42acafa..82ef5bfaac 100644 --- a/src/subcommand/wallet/inscribe.rs +++ b/src/subcommand/wallet/inscribe.rs @@ -34,10 +34,7 @@ impl Inscribe { let inscription_satpoints = index.get_inscription_satpoints()?; if inscription_satpoints.contains(&self.satpoint) { - return Err(anyhow!( - "sat at {} already inscribed", - self.satpoint - )); + return Err(anyhow!("sat at {} already inscribed", self.satpoint)); } let commit_tx_change = get_change_addresses(&options, 2)?; diff --git a/tests/wallet.rs b/tests/wallet.rs index 9d8f2b96bb..88bebdce37 100644 --- a/tests/wallet.rs +++ b/tests/wallet.rs @@ -399,7 +399,7 @@ fn refuse_to_reinscribe_sats() { .stdout_regex("commit\t[[:xdigit:]]{64}\nreveal\t[[:xdigit:]]{64}\n") .run(); - let first_inscription_id = stdout.split("reveal\t").collect::>()[1].trim(); + let first_inscription_id = reveal_txid_from_inscribe_stdout(&stdout); rpc_server.mine_blocks_with_subsidy(1, 100)[0].txdata[0].txid();