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

Allow setting the sat to inscribe #2765

Merged
merged 6 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 2 additions & 0 deletions src/subcommand/preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ impl Preview {
postage: Some(TransactionBuilder::TARGET_POSTAGE),
reinscribe: false,
satpoint: None,
sat: None,
},
)),
}
Expand Down Expand Up @@ -144,6 +145,7 @@ impl Preview {
postage: Some(TransactionBuilder::TARGET_POSTAGE),
reinscribe: false,
satpoint: None,
sat: None,
},
)),
}
Expand Down
34 changes: 33 additions & 1 deletion src/subcommand/wallet/inscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ pub(crate) struct Inscribe {
pub(crate) reinscribe: bool,
#[arg(long, help = "Inscribe <SATPOINT>.")]
pub(crate) satpoint: Option<SatPoint>,
#[arg(long, help = "Inscribe <SAT>.", conflicts_with = "satpoint")]
pub(crate) sat: Option<Sat>,
}

impl Inscribe {
Expand All @@ -115,6 +117,15 @@ impl Inscribe {
let index = Index::open(&options)?;
index.update()?;

let satpoint = if let Some(sat) = self.sat {
if !index.has_sat_index() {
return Err(anyhow!("run with --index-sats to use the --sat argument"));
raphjaph marked this conversation as resolved.
Show resolved Hide resolved
}
index.find(sat.0)?
raphjaph marked this conversation as resolved.
Show resolved Hide resolved
} else {
self.satpoint
};

let utxos = index.get_unspent_outputs(Wallet::load(&options)?)?;

let locked_utxos = index.get_locked_outputs(Wallet::load(&options)?)?;
Expand Down Expand Up @@ -188,7 +199,7 @@ impl Inscribe {
postage,
reinscribe: self.reinscribe,
reveal_fee_rate: self.fee_rate,
satpoint: self.satpoint,
satpoint,
}
.inscribe(chain, &index, &client, &locked_utxos, &utxos)
}
Expand Down Expand Up @@ -1322,4 +1333,25 @@ inscriptions:
.contains("error: the following required arguments were not provided:\n <--file <FILE>|--batch <BATCH>>")
);
}

#[test]
fn satpoint_and_sat_flags_conflict() {
assert_regex_match!(
Arguments::try_parse_from([
"ord",
"--index-sats",
"wallet",
"inscribe",
"--sat",
"50000000000",
"--satpoint",
"038112028c55f3f77cc0b8b413df51f70675f66be443212da0642b7636f68a00:1:0",
"--file",
"baz",
])
.unwrap_err()
.to_string(),
".*--sat.*cannot be used with.*--satpoint.*"
);
}
}
32 changes: 32 additions & 0 deletions tests/wallet/inscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1577,3 +1577,35 @@ fn batch_same_sat_with_parent() {
format!(r".*<a href=/inscription/{}>.*</a>.*<a href=/inscription/{}>.*</a>.*<a href=/inscription/{}>.*</a>.*", output.inscriptions[0].id, output.inscriptions[1].id, output.inscriptions[2].id),
);
}

#[test]
fn inscribe_with_sat_arg() {
let rpc_server = test_bitcoincore_rpc::spawn();
create_wallet(&rpc_server);
rpc_server.mine_blocks(2);

CommandBuilder::new("wallet inscribe --file foo.txt --sat 5010000000 --fee-rate 1")
.write("foo.txt", "FOO")
.rpc_server(&rpc_server)
.expected_exit_code(1)
.expected_stderr("error: run with --index-sats to use the --sat argument\n");

let Inscribe { inscriptions, .. } = CommandBuilder::new(
"--index-sats wallet inscribe --file foo.txt --sat 5010000000 --fee-rate 1",
)
.write("foo.txt", "FOO")
.rpc_server(&rpc_server)
.run_and_deserialize_output();

let inscription = inscriptions[0].id;

rpc_server.mine_blocks(1);

TestServer::spawn_with_args(&rpc_server, &["--index-sats"]).assert_response_regex(
"/sat/5010000000",
format!(".*<a href=/inscription/{inscription}>.*"),
);

TestServer::spawn_with_args(&rpc_server, &[])
.assert_response_regex(format!("/content/{inscription}",), "FOO");
}
Loading