@@ -5,7 +5,6 @@ use nom::IResult;
5
5
use rand_core:: RngCore ;
6
6
use serde_json:: Value ;
7
7
use std:: collections:: HashMap ;
8
- use std:: error:: Error ;
9
8
use std:: fs;
10
9
use std:: path:: PathBuf ;
11
10
use tokio:: process:: Command ;
@@ -14,23 +13,16 @@ use crate::chain_observer::interface::*;
14
13
use crate :: chain_observer:: { ChainAddress , TxDatum } ;
15
14
use crate :: crypto_helper:: { KESPeriod , OpCert , SerDeShelleyFileFormat } ;
16
15
use crate :: entities:: { Epoch , StakeDistribution } ;
17
- use crate :: CardanoNetwork ;
16
+ use crate :: { CardanoNetwork , StdResult } ;
18
17
19
18
#[ async_trait]
20
19
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 > ;
34
26
}
35
27
36
28
/// A runner able to request data from a Cardano node using the
@@ -52,7 +44,7 @@ impl CardanoCliRunner {
52
44
}
53
45
}
54
46
55
- fn random_out_file ( ) -> Result < PathBuf , Box < dyn Error + Sync + Send > > {
47
+ fn random_out_file ( ) -> StdResult < PathBuf > {
56
48
let mut rng = rand_core:: OsRng ;
57
49
let dir = std:: env:: temp_dir ( ) . join ( "cardano-cli-runner" ) ;
58
50
if !dir. exists ( ) {
@@ -153,7 +145,7 @@ impl CardanoCliRunner {
153
145
154
146
#[ async_trait]
155
147
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 > {
157
149
let out_file = Self :: random_out_file ( ) ?;
158
150
let output = self
159
151
. command_for_utxo ( address, out_file. clone ( ) )
@@ -174,7 +166,7 @@ impl CliRunner for CardanoCliRunner {
174
166
}
175
167
}
176
168
177
- async fn launch_stake_distribution ( & self ) -> Result < String , Box < dyn Error + Sync + Send > > {
169
+ async fn launch_stake_distribution ( & self ) -> StdResult < String > {
178
170
let output = self . command_for_stake_distribution ( ) . output ( ) . await ?;
179
171
180
172
if output. status . success ( ) {
@@ -191,10 +183,7 @@ impl CliRunner for CardanoCliRunner {
191
183
}
192
184
}
193
185
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 > {
198
187
let output = self
199
188
. command_for_stake_snapshot ( stake_pool_id)
200
189
. output ( )
@@ -214,9 +203,7 @@ impl CliRunner for CardanoCliRunner {
214
203
}
215
204
}
216
205
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 > {
220
207
let output = self . command_for_stake_snapshot_all_pools ( ) . output ( ) . await ?;
221
208
222
209
if output. status . success ( ) {
@@ -233,7 +220,7 @@ impl CliRunner for CardanoCliRunner {
233
220
}
234
221
}
235
222
236
- async fn launch_epoch ( & self ) -> Result < String , Box < dyn Error + Sync + Send > > {
223
+ async fn launch_epoch ( & self ) -> StdResult < String > {
237
224
let output = self . command_for_epoch ( ) . output ( ) . await ?;
238
225
239
226
if output. status . success ( ) {
@@ -250,10 +237,7 @@ impl CliRunner for CardanoCliRunner {
250
237
}
251
238
}
252
239
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 > {
257
241
let output = self . command_for_kes_period ( opcert_file) . output ( ) . await ?;
258
242
259
243
if output. status . success ( ) {
@@ -284,12 +268,10 @@ impl CardanoCliChainObserver {
284
268
285
269
// This is the only way I found to tell the compiler the correct types
286
270
// and lifetimes for the function `double`.
287
- #[ allow( dead_code) ]
288
271
fn parse_string < ' a > ( & ' a self , string : & ' a str ) -> IResult < & str , f64 > {
289
272
nom:: number:: complete:: double ( string)
290
273
}
291
274
292
- #[ allow( dead_code) ]
293
275
async fn get_current_stake_value (
294
276
& self ,
295
277
stake_pool_id : & str ,
@@ -525,10 +507,7 @@ mod tests {
525
507
526
508
#[ async_trait]
527
509
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 > {
532
511
let output = r#"
533
512
{
534
513
"1fd4d3e131afe3c8b212772a3f3083d2fbc6b2a7b20e54e4ff08e001598818d8#0": {
@@ -564,7 +543,7 @@ mod tests {
564
543
Ok ( output. to_string ( ) )
565
544
}
566
545
567
- async fn launch_stake_distribution ( & self ) -> Result < String , Box < dyn Error + Sync + Send > > {
546
+ async fn launch_stake_distribution ( & self ) -> StdResult < String > {
568
547
let output = r#"
569
548
PoolId Stake frac
570
549
------------------------------------------------------------------------------
@@ -581,10 +560,7 @@ pool1qz2vzszautc2c8mljnqre2857dpmheq7kgt6vav0s38tvvhxm6w 1.051e-6
581
560
Ok ( output. to_string ( ) )
582
561
}
583
562
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 > {
588
564
let mut output = r#"
589
565
{
590
566
"poolStakeGo": 1000000,
@@ -611,9 +587,7 @@ pool1qz2vzszautc2c8mljnqre2857dpmheq7kgt6vav0s38tvvhxm6w 1.051e-6
611
587
Ok ( output. to_string ( ) )
612
588
}
613
589
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 > {
617
591
let output = r#"
618
592
{
619
593
"pools": {
@@ -650,7 +624,7 @@ pool1qz2vzszautc2c8mljnqre2857dpmheq7kgt6vav0s38tvvhxm6w 1.051e-6
650
624
}
651
625
}
652
626
653
- async fn launch_epoch ( & self ) -> Result < String , Box < dyn Error + Sync + Send > > {
627
+ async fn launch_epoch ( & self ) -> StdResult < String > {
654
628
let output = r#"
655
629
{
656
630
"era": "Alonzo",
@@ -664,10 +638,7 @@ pool1qz2vzszautc2c8mljnqre2857dpmheq7kgt6vav0s38tvvhxm6w 1.051e-6
664
638
Ok ( output. to_string ( ) )
665
639
}
666
640
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 > {
671
642
let output = r#"
672
643
✓ The operational certificate counter agrees with the node protocol state counter
673
644
✓ Operational certificate's kes period is within the correct KES period interval
0 commit comments