Skip to content

Commit

Permalink
Opt wallet transactions into RBF (#901)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Dec 7, 2022
1 parent e991bc1 commit 32f7232
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
24 changes: 23 additions & 1 deletion src/subcommand/wallet/inscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl Inscribe {
},
script_sig: script::Builder::new().into_script(),
witness: Witness::new(),
sequence: Sequence::MAX,
sequence: Sequence::ENABLE_RBF_NO_LOCKTIME,
}],
output: vec![TxOut {
script_pubkey: destination.script_pubkey(),
Expand Down Expand Up @@ -324,4 +324,26 @@ mod tests {
error
);
}

#[test]
fn inscript_tansactions_opt_in_to_rbf() {
let utxos = vec![(outpoint(1), Amount::from_sat(5000))];
let inscription = inscription("text/plain", "ord");
let commit_address = change(0);
let reveal_address = recipient();

let (commit_tx, reveal_tx, _) = Inscribe::create_inscription_transactions(
satpoint(1, 0),
inscription,
BTreeMap::new(),
bitcoin::Network::Signet,
utxos.into_iter().collect(),
vec![commit_address, change(1)],
reveal_address,
)
.unwrap();

assert!(commit_tx.is_explicitly_rbf());
assert!(reveal_tx.is_explicitly_rbf());
}
}
19 changes: 17 additions & 2 deletions src/subcommand/wallet/transaction_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ impl TransactionBuilder {
.push_slice(&[0; 71])
.push_slice(&[0; 65])
.into_script(),
sequence: Sequence::MAX,
sequence: Sequence::ENABLE_RBF_NO_LOCKTIME,
witness: Witness::new(),
})
.collect(),
Expand Down Expand Up @@ -305,7 +305,7 @@ impl TransactionBuilder {
.map(|outpoint| TxIn {
previous_output: *outpoint,
script_sig: Script::new(),
sequence: Sequence::MAX,
sequence: Sequence::ENABLE_RBF_NO_LOCKTIME,
witness: Witness::new(),
})
.collect(),
Expand Down Expand Up @@ -560,6 +560,21 @@ mod tests {
)
}

#[test]
fn transactions_are_rbf() {
let utxos = vec![(outpoint(1), Amount::from_sat(5_000))];

assert!(TransactionBuilder::build_transaction(
satpoint(1, 0),
BTreeMap::new(),
utxos.into_iter().collect(),
recipient(),
vec![change(0), change(1)],
)
.unwrap()
.is_explicitly_rbf())
}

#[test]
fn deduct_fee() {
let utxos = vec![(outpoint(1), Amount::from_sat(5_000))];
Expand Down
2 changes: 1 addition & 1 deletion src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub(crate) fn tx_in(previous_output: OutPoint) -> TxIn {
TxIn {
previous_output,
script_sig: Script::new(),
sequence: Sequence::MAX,
sequence: Sequence::ENABLE_RBF_NO_LOCKTIME,
witness: Witness::new(),
}
}
Expand Down

0 comments on commit 32f7232

Please sign in to comment.