mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-01-12 16:09:29 -05:00
Create network::Seed from swap::Seed instead of abstracting over byte array
This commit is contained in:
parent
f18d01dfaf
commit
664958939d
@ -114,7 +114,7 @@ async fn main() -> Result<()> {
|
|||||||
monero_wallet,
|
monero_wallet,
|
||||||
config,
|
config,
|
||||||
db,
|
db,
|
||||||
&seed,
|
seed,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
@ -167,7 +167,7 @@ async fn main() -> Result<()> {
|
|||||||
db,
|
db,
|
||||||
alice_peer_id,
|
alice_peer_id,
|
||||||
alice_addr,
|
alice_addr,
|
||||||
&seed,
|
seed,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
@ -211,7 +211,7 @@ async fn main() -> Result<()> {
|
|||||||
monero_wallet,
|
monero_wallet,
|
||||||
config,
|
config,
|
||||||
db,
|
db,
|
||||||
&seed,
|
seed,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
@ -244,7 +244,7 @@ async fn main() -> Result<()> {
|
|||||||
db,
|
db,
|
||||||
alice_peer_id,
|
alice_peer_id,
|
||||||
alice_addr,
|
alice_addr,
|
||||||
&seed,
|
seed,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
@ -288,9 +288,9 @@ async fn alice_swap(
|
|||||||
monero_wallet: Arc<swap::monero::Wallet>,
|
monero_wallet: Arc<swap::monero::Wallet>,
|
||||||
config: Config,
|
config: Config,
|
||||||
db: Database,
|
db: Database,
|
||||||
seed: &Seed,
|
seed: Seed,
|
||||||
) -> Result<AliceState> {
|
) -> Result<AliceState> {
|
||||||
let alice_behaviour = alice::Behaviour::new(network::Seed::new(seed.bytes()));
|
let alice_behaviour = alice::Behaviour::new(network::Seed::new(seed));
|
||||||
let alice_peer_id = alice_behaviour.peer_id();
|
let alice_peer_id = alice_behaviour.peer_id();
|
||||||
info!("Own Peer-ID: {}", alice_peer_id);
|
info!("Own Peer-ID: {}", alice_peer_id);
|
||||||
let alice_transport = build(alice_behaviour.identity())?;
|
let alice_transport = build(alice_behaviour.identity())?;
|
||||||
@ -321,9 +321,9 @@ async fn bob_swap(
|
|||||||
db: Database,
|
db: Database,
|
||||||
alice_peer_id: PeerId,
|
alice_peer_id: PeerId,
|
||||||
alice_addr: Multiaddr,
|
alice_addr: Multiaddr,
|
||||||
seed: &Seed,
|
seed: Seed,
|
||||||
) -> Result<BobState> {
|
) -> Result<BobState> {
|
||||||
let bob_behaviour = bob::Behaviour::new(network::Seed::new(seed.bytes()));
|
let bob_behaviour = bob::Behaviour::new(network::Seed::new(seed));
|
||||||
let bob_transport = build(bob_behaviour.identity())?;
|
let bob_transport = build(bob_behaviour.identity())?;
|
||||||
|
|
||||||
let (event_loop, handle) =
|
let (event_loop, handle) =
|
||||||
|
@ -25,17 +25,17 @@ pub struct Seed([u8; SEED_LENGTH]);
|
|||||||
|
|
||||||
impl Seed {
|
impl Seed {
|
||||||
/// prefix "NETWORK" to the provided seed and apply sha256
|
/// prefix "NETWORK" to the provided seed and apply sha256
|
||||||
pub fn new(seed: [u8; crate::seed::SEED_LENGTH]) -> Self {
|
pub fn new(seed: crate::seed::Seed) -> Self {
|
||||||
let mut engine = sha256::HashEngine::default();
|
let mut engine = sha256::HashEngine::default();
|
||||||
|
|
||||||
engine.input(&seed);
|
engine.input(&seed.bytes());
|
||||||
engine.input(b"NETWORK");
|
engine.input(b"NETWORK");
|
||||||
|
|
||||||
let hash = sha256::Hash::from_engine(engine);
|
let hash = sha256::Hash::from_engine(engine);
|
||||||
Self(hash.into_inner())
|
Self(hash.into_inner())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bytes(&self) -> [u8; SEED_LENGTH] {
|
fn bytes(&self) -> [u8; SEED_LENGTH] {
|
||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ async fn happy_path() {
|
|||||||
xmr_alice,
|
xmr_alice,
|
||||||
alice_multiaddr.clone(),
|
alice_multiaddr.clone(),
|
||||||
config,
|
config,
|
||||||
&Seed::random().unwrap(),
|
Seed::random().unwrap(),
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ async fn given_alice_restarts_after_encsig_is_learned_resume_swap() {
|
|||||||
alice_xmr_starting_balance,
|
alice_xmr_starting_balance,
|
||||||
alice_multiaddr.clone(),
|
alice_multiaddr.clone(),
|
||||||
config,
|
config,
|
||||||
&alice_seed,
|
alice_seed,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
@ -128,7 +128,7 @@ async fn given_alice_restarts_after_encsig_is_learned_resume_swap() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let (mut event_loop_after_restart, event_loop_handle_after_restart) =
|
let (mut event_loop_after_restart, event_loop_handle_after_restart) =
|
||||||
testutils::init_alice_event_loop(alice_multiaddr, &alice_seed);
|
testutils::init_alice_event_loop(alice_multiaddr, alice_seed);
|
||||||
tokio::spawn(async move { event_loop_after_restart.run().await });
|
tokio::spawn(async move { event_loop_after_restart.run().await });
|
||||||
|
|
||||||
let alice_state = alice::swap::swap(
|
let alice_state = alice::swap::swap(
|
||||||
|
@ -58,7 +58,7 @@ async fn given_bob_restarts_after_encsig_is_sent_resume_swap() {
|
|||||||
alice_xmr_starting_balance,
|
alice_xmr_starting_balance,
|
||||||
alice_multiaddr.clone(),
|
alice_multiaddr.clone(),
|
||||||
config,
|
config,
|
||||||
&Seed::random().unwrap(),
|
Seed::random().unwrap(),
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ async fn given_bob_restarts_after_xmr_is_locked_resume_swap() {
|
|||||||
alice_xmr_starting_balance,
|
alice_xmr_starting_balance,
|
||||||
alice_multiaddr.clone(),
|
alice_multiaddr.clone(),
|
||||||
Config::regtest(),
|
Config::regtest(),
|
||||||
&Seed::random().unwrap(),
|
Seed::random().unwrap(),
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ async fn alice_punishes_if_bob_never_acts_after_fund() {
|
|||||||
alice_xmr_starting_balance,
|
alice_xmr_starting_balance,
|
||||||
alice_multiaddr.clone(),
|
alice_multiaddr.clone(),
|
||||||
config,
|
config,
|
||||||
&Seed::random().unwrap(),
|
Seed::random().unwrap(),
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ async fn given_alice_restarts_after_xmr_is_locked_abort_swap() {
|
|||||||
alice_xmr_starting_balance,
|
alice_xmr_starting_balance,
|
||||||
alice_multiaddr.clone(),
|
alice_multiaddr.clone(),
|
||||||
Config::regtest(),
|
Config::regtest(),
|
||||||
&alice_seed,
|
alice_seed,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
@ -124,7 +124,7 @@ async fn given_alice_restarts_after_xmr_is_locked_abort_swap() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let (mut alice_event_loop_2, alice_event_loop_handle_2) =
|
let (mut alice_event_loop_2, alice_event_loop_handle_2) =
|
||||||
testutils::init_alice_event_loop(alice_multiaddr, &alice_seed);
|
testutils::init_alice_event_loop(alice_multiaddr, alice_seed);
|
||||||
|
|
||||||
let alice_final_state = {
|
let alice_final_state = {
|
||||||
let alice_db = Database::open(alice_db_datadir.path()).unwrap();
|
let alice_db = Database::open(alice_db_datadir.path()).unwrap();
|
||||||
|
@ -107,12 +107,12 @@ pub async fn init_alice_state(
|
|||||||
|
|
||||||
pub fn init_alice_event_loop(
|
pub fn init_alice_event_loop(
|
||||||
listen: Multiaddr,
|
listen: Multiaddr,
|
||||||
seed: &Seed,
|
seed: Seed,
|
||||||
) -> (
|
) -> (
|
||||||
alice::event_loop::EventLoop,
|
alice::event_loop::EventLoop,
|
||||||
alice::event_loop::EventLoopHandle,
|
alice::event_loop::EventLoopHandle,
|
||||||
) {
|
) {
|
||||||
let alice_behaviour = alice::Behaviour::new(network::Seed::new(seed.bytes()));
|
let alice_behaviour = alice::Behaviour::new(network::Seed::new(seed));
|
||||||
let alice_transport = build(alice_behaviour.identity()).unwrap();
|
let alice_transport = build(alice_behaviour.identity()).unwrap();
|
||||||
alice::event_loop::EventLoop::new(alice_transport, alice_behaviour, listen).unwrap()
|
alice::event_loop::EventLoop::new(alice_transport, alice_behaviour, listen).unwrap()
|
||||||
}
|
}
|
||||||
@ -126,7 +126,7 @@ pub async fn init_alice(
|
|||||||
xmr_starting_balance: monero::Amount,
|
xmr_starting_balance: monero::Amount,
|
||||||
listen: Multiaddr,
|
listen: Multiaddr,
|
||||||
config: Config,
|
config: Config,
|
||||||
seed: &Seed,
|
seed: Seed,
|
||||||
) -> (
|
) -> (
|
||||||
AliceState,
|
AliceState,
|
||||||
alice::event_loop::EventLoop,
|
alice::event_loop::EventLoop,
|
||||||
@ -193,7 +193,7 @@ pub fn init_bob_event_loop(
|
|||||||
alice_addr: Multiaddr,
|
alice_addr: Multiaddr,
|
||||||
) -> (bob::event_loop::EventLoop, bob::event_loop::EventLoopHandle) {
|
) -> (bob::event_loop::EventLoop, bob::event_loop::EventLoopHandle) {
|
||||||
let seed = Seed::random().unwrap();
|
let seed = Seed::random().unwrap();
|
||||||
let bob_behaviour = bob::Behaviour::new(network::Seed::new(seed.bytes()));
|
let bob_behaviour = bob::Behaviour::new(network::Seed::new(seed));
|
||||||
let bob_transport = build(bob_behaviour.identity()).unwrap();
|
let bob_transport = build(bob_behaviour.identity()).unwrap();
|
||||||
bob::event_loop::EventLoop::new(bob_transport, bob_behaviour, alice_peer_id, alice_addr)
|
bob::event_loop::EventLoop::new(bob_transport, bob_behaviour, alice_peer_id, alice_addr)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
Loading…
Reference in New Issue
Block a user