Skip to content

Commit 2d7aed8

Browse files
authored
Merge pull request #123 from stejbac/clean-dependencies-and-imports
Clean dependencies and imports
2 parents fb3497e + 6638ddc commit 2d7aed8

20 files changed

Lines changed: 677 additions & 575 deletions

Cargo.lock

Lines changed: 412 additions & 273 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,28 @@ members = ["protocol", "rpc", "wallet", "testenv"]
44
exclude = ["poc"]
55

66
[workspace.dependencies]
7-
anyhow = "1.0.100"
7+
anyhow = "1.0.101"
8+
argon2 = { version = "0.5.3", default-features = false }
9+
base64 = "0.22.1"
810
bdk_bitcoind_rpc = "0.22.0"
911
bdk_electrum = { version = "0.23.2", default-features = false, features = ["use-rustls-ring"] }
10-
rustls = { version = "0.23.35", default-features = false, features = ["ring", "std", "tls12", "logging"] }
12+
bdk_kyoto = "0.15.4"
1113
# v2.2.0 deprecates `bdk_wallet::wallet::signer` without making it clear what alternative to use & how:
1214
bdk_wallet = { version = "~2.1.0", features = ["rusqlite", "keys-bip39"] }
13-
bdk_kyoto = "0.15.3"
1415
const_format = "0.2.35"
15-
rusqlite = { version = "0.31.0", features = ["bundled-sqlcipher"] }
16-
16+
hex = "0.4.3"
1717
musig2 = { version = "0.3.1", features = ["rand"] }
1818
rand = "0.9.2"
1919
rand_chacha = "0.9.0"
20+
rusqlite = { version = "0.31.0", features = ["bundled-sqlcipher"] }
2021
secp = "0.6.0"
21-
thiserror = "2.0.16"
22-
tokio = "1.48.0"
23-
base64 = "0.22.1"
24-
hex = "0.4"
25-
zeroize = "1.8.1"
26-
argon2 = { version = "0.5.3", default-features = false }
27-
tracing = "0.1"
28-
tracing-subscriber = "0.3"
22+
simple-semaphore = "0.2.0"
23+
tempfile = "3.25.0"
24+
thiserror = "2.0.18"
25+
tokio = "1.49.0"
26+
tracing = "0.1.44"
27+
tracing-subscriber = "0.3.22"
28+
zeroize = "1.8.2"
2929

3030
[workspace.lints.rust]
3131
rust-2024-compatibility = "warn"

protocol/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ paste = "1.0.15"
1313
rand = { workspace = true }
1414
rand_chacha = { workspace = true }
1515
thiserror = { workspace = true }
16-
rustls = { workspace = true }
17-
# this should move to the dev section
18-
testenv = { path = "../testenv"}
16+
# TODO move this to dev-dependencies:
17+
testenv = { path = "../testenv" }
1918

2019
[dev-dependencies]
2120
bdk_wallet = { workspace = true, features = ["test-utils"] }

protocol/src/protocol_musig_adaptor.rs

Lines changed: 34 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
use std::io::Write as _;
22
use 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;
105
use bdk_electrum::electrum_client::Client;
11-
use bdk_electrum::{electrum_client, BdkElectrumClient};
126
use bdk_wallet::bitcoin::bip32::Xpriv;
137
use 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
};
1711
use bdk_wallet::template::{Bip86, DescriptorTemplate as _};
1812
use bdk_wallet::{AddressInfo, KeychainKind, SignOptions, Wallet};
@@ -21,9 +15,16 @@ use musig2::{PartialSignature, PubNonce};
2115
use rand::RngCore as _;
2216
use 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+
2425
pub struct MemWallet {
2526
wallet: Wallet,
26-
client: BdkElectrumClient<electrum_client::Client>,
27+
client: BdkElectrumClient<Client>,
2728
}
2829

2930
impl 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
213212
pub 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)]
444441
pub 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)]
518511
pub 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.
570561
pub 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
669658
pub 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.

protocol/tests/protocol_integration_tests.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
use bdk_electrum::bdk_core::bitcoin;
2-
use bdk_electrum::bdk_core::bitcoin::key::{Keypair, Secp256k1, TweakedKeypair, TweakedPublicKey};
3-
use bdk_electrum::bdk_core::bitcoin::secp256k1::Message;
4-
use bdk_electrum::bdk_core::bitcoin::{Amount, TapSighashType};
5-
use bdk_wallet::bitcoin::key::TapTweak as _;
6-
use musig2::secp::Point;
1+
use bdk_wallet::bitcoin;
2+
use bitcoin::key::{Keypair, Secp256k1, TapTweak as _, TweakedKeypair, TweakedPublicKey};
3+
use bitcoin::secp256k1::Message;
4+
use bitcoin::{Amount, TapSighashType};
75
use musig2::KeyAggContext;
6+
use musig2::secp::Point;
87
use protocol::protocol_musig_adaptor::{BMPContext, BMPProtocol, MemWallet, ProtocolRole};
98
use protocol::transaction::WithWitnesses as _;
109
use protocol::wallet_service::WalletService;
@@ -18,7 +17,6 @@ fn test_initial_tx_creation() -> anyhow::Result<()> {
1817
Ok(())
1918
}
2019

21-
2220
fn initial_tx_creation(env: &TestEnv) -> anyhow::Result<(BMPProtocol, BMPProtocol)> {
2321
println!("running...");
2422
let alice_funds = MemWallet::funded_wallet(env);
@@ -66,8 +64,8 @@ fn initial_tx_creation(env: &TestEnv) -> anyhow::Result<(BMPProtocol, BMPProtoco
6664

6765
#[test]
6866
fn test_swap() -> anyhow::Result<()> {
69-
let mut env = TestEnv::new()?;
70-
env.start_explorer_in_container()?;
67+
let env = TestEnv::new()?;
68+
// env.start_explorer_in_container()?;
7169

7270
// create all transaction and Broadcast DepositTx already
7371
let (mut alice, mut bob) = initial_tx_creation(&env)?;

rpc/Cargo.toml

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,37 @@ default-run = "musig-cli"
99
bdk_bitcoind_rpc = { workspace = true }
1010
bdk_wallet = { workspace = true }
1111
drop-stream = "0.3.2"
12-
futures-util = { version = "0.3.31", default-features = false, features = ["alloc"] }
12+
futures-util = { version = "0.3.32", default-features = false, features = ["alloc"] }
1313
guardian = "1.3.0"
1414
musig2 = { workspace = true }
15-
prost = "0.14.1"
15+
prost = "0.14.3"
1616
protocol = { path = "../protocol" }
1717
rand = { workspace = true }
1818
serde = { version = "1.0.228", features = ["derive"] }
19-
serde_with = { version = "3.15.1", features = ["base64", "hex"] }
19+
serde_with = { version = "3.16.1", features = ["base64", "hex"] }
2020
thiserror = { workspace = true }
21-
rustls = { workspace = true }
2221
tokio = { workspace = true, features = ["macros", "rt-multi-thread", "time"] }
23-
tokio-stream = "0.1.17"
24-
tonic = "0.14.2"
25-
tonic-prost = "0.14.2"
26-
tracing = "0.1.41"
22+
tokio-stream = "0.1.18"
23+
tonic = "0.14.4"
24+
tonic-prost = "0.14.4"
25+
tracing = { workspace = true }
2726
unimock = { version = "0.6.8", optional = true }
2827
# Dependencies used only by the binary target(s):
2928
# TODO: Consider making a workspace of separate packages to avoid pulling these into the library:
30-
clap = { version = "4.5.51", features = ["derive"] }
31-
tracing-subscriber = { version = "0.3.20", features = ["env-filter"] }
32-
# TODO move this to dev-dependencies
29+
clap = { version = "4.5.59", features = ["derive"] }
30+
tracing-subscriber = { workspace = true, features = ["env-filter"] }
31+
# TODO move this to dev-dependencies:
3332
testenv = { path ="../testenv"}
3433

3534
[build-dependencies]
36-
tonic-prost-build = "0.14.2"
35+
tonic-prost-build = "0.14.4"
3736

3837
[dev-dependencies]
3938
rpc = { path = ".", features = ["unimock"] }
4039
anyhow = { workspace = true }
41-
assert_cmd = "2.1.1"
40+
assert_cmd = "2.1.2"
4241
const_format = { workspace = true }
43-
predicates = "3.1.3"
42+
predicates = "3.1.4"
4443

4544
[lints]
4645
workspace = true

rpc/src/bin/musigd.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
use std::error::Error;
2+
use std::sync::Arc;
3+
14
use clap::Parser;
25
use rpc::bmp_service::BmpServiceImpl;
36
use rpc::bmp_wallet_service::BmpWalletServiceImpl;
47
use rpc::pb::bmp_protocol::bmp_protocol_service_server::BmpProtocolServiceServer;
58
use rpc::pb::bmp_wallet::wallet_server::WalletServer as BmpWalletServer;
69
use rpc::server::{MusigImpl, MusigServer, WalletImpl, WalletServer};
710
use rpc::wallet::WalletServiceImpl;
8-
use std::error::Error;
9-
use std::sync::Arc;
1011
use testenv::TestEnv;
1112
use tonic::transport::Server;
1213
use tracing::info;

rpc/src/bmp_service.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
use std::collections::HashMap;
22
use std::sync::Mutex;
33

4-
use crate::pb::bmp_protocol::bmp_protocol_service_server::BmpProtocolService;
5-
use crate::pb::bmp_protocol::{self, InitializeRequest, InitializeResponse, Role};
6-
use crate::pb::convert::TryProtoInto as _;
74
use bdk_wallet::bitcoin::Amount;
8-
use protocol::protocol_musig_adaptor::{BMPContext, BMPProtocol, MemWallet, ProtocolRole, Round1Parameter};
5+
use protocol::protocol_musig_adaptor::{
6+
BMPContext, BMPProtocol, MemWallet, ProtocolRole, Round1Parameter,
7+
};
98
use protocol::wallet_service::WalletService;
109
use testenv::TestEnv;
1110
use tonic::{Request, Response, Result, Status};
1211
use tracing::info;
1312

13+
use crate::pb::bmp_protocol::bmp_protocol_service_server::BmpProtocolService;
14+
use crate::pb::bmp_protocol::{self, InitializeRequest, InitializeResponse, Role};
15+
use crate::pb::convert::TryProtoInto as _;
16+
1417
#[derive(Default)]
1518
pub struct BmpServiceImpl {
1619
// Each trade protocol is stored against a unique ID.

rpc/src/observable.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ fn shrink_amortized<T>(vec: &mut Vec<T>) {
6464
vec.shrink_to(vec.len() * 2);
6565
}
6666
}
67+
6768
#[derive(Debug)]
6869
pub struct ObservableHashMap<K, V> {
6970
map: HashMap<K, Observable<Option<V>>>,
@@ -121,7 +122,7 @@ impl<K, V> ObservableHashMap<K, V>
121122
}
122123

123124
impl<K, V> ObservableHashMap<K, V>
124-
where
125+
where
125126
K: Clone + Eq + Hash + Debug,
126127
V: Clone + PartialEq + Debug,
127128
{
@@ -134,7 +135,7 @@ where
134135
for key in remaining_keys {
135136
self.remove(&key);
136137
}
137-
trace!("ObservableHashMap.len {}",self.map.len());
138+
trace!("ObservableHashMap.len {}", self.map.len());
138139
// dbg!(&self.map);
139140
}
140141
}

0 commit comments

Comments
 (0)