gui: use helper for unsigned tx max size
This commit is contained in:
parent
dee069e723
commit
e373ad45d4
2
gui/Cargo.lock
generated
2
gui/Cargo.lock
generated
@ -2431,7 +2431,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "liana"
|
name = "liana"
|
||||||
version = "4.0.0"
|
version = "4.0.0"
|
||||||
source = "git+https://github.com/wizardsardine/liana?branch=master#87d1c55d2e5b6edc5cc2033759a6a936435b67b6"
|
source = "git+https://github.com/wizardsardine/liana?branch=master#dee069e72343a67607f4429125e4c80dc0d73055"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"backtrace",
|
"backtrace",
|
||||||
"bdk_coin_select",
|
"bdk_coin_select",
|
||||||
|
|||||||
@ -38,9 +38,9 @@ pub struct SpendTx {
|
|||||||
pub change_indexes: Vec<usize>,
|
pub change_indexes: Vec<usize>,
|
||||||
pub spend_amount: Amount,
|
pub spend_amount: Amount,
|
||||||
pub fee_amount: Option<Amount>,
|
pub fee_amount: Option<Amount>,
|
||||||
/// The maximum size difference (in virtual bytes) of
|
/// Maximum possible size of the unsigned transaction after satisfaction
|
||||||
/// an input in this transaction before and after satisfaction.
|
/// (assuming all inputs are for the same descriptor).
|
||||||
pub max_sat_vbytes: usize,
|
pub max_vbytes: u64,
|
||||||
pub status: SpendStatus,
|
pub status: SpendStatus,
|
||||||
pub sigs: PartialSpendInfo,
|
pub sigs: PartialSpendInfo,
|
||||||
pub updated_at: Option<u32>,
|
pub updated_at: Option<u32>,
|
||||||
@ -63,7 +63,7 @@ impl SpendTx {
|
|||||||
desc: &LianaDescriptor,
|
desc: &LianaDescriptor,
|
||||||
network: Network,
|
network: Network,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let max_sat_vbytes = desc.max_sat_vbytes();
|
let max_vbytes = desc.unsigned_tx_max_vbytes(&psbt.unsigned_tx);
|
||||||
let mut change_indexes = Vec::new();
|
let mut change_indexes = Vec::new();
|
||||||
let (change_amount, spend_amount) = psbt.unsigned_tx.output.iter().enumerate().fold(
|
let (change_amount, spend_amount) = psbt.unsigned_tx.output.iter().enumerate().fold(
|
||||||
(Amount::from_sat(0), Amount::from_sat(0)),
|
(Amount::from_sat(0), Amount::from_sat(0)),
|
||||||
@ -167,7 +167,7 @@ impl SpendTx {
|
|||||||
change_indexes,
|
change_indexes,
|
||||||
spend_amount,
|
spend_amount,
|
||||||
fee_amount: inputs_amount.and_then(|a| a.checked_sub(spend_amount + change_amount)),
|
fee_amount: inputs_amount.and_then(|a| a.checked_sub(spend_amount + change_amount)),
|
||||||
max_sat_vbytes,
|
max_vbytes,
|
||||||
status,
|
status,
|
||||||
sigs,
|
sigs,
|
||||||
network,
|
network,
|
||||||
@ -203,10 +203,11 @@ impl SpendTx {
|
|||||||
|
|
||||||
/// Feerate obtained if all transaction inputs have the maximum satisfaction size.
|
/// Feerate obtained if all transaction inputs have the maximum satisfaction size.
|
||||||
pub fn min_feerate_vb(&self) -> Option<u64> {
|
pub fn min_feerate_vb(&self) -> Option<u64> {
|
||||||
// This assumes all inputs are internal (have same max satisfaction size).
|
self.fee_amount.map(|a| {
|
||||||
let max_tx_vbytes =
|
a.to_sat()
|
||||||
self.psbt.unsigned_tx.vsize() + (self.max_sat_vbytes * self.psbt.inputs.len());
|
.checked_div(self.max_vbytes)
|
||||||
self.fee_amount.map(|a| a.to_sat() / max_tx_vbytes as u64)
|
.expect("a descriptor's satisfaction size is never 0")
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_send_to_self(&self) -> bool {
|
pub fn is_send_to_self(&self) -> bool {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user