Skip to content

Commit

Permalink
handle error and include some traits
Browse files Browse the repository at this point in the history
  • Loading branch information
malik672 committed Feb 18, 2024
1 parent c80c735 commit 3318164
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
17 changes: 13 additions & 4 deletions src/behaviors/deployer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use ethers::types::H160;
use super::*;
use crate::bindings::{token::ArbiterToken, uniswap_v3_factory::UniswapV3Factory};

#[derive(Debug, Deserialize, Serialize)]
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct DeploymentData {
token_0: H160,
token_1: H160,
Expand All @@ -30,7 +30,7 @@ impl DeploymentData {
}
}

#[derive(Debug, Deserialize, Serialize)]
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct Deployer;

#[async_trait::async_trait]
Expand All @@ -54,7 +54,7 @@ impl Behavior<()> for Deployer {
.send()
.await?;

let factory = UniswapV3Factory::deploy(client, ())?.send().await?;
let factory = UniswapV3Factory::deploy(client.clone(), ())?.send().await?;

let pool = factory
.create_pool(token_0.address(), token_1.address(), 100)
Expand All @@ -69,7 +69,16 @@ impl Behavior<()> for Deployer {
pool,
);

messager.send(To::All, serde_json::to_string(&deployment_data)?).await;
match serde_json::to_string(&deployment_data) {
Ok(json_string) => {
messager
.send(To::All, json_string)
.await?;
}
Err(_) => {
return Err(anyhow::anyhow!("Failed to serialize deployment data"));
}
}

Ok(None)
}
Expand Down
2 changes: 1 addition & 1 deletion src/behaviors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ use serde::{Deserialize, Serialize};

pub mod deployer;

pub use deployer::Deployer;
pub use deployer::Deployer;
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ async fn main() {
let deployer = Agent::builder("deployer").with_behavior(Deployer);

world.add_agent(deployer);
world.run().await;
let _ = world.run().await;
}

0 comments on commit 3318164

Please sign in to comment.