Skip to content

Commit 1973693

Browse files
committed
Apply review comments
1 parent 3528d5d commit 1973693

File tree

1 file changed

+20
-49
lines changed

1 file changed

+20
-49
lines changed

mithril-common/src/chain_observer/cli_observer.rs

Lines changed: 20 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use nom::IResult;
55
use rand_core::RngCore;
66
use serde_json::Value;
77
use std::collections::HashMap;
8-
use std::error::Error;
98
use std::fs;
109
use std::path::PathBuf;
1110
use tokio::process::Command;
@@ -14,23 +13,16 @@ use crate::chain_observer::interface::*;
1413
use crate::chain_observer::{ChainAddress, TxDatum};
1514
use crate::crypto_helper::{KESPeriod, OpCert, SerDeShelleyFileFormat};
1615
use crate::entities::{Epoch, StakeDistribution};
17-
use crate::CardanoNetwork;
16+
use crate::{CardanoNetwork, StdResult};
1817

1918
#[async_trait]
2019
pub trait CliRunner {
21-
async fn launch_utxo(&self, address: &str) -> Result<String, Box<dyn Error + Sync + Send>>;
22-
async fn launch_stake_distribution(&self) -> Result<String, Box<dyn Error + Sync + Send>>;
23-
async fn launch_stake_snapshot(
24-
&self,
25-
stake_pool_id: &str,
26-
) -> Result<String, Box<dyn Error + Sync + Send>>;
27-
async fn launch_stake_snapshot_all_pools(&self)
28-
-> Result<String, Box<dyn Error + Sync + Send>>;
29-
async fn launch_epoch(&self) -> Result<String, Box<dyn Error + Sync + Send>>;
30-
async fn launch_kes_period(
31-
&self,
32-
opcert_file: &str,
33-
) -> Result<String, Box<dyn Error + Sync + Send>>;
20+
async fn launch_utxo(&self, address: &str) -> StdResult<String>;
21+
async fn launch_stake_distribution(&self) -> StdResult<String>;
22+
async fn launch_stake_snapshot(&self, stake_pool_id: &str) -> StdResult<String>;
23+
async fn launch_stake_snapshot_all_pools(&self) -> StdResult<String>;
24+
async fn launch_epoch(&self) -> StdResult<String>;
25+
async fn launch_kes_period(&self, opcert_file: &str) -> StdResult<String>;
3426
}
3527

3628
/// A runner able to request data from a Cardano node using the
@@ -52,7 +44,7 @@ impl CardanoCliRunner {
5244
}
5345
}
5446

55-
fn random_out_file() -> Result<PathBuf, Box<dyn Error + Sync + Send>> {
47+
fn random_out_file() -> StdResult<PathBuf> {
5648
let mut rng = rand_core::OsRng;
5749
let dir = std::env::temp_dir().join("cardano-cli-runner");
5850
if !dir.exists() {
@@ -153,7 +145,7 @@ impl CardanoCliRunner {
153145

154146
#[async_trait]
155147
impl CliRunner for CardanoCliRunner {
156-
async fn launch_utxo(&self, address: &str) -> Result<String, Box<dyn Error + Sync + Send>> {
148+
async fn launch_utxo(&self, address: &str) -> StdResult<String> {
157149
let out_file = Self::random_out_file()?;
158150
let output = self
159151
.command_for_utxo(address, out_file.clone())
@@ -174,7 +166,7 @@ impl CliRunner for CardanoCliRunner {
174166
}
175167
}
176168

177-
async fn launch_stake_distribution(&self) -> Result<String, Box<dyn Error + Sync + Send>> {
169+
async fn launch_stake_distribution(&self) -> StdResult<String> {
178170
let output = self.command_for_stake_distribution().output().await?;
179171

180172
if output.status.success() {
@@ -191,10 +183,7 @@ impl CliRunner for CardanoCliRunner {
191183
}
192184
}
193185

194-
async fn launch_stake_snapshot(
195-
&self,
196-
stake_pool_id: &str,
197-
) -> Result<String, Box<dyn Error + Sync + Send>> {
186+
async fn launch_stake_snapshot(&self, stake_pool_id: &str) -> StdResult<String> {
198187
let output = self
199188
.command_for_stake_snapshot(stake_pool_id)
200189
.output()
@@ -214,9 +203,7 @@ impl CliRunner for CardanoCliRunner {
214203
}
215204
}
216205

217-
async fn launch_stake_snapshot_all_pools(
218-
&self,
219-
) -> Result<String, Box<dyn Error + Sync + Send>> {
206+
async fn launch_stake_snapshot_all_pools(&self) -> StdResult<String> {
220207
let output = self.command_for_stake_snapshot_all_pools().output().await?;
221208

222209
if output.status.success() {
@@ -233,7 +220,7 @@ impl CliRunner for CardanoCliRunner {
233220
}
234221
}
235222

236-
async fn launch_epoch(&self) -> Result<String, Box<dyn Error + Sync + Send>> {
223+
async fn launch_epoch(&self) -> StdResult<String> {
237224
let output = self.command_for_epoch().output().await?;
238225

239226
if output.status.success() {
@@ -250,10 +237,7 @@ impl CliRunner for CardanoCliRunner {
250237
}
251238
}
252239

253-
async fn launch_kes_period(
254-
&self,
255-
opcert_file: &str,
256-
) -> Result<String, Box<dyn Error + Sync + Send>> {
240+
async fn launch_kes_period(&self, opcert_file: &str) -> StdResult<String> {
257241
let output = self.command_for_kes_period(opcert_file).output().await?;
258242

259243
if output.status.success() {
@@ -284,12 +268,10 @@ impl CardanoCliChainObserver {
284268

285269
// This is the only way I found to tell the compiler the correct types
286270
// and lifetimes for the function `double`.
287-
#[allow(dead_code)]
288271
fn parse_string<'a>(&'a self, string: &'a str) -> IResult<&str, f64> {
289272
nom::number::complete::double(string)
290273
}
291274

292-
#[allow(dead_code)]
293275
async fn get_current_stake_value(
294276
&self,
295277
stake_pool_id: &str,
@@ -525,10 +507,7 @@ mod tests {
525507

526508
#[async_trait]
527509
impl CliRunner for TestCliRunner {
528-
async fn launch_utxo(
529-
&self,
530-
_address: &str,
531-
) -> Result<String, Box<dyn Error + Sync + Send>> {
510+
async fn launch_utxo(&self, _address: &str) -> StdResult<String> {
532511
let output = r#"
533512
{
534513
"1fd4d3e131afe3c8b212772a3f3083d2fbc6b2a7b20e54e4ff08e001598818d8#0": {
@@ -564,7 +543,7 @@ mod tests {
564543
Ok(output.to_string())
565544
}
566545

567-
async fn launch_stake_distribution(&self) -> Result<String, Box<dyn Error + Sync + Send>> {
546+
async fn launch_stake_distribution(&self) -> StdResult<String> {
568547
let output = r#"
569548
PoolId Stake frac
570549
------------------------------------------------------------------------------
@@ -581,10 +560,7 @@ pool1qz2vzszautc2c8mljnqre2857dpmheq7kgt6vav0s38tvvhxm6w 1.051e-6
581560
Ok(output.to_string())
582561
}
583562

584-
async fn launch_stake_snapshot(
585-
&self,
586-
stake_pool_id: &str,
587-
) -> Result<String, Box<dyn Error + Sync + Send>> {
563+
async fn launch_stake_snapshot(&self, stake_pool_id: &str) -> StdResult<String> {
588564
let mut output = r#"
589565
{
590566
"poolStakeGo": 1000000,
@@ -611,9 +587,7 @@ pool1qz2vzszautc2c8mljnqre2857dpmheq7kgt6vav0s38tvvhxm6w 1.051e-6
611587
Ok(output.to_string())
612588
}
613589

614-
async fn launch_stake_snapshot_all_pools(
615-
&self,
616-
) -> Result<String, Box<dyn Error + Sync + Send>> {
590+
async fn launch_stake_snapshot_all_pools(&self) -> StdResult<String> {
617591
let output = r#"
618592
{
619593
"pools": {
@@ -650,7 +624,7 @@ pool1qz2vzszautc2c8mljnqre2857dpmheq7kgt6vav0s38tvvhxm6w 1.051e-6
650624
}
651625
}
652626

653-
async fn launch_epoch(&self) -> Result<String, Box<dyn Error + Sync + Send>> {
627+
async fn launch_epoch(&self) -> StdResult<String> {
654628
let output = r#"
655629
{
656630
"era": "Alonzo",
@@ -664,10 +638,7 @@ pool1qz2vzszautc2c8mljnqre2857dpmheq7kgt6vav0s38tvvhxm6w 1.051e-6
664638
Ok(output.to_string())
665639
}
666640

667-
async fn launch_kes_period(
668-
&self,
669-
_opcert_file: &str,
670-
) -> Result<String, Box<dyn Error + Sync + Send>> {
641+
async fn launch_kes_period(&self, _opcert_file: &str) -> StdResult<String> {
671642
let output = r#"
672643
✓ The operational certificate counter agrees with the node protocol state counter
673644
✓ Operational certificate's kes period is within the correct KES period interval

0 commit comments

Comments
 (0)