Create network::Seed from swap::Seed instead of abstracting over byte array

pull/127/head
Daniel Karzel 3 years ago
parent f18d01dfaf
commit 664958939d

@ -114,7 +114,7 @@ async fn main() -> Result<()> {
monero_wallet,
config,
db,
&seed,
seed,
)
.await?;
}
@ -167,7 +167,7 @@ async fn main() -> Result<()> {
db,
alice_peer_id,
alice_addr,
&seed,
seed,
)
.await?;
}
@ -211,7 +211,7 @@ async fn main() -> Result<()> {
monero_wallet,
config,
db,
&seed,
seed,
)
.await?;
}
@ -244,7 +244,7 @@ async fn main() -> Result<()> {
db,
alice_peer_id,
alice_addr,
&seed,
seed,
)
.await?;
}
@ -288,9 +288,9 @@ async fn alice_swap(
monero_wallet: Arc<swap::monero::Wallet>,
config: Config,
db: Database,
seed: &Seed,
seed: Seed,
) -> 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();
info!("Own Peer-ID: {}", alice_peer_id);
let alice_transport = build(alice_behaviour.identity())?;
@ -321,9 +321,9 @@ async fn bob_swap(
db: Database,
alice_peer_id: PeerId,
alice_addr: Multiaddr,
seed: &Seed,
seed: Seed,
) -> 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 (event_loop, handle) =

@ -25,17 +25,17 @@ pub struct Seed([u8; SEED_LENGTH]);
impl Seed {
/// 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();
engine.input(&seed);
engine.input(&seed.bytes());
engine.input(b"NETWORK");
let hash = sha256::Hash::from_engine(engine);
Self(hash.into_inner())
}
pub fn bytes(&self) -> [u8; SEED_LENGTH] {
fn bytes(&self) -> [u8; SEED_LENGTH] {
self.0
}

@ -66,7 +66,7 @@ async fn happy_path() {
xmr_alice,
alice_multiaddr.clone(),
config,
&Seed::random().unwrap(),
Seed::random().unwrap(),
)
.await;

@ -59,7 +59,7 @@ async fn given_alice_restarts_after_encsig_is_learned_resume_swap() {
alice_xmr_starting_balance,
alice_multiaddr.clone(),
config,
&alice_seed,
alice_seed,
)
.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) =
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 });
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_multiaddr.clone(),
config,
&Seed::random().unwrap(),
Seed::random().unwrap(),
)
.await;

@ -60,7 +60,7 @@ async fn given_bob_restarts_after_xmr_is_locked_resume_swap() {
alice_xmr_starting_balance,
alice_multiaddr.clone(),
Config::regtest(),
&Seed::random().unwrap(),
Seed::random().unwrap(),
)
.await;

@ -64,7 +64,7 @@ async fn alice_punishes_if_bob_never_acts_after_fund() {
alice_xmr_starting_balance,
alice_multiaddr.clone(),
config,
&Seed::random().unwrap(),
Seed::random().unwrap(),
)
.await;

@ -64,7 +64,7 @@ async fn given_alice_restarts_after_xmr_is_locked_abort_swap() {
alice_xmr_starting_balance,
alice_multiaddr.clone(),
Config::regtest(),
&alice_seed,
alice_seed,
)
.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) =
testutils::init_alice_event_loop(alice_multiaddr, &alice_seed);
testutils::init_alice_event_loop(alice_multiaddr, alice_seed);
let alice_final_state = {
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(
listen: Multiaddr,
seed: &Seed,
seed: Seed,
) -> (
alice::event_loop::EventLoop,
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();
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,
listen: Multiaddr,
config: Config,
seed: &Seed,
seed: Seed,
) -> (
AliceState,
alice::event_loop::EventLoop,
@ -193,7 +193,7 @@ pub fn init_bob_event_loop(
alice_addr: Multiaddr,
) -> (bob::event_loop::EventLoop, bob::event_loop::EventLoopHandle) {
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();
bob::event_loop::EventLoop::new(bob_transport, bob_behaviour, alice_peer_id, alice_addr)
.unwrap()

Loading…
Cancel
Save