Add add_data method for txbuilder op_return (#163)
This commit is contained in:
parent
80ed21e4c9
commit
6be22daf84
@ -195,6 +195,8 @@ interface TxBuilder {
|
|||||||
|
|
||||||
TxBuilder enable_rbf_with_sequence(u32 nsequence);
|
TxBuilder enable_rbf_with_sequence(u32 nsequence);
|
||||||
|
|
||||||
|
TxBuilder add_data(sequence<u8> data);
|
||||||
|
|
||||||
[Throws=BdkError]
|
[Throws=BdkError]
|
||||||
PartiallySignedBitcoinTransaction finish([ByRef] Wallet wallet);
|
PartiallySignedBitcoinTransaction finish([ByRef] Wallet wallet);
|
||||||
};
|
};
|
||||||
|
13
src/lib.rs
13
src/lib.rs
@ -344,6 +344,7 @@ struct TxBuilder {
|
|||||||
drain_wallet: bool,
|
drain_wallet: bool,
|
||||||
drain_to: Option<String>,
|
drain_to: Option<String>,
|
||||||
rbf: Option<RbfValue>,
|
rbf: Option<RbfValue>,
|
||||||
|
data: Vec<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TxBuilder {
|
impl TxBuilder {
|
||||||
@ -354,6 +355,7 @@ impl TxBuilder {
|
|||||||
drain_wallet: false,
|
drain_wallet: false,
|
||||||
drain_to: None,
|
drain_to: None,
|
||||||
rbf: None,
|
rbf: None,
|
||||||
|
data: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -401,6 +403,13 @@ impl TxBuilder {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn add_data(&self, data: Vec<u8>) -> Arc<Self> {
|
||||||
|
Arc::new(TxBuilder {
|
||||||
|
data,
|
||||||
|
..self.clone()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
fn finish(&self, wallet: &Wallet) -> Result<Arc<PartiallySignedBitcoinTransaction>, Error> {
|
fn finish(&self, wallet: &Wallet) -> Result<Arc<PartiallySignedBitcoinTransaction>, Error> {
|
||||||
let wallet = wallet.get_wallet();
|
let wallet = wallet.get_wallet();
|
||||||
let mut tx_builder = wallet.build_tx();
|
let mut tx_builder = wallet.build_tx();
|
||||||
@ -426,6 +435,10 @@ impl TxBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if !&self.data.is_empty() {
|
||||||
|
tx_builder.add_data(&self.data.as_slice());
|
||||||
|
}
|
||||||
|
|
||||||
tx_builder
|
tx_builder
|
||||||
.finish()
|
.finish()
|
||||||
.map(|(psbt, _)| PartiallySignedBitcoinTransaction {
|
.map(|(psbt, _)| PartiallySignedBitcoinTransaction {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user