Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set postage #2331

Merged
merged 14 commits into from
Aug 17, 2023
1 change: 1 addition & 0 deletions src/subcommand/preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ impl Preview {
dry_run: false,
no_limit: false,
destination: None,
postage: Some(TransactionBuilder::TARGET_POSTAGE),
},
)),
}
Expand Down
2 changes: 1 addition & 1 deletion src/subcommand/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub mod receive;
mod restore;
pub mod sats;
pub mod send;
pub(crate) mod transaction_builder;
pub mod transaction_builder;
pub mod transactions;

#[derive(Debug, Parser)]
Expand Down
27 changes: 23 additions & 4 deletions src/subcommand/wallet/inscribe.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use {
super::*,
crate::wallet::Wallet,
crate::{subcommand::wallet::transaction_builder::Target, wallet::Wallet},
bitcoin::{
blockdata::{opcodes, script},
key::PrivateKey,
Expand Down Expand Up @@ -51,6 +51,11 @@ pub(crate) struct Inscribe {
pub(crate) dry_run: bool,
#[clap(long, help = "Send inscription to <DESTINATION>.")]
pub(crate) destination: Option<Address<NetworkUnchecked>>,
#[clap(
long,
help = "Amount of postage to include in the inscription. Default `10000sat`"
)]
pub(crate) postage: Option<Amount>,
}

impl Inscribe {
Expand Down Expand Up @@ -88,6 +93,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::TARGET_POSTAGE,
},
)?;

utxos.insert(
Expand Down Expand Up @@ -155,6 +164,7 @@ impl Inscribe {
commit_fee_rate: FeeRate,
reveal_fee_rate: FeeRate,
no_limit: bool,
postage: Amount,
) -> Result<(Transaction, Transaction, TweakedKeyPair)> {
let satpoint = if let Some(satpoint) = satpoint {
satpoint
Expand Down Expand Up @@ -220,15 +230,16 @@ impl Inscribe {
&reveal_script,
);

let unsigned_commit_tx = TransactionBuilder::build_transaction_with_value(
let unsigned_commit_tx = TransactionBuilder::new(
satpoint,
inscriptions,
utxos,
commit_tx_address.clone(),
change,
commit_fee_rate,
reveal_fee + TransactionBuilder::TARGET_POSTAGE,
)?;
Target::Value(reveal_fee + postage),
)
.build_transaction()?;

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

Expand Down Expand Up @@ -424,6 +436,7 @@ mod tests {
FeeRate::try_from(1.0).unwrap(),
FeeRate::try_from(1.0).unwrap(),
false,
TransactionBuilder::TARGET_POSTAGE,
)
.unwrap();

Expand Down Expand Up @@ -459,6 +472,7 @@ mod tests {
FeeRate::try_from(1.0).unwrap(),
FeeRate::try_from(1.0).unwrap(),
false,
TransactionBuilder::TARGET_POSTAGE,
)
.unwrap_err()
.to_string();
Expand Down Expand Up @@ -501,6 +515,7 @@ mod tests {
FeeRate::try_from(1.0).unwrap(),
FeeRate::try_from(1.0).unwrap(),
false,
TransactionBuilder::TARGET_POSTAGE,
)
.is_ok())
}
Expand Down Expand Up @@ -537,6 +552,7 @@ mod tests {
FeeRate::try_from(fee_rate).unwrap(),
FeeRate::try_from(fee_rate).unwrap(),
false,
TransactionBuilder::TARGET_POSTAGE,
)
.unwrap();

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

Expand Down Expand Up @@ -648,6 +665,7 @@ mod tests {
FeeRate::try_from(1.0).unwrap(),
FeeRate::try_from(1.0).unwrap(),
false,
TransactionBuilder::TARGET_POSTAGE,
)
.unwrap_err()
.to_string();
Expand Down Expand Up @@ -679,6 +697,7 @@ mod tests {
FeeRate::try_from(1.0).unwrap(),
FeeRate::try_from(1.0).unwrap(),
true,
TransactionBuilder::TARGET_POSTAGE,
)
.unwrap();

Expand Down
19 changes: 16 additions & 3 deletions src/subcommand/wallet/send.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
use {super::*, crate::wallet::Wallet};
use {super::*, crate::subcommand::wallet::transaction_builder::Target, crate::wallet::Wallet};

#[derive(Debug, Parser)]
pub(crate) struct Send {
address: Address<NetworkUnchecked>,
outgoing: Outgoing,
#[clap(long, help = "Use fee rate of <FEE_RATE> sats/vB")]
fee_rate: FeeRate,
#[clap(
long,
help = "Target amount of postage to include with sent inscriptions. Default `10000sat`"
)]
pub(crate) postage: Option<Amount>,
}

#[derive(Serialize, Deserialize)]
Expand Down Expand Up @@ -67,14 +72,22 @@ impl Send {
get_change_address(&client, &options)?,
];

let unsigned_transaction = TransactionBuilder::build_transaction_with_postage(
let postage = if let Some(postage) = self.postage {
Target::ExactPostage(postage)
} else {
Target::Postage
};

let unsigned_transaction = TransactionBuilder::new(
satpoint,
inscriptions,
unspent_outputs,
address,
change,
self.fee_rate,
)?;
postage,
)
.build_transaction()?;

let signed_tx = client
.sign_raw_transaction_with_wallet(&unsigned_transaction, None, None)?
Expand Down
Loading