Add PartialSpendInfo to SpendTx model
This commit is contained in:
parent
9a1cda2f5e
commit
1f3399bd0f
@ -160,6 +160,7 @@ impl State for RecoveryPanel {
|
||||
let address = Address::from_str(&self.recipient.value).expect("Checked before");
|
||||
let feerate_vb = self.feerate.value.parse::<u64>().expect("Checked before");
|
||||
self.warning = None;
|
||||
let desc = self.wallet.main_descriptor.clone();
|
||||
return Command::perform(
|
||||
async move {
|
||||
let psbt = daemon.create_recovery(address, feerate_vb)?;
|
||||
@ -174,7 +175,8 @@ impl State for RecoveryPanel {
|
||||
})
|
||||
.copied()
|
||||
.collect();
|
||||
Ok(SpendTx::new(psbt, coins))
|
||||
let sigs = desc.partial_spend_info(&psbt).unwrap();
|
||||
Ok(SpendTx::new(psbt, coins, sigs))
|
||||
},
|
||||
Message::Recovery,
|
||||
);
|
||||
|
||||
@ -447,10 +447,16 @@ impl SaveSpend {
|
||||
|
||||
impl Step for SaveSpend {
|
||||
fn load(&mut self, draft: &TransactionDraft) {
|
||||
let psbt = draft.generated.clone().unwrap();
|
||||
let sigs = self
|
||||
.wallet
|
||||
.main_descriptor
|
||||
.partial_spend_info(&psbt)
|
||||
.unwrap();
|
||||
self.spend = Some(detail::SpendTxState::new(
|
||||
self.wallet.clone(),
|
||||
self.config.clone(),
|
||||
SpendTx::new(draft.generated.clone().unwrap(), draft.inputs.clone()),
|
||||
SpendTx::new(psbt, draft.inputs.clone(), sigs),
|
||||
false,
|
||||
));
|
||||
}
|
||||
|
||||
@ -72,25 +72,29 @@ pub trait Daemon: Debug {
|
||||
fn list_txs(&self, txid: &[Txid]) -> Result<model::ListTransactionsResult, DaemonError>;
|
||||
|
||||
fn list_spend_transactions(&self) -> Result<Vec<model::SpendTx>, DaemonError> {
|
||||
let info = self.get_info()?;
|
||||
let coins = self.list_coins()?.coins;
|
||||
let spend_txs = self.list_spend_txs()?.spend_txs;
|
||||
Ok(spend_txs
|
||||
.into_iter()
|
||||
.map(|tx| {
|
||||
let coins = coins
|
||||
.iter()
|
||||
.filter(|coin| {
|
||||
tx.psbt
|
||||
.unsigned_tx
|
||||
.input
|
||||
.iter()
|
||||
.any(|input| input.previous_output == coin.outpoint)
|
||||
})
|
||||
.copied()
|
||||
.collect();
|
||||
model::SpendTx::new(tx.psbt, coins)
|
||||
})
|
||||
.collect())
|
||||
let mut spend_txs = Vec::new();
|
||||
for tx in self.list_spend_txs()?.spend_txs {
|
||||
let coins = coins
|
||||
.iter()
|
||||
.filter(|coin| {
|
||||
tx.psbt
|
||||
.unsigned_tx
|
||||
.input
|
||||
.iter()
|
||||
.any(|input| input.previous_output == coin.outpoint)
|
||||
})
|
||||
.copied()
|
||||
.collect();
|
||||
let sigs = info
|
||||
.descriptors
|
||||
.main
|
||||
.partial_spend_info(&tx.psbt)
|
||||
.map_err(|e| DaemonError::Unexpected(e.to_string()))?;
|
||||
spend_txs.push(model::SpendTx::new(tx.psbt, coins, sigs))
|
||||
}
|
||||
Ok(spend_txs)
|
||||
}
|
||||
|
||||
fn list_history_txs(
|
||||
|
||||
@ -3,6 +3,7 @@ pub use liana::{
|
||||
CreateSpendResult, GetAddressResult, GetInfoResult, ListCoinsEntry, ListCoinsResult,
|
||||
ListSpendEntry, ListSpendResult, ListTransactionsResult, TransactionInfo,
|
||||
},
|
||||
descriptors::PartialSpendInfo,
|
||||
miniscript::bitcoin::{util::psbt::Psbt, Amount, Transaction},
|
||||
};
|
||||
|
||||
@ -28,6 +29,7 @@ pub struct SpendTx {
|
||||
pub spend_amount: Amount,
|
||||
pub fee_amount: Amount,
|
||||
pub status: SpendStatus,
|
||||
pub sigs: PartialSpendInfo,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
@ -38,7 +40,7 @@ pub enum SpendStatus {
|
||||
}
|
||||
|
||||
impl SpendTx {
|
||||
pub fn new(psbt: Psbt, coins: Vec<Coin>) -> Self {
|
||||
pub fn new(psbt: Psbt, coins: Vec<Coin>, sigs: PartialSpendInfo) -> Self {
|
||||
let mut change_indexes = Vec::new();
|
||||
let (change_amount, spend_amount) = psbt.unsigned_tx.output.iter().enumerate().fold(
|
||||
(Amount::from_sat(0), Amount::from_sat(0)),
|
||||
@ -72,6 +74,7 @@ impl SpendTx {
|
||||
spend_amount,
|
||||
fee_amount: inputs_amount - spend_amount - change_amount,
|
||||
status,
|
||||
sigs,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user