Skip to content

Commit

Permalink
chore: adding example of how to use formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
raventid committed Feb 9, 2024
1 parent 1e744a9 commit ca5abd6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
Empty file modified scripts/different-outputs.sh
100644 → 100755
Empty file.
50 changes: 33 additions & 17 deletions src/cli/simple/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use aurora_engine_types::{types::Wei, H256, U256};
use near_primitives::views::{CallResult, FinalExecutionStatus};
use serde_json::{to_string_pretty, Value};

use crate::cli::simple::WithdrawSerialization;
use crate::cli::simple::OutputFormat;
use crate::cli::simple::WithdrawSerialization;
use crate::{
client::Context,
utils::{self, hex_to_address, hex_to_arr, hex_to_vec, near_to_yocto, secret_key_from_hex},
Expand Down Expand Up @@ -149,7 +149,13 @@ pub async fn init(
("new_eth_connector".to_string(), eth_connector_init_args),
];

match context.client.near().contract_call_batch(batch).await?.status {
match context
.client
.near()
.contract_call_batch(batch)
.await?
.status
{
FinalExecutionStatus::Failure(e) => {
anyhow::bail!("Error while initializing Aurora EVM: {e}")
}
Expand Down Expand Up @@ -226,7 +232,12 @@ pub async fn create_account(
account: &str,
initial_balance: f64,
) -> anyhow::Result<()> {
match context.client.near().create_account(account, initial_balance).await {
match context
.client
.near()
.create_account(account, initial_balance)
.await
{
Ok(result) => println!("{result}"),
Err(e) => eprintln!("{e:?}"),
}
Expand Down Expand Up @@ -538,7 +549,10 @@ pub async fn paused_precompiles(context: Context) -> anyhow::Result<()> {
}

/// Set relayer key manager.
pub async fn set_key_manager(context: Context, key_manager: Option<AccountId>) -> anyhow::Result<()> {
pub async fn set_key_manager(
context: Context,
key_manager: Option<AccountId>,
) -> anyhow::Result<()> {
let message = key_manager.as_ref().map_or_else(
|| "has been removed".to_string(),
|account_id| format!("{account_id} has been set"),
Expand Down Expand Up @@ -616,7 +630,11 @@ pub async fn get_nep141_from_erc20(context: Context, address: String) -> anyhow:
pub async fn get_erc20_metadata(context: Context, identifier: String) -> anyhow::Result<()> {
let args = str_to_identifier(&identifier)
.and_then(|id| serde_json::to_vec(&id).map_err(Into::into))?;
let result = context.client.near().view_call("get_erc20_metadata", args).await?;
let result = context
.client
.near()
.view_call("get_erc20_metadata", args)
.await?;
let output = serde_json::from_slice::<Erc20Metadata>(&result.result)
.and_then(|metadata| serde_json::to_string_pretty(&metadata))?;

Expand Down Expand Up @@ -828,19 +846,17 @@ impl ContractCall<'_> {
FinalExecutionStatus::Failure(e) => {
anyhow::bail!("{}: {e}", self.error_message)
}
FinalExecutionStatus::SuccessValue(_) => {
match context.output_format {
OutputFormat::Plain => println!("{}", self.success_message),
OutputFormat::Json => {
let formatted = to_string_pretty(&result.transaction_outcome)?;
println!("{}", formatted);
},
OutputFormat::Toml => {
let formatted = toml::to_string_pretty(&result.transaction_outcome)?;
println!("{}", formatted);
},
FinalExecutionStatus::SuccessValue(_) => match context.output_format {
OutputFormat::Plain => println!("{}", self.success_message),
OutputFormat::Json => {
let formatted = to_string_pretty(&result.transaction_outcome)?;
println!("{}", formatted);

Check failure on line 853 in src/cli/simple/command/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

variables can be used directly in the `format!` string

error: variables can be used directly in the `format!` string --> src/cli/simple/command/mod.rs:853:21 | 853 | println!("{}", formatted); | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args note: the lint level is defined here --> src/main.rs:1:9 | 1 | #![deny(clippy::pedantic, clippy::nursery)] | ^^^^^^^^^^^^^^^^ = note: `#[deny(clippy::uninlined_format_args)]` implied by `#[deny(clippy::pedantic)]` help: change this to | 853 - println!("{}", formatted); 853 + println!("{formatted}"); |

Check failure on line 853 in src/cli/simple/command/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

variables can be used directly in the `format!` string

error: variables can be used directly in the `format!` string --> src/cli/simple/command/mod.rs:853:21 | 853 | println!("{}", formatted); | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args note: the lint level is defined here --> src/main.rs:1:9 | 1 | #![deny(clippy::pedantic, clippy::nursery)] | ^^^^^^^^^^^^^^^^ = note: `#[deny(clippy::uninlined_format_args)]` implied by `#[deny(clippy::pedantic)]` help: change this to | 853 - println!("{}", formatted); 853 + println!("{formatted}"); |
}
}
OutputFormat::Toml => {
let formatted = toml::to_string_pretty(&result.transaction_outcome)?;
println!("{}", formatted);

Check failure on line 857 in src/cli/simple/command/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

variables can be used directly in the `format!` string

error: variables can be used directly in the `format!` string --> src/cli/simple/command/mod.rs:857:21 | 857 | println!("{}", formatted); | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 857 - println!("{}", formatted); 857 + println!("{formatted}"); |

Check failure on line 857 in src/cli/simple/command/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

variables can be used directly in the `format!` string

error: variables can be used directly in the `format!` string --> src/cli/simple/command/mod.rs:857:21 | 857 | println!("{}", formatted); | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 857 - println!("{}", formatted); 857 + println!("{formatted}"); |
}
},
}

Ok(())
Expand Down

0 comments on commit ca5abd6

Please sign in to comment.