Skip to content

Commit

Permalink
Add option to set inscription destination address (#1536)
Browse files Browse the repository at this point in the history
  • Loading branch information
rot13maxi authored Feb 20, 2023
1 parent 6750136 commit cc112e2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
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
27 changes: 27 additions & 0 deletions tests/wallet/inscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,33 @@ 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;

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

0 comments on commit cc112e2

Please sign in to comment.