@@ -23,7 +23,6 @@ pub struct SentryApi<T: Adapter> {
23
23
pub logging : bool ,
24
24
pub channel : Channel ,
25
25
pub config : Config ,
26
- pub whoami : ValidatorId ,
27
26
pub propagate_to : Vec < ( ValidatorDesc , String ) > ,
28
27
}
29
28
@@ -33,15 +32,14 @@ impl<T: Adapter + 'static> SentryApi<T> {
33
32
channel : & Channel ,
34
33
config : & Config ,
35
34
logging : bool ,
36
- whoami : & ValidatorId ,
37
35
) -> Result < Self , ValidatorWorker > {
38
36
let client = Client :: builder ( )
39
37
. timeout ( Duration :: from_secs ( config. fetch_timeout . into ( ) ) )
40
38
. build ( )
41
39
. unwrap ( ) ;
42
40
43
41
// validate that we are to validate the channel
44
- match channel. spec . validators . find ( & whoami) {
42
+ match channel. spec . validators . find ( adapter . whoami ( ) ) {
45
43
SpecValidator :: Leader ( v) | SpecValidator :: Follower ( v) => {
46
44
let channel_id = format ! ( "0x{}" , hex:: encode( & channel. id) ) ;
47
45
let validator_url = format ! ( "{}/channel/{}" , v. url, channel_id) ;
@@ -70,7 +68,6 @@ impl<T: Adapter + 'static> SentryApi<T> {
70
68
propagate_to,
71
69
channel : channel. to_owned ( ) ,
72
70
config : config. to_owned ( ) ,
73
- whoami : whoami. to_owned ( ) ,
74
71
} )
75
72
}
76
73
SpecValidator :: None => Err ( ValidatorWorker :: Failed (
@@ -92,13 +89,15 @@ impl<T: Adapter + 'static> SentryApi<T> {
92
89
93
90
pub async fn get_latest_msg (
94
91
& self ,
95
- from : String ,
92
+ from : & ValidatorId ,
96
93
message_types : & [ & str ] ,
97
94
) -> Result < Option < MessageTypes > , reqwest:: Error > {
98
95
let message_type = message_types. join ( "+" ) ;
99
96
let url = format ! (
100
97
"{}/validator-messages/{}/{}?limit=1" ,
101
- self . validator_url, from, message_type
98
+ self . validator_url,
99
+ from. to_string( ) ,
100
+ message_type
102
101
) ;
103
102
let result = self
104
103
. client
@@ -115,7 +114,7 @@ impl<T: Adapter + 'static> SentryApi<T> {
115
114
& self ,
116
115
message_types : & [ & str ] ,
117
116
) -> Result < Option < MessageTypes > , reqwest:: Error > {
118
- self . get_latest_msg ( self . whoami . to_string ( ) , message_types)
117
+ self . get_latest_msg ( self . adapter . whoami ( ) , message_types)
119
118
. await
120
119
}
121
120
@@ -133,7 +132,7 @@ impl<T: Adapter + 'static> SentryApi<T> {
133
132
let future = self
134
133
. client
135
134
. get ( & format ! (
136
- "{}/last-approved?withHearbeat =true" ,
135
+ "{}/last-approved?withHeartbeat =true" ,
137
136
self . validator_url
138
137
) )
139
138
. send ( )
@@ -148,7 +147,7 @@ impl<T: Adapter + 'static> SentryApi<T> {
148
147
) -> Result < EventAggregateResponse , Box < ValidatorWorker > > {
149
148
let auth_token = self
150
149
. adapter
151
- . get_auth ( & self . whoami )
150
+ . get_auth ( self . adapter . whoami ( ) )
152
151
. map_err ( |e| Box :: new ( ValidatorWorker :: Failed ( e. to_string ( ) ) ) ) ?;
153
152
154
153
let url = format ! (
@@ -222,18 +221,17 @@ fn handle_http_error(e: reqwest::Error) {
222
221
223
222
pub async fn all_channels (
224
223
sentry_url : & str ,
225
- whoami : String ,
224
+ whoami : & ValidatorId ,
226
225
) -> Result < Vec < Channel > , reqwest:: Error > {
227
226
let url = sentry_url. to_owned ( ) ;
228
- let first_page = fetch_page ( url. clone ( ) , 0 , whoami. clone ( ) ) . await ?;
227
+ let first_page = fetch_page ( url. clone ( ) , 0 , & whoami) . await ?;
229
228
230
229
if first_page. total_pages < 2 {
231
230
Ok ( first_page. channels )
232
231
} else {
233
- let mut all: Vec < ChannelListResponse > = try_join_all (
234
- ( 1 ..first_page. total_pages ) . map ( |i| fetch_page ( url. clone ( ) , i, whoami. clone ( ) ) ) ,
235
- )
236
- . await ?;
232
+ let mut all: Vec < ChannelListResponse > =
233
+ try_join_all ( ( 1 ..first_page. total_pages ) . map ( |i| fetch_page ( url. clone ( ) , i, & whoami) ) )
234
+ . await ?;
237
235
238
236
all. push ( first_page) ;
239
237
let result_all: Vec < Channel > = all
@@ -247,15 +245,18 @@ pub async fn all_channels(
247
245
async fn fetch_page (
248
246
sentry_url : String ,
249
247
page : u64 ,
250
- validator : String ,
248
+ validator : & ValidatorId ,
251
249
) -> Result < ChannelListResponse , reqwest:: Error > {
252
250
let client = Client :: new ( ) ;
253
251
254
- let mut query = vec ! [ format!( "page={}" , page) ] ;
255
- query. push ( format ! ( "validator={}" , validator. to_string( ) ) ) ;
252
+ let query = [
253
+ format ! ( "page={}" , page) ,
254
+ format ! ( "validator={}" , validator. to_hex_checksummed_string( ) ) ,
255
+ ]
256
+ . join ( "&" ) ;
256
257
257
258
let future = client
258
- . get ( format ! ( "{}/channel/list?{}" , sentry_url, query. join ( "&" ) ) . as_str ( ) )
259
+ . get ( & format ! ( "{}/channel/list?{}" , sentry_url, query) )
259
260
. send ( )
260
261
. and_then ( |mut res : Response | res. json :: < ChannelListResponse > ( ) ) ;
261
262
0 commit comments