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 @@ -81,6 +81,7 @@ impl Preview {
no_backup: true,
satpoint: None,
dry_run: false,
inscription_destination: None,
},
)),
}
Expand Down
32 changes: 31 additions & 1 deletion src/subcommand/wallet/inscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ pub(crate) struct Inscribe {
pub(crate) no_backup: bool,
#[clap(long, help = "Don't sign or broadcast transactions.")]
pub(crate) dry_run: bool,
#[clap(long, help = "Send reveal output to <INSCRIPTION_DESTINATION>")]
pub(crate) inscription_destination: Option<Address>,
rot13maxi marked this conversation as resolved.
Show resolved Hide resolved
}

impl Inscribe {
Expand All @@ -63,7 +65,9 @@ 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
.inscription_destination
.unwrap_or(get_change_address(&client)?);
rot13maxi marked this conversation as resolved.
Show resolved Hide resolved

let (unsigned_commit_tx, reveal_tx, recovery_key_pair) =
Inscribe::create_inscription_transactions(
Expand Down Expand Up @@ -635,4 +639,30 @@ mod tests {
error
);
}

#[test]
fn inscribe_with_specific_destination() {
rot13maxi marked this conversation as resolved.
Show resolved Hide resolved
let utxos = vec![(outpoint(1), Amount::from_sat(20000))];
let inscription = inscription("text/plain", "ord");
let commit_address = change(0);
let reveal_address = recipient();

let (_, reveal_tx, _) = Inscribe::create_inscription_transactions(
Some(satpoint(1, 0)),
inscription,
BTreeMap::new(),
Network::Bitcoin,
utxos.into_iter().collect(),
[commit_address, change(1)],
reveal_address,
FeeRate::try_from(1.0).unwrap(),
FeeRate::try_from(1.0).unwrap(),
)
.unwrap();

assert_eq!(
reveal_tx.output.first().unwrap().script_pubkey,
recipient().script_pubkey()
);
}
}