11use std:: io:: Write as _;
22use std:: str:: FromStr as _;
33
4- use crate :: multisig:: { KeyCtx , SigCtx } ;
5- use crate :: receiver:: { Receiver , ReceiverList } ;
6- use crate :: transaction:: {
7- DepositTxBuilder , ForwardingTxBuilder , RedirectTxBuilder , WarningTxBuilder , WithWitnesses as _,
8- } ;
9- use crate :: wallet_service:: WalletService ;
4+ use bdk_electrum:: BdkElectrumClient ;
105use bdk_electrum:: electrum_client:: Client ;
11- use bdk_electrum:: { electrum_client, BdkElectrumClient } ;
126use bdk_wallet:: bitcoin:: bip32:: Xpriv ;
137use bdk_wallet:: bitcoin:: {
14- relative , Address , Amount , FeeRate , Network , OutPoint , Psbt , ScriptBuf , Transaction , TxOut ,
15- Txid ,
8+ Address , Amount , FeeRate , Network , OutPoint , Psbt , ScriptBuf , Transaction , TxOut , Txid ,
9+ relative ,
1610} ;
1711use bdk_wallet:: template:: { Bip86 , DescriptorTemplate as _} ;
1812use bdk_wallet:: { AddressInfo , KeychainKind , SignOptions , Wallet } ;
@@ -21,9 +15,16 @@ use musig2::{PartialSignature, PubNonce};
2115use rand:: RngCore as _;
2216use testenv:: TestEnv ;
2317
18+ use crate :: multisig:: { KeyCtx , SigCtx } ;
19+ use crate :: receiver:: { Receiver , ReceiverList } ;
20+ use crate :: transaction:: {
21+ DepositTxBuilder , ForwardingTxBuilder , RedirectTxBuilder , WarningTxBuilder , WithWitnesses as _,
22+ } ;
23+ use crate :: wallet_service:: WalletService ;
24+
2425pub struct MemWallet {
2526 wallet : Wallet ,
26- client : BdkElectrumClient < electrum_client :: Client > ,
27+ client : BdkElectrumClient < Client > ,
2728}
2829
2930impl MemWallet {
@@ -43,7 +44,7 @@ impl MemWallet {
4344 pub fn funded_wallet ( env : & TestEnv ) -> Self {
4445 // TODO move this line to TestEnv
4546 let client =
46- BdkElectrumClient :: new ( electrum_client :: Client :: new ( & env. electrum_url ( ) ) . unwrap ( ) ) ;
47+ BdkElectrumClient :: new ( Client :: new ( & env. electrum_url ( ) ) . unwrap ( ) ) ;
4748 let mut wallet = Self :: new ( client) . unwrap ( ) ;
4849 let address = wallet. next_unused_address ( ) ;
4950 let txid = env
@@ -207,9 +208,7 @@ pub struct Round4Parameter {
207208 pub deposit_tx_signed : Psbt ,
208209}
209210
210- /**
211- this context is for the whole process and need to be persisted by the caller
212- */
211+ /// this context is for the whole process and need to be persisted by the caller
213212pub struct BMPContext {
214213 // first of all, everything which is general to the protocol itself
215214 pub funds : MemWallet ,
@@ -428,18 +427,16 @@ impl BMPProtocol {
428427 }
429428}
430429
431- /**
432- `RedirectTx` -- this redirects the funds from the `WarningTx` to the DAO.
433- This is expected if the traders have some sor of conflict, which they cannot resolve themselves.
434- One trader sends the `WarningTx`, the other trader answers by sending the `RedirectTx`.
435- If a redirectTx is not send within `t_2`, then the trader which sent the `WarningTx` can
436- send the `ClaimTx` and gets the hole funds for himself.
437- Since `RedirectTx` sends the funds to the DAO, it needs an anchors for the trader, so he
438- can raise the fees with CPFP to get it mined before `ClaimTx` can be broadcast.
439-
440- `RedirectTx` Bob spends from `WarningTx` Alice, that's important.
441- Sending funds to the DAO is done by having a list of addresses (from contributors) and percentages. (must add up to 100%)
442- */
430+ /// `RedirectTx` -- this redirects the funds from the `WarningTx` to the DAO.
431+ /// This is expected if the traders have some sor of conflict, which they cannot resolve themselves.
432+ /// One trader sends the `WarningTx`, the other trader answers by sending the `RedirectTx`.
433+ /// If a redirectTx is not send within `t_2`, then the trader which sent the `WarningTx` can
434+ /// send the `ClaimTx` and gets the hole funds for himself.
435+ /// Since `RedirectTx` sends the funds to the DAO, it needs an anchors for the trader, so he
436+ /// can raise the fees with CPFP to get it mined before `ClaimTx` can be broadcast.
437+ ///
438+ /// `RedirectTx` Bob spends from `WarningTx` Alice, that's important.
439+ /// Sending funds to the DAO is done by having a list of addresses (from contributors) and percentages. (must add up to 100%)
443440#[ derive( Default ) ]
444441pub struct RedirectTx {
445442 pub sig : SigCtx ,
@@ -496,9 +493,7 @@ impl RedirectTx {
496493 Ok ( me. funds . client . transaction_broadcast ( self . builder . signed_tx ( ) ?) ?)
497494 }
498495
499- /**
500- sum of all f64 must be 1
501- */
496+ /// sum of all f64 must be 1
502497 //noinspection SpellCheckingInspection
503498 fn get_dao_bm ( ) -> Vec < ( Address , f64 ) > {
504499 // TODO this needs a real implementation, and check that sum of ratios is 1
@@ -509,11 +504,9 @@ impl RedirectTx {
509504 }
510505}
511506
512- /**
513- `ClaimTx` -- One version for Alice and one for Bob.
514- If the other side will not react on the `WarningTx` (by sending the `RedirectTx`)
515- then Alice can claim the total amounts for herself.
516- */
507+ /// `ClaimTx` -- One version for Alice and one for Bob.
508+ /// If the other side will not react on the `WarningTx` (by sending the `RedirectTx`)
509+ /// then Alice can claim the total amounts for herself.
517510#[ derive( Default ) ]
518511pub struct ClaimTx {
519512 pub sig : SigCtx ,
@@ -563,10 +556,8 @@ impl ClaimTx {
563556 }
564557}
565558
566- /**
567- `WarningTx` -- there is one version for Alice and one for Bob.
568- That means each party generates both transaction and sign them.
569- */
559+ /// `WarningTx` -- there is one version for Alice and one for Bob.
560+ /// That means each party generates both transaction and sign them.
570561pub struct WarningTx {
571562 // is that my WarningTx? (mainly for safety checking):
572563 role : ProtocolRole ,
@@ -663,9 +654,7 @@ impl WarningTx {
663654 }
664655}
665656
666- /**
667- Only the seller gets a `SwapTx`, this is the only asymmetric part of the p3
668- */
657+ /// Only the seller gets a `SwapTx`, this is the only asymmetric part of the p3
669658pub struct SwapTx {
670659 // this transaction is only for Alice, however even Bob will construct it for signing:
671660 pub role : ProtocolRole ,
@@ -684,10 +673,8 @@ impl SwapTx {
684673 self . swap_spend . clone ( )
685674 }
686675
687- /**
688- even though only the seller gets a `SwapTx` transaction, both parties are constructing the transaction
689- and only the buyer will send the seller the signature.
690- */
676+ /// even though only the seller gets a `SwapTx` transaction, both parties are constructing the transaction
677+ /// and only the buyer will send the seller the signature.
691678 fn new ( role : ProtocolRole ) -> Self {
692679 Self {
693680 role,
@@ -753,10 +740,8 @@ impl SwapTx {
753740 }
754741 }
755742
756- /**
757- if Bob finds a `SwapTx` on chain (or in mempool), we can (and should) extract Alice key for
758- unlocking the seller's deposit and fund, which is as adaptive secret in the signature
759- */
743+ /// if Bob finds a `SwapTx` on chain (or in mempool), we can (and should) extract Alice key for
744+ /// unlocking the seller's deposit and fund, which is as adaptive secret in the signature
760745 pub fn reveal ( & self , swap_tx : & Transaction , p_tik : & mut KeyCtx ) -> anyhow:: Result < ( ) > {
761746 let signature = swap_tx. key_spend_signature ( 0 ) ?;
762747 // calculate the aggregated secret key as well.
0 commit comments