[wallet] Add RBF and custom versions in TxBuilder

This commit is contained in:
Alekos Filini
2020-08-07 16:30:19 +02:00
parent 0665c9e854
commit 85090a28eb
2 changed files with 57 additions and 7 deletions

View File

@@ -18,6 +18,8 @@ pub struct TxBuilder<Cs: CoinSelectionAlgorithm> {
pub(crate) sighash: Option<SigHashType>,
pub(crate) ordering: TxOrdering,
pub(crate) locktime: Option<u32>,
pub(crate) rbf: Option<u32>,
pub(crate) version: Version,
pub(crate) coin_selection: Cs,
}
@@ -92,6 +94,20 @@ impl<Cs: CoinSelectionAlgorithm> TxBuilder<Cs> {
self
}
pub fn enable_rbf(self) -> Self {
self.enable_rbf_with_sequence(0xFFFFFFFD)
}
pub fn enable_rbf_with_sequence(mut self, nsequence: u32) -> Self {
self.rbf = Some(nsequence);
self
}
pub fn version(mut self, version: u32) -> Self {
self.version = Version(version);
self
}
pub fn coin_selection<P: CoinSelectionAlgorithm>(self, coin_selection: P) -> TxBuilder<P> {
TxBuilder {
addressees: self.addressees,
@@ -103,6 +119,8 @@ impl<Cs: CoinSelectionAlgorithm> TxBuilder<Cs> {
sighash: self.sighash,
ordering: self.ordering,
locktime: self.locktime,
rbf: self.rbf,
version: self.version,
coin_selection,
}
}
@@ -148,6 +166,16 @@ impl TxOrdering {
}
}
// Helper type that wraps u32 and has a default value of 1
#[derive(Debug)]
pub(crate) struct Version(pub(crate) u32);
impl Default for Version {
fn default() -> Self {
Version(1)
}
}
#[cfg(test)]
mod test {
const ORDERING_TEST_TX: &'static str = "0200000003c26f3eb7932f7acddc5ddd26602b77e7516079b03090a16e2c2f54\