mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-10-14 06:20:57 -04:00
Eliminate build_bitcoin_punish_transaction
We reduce indirection by constructing TxPunish directly based off `State3` and make the type itself more powerful by moving the logic of completing it with a signature onto it.
This commit is contained in:
parent
dd6c66a594
commit
6beb732e35
5 changed files with 34 additions and 46 deletions
|
@ -1,12 +1,11 @@
|
|||
use crate::bitcoin::{Address, PublicKey, PunishTimelock, Transaction, TxCancel};
|
||||
use crate::bitcoin::{self, Address, PunishTimelock, Transaction, TxCancel};
|
||||
use ::bitcoin::util::bip143::SigHashCache;
|
||||
use ::bitcoin::{SigHash, SigHashType};
|
||||
use anyhow::Result;
|
||||
use ecdsa_fun::Signature;
|
||||
use anyhow::{Context, Result};
|
||||
use miniscript::{Descriptor, DescriptorTrait};
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct TxPunish {
|
||||
inner: Transaction,
|
||||
digest: SigHash,
|
||||
|
@ -39,22 +38,20 @@ impl TxPunish {
|
|||
self.digest
|
||||
}
|
||||
|
||||
pub fn add_signatures(
|
||||
pub fn complete(
|
||||
self,
|
||||
(A, sig_a): (PublicKey, Signature),
|
||||
(B, sig_b): (PublicKey, Signature),
|
||||
tx_punish_sig_bob: bitcoin::Signature,
|
||||
a: bitcoin::SecretKey,
|
||||
B: bitcoin::PublicKey,
|
||||
) -> Result<Transaction> {
|
||||
let sig_a = a.sign(self.digest());
|
||||
let sig_b = tx_punish_sig_bob;
|
||||
|
||||
let satisfier = {
|
||||
let mut satisfier = HashMap::with_capacity(2);
|
||||
|
||||
let A = ::bitcoin::PublicKey {
|
||||
compressed: true,
|
||||
key: A.0.into(),
|
||||
};
|
||||
let B = ::bitcoin::PublicKey {
|
||||
compressed: true,
|
||||
key: B.0.into(),
|
||||
};
|
||||
let A = a.public().into();
|
||||
let B = B.into();
|
||||
|
||||
// The order in which these are inserted doesn't matter
|
||||
satisfier.insert(A, (sig_a.into(), ::bitcoin::SigHashType::All));
|
||||
|
@ -65,7 +62,8 @@ impl TxPunish {
|
|||
|
||||
let mut tx_punish = self.inner;
|
||||
self.cancel_output_descriptor
|
||||
.satisfy(&mut tx_punish.input[0], satisfier)?;
|
||||
.satisfy(&mut tx_punish.input[0], satisfier)
|
||||
.context("Failed to satisfy inputs with given signatures")?;
|
||||
|
||||
Ok(tx_punish)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue