Add add_data method for txbuilder op_return (#163)

This commit is contained in:
Pedro 2022-06-23 04:20:02 -07:00 committed by GitHub
parent 80ed21e4c9
commit 6be22daf84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

@ -195,6 +195,8 @@ interface TxBuilder {
TxBuilder enable_rbf_with_sequence(u32 nsequence);
TxBuilder add_data(sequence<u8> data);
[Throws=BdkError]
PartiallySignedBitcoinTransaction finish([ByRef] Wallet wallet);
};

View File

@ -344,6 +344,7 @@ struct TxBuilder {
drain_wallet: bool,
drain_to: Option<String>,
rbf: Option<RbfValue>,
data: Vec<u8>,
}
impl TxBuilder {
@ -354,6 +355,7 @@ impl TxBuilder {
drain_wallet: false,
drain_to: 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> {
let wallet = wallet.get_wallet();
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
.finish()
.map(|(psbt, _)| PartiallySignedBitcoinTransaction {