Skip to content

Commit 6ab7303

Browse files
committed
fix; adapter get_auth remove mutable arg
1 parent 02b1edd commit 6ab7303

File tree

3 files changed

+18
-29
lines changed

3 files changed

+18
-29
lines changed

adapter/src/dummy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl Adapter for DummyAdapter {
8888
}
8989
}
9090

91-
fn get_auth(&mut self, _validator: &ValidatorId) -> AdapterResult<String> {
91+
fn get_auth(&self, _validator: &ValidatorId) -> AdapterResult<String> {
9292
let who = self
9393
.session_tokens
9494
.iter()

adapter/src/ethereum.rs

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -227,33 +227,22 @@ impl Adapter for EthereumAdapter {
227227
Ok(sess)
228228
}
229229

230-
fn get_auth(&mut self, validator_id: &ValidatorId) -> AdapterResult<String> {
231-
let validator = validator_id.to_owned();
232-
match (
233-
&self.wallet,
234-
self.authorization_tokens.get(&validator.to_string()),
235-
) {
236-
(Some(_), Some(token)) => Ok(token.to_owned()),
237-
(Some(wallet), None) => {
238-
let era = Utc::now().timestamp_millis() as f64 / 60000.0;
239-
let payload = Payload {
240-
id: validator.to_hex_checksummed_string(),
241-
era: era.floor() as i64,
242-
identity: None,
243-
address: self.whoami().to_hex_checksummed_string(),
244-
};
245-
let token = ewt_sign(wallet, &self.keystore_pwd, &payload)
246-
.map_err(|_| map_error("Failed to sign token"))?;
247-
248-
self.authorization_tokens
249-
.insert(validator.to_string(), token.clone());
250-
251-
Ok(token)
252-
}
253-
(_, _) => Err(AdapterError::Configuration(
254-
"failed to unlock wallet".to_string(),
255-
)),
256-
}
230+
fn get_auth(&self, validator: &ValidatorId) -> AdapterResult<String> {
231+
let wallet = self.wallet.clone().ok_or_else(|| AdapterError::Configuration(
232+
"failed to unlock wallet".to_string()
233+
))?;
234+
235+
let era = Utc::now().timestamp_millis() as f64 / 60000.0;
236+
let payload = Payload {
237+
id: validator.to_hex_checksummed_string(),
238+
era: era.floor() as i64,
239+
identity: None,
240+
address: self.whoami().to_hex_checksummed_string(),
241+
};
242+
let token = ewt_sign(&wallet, &self.keystore_pwd, &payload)
243+
.map_err(|_| map_error("Failed to sign token"))?;
244+
245+
Ok(token)
257246
}
258247
}
259248

primitives/src/adapter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,5 @@ pub trait Adapter: ChannelValidator + Send + Clone + Debug {
8484
fn session_from_token(&self, token: &str) -> AdapterResult<Session>;
8585

8686
/// Gets authentication for specific validator
87-
fn get_auth(&mut self, validator_id: &ValidatorId) -> AdapterResult<String>;
87+
fn get_auth(&self, validator_id: &ValidatorId) -> AdapterResult<String>;
8888
}

0 commit comments

Comments
 (0)