Skip to content

Commit

Permalink
Merge branch 'postage-as-parameter'
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Martin committed Mar 31, 2023
2 parents 6d3e099 + 53d7799 commit 5b591a3
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/subcommand/preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ impl Preview {
no_limit: false,
destination: None,
alignment: None,
postage: Some(TransactionBuilder::DEFAULT_TARGET_POSTAGE),
},
)),
}
Expand Down
17 changes: 16 additions & 1 deletion src/subcommand/wallet/inscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ pub(crate) struct Inscribe {
pub(crate) destination: Option<Address>,
#[clap(long, help = "Send any alignment output to <ALIGNMENT>.")]
pub(crate) alignment: Option<Address>,
#[clap(long, help = "Amount of postage to include in the inscription. Default `10000 sats`")]
pub(crate) postage: Option<Amount>,
}

impl Inscribe {
Expand Down Expand Up @@ -102,6 +104,10 @@ impl Inscribe {
self.commit_fee_rate.unwrap_or(self.fee_rate),
self.fee_rate,
self.no_limit,
match self.postage {
Some(postage) => postage,
_ => TransactionBuilder::DEFAULT_TARGET_POSTAGE,
},
)?;

utxos.insert(
Expand Down Expand Up @@ -172,6 +178,7 @@ impl Inscribe {
commit_fee_rate: FeeRate,
reveal_fee_rate: FeeRate,
no_limit: bool,
postage: Amount,
) -> Result<(SatPoint, Transaction, Transaction, TweakedKeyPair)> {
let satpoint = if let Some(satpoint) = satpoint {
satpoint
Expand Down Expand Up @@ -245,7 +252,7 @@ impl Inscribe {
alignment,
change,
commit_fee_rate,
reveal_fee + TransactionBuilder::TARGET_POSTAGE,
reveal_fee + postage,
)?;

let (vout, output) = unsigned_commit_tx
Expand Down Expand Up @@ -413,6 +420,7 @@ mod tests {
FeeRate::try_from(1.0).unwrap(),
FeeRate::try_from(1.0).unwrap(),
false,
TransactionBuilder::DEFAULT_TARGET_POSTAGE,
)
.unwrap();

Expand Down Expand Up @@ -445,6 +453,7 @@ mod tests {
FeeRate::try_from(1.0).unwrap(),
FeeRate::try_from(1.0).unwrap(),
false,
TransactionBuilder::DEFAULT_TARGET_POSTAGE,
)
.unwrap();

Expand Down Expand Up @@ -481,6 +490,7 @@ mod tests {
FeeRate::try_from(1.0).unwrap(),
FeeRate::try_from(1.0).unwrap(),
false,
TransactionBuilder::DEFAULT_TARGET_POSTAGE,
)
.unwrap_err()
.to_string();
Expand Down Expand Up @@ -524,6 +534,7 @@ mod tests {
FeeRate::try_from(1.0).unwrap(),
FeeRate::try_from(1.0).unwrap(),
false,
TransactionBuilder::DEFAULT_TARGET_POSTAGE,
)
.is_ok())
}
Expand Down Expand Up @@ -562,6 +573,7 @@ mod tests {
FeeRate::try_from(fee_rate).unwrap(),
FeeRate::try_from(fee_rate).unwrap(),
false,
TransactionBuilder::DEFAULT_TARGET_POSTAGE,
)
.unwrap();

Expand Down Expand Up @@ -626,6 +638,7 @@ mod tests {
FeeRate::try_from(commit_fee_rate).unwrap(),
FeeRate::try_from(fee_rate).unwrap(),
false,
TransactionBuilder::DEFAULT_TARGET_POSTAGE,
)
.unwrap();

Expand Down Expand Up @@ -676,6 +689,7 @@ mod tests {
FeeRate::try_from(1.0).unwrap(),
FeeRate::try_from(1.0).unwrap(),
false,
TransactionBuilder::DEFAULT_TARGET_POSTAGE,
)
.unwrap_err()
.to_string();
Expand Down Expand Up @@ -709,6 +723,7 @@ mod tests {
FeeRate::try_from(1.0).unwrap(),
FeeRate::try_from(1.0).unwrap(),
true,
TransactionBuilder::DEFAULT_TARGET_POSTAGE,
)
.unwrap();

Expand Down
12 changes: 12 additions & 0 deletions src/subcommand/wallet/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ pub(crate) struct Send {
fee_rate: FeeRate,
#[clap(long, help = "Send any alignment output to <ALIGNMENT>.")]
pub(crate) alignment: Option<Address>,
#[clap(long, help = "Target amount of postage to include in the sent output. Default `10000 sats`")]
pub(crate) target_postage: Option<Amount>,
#[clap(long, help = "Maximum amount of postage to include in the sent output. Default `20000 sats`")]
pub(crate) max_postage: Option<Amount>,
}

#[derive(Serialize, Deserialize)]
Expand Down Expand Up @@ -91,6 +95,14 @@ impl Send {
self.alignment,
change,
self.fee_rate,
match self.target_postage {
Some(target_postage) => target_postage,
_ => TransactionBuilder::DEFAULT_TARGET_POSTAGE,
},
match self.max_postage {
Some(max_postage) => max_postage,
_ => TransactionBuilder::DEFAULT_MAX_POSTAGE,
},
)?;

let signed_tx = client
Expand Down
Loading

0 comments on commit 5b591a3

Please sign in to comment.