Skip to content

Commit

Permalink
Refuse to inscribe sats that have already been inscribe (#878)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphjaph authored Dec 1, 2022
1 parent c991229 commit 8ded343
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/subcommand/wallet/inscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ 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();
Expand Down
29 changes: 29 additions & 0 deletions tests/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = reveal_txid_from_inscribe_stdout(&stdout);

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();
}

0 comments on commit 8ded343

Please sign in to comment.