Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
0xmovses committed Jun 6, 2024
1 parent 54b1c17 commit adb3f91
Show file tree
Hide file tree
Showing 48 changed files with 5,832 additions and 5,822 deletions.
217 changes: 110 additions & 107 deletions networks/monza/monza-client/src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
coin_client::CoinClient,
rest_client::{Client, FaucetClient},
types::LocalAccount,
coin_client::CoinClient,
rest_client::{Client, FaucetClient},
types::LocalAccount,
};
use anyhow::{Context, Result};
use async_channel::Sender;
Expand All @@ -11,131 +11,134 @@ use suzuka_executor::v1::SuzukaExecutorV1;
use url::Url;

static MONZA_CONFIG: Lazy<maptos_execution_util::config::Config> = Lazy::new(|| {
maptos_execution_util::config::Config::try_from_env()
.context("Failed to create the config")
.unwrap()
maptos_execution_util::config::Config::try_from_env()
.context("Failed to create the config")
.unwrap()
});

// :!:>section_1c
static NODE_URL: Lazy<Url> = Lazy::new(|| {
Url::from_str(
format!("http://{}", MONZA_CONFIG.aptos_config.aptos_rest_listen_url.as_str()).as_str(),
)
.unwrap()
Url::from_str(
format!("http://{}", MONZA_CONFIG.aptos_config.aptos_rest_listen_url.as_str()).as_str(),
)
.unwrap()
});

static FAUCET_URL: Lazy<Url> = Lazy::new(|| {
Url::from_str(
format!("http://{}", MONZA_CONFIG.aptos_config.aptos_faucet_listen_url.as_str()).as_str(),
)
.unwrap()
Url::from_str(
format!("http://{}", MONZA_CONFIG.aptos_config.aptos_faucet_listen_url.as_str()).as_str(),
)
.unwrap()
});
// <:!:section_1c

#[tokio::test]
async fn test_example_interaction() -> Result<()> {
// :!:>section_1a
let rest_client = Client::new(NODE_URL.clone());
let faucet_client = FaucetClient::new(FAUCET_URL.clone(), NODE_URL.clone()); // <:!:section_1a
// :!:>section_1a
let rest_client = Client::new(NODE_URL.clone());
let faucet_client = FaucetClient::new(FAUCET_URL.clone(), NODE_URL.clone()); // <:!:section_1a

// :!:>section_1b
let coin_client = CoinClient::new(&rest_client); // <:!:section_1b
// :!:>section_1b
let coin_client = CoinClient::new(&rest_client); // <:!:section_1b

// Create two accounts locally, Alice and Bob.
// :!:>section_2
let mut alice = LocalAccount::generate(&mut rand::rngs::OsRng);
let bob = LocalAccount::generate(&mut rand::rngs::OsRng); // <:!:section_2
// Create two accounts locally, Alice and Bob.
// :!:>section_2
let mut alice = LocalAccount::generate(&mut rand::rngs::OsRng);
let bob = LocalAccount::generate(&mut rand::rngs::OsRng); // <:!:section_2

// Print account addresses.
println!("\n=== Addresses ===");
println!("Alice: {}", alice.address().to_hex_literal());
println!("Bob: {}", bob.address().to_hex_literal());
// Print account addresses.
println!("\n=== Addresses ===");
println!("Alice: {}", alice.address().to_hex_literal());
println!("Bob: {}", bob.address().to_hex_literal());

// Create the accounts on chain, but only fund Alice.
// :!:>section_3
faucet_client
.fund(alice.address(), 100_000_000)
.await
.context("Failed to fund Alice's account")?;
faucet_client.create_account(bob.address()).await.context("Failed to fund Bob's account")?; // <:!:section_3
// Create the accounts on chain, but only fund Alice.
// :!:>section_3
faucet_client
.fund(alice.address(), 100_000_000)
.await
.context("Failed to fund Alice's account")?;
faucet_client
.create_account(bob.address())
.await
.context("Failed to fund Bob's account")?; // <:!:section_3

// Print initial balances.
println!("\n=== Initial Balances ===");
println!(
"Alice: {:?}",
coin_client
.get_account_balance(&alice.address())
.await
.context("Failed to get Alice's account balance")?
);
println!(
"Bob: {:?}",
coin_client
.get_account_balance(&bob.address())
.await
.context("Failed to get Bob's account balance")?
);
// Print initial balances.
println!("\n=== Initial Balances ===");
println!(
"Alice: {:?}",
coin_client
.get_account_balance(&alice.address())
.await
.context("Failed to get Alice's account balance")?
);
println!(
"Bob: {:?}",
coin_client
.get_account_balance(&bob.address())
.await
.context("Failed to get Bob's account balance")?
);

// Have Alice send Bob some coins.
let txn_hash = coin_client
.transfer(&mut alice, bob.address(), 1_000, None)
.await
.context("Failed to submit transaction to transfer coins")?;
rest_client
.wait_for_transaction(&txn_hash)
.await
.context("Failed when waiting for the transfer transaction")?;
// Have Alice send Bob some coins.
let txn_hash = coin_client
.transfer(&mut alice, bob.address(), 1_000, None)
.await
.context("Failed to submit transaction to transfer coins")?;
rest_client
.wait_for_transaction(&txn_hash)
.await
.context("Failed when waiting for the transfer transaction")?;

// Print intermediate balances.
println!("\n=== Intermediate Balances ===");
// :!:>section_4
println!(
"Alice: {:?}",
coin_client
.get_account_balance(&alice.address())
.await
.context("Failed to get Alice's account balance the second time")?
);
println!(
"Bob: {:?}",
coin_client
.get_account_balance(&bob.address())
.await
.context("Failed to get Bob's account balance the second time")?
); // <:!:section_4
// Print intermediate balances.
println!("\n=== Intermediate Balances ===");
// :!:>section_4
println!(
"Alice: {:?}",
coin_client
.get_account_balance(&alice.address())
.await
.context("Failed to get Alice's account balance the second time")?
);
println!(
"Bob: {:?}",
coin_client
.get_account_balance(&bob.address())
.await
.context("Failed to get Bob's account balance the second time")?
); // <:!:section_4

// Have Alice send Bob some more coins.
// :!:>section_5
let txn_hash = coin_client
.transfer(&mut alice, bob.address(), 1_000, None)
.await
.context("Failed to submit transaction to transfer coins")?; // <:!:section_5
// :!:>section_6
rest_client
.wait_for_transaction(&txn_hash)
.await
.context("Failed when waiting for the transfer transaction")?; // <:!:section_6
// Have Alice send Bob some more coins.
// :!:>section_5
let txn_hash = coin_client
.transfer(&mut alice, bob.address(), 1_000, None)
.await
.context("Failed to submit transaction to transfer coins")?; // <:!:section_5
// :!:>section_6
rest_client
.wait_for_transaction(&txn_hash)
.await
.context("Failed when waiting for the transfer transaction")?; // <:!:section_6

// Print final balances.
println!("\n=== Final Balances ===");
println!(
"Alice: {:?}",
coin_client
.get_account_balance(&alice.address())
.await
.context("Failed to get Alice's account balance the second time")?
);
println!(
"Bob: {:?}",
coin_client
.get_account_balance(&bob.address())
.await
.context("Failed to get Bob's account balance the second time")?
);
// Print final balances.
println!("\n=== Final Balances ===");
println!(
"Alice: {:?}",
coin_client
.get_account_balance(&alice.address())
.await
.context("Failed to get Alice's account balance the second time")?
);
println!(
"Bob: {:?}",
coin_client
.get_account_balance(&bob.address())
.await
.context("Failed to get Bob's account balance the second time")?
);

let (tx, _rx) = async_channel::unbounded();
let executor = SuzukaExecutorV1::try_from_env(tx).await?;
let api = executor.get_apis();
let (tx, _rx) = async_channel::unbounded();
let executor = SuzukaExecutorV1::try_from_env(tx).await?;
let api = executor.get_apis();

Ok(())
Ok(())
}
10 changes: 5 additions & 5 deletions networks/monza/monza-config/src/bin/monza_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use monza_config::Config;

#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
// read any values from env, but populate the default values if they are not present
let config = Config::try_from_env()?;
// write the values to the env
print!("{}", config.write_bash_export_string()?);
Ok(())
// read any values from env, but populate the default values if they are not present
let config = Config::try_from_env()?;
// write the values to the env
print!("{}", config.write_bash_export_string()?);
Ok(())
}
30 changes: 15 additions & 15 deletions networks/monza/monza-config/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Config {
pub execution_config: maptos_execution_util::config::Config,
pub execution_config: maptos_execution_util::config::Config,
}

impl Config {
pub fn new(execution_config: maptos_execution_util::config::Config) -> Self {
Self { execution_config }
}
pub fn new(execution_config: maptos_execution_util::config::Config) -> Self {
Self { execution_config }
}

pub fn try_from_env() -> Result<Self, anyhow::Error> {
let execution_config = maptos_execution_util::config::Config::try_from_env()?;
pub fn try_from_env() -> Result<Self, anyhow::Error> {
let execution_config = maptos_execution_util::config::Config::try_from_env()?;

Ok(Self { execution_config })
}
Ok(Self { execution_config })
}

pub fn write_to_env(&self) -> Result<(), anyhow::Error> {
self.execution_config.write_to_env()?;
Ok(())
}
pub fn write_to_env(&self) -> Result<(), anyhow::Error> {
self.execution_config.write_to_env()?;
Ok(())
}

pub fn write_bash_export_string(&self) -> Result<String, anyhow::Error> {
Ok(format!("{}", self.execution_config.write_bash_export_string()?))
}
pub fn write_bash_export_string(&self) -> Result<String, anyhow::Error> {
Ok(format!("{}", self.execution_config.write_bash_export_string()?))
}
}
24 changes: 12 additions & 12 deletions networks/monza/monza-full-node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ pub mod partial;
pub mod tests;

pub trait MonzaFullNode {
/// Runs the services until crash or shutdown.
async fn run_services(&self) -> Result<(), anyhow::Error>;
/// Runs the services until crash or shutdown.
async fn run_services(&self) -> Result<(), anyhow::Error>;

/// Runs the background tasks until crash or shutdown.
async fn run_background_tasks(&self) -> Result<(), anyhow::Error>;
/// Runs the background tasks until crash or shutdown.
async fn run_background_tasks(&self) -> Result<(), anyhow::Error>;

/// Runs the executor until crash or shutdown.
async fn run_executor(&self) -> Result<(), anyhow::Error>;
/// Runs the executor until crash or shutdown.
async fn run_executor(&self) -> Result<(), anyhow::Error>;

/// Runs the full node until crash or shutdown.
async fn run(&self) -> Result<(), anyhow::Error> {
// run services and executor concurrently
tokio::try_join!(self.run_background_tasks(), self.run_services(), self.run_executor())?;
/// Runs the full node until crash or shutdown.
async fn run(&self) -> Result<(), anyhow::Error> {
// run services and executor concurrently
tokio::try_join!(self.run_background_tasks(), self.run_services(), self.run_executor())?;

Ok(())
}
Ok(())
}
}
27 changes: 14 additions & 13 deletions networks/monza/monza-full-node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ use monza_full_node::{partial::MonzaPartialNode, MonzaFullNode};

#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
#[cfg(feature = "logging")]
{
use tracing_subscriber::EnvFilter;
#[cfg(feature = "logging")]
{
use tracing_subscriber::EnvFilter;

tracing_subscriber::fmt()
.with_env_filter(
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")),
)
.init();
}
tracing_subscriber::fmt()
.with_env_filter(
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")),
)
.init();
}

let executor =
MonzaPartialNode::try_from_env().await.context("Failed to create the executor")?;
let executor = MonzaPartialNode::try_from_env()
.await
.context("Failed to create the executor")?;

executor.run().await.context("Failed to run the executor")?;
executor.run().await.context("Failed to run the executor")?;

Ok(())
Ok(())
}
Loading

0 comments on commit adb3f91

Please sign in to comment.