Skip to content

Commit

Permalink
Refuse to send inscriptions by satpoint (#898)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Dec 6, 2022
1 parent 90c90c3 commit 936a431
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
13 changes: 10 additions & 3 deletions src/subcommand/wallet/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl FromStr for Reference {

#[derive(Debug, Parser)]
pub(crate) struct Send {
reference: Reference,
outgoing: Reference,
address: Address,
}

Expand All @@ -45,8 +45,15 @@ impl Send {

let change = get_change_addresses(&options, 2)?;

let satpoint = match self.reference {
Reference::SatPoint(satpoint) => satpoint,
let satpoint = match self.outgoing {
Reference::SatPoint(satpoint) => {
for inscription_satpoint in inscriptions.keys() {
if satpoint == *inscription_satpoint {
bail!("inscriptions must be sent by inscription ID");
}
}
satpoint
}
Reference::InscriptionId(txid) => match index.get_inscription_by_inscription_id(txid)? {
Some((_inscription, satpoint)) => satpoint,
None => bail!("No inscription found for {txid}"),
Expand Down
2 changes: 1 addition & 1 deletion tests/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ HELLOWORLD.*",
);

let txid = CommandBuilder::new(format!(
"--chain regtest wallet send {reveal_txid}:0:0 bcrt1q6rhpng9evdsfnn833a4f4vej0asu6dk5srld6x"
"--chain regtest wallet send {reveal_txid} bcrt1q6rhpng9evdsfnn833a4f4vej0asu6dk5srld6x"
))
.write("hello.txt", "HELLOWORLD")
.rpc_server(&rpc_server)
Expand Down
29 changes: 28 additions & 1 deletion tests/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ fn send_works_on_signet() {
rpc_server.mine_blocks(1);

let stdout = CommandBuilder::new(format!(
"--chain signet wallet send {reveal_txid}:0:0 tb1qx4gf3ya0cxfcwydpq8vr2lhrysneuj5d7lqatw"
"--chain signet wallet send {reveal_txid} tb1qx4gf3ya0cxfcwydpq8vr2lhrysneuj5d7lqatw"
))
.rpc_server(&rpc_server)
.stdout_regex(r".*")
Expand Down Expand Up @@ -495,3 +495,30 @@ fn refuse_to_inscribe_already_inscribed_utxo() {
))
.run();
}

#[test]
fn inscriptions_cannot_be_sent_by_satpoint() {
let rpc_server = test_bitcoincore_rpc::spawn_with(Network::Regtest, "ord");
let txid = rpc_server.mine_blocks(1)[0].txdata[0].txid();

let stdout = CommandBuilder::new(format!(
"--chain regtest wallet inscribe --satpoint {txid}:0:0 --file hello.txt"
))
.write("hello.txt", "HELLOWORLD")
.rpc_server(&rpc_server)
.stdout_regex("commit\t[[:xdigit:]]{64}\nreveal\t[[:xdigit:]]{64}\n")
.run();

let reveal_txid = stdout.split("reveal\t").collect::<Vec<&str>>()[1].trim();

rpc_server.mine_blocks(1);

CommandBuilder::new(format!(
"--chain regtest wallet send {reveal_txid}:0:0 bcrt1q6rhpng9evdsfnn833a4f4vej0asu6dk5srld6x"
))
.write("hello.txt", "HELLOWORLD")
.rpc_server(&rpc_server)
.expected_stderr("error: inscriptions must be sent by inscription ID\n")
.expected_exit_code(1)
.run();
}

0 comments on commit 936a431

Please sign in to comment.