Calculate max_giveable based on spending script size

This commit is contained in:
Thomas Eizinger 2021-03-01 15:35:45 +11:00
parent 7251588e79
commit 9f0b1c5cbe
No known key found for this signature in database
GPG key ID: 651AC83A6C6C8B96
3 changed files with 16 additions and 8 deletions

View file

@ -3,7 +3,9 @@ use crate::bitcoin::{
};
use ::bitcoin::{util::psbt::PartiallySignedTransaction, OutPoint, TxIn, TxOut, Txid};
use anyhow::Result;
use ecdsa_fun::fun::Point;
use miniscript::{Descriptor, DescriptorTrait};
use rand::thread_rng;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
@ -42,6 +44,16 @@ impl TxLock {
OutPoint::new(self.txid(), self.lock_output_vout() as u32)
}
/// Calculate the size of the script used by this transaction.
pub fn script_size() -> usize {
build_shared_output_descriptor(
Point::random(&mut thread_rng()),
Point::random(&mut thread_rng()),
)
.script_pubkey()
.len()
}
/// Retreive the index of the locked output in the transaction outputs
/// vector
fn lock_output_vout(&self) -> usize {