Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle error and include some traits #4

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 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 Down Expand Up @@ -69,7 +69,9 @@ impl Behavior<()> for Deployer {
pool,
);

messager.send(To::All, serde_json::to_string(&deployment_data)?).await;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could just ? here to save LOC as it is effectively the same thing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, prefer using this ? tbh, mistake on my path

let _ = messager
.send(To::All, serde_json::to_string(&deployment_data)?)
.await;
Comment on lines +72 to +74
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let _ = messager
.send(To::All, serde_json::to_string(&deployment_data)?)
.await;
messager
.send(To::All, serde_json::to_string(&deployment_data)?)
.await?;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually prefer to use the ? and not even catch the errors manually unless I need to do something with them. https://doc.rust-lang.org/rust-by-example/std/result/question_mark.html

The linter gets mad when you do messager.send(_).await as the Result<_,_> type is tagged by clippy as must_use. By doing let _ = messager.send(_).await what happens is that the Result is actually immediately dropped and we won't know if it is Ok or Err!


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;
15 changes: 3 additions & 12 deletions src/bindings/bit_math.rs
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not change any bindings files as they are quite finnicky and autogenned

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Autoparallel yep, will close this

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub use bit_math::*;
non_camel_case_types
)]
pub mod bit_math {

#[allow(deprecated)]
fn __abi() -> ::ethers::core::abi::Abi {
::ethers::core::abi::ethabi::Contract {
Expand All @@ -34,12 +35,8 @@ pub mod bit_math {
/// The deployed bytecode of the contract.
pub static BITMATH_DEPLOYED_BYTECODE: ::ethers::core::types::Bytes =
::ethers::core::types::Bytes::from_static(__DEPLOYED_BYTECODE);
#[derive(core::clone::Clone, core::fmt::Debug)]
pub struct BitMath<M>(::ethers::contract::Contract<M>);
impl<M> ::core::clone::Clone for BitMath<M> {
fn clone(&self) -> Self {
Self(::core::clone::Clone::clone(&self.0))
}
}
impl<M> ::core::ops::Deref for BitMath<M> {
type Target = ::ethers::contract::Contract<M>;
fn deref(&self) -> &Self::Target {
Expand All @@ -51,13 +48,7 @@ pub mod bit_math {
&mut self.0
}
}
impl<M> ::core::fmt::Debug for BitMath<M> {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.debug_tuple(::core::stringify!(BitMath))
.field(&self.address())
.finish()
}
}

impl<M: ::ethers::providers::Middleware> BitMath<M> {
/// Creates a new contract instance with the specified `ethers` client at
/// `address`. The contract derefs to a `ethers::Contract` object.
Expand Down
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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For clippy?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For clippy?

yeah

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a crate?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}