mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-10-12 21:40:53 -04:00
Move more domain knowledge onto the TxCancel
type
This commit is contained in:
parent
75aec95b0c
commit
c92f2dbc77
3 changed files with 46 additions and 25 deletions
|
@ -1,12 +1,12 @@
|
|||
use crate::bitcoin;
|
||||
use crate::bitcoin::wallet::Watchable;
|
||||
use crate::bitcoin::{
|
||||
build_shared_output_descriptor, Address, Amount, BlockHeight, PublicKey, Transaction, TxLock,
|
||||
TX_FEE,
|
||||
};
|
||||
use ::bitcoin::util::bip143::SigHashCache;
|
||||
use ::bitcoin::{OutPoint, SigHash, SigHashType, TxIn, TxOut, Txid};
|
||||
use ::bitcoin::{OutPoint, Script, SigHash, SigHashType, TxIn, TxOut, Txid};
|
||||
use anyhow::Result;
|
||||
use bitcoin::Script;
|
||||
use ecdsa_fun::Signature;
|
||||
use miniscript::{Descriptor, DescriptorTrait};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
@ -149,7 +149,39 @@ impl TxCancel {
|
|||
OutPoint::new(self.inner.txid(), 0)
|
||||
}
|
||||
|
||||
pub fn add_signatures(
|
||||
pub fn complete_as_alice(
|
||||
self,
|
||||
a: bitcoin::SecretKey,
|
||||
B: bitcoin::PublicKey,
|
||||
tx_cancel_sig_B: bitcoin::Signature,
|
||||
) -> Result<Transaction> {
|
||||
let sig_a = a.sign(self.digest());
|
||||
let sig_b = tx_cancel_sig_B;
|
||||
|
||||
let tx_cancel = self
|
||||
.add_signatures((a.public(), sig_a), (B, sig_b))
|
||||
.expect("sig_{a,b} to be valid signatures for tx_cancel");
|
||||
|
||||
Ok(tx_cancel)
|
||||
}
|
||||
|
||||
pub fn complete_as_bob(
|
||||
self,
|
||||
A: bitcoin::PublicKey,
|
||||
b: bitcoin::SecretKey,
|
||||
tx_cancel_sig_A: bitcoin::Signature,
|
||||
) -> Result<Transaction> {
|
||||
let sig_a = tx_cancel_sig_A;
|
||||
let sig_b = b.sign(self.digest());
|
||||
|
||||
let tx_cancel = self
|
||||
.add_signatures((A, sig_a), (b.public(), sig_b))
|
||||
.expect("sig_{a,b} to be valid signatures for tx_cancel");
|
||||
|
||||
Ok(tx_cancel)
|
||||
}
|
||||
|
||||
fn add_signatures(
|
||||
self,
|
||||
(A, sig_a): (PublicKey, Signature),
|
||||
(B, sig_b): (PublicKey, Signature),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue