Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
kinrezC committed Feb 2, 2024
1 parent 55425dc commit ba9c0ed
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 19 deletions.
17 changes: 11 additions & 6 deletions arbiter-engine/src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,23 @@ use std::{fmt::Debug, sync::Arc};

use arbiter_core::middleware::RevmMiddleware;
use serde::de::DeserializeOwned;
use thiserror::Error;

use crate::{
machine::{Behavior, Engine, State, StateMachine},
messager::Messager,
};
use thiserror::Error;

/// An agent is an entity capable of processing events and producing actions.
/// These are the core actors in simulations or in onchain systems.
/// Agents can be connected of other agents either as a dependent, or a
/// dependency.
///
/// # How it works
/// When the [`World`] that owns the [`Agent`] is ran, it has each [`Agent`] run each of its [`Behavior`]s `startup()` methods.
/// The [`Behavior`]s themselves will return a stream of events that then let the [`Behavior`] move into the `State::Processing` stage.
/// When the [`World`] that owns the [`Agent`] is ran, it has each [`Agent`] run
/// each of its [`Behavior`]s `startup()` methods. The [`Behavior`]s themselves
/// will return a stream of events that then let the [`Behavior`] move into the
/// `State::Processing` stage.
pub struct Agent {
/// Identifier for this agent.
/// Used for routing messages.
Expand Down Expand Up @@ -49,7 +51,8 @@ impl Agent {
}
}

/// [`AgentBuilder`] represents the intermediate state of agent creation before it is converted into a full on [`Agent`]
/// [`AgentBuilder`] represents the intermediate state of agent creation before
/// it is converted into a full on [`Agent`]
pub struct AgentBuilder {
/// Identifier for this agent.
/// Used for routing messages.
Expand All @@ -60,7 +63,8 @@ pub struct AgentBuilder {
}

impl AgentBuilder {
/// Appends a behavior onto an [`AgentBuilder`]. Behaviors are initialized when the agent builder is added to the [`crate::world::World`]
/// Appends a behavior onto an [`AgentBuilder`]. Behaviors are initialized
/// when the agent builder is added to the [`crate::world::World`]
pub fn with_behavior<E: DeserializeOwned + Send + Sync + Debug + 'static>(
mut self,
behavior: impl Behavior<E> + 'static,
Expand Down Expand Up @@ -96,7 +100,8 @@ impl AgentBuilder {
/// enum representing the possible error states encountered by the agent builder
#[derive(Debug, Error, Clone, PartialEq, Eq)]
pub enum AgentBuildError {
/// Error representing the case where the agent is missing behavior engines; an agent has to have behaviors to be useful!
/// Error representing the case where the agent is missing behavior engines;
/// an agent has to have behaviors to be useful!
#[error("Agent is missing behavior engines")]
MissingBehaviorEngines,
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use self::examples::minter::agents::token_admin::TokenAdmin;

use super::*;

/// Used as an action to ask what tokens are available.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use self::examples::minter::agents::token_requester::TokenRequester;
use super::*;
use arbiter_bindings::bindings::arbiter_token::TransferFilter;
use arbiter_core::data_collection::EventLogger;
use token_admin::{MintRequest, TokenAdminQuery};

use self::examples::minter::agents::token_requester::TokenRequester;
use super::*;

#[async_trait::async_trait]
impl Behavior<TransferFilter> for TokenRequester {
#[tracing::instrument(skip(self), fields(id = messager.id.as_deref()))]
Expand Down
8 changes: 5 additions & 3 deletions arbiter-engine/src/examples/minter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ pub mod agents;
pub mod behaviors;
pub mod token_minter;

use std::pin::Pin;

use futures_util::Stream;
use tracing::error;

use crate::{
agent::Agent,
machine::{Behavior, MachineHalt, MachineInstruction, StateMachine},
messager::To,
world::World,
};
use futures_util::Stream;
use std::pin::Pin;
use tracing::error;

const TOKEN_ADMIN_ID: &str = "token_admin";
const REQUESTER_ID: &str = "requester";
Expand Down
8 changes: 5 additions & 3 deletions arbiter-engine/src/examples/minter/token_minter.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use super::*;
use crate::world::World;
use std::{str::FromStr, time::Duration};

use agents::{token_admin::TokenAdmin, token_requester::TokenRequester};
use arbiter_core::data_collection::EventLogger;
use ethers::types::Address;
use std::{str::FromStr, time::Duration};
use tokio::time::timeout;

use super::*;
use crate::world::World;

#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn token_minter_simulation() {
let mut world = World::new("test_world");
Expand Down
3 changes: 2 additions & 1 deletion arbiter-engine/src/messager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ impl Messager {
}
}

/// utility function for getting the next value from the broadcast_receiver without streaming
/// utility function for getting the next value from the broadcast_receiver
/// without streaming
pub async fn get_next(&mut self) -> Message {
while let Ok(message) = self.broadcast_receiver.as_mut().unwrap().recv().await {
match &message.to {
Expand Down
8 changes: 5 additions & 3 deletions arbiter-engine/src/world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ use crate::{agent::Agent, machine::State, messager::Messager};
/// responsible for managing the agents and their state transitions.
///
/// # How it works
/// The [`World`] holds on to a collection of [`Agent`]s and can run them all concurrently when the
/// [`run`] method is called. The [`World`] takes in [`AgentBuilder`]s and when it does so, it creates [`Agent`]s that are now
/// connected to the world via a client ([`Arc<RevmMiddleware>`]) and a messager ([`Messager`]).
/// The [`World`] holds on to a collection of [`Agent`]s and can run them all
/// concurrently when the [`run`] method is called. The [`World`] takes in
/// [`AgentBuilder`]s and when it does so, it creates [`Agent`]s that are now
/// connected to the world via a client ([`Arc<RevmMiddleware>`]) and a messager
/// ([`Messager`]).
pub struct World {
/// The identifier of the world.
pub id: String,
Expand Down

0 comments on commit ba9c0ed

Please sign in to comment.