-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #225 from rainlanguage/2024-02-12-cli-take-orders
2024 02 12 cli take orders list
- Loading branch information
Showing
13 changed files
with
487 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
mod order; | ||
mod order_clear; | ||
mod order_take; | ||
mod vault; | ||
|
||
pub use self::{order::Order, order_clear::OrderClear, vault::Vault}; | ||
pub use self::{order::Order, order_clear::OrderClear, order_take::OrderTake, vault::Vault}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
use crate::{ | ||
execute::Execute, | ||
subgraph::{CliPaginationArgs, CliSubgraphArgs}, | ||
}; | ||
use anyhow::Result; | ||
use clap::Args; | ||
use comfy_table::Table; | ||
use rain_orderbook_common::subgraph::SubgraphArgs; | ||
use rain_orderbook_subgraph_client::{ | ||
types::flattened::{OrderTakeFlattened, TryIntoFlattenedError}, | ||
PaginationArgs, TryIntoCsv, | ||
}; | ||
use tracing::info; | ||
|
||
#[derive(Args, Clone)] | ||
pub struct CliOrderTakesListArgs { | ||
#[arg(short = 'i', long, help = "ID of the Order")] | ||
order_id: String, | ||
|
||
#[clap(flatten)] | ||
pagination_args: CliPaginationArgs, | ||
|
||
#[clap(flatten)] | ||
subgraph_args: CliSubgraphArgs, | ||
} | ||
|
||
impl Execute for CliOrderTakesListArgs { | ||
async fn execute(&self) -> Result<()> { | ||
let subgraph_args: SubgraphArgs = self.subgraph_args.clone().into(); | ||
let pagination_args: PaginationArgs = self.pagination_args.clone().into(); | ||
let order_takes = subgraph_args | ||
.to_subgraph_client() | ||
.await? | ||
.order_takes_list(self.order_id.clone().into(), pagination_args) | ||
.await?; | ||
let order_takes_flattened: Vec<OrderTakeFlattened> = order_takes | ||
.into_iter() | ||
.map(|o| o.try_into()) | ||
.collect::<Result<Vec<OrderTakeFlattened>, TryIntoFlattenedError>>()?; | ||
|
||
if self.pagination_args.csv { | ||
let csv_text = order_takes_flattened.try_into_csv()?; | ||
println!("{}", csv_text); | ||
} else { | ||
let table = build_table(order_takes_flattened)?; | ||
info!("\n{}", table); | ||
} | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
fn build_table(order_take: Vec<OrderTakeFlattened>) -> Result<Table> { | ||
let mut table = comfy_table::Table::new(); | ||
table | ||
.load_preset(comfy_table::presets::UTF8_FULL) | ||
.set_content_arrangement(comfy_table::ContentArrangement::Dynamic) | ||
.set_header(vec![ | ||
"ID", "Taken At", "Sender", "Input", "Output", "IO Ratio", | ||
]); | ||
|
||
for order_take in order_take.into_iter() { | ||
table.add_row(vec![ | ||
order_take.id, | ||
order_take.timestamp_display, | ||
order_take.sender.0, | ||
format!( | ||
"{} {}", | ||
order_take.input_display.0, order_take.input_token_symbol | ||
), | ||
format!( | ||
"{} {}", | ||
order_take.output_display.0, order_take.output_token_symbol | ||
), | ||
format!( | ||
"{} {}/{}", | ||
order_take.ioratio.0, order_take.input_token_symbol, order_take.output_token_symbol | ||
), | ||
]); | ||
} | ||
|
||
Ok(table) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
mod list; | ||
|
||
use crate::execute::Execute; | ||
use anyhow::Result; | ||
use clap::Parser; | ||
use list::CliOrderTakesListArgs; | ||
|
||
#[derive(Parser)] | ||
pub enum OrderTake { | ||
#[command(about = "List takes for an Order", alias = "ls")] | ||
List(CliOrderTakesListArgs), | ||
} | ||
|
||
impl Execute for OrderTake { | ||
async fn execute(&self) -> Result<()> { | ||
match self { | ||
OrderTake::List(list) => list.execute().await, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
query OrderTakesListQuery($id: ID!, $skip: Int = 0, $first: Int = 25) { | ||
takeOrderEntities(orderBy: timestamp, orderDirection: desc, skip: $skip, first: $first, where: { | ||
order_: { | ||
id: $id | ||
} | ||
}) { | ||
id | ||
transaction { | ||
id | ||
} | ||
sender { | ||
id | ||
} | ||
timestamp | ||
order { | ||
id | ||
} | ||
IORatio | ||
input | ||
inputDisplay | ||
inputToken { | ||
id | ||
name | ||
symbol | ||
decimals | ||
} | ||
inputIOIndex | ||
output | ||
outputDisplay | ||
outputToken { | ||
id | ||
name | ||
symbol | ||
decimals | ||
} | ||
outputIOIndex | ||
context { | ||
callingContext | ||
calculationsContext | ||
vaultInputsContext | ||
vaultOutputsContext | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.