Skip to content

Commit

Permalink
Add --force-input to wallet inscribe and wallet send.
Browse files Browse the repository at this point in the history
  • Loading branch information
gmart7t2 committed Nov 26, 2023
1 parent 0f6bf48 commit 1a91575
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/subcommand/preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ impl Preview {
destination: None,
dry_run: false,
fee_rate: FeeRate::try_from(1.0).unwrap(),
force_input: Vec::new(),
file: Some(file),
json_metadata: None,
metaprotocol: None,
Expand Down
4 changes: 3 additions & 1 deletion src/subcommand/wallet/inscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ pub(crate) struct Inscribe {
pub(crate) dump: bool,
#[clap(long, help = "Do not broadcast any transactions. Implies --dump.")]
pub(crate) no_broadcast: bool,
#[clap(long, help = "Require this utxo to be spent. Useful for forcing CPFP.")]
pub(crate) force_input: Vec<OutPoint>,
}

impl Inscribe {
Expand Down Expand Up @@ -286,7 +288,7 @@ impl Inscribe {
reveal_input: self.reveal_input,
satpoint: self.satpoint,
}
.inscribe(chain, &index, &client, &locked_utxos, &utxos)
.inscribe(chain, &index, &client, &locked_utxos, &utxos, self.force_input)
}

fn parse_metadata(cbor: Option<PathBuf>, json: Option<PathBuf>) -> Result<Option<Vec<u8>>> {
Expand Down
4 changes: 4 additions & 0 deletions src/subcommand/wallet/inscribe/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ impl Batch {
client: &Client,
locked_utxos: &BTreeSet<OutPoint>,
utxos: &BTreeMap<OutPoint, Amount>,
force_input: Vec<OutPoint>,
) -> SubcommandResult {
let wallet_inscriptions = index.get_inscriptions(utxos)?;

Expand All @@ -74,6 +75,7 @@ impl Batch {
locked_utxos.clone(),
utxos.clone(),
commit_tx_change,
force_input,
)?;

if self.dry_run {
Expand Down Expand Up @@ -254,6 +256,7 @@ impl Batch {
locked_utxos: BTreeSet<OutPoint>,
mut utxos: BTreeMap<OutPoint, Amount>,
change: [Address; 2],
force_input: Vec<OutPoint>,
) -> Result<(Transaction, Transaction, TweakedKeyPair, u64)> {
if let Some(parent_info) = &self.parent_info {
assert!(self
Expand Down Expand Up @@ -456,6 +459,7 @@ impl Batch {
} else {
Target::Value(reveal_fee + total_postage)
},
force_input,
)
.build_transaction()?
};
Expand Down
3 changes: 3 additions & 0 deletions src/subcommand/wallet/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ pub(crate) struct Send {
help = "Target amount of postage to include with sent inscriptions. Default `10000sat`"
)]
pub(crate) postage: Option<Amount>,
#[clap(long, help = "Require this utxo to be spent. Useful for forcing CPFP.")]
pub(crate) force_input: Vec<OutPoint>,
}

#[derive(Serialize, Deserialize)]
Expand Down Expand Up @@ -107,6 +109,7 @@ impl Send {
change,
self.fee_rate,
postage,
self.force_input,
)
.build_transaction()?;

Expand Down
10 changes: 9 additions & 1 deletion src/subcommand/wallet/transaction_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ pub struct TransactionBuilder {
amounts: BTreeMap<OutPoint, Amount>,
change_addresses: BTreeSet<Address>,
fee_rate: FeeRate,
force_input: Vec<OutPoint>,
inputs: Vec<OutPoint>,
inscriptions: BTreeMap<SatPoint, InscriptionId>,
outgoing: SatPoint,
Expand Down Expand Up @@ -132,6 +133,7 @@ impl TransactionBuilder {
change: [Address; 2],
fee_rate: FeeRate,
target: Target,
force_input: Vec<OutPoint>,
) -> Self {
Self {
utxos: amounts.keys().cloned().collect(),
Expand All @@ -140,6 +142,7 @@ impl TransactionBuilder {
change_addresses: change.iter().cloned().collect(),
fee_rate,
inputs: Vec::new(),
force_input: force_input,
inscriptions,
outgoing,
outputs: Vec::new(),
Expand Down Expand Up @@ -206,7 +209,7 @@ impl TransactionBuilder {
}
}

let amount = *self
let mut amount = *self
.amounts
.get(&self.outgoing.outpoint)
.ok_or(Error::NotInWallet(self.outgoing))?;
Expand All @@ -217,6 +220,11 @@ impl TransactionBuilder {

self.utxos.remove(&self.outgoing.outpoint);
self.inputs.push(self.outgoing.outpoint);
for input in &self.force_input {
self.inputs.push(*input);
amount += *self.amounts.get(&input).unwrap();
self.utxos.remove(&input);
}
self.outputs.push((self.recipient.clone(), amount));

tprintln!(
Expand Down

0 comments on commit 1a91575

Please sign in to comment.