Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
kariy committed Apr 14, 2024
1 parent 228c2ae commit ea7db12
Show file tree
Hide file tree
Showing 23 changed files with 440 additions and 1,277 deletions.
1,133 changes: 43 additions & 1,090 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ members = [
"crates/context-macro",
"crates/fmt",
"crates/ops",
"crates/rika",
# "crates/rika",
"crates/waiter",
]
resolver = "2"
Expand All @@ -24,6 +24,7 @@ rika-args = { path = "crates/args" }
rika-fmt = { path = "crates/fmt" }
rika-ops = { path = "crates/ops" }

alloy-primitives = "0.7.0"
chrono = "0.4.23"
clap = { version = "4.1.8", features = [ "derive", "env" ] }
clap_complete = "4.1.0"
Expand Down
21 changes: 11 additions & 10 deletions bin/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,18 @@ pub mod rpc {

pub fn execute(command: RpcCommands) -> Result<()> {
match command {
RpcCommands::Call(args) => ops::rpc::call::call(args)?,
RpcCommands::Balance(args) => ops::rpc::balance::get(args)?,
RpcCommands::Tx(args) => ops::rpc::transaction::get(args)?,
RpcCommands::TxCount(args) => ops::rpc::transaction::count(args)?,
RpcCommands::TxStatus(args) => ops::rpc::transaction::status(args)?,
// RpcCommands::Call(args) => ops::rpc::call::call(args)?,
// RpcCommands::Balance(args) => ops::rpc::balance::get(args)?,
// RpcCommands::Tx(args) => ops::rpc::transaction::get(args)?,
// RpcCommands::TxCount(args) => ops::rpc::transaction::count(args)?,
// RpcCommands::TxStatus(args) => ops::rpc::transaction::status(args)?,
RpcCommands::Receipt(args) => ops::rpc::transaction::receipt(args)?,
RpcCommands::Rpc(args) => ops::rpc::raw::send(args)?,
RpcCommands::Block(args) => ops::rpc::block::get(args)?,
RpcCommands::Age(args) => ops::rpc::block::age(args)?,
RpcCommands::BlockNumber(args) => ops::rpc::block::number(args)?,

// RpcCommands::Rpc(args) => ops::rpc::raw::send(args)?,
// RpcCommands::Block(args) => ops::rpc::block::get(args)?,
// RpcCommands::Age(args) => ops::rpc::block::age(args)?,
// RpcCommands::BlockNumber(args) => ops::rpc::block::number(args)?,
// RpcCommands::ChainId(args) => ops::rpc::chain::id(args)?,
// RpcCommands::Syncing(args) => ops::rpc::chain::syncing(args)?,
_ => {
unimplemented!("This command is not implemented yet")
}
Expand Down
2 changes: 2 additions & 0 deletions crates/args/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ version.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rika-fmt.workspace = true

chrono.workspace = true
clap.workspace = true
clap_complete.workspace = true
Expand Down
5 changes: 3 additions & 2 deletions crates/args/src/commands/rpc/block.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use clap::Parser;
use serde_json::Value;
use starknet::core::types::BlockId;

use crate::opts::display::DisplayOptions;
use crate::opts::display::{DisplayOptions, JsonDisplay};
use crate::opts::starknet::StarknetOptions;
use crate::parser::BlockIdParser;

Expand Down Expand Up @@ -46,7 +47,7 @@ pub struct BlockArgs {

#[command(flatten)]
#[command(next_help_heading = "Display options")]
pub display: DisplayOptions,
pub display: DisplayOptions<JsonDisplay<Value>>,

#[command(flatten)]
#[command(next_help_heading = "Starknet options")]
Expand Down
9 changes: 6 additions & 3 deletions crates/args/src/commands/rpc/chain.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
use clap::Parser;

use crate::opts::starknet::StarknetOptions;
use crate::opts::{display::DisplayOptions, starknet::StarknetOptions};

#[derive(Debug, Parser)]
pub struct ChainIdArgs {
#[command(flatten)]
#[command(next_help_heading = "Starknet options")]
starknet: StarknetOptions,
pub starknet: StarknetOptions,
}

#[derive(Debug, Parser)]
pub struct SyncingArgs {
// #[command(flatten)]
// #[command(next_help_heading = "Display options")]
// pub display: DisplayOptions,
#[command(flatten)]
#[command(next_help_heading = "Starknet options")]
starknet: StarknetOptions,
pub starknet: StarknetOptions,
}
7 changes: 3 additions & 4 deletions crates/args/src/commands/rpc/state_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ pub struct StateUpdateArgs {
)]
block_id: BlockId,

#[command(flatten)]
#[command(next_help_heading = "Display options")]
display: DisplayOptions,

// #[command(flatten)]
// #[command(next_help_heading = "Display options")]
// display: DisplayOptions,
#[command(flatten)]
#[command(next_help_heading = "Starknet options")]
starknet: StarknetOptions,
Expand Down
17 changes: 13 additions & 4 deletions crates/args/src/commands/rpc/transaction.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use clap::Parser;
use starknet::core::types::{BlockId, FieldElement};
use starknet::core::types::{
BlockId, FieldElement, MaybePendingTransactionReceipt, Transaction, TransactionStatus,
};

use crate::opts::display::DisplayOptions;
use crate::opts::display::{DisplayOptions, JsonDisplay};
use crate::opts::starknet::StarknetOptions;
use crate::parser::BlockIdParser;

Expand All @@ -12,7 +14,7 @@ pub struct TxArgs {

#[command(flatten)]
#[command(next_help_heading = "Display options")]
pub display: DisplayOptions,
pub display: DisplayOptions<JsonDisplay<Transaction>>,

#[command(flatten)]
#[command(next_help_heading = "Starknet options")]
Expand All @@ -29,6 +31,9 @@ pub struct TxCountArgs {
)]
pub block_id: BlockId,

#[command(flatten)]
pub display: DisplayOptions,

#[command(flatten)]
#[command(next_help_heading = "Starknet options")]
pub starknet: StarknetOptions,
Expand All @@ -39,6 +44,10 @@ pub struct TxStatusArgs {
#[arg(value_name = "TX_HASH")]
pub hash: FieldElement,

#[command(flatten)]
#[command(next_help_heading = "Display options")]
pub display: DisplayOptions<JsonDisplay<TransactionStatus>>,

#[command(flatten)]
#[command(next_help_heading = "Starknet options")]
pub starknet: StarknetOptions,
Expand All @@ -51,7 +60,7 @@ pub struct ReceiptArgs {

#[command(flatten)]
#[command(next_help_heading = "Display options")]
pub display: DisplayOptions,
pub display: DisplayOptions<JsonDisplay<MaybePendingTransactionReceipt>>,

#[command(flatten)]
#[command(next_help_heading = "Starknet options")]
Expand Down
2 changes: 1 addition & 1 deletion crates/args/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pub mod account;
pub mod commands;
pub mod fmt;
// pub mod fmt;
pub mod opts;
pub mod parser;
mod utils;
80 changes: 0 additions & 80 deletions crates/args/src/opts/display.rs

This file was deleted.

18 changes: 14 additions & 4 deletions crates/args/src/opts/display/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,27 @@ use clap::Args;
use eyre::Result;

pub use self::json::JsonDisplay;
use crate::fmt::Pretty;
use rika_fmt::Pretty;

#[derive(Debug, Args)]
pub struct DisplayOptions<T>
pub struct DisplayOptions<T = NullDisplayOptions>
where
T: Args + RawDisplay,
T: Args,
{
#[command(flatten)]
pub raw_format: T,
}

impl DisplayOptions {
pub fn print(&self, value: impl std::fmt::Display) -> Result<()> {
println!("{value}");
Ok(())
}
}

impl<T> DisplayOptions<T>
where
T: RawDisplay + Args,
T: Args + RawDisplay,
{
pub fn print(&self, value: <T as RawDisplay>::Value) -> Result<()>
where
Expand All @@ -44,3 +51,6 @@ pub trait RawDisplay {
false
}
}

#[derive(Debug, Args)]
pub struct NullDisplayOptions;
2 changes: 2 additions & 0 deletions crates/fmt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ version.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
alloy-primitives.workspace = true
bigdecimal = "0.4.3"
chrono.workspace = true
prettytable-rs = "0.10.0"
starknet.workspace = true
41 changes: 25 additions & 16 deletions crates/fmt/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
use std::vec;
mod rpc;
pub mod utils;

use chrono::{Local, TimeZone};
use prettytable::format::consts::FORMAT_NO_LINESEP_WITH_TITLE;
use prettytable::format::TableFormat;
use prettytable::Table;
use starknet::core::types::{
DataAvailabilityMode, DeclareTransaction, DeployAccountTransaction, FieldElement,
MaybePendingBlockWithTxHashes, TransactionExecutionStatus, TransactionStatus,
};
use starknet::core::types::{
Event, InvokeTransaction, MaybePendingBlockWithTxs, MaybePendingTransactionReceipt, MsgToL1,
Transaction, TransactionReceipt,
};
use starknet::core::types::FieldElement;

/// Display trait for pretty printing
pub trait Pretty {
Expand All @@ -25,15 +18,22 @@ impl<T: Tabular> Pretty for T {

/// Display trait for types that can be tabulated
pub trait Tabular {
/// Convert the type to a prettytable::Table
fn tablify(&self) -> Table;
/// Build the table using the given table.
fn build_table(&self, table: &mut Table);

/// Get the default table format
fn with_default_table() -> Table {
/// Convert the type to a prettytable::Table
fn tablify(&self) -> Table {
let mut table = Table::new();
table.set_format(*FORMAT_NO_LINESEP_WITH_TITLE);
table.set_format(Self::format());
self.build_table(&mut table);
table
}

/// Get the default table format
fn format() -> TableFormat {
use prettytable::format::consts::FORMAT_BOX_CHARS;
*FORMAT_BOX_CHARS
}
}

/// Macro for implementing the [Pretty] trait for types implement [LowerHex](std::fmt::LowerHex) trait.
Expand All @@ -50,3 +50,12 @@ macro_rules! pretty_for_lower_hex {
}

pretty_for_lower_hex!(FieldElement, u64);

impl<T: Pretty> Pretty for Vec<T> {
fn prettify(&self) -> String {
self.iter()
.map(|i| i.prettify())
.collect::<Vec<String>>()
.join("\n")
}
}
Loading

0 comments on commit ea7db12

Please sign in to comment.