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 option to set inscription destination #1536

Merged
merged 12 commits into from
Feb 20, 2023
1 change: 1 addition & 0 deletions src/subcommand/preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ impl Preview {
satpoint: None,
dry_run: false,
no_limit: false,
destination: None,
},
)),
}
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 @@ -52,6 +52,8 @@ pub(crate) struct Inscribe {
pub(crate) no_limit: bool,
#[clap(long, help = "Don't sign or broadcast transactions.")]
pub(crate) dry_run: bool,
#[clap(long, help = "Send inscription to <DESTINATION>.")]
pub(crate) destination: Option<Address>,
}

impl Inscribe {
Expand All @@ -69,7 +71,10 @@ impl Inscribe {

let commit_tx_change = [get_change_address(&client)?, get_change_address(&client)?];

let reveal_tx_destination = get_change_address(&client)?;
let reveal_tx_destination = self
.destination
.map(Ok)
.unwrap_or_else(|| get_change_address(&client))?;

let (unsigned_commit_tx, reveal_tx, recovery_key_pair) =
Inscribe::create_inscription_transactions(
Expand Down
26 changes: 26 additions & 0 deletions tests/wallet/inscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,32 @@ fn inscribe_with_dry_run_flag_fees_inscrease() {
assert!(total_fee_dry_run < total_fee_normal);
}

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

let destination = CommandBuilder::new("wallet receive")
.rpc_server(&rpc_server)
.output::<ord::subcommand::wallet::receive::Output>()
.address;

let txid = CommandBuilder::new(format!(
"wallet inscribe --destination {destination} degenerate.png"
))
.write("degenerate.png", [1; 520])
.rpc_server(&rpc_server)
.output::<Inscribe>()
.reveal;
raphjaph marked this conversation as resolved.
Show resolved Hide resolved
let reveal_tx = &rpc_server.mempool()[1]; // item 0 is the commit, item 1 is the reveal.
assert_eq!(reveal_tx.txid(), txid);
assert_eq!(
reveal_tx.output.first().unwrap().script_pubkey,
destination.script_pubkey()
);
}

#[test]
fn inscribe_with_no_limit() {
let rpc_server = test_bitcoincore_rpc::spawn();
Expand Down