Skip to content

Commit 1e547cd

Browse files
committed
Add the add_data option to create_tx to create an op_return output
1 parent d8e93ab commit 1e547cd

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
- Rewrite relevant doc comments as `structopt` help document.
1212
- Update `bdk` and `bdk-reserves` to v0.19.0.
1313
- Change default database to `sqlite`.
14+
- Add the add_data option to create_tx to create an op_return output.
1415

1516
## [0.5.0]
1617

src/commands.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,22 @@ pub enum OfflineWalletSubCommand {
339339
/// Selects which policy should be used to satisfy the internal descriptor
340340
#[structopt(name = "INT_POLICY", long = "internal_policy")]
341341
internal_policy: Option<String>,
342+
/// Add string as an output using OP_RETURN
343+
#[structopt(
344+
name = "ADD_STRING",
345+
long = "add_string",
346+
short = "s",
347+
conflicts_with = "ADD_DATA"
348+
)]
349+
add_string: Option<String>,
350+
/// Add arbitrary data (max 80-bytes) as an output using OP_RETURN
351+
#[structopt(
352+
name = "ADD_DATA",
353+
long = "add_data",
354+
short = "o",
355+
conflicts_with = "ADD_STRING"
356+
)]
357+
add_data: Option<String>,
342358
},
343359
/// Bumps the fees of an RBF transaction
344360
BumpFee {
@@ -944,6 +960,8 @@ mod test {
944960
fee_rate: None,
945961
external_policy: None,
946962
internal_policy: None,
963+
add_data: None,
964+
add_string: None,
947965
}),
948966
},
949967
};

src/handlers.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ where
125125
fee_rate,
126126
external_policy,
127127
internal_policy,
128+
add_data,
129+
add_string,
128130
} => {
129131
let mut tx_builder = wallet.build_tx();
130132

@@ -154,6 +156,13 @@ where
154156
tx_builder.unspendable(unspendable);
155157
}
156158

159+
if let Some(base64_data) = add_data {
160+
let op_return_data = base64::decode(&base64_data).unwrap();
161+
tx_builder.add_data(op_return_data.as_slice());
162+
} else if let Some(string_data) = add_string {
163+
tx_builder.add_data(string_data.as_bytes());
164+
}
165+
157166
let policies = vec![
158167
external_policy.map(|p| (p, KeychainKind::External)),
159168
internal_policy.map(|p| (p, KeychainKind::Internal)),

0 commit comments

Comments
 (0)