Skip to content

Commit

Permalink
handle relayer peg client initialization state
Browse files Browse the repository at this point in the history
  • Loading branch information
keppel committed Nov 8, 2019
1 parent c6f1725 commit 4a2de88
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions relayer/src/relayer.rs
@@ -1,4 +1,5 @@
use bitcoincore_rpc::{Auth, Client, Error, RpcApi};
use nomic_client::{Client as PegClient, ClientError as PegClientError};
use nomic_primitives::transaction::Transaction;
use std::env;

Expand Down Expand Up @@ -61,13 +62,15 @@ impl RelayerState {
pub struct RelayerStateMachine {
pub state: RelayerState,
rpc: Option<Client>,
peg_client: Option<PegClient>,
}

impl RelayerStateMachine {
pub fn new() -> Self {
RelayerStateMachine {
state: RelayerState::InitializeBitcoinRpc,
rpc: None,
peg_client: None,
}
}

Expand All @@ -85,6 +88,16 @@ impl RelayerStateMachine {
Err(_) => InitializeBitcoinRpcFailure,
}
}
InitializePegClient => {
let peg_client = PegClient::new();
match peg_client {
Ok(peg_client) => {
self.peg_client = Some(peg_client);
InitializePegClientSuccess
}
Err(_) => InitializePegClientFailure,
}
}
_ => panic!("Relayer is in an unhandled state"),
}
}
Expand All @@ -109,8 +122,10 @@ mod tests {
#[test]
fn run_relayer_state_machine() {
let mut sm = RelayerStateMachine::new();
let event = sm.run();
sm.state = sm.state.next(event);
println!("sm state: {:?}", sm.state);
for _ in 0..2 {
let event = sm.run();
sm.state = sm.state.next(event);
println!("sm state: {:?}", sm.state);
}
}
}

0 comments on commit 4a2de88

Please sign in to comment.