Skip to content

Commit 7b62c9a

Browse files
Address account domain review feedback
1 parent e44659e commit 7b62c9a

3 files changed

Lines changed: 16 additions & 8 deletions

File tree

crates/sncast/src/accounts/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ pub enum AccountsError {
66
#[error("{kind} cannot be empty")]
77
EmptyIdentifier { kind: &'static str },
88

9+
#[error("invalid account type `{account_type}`")]
10+
InvalidAccountType { account_type: String },
11+
912
#[error("account is missing required field `{field}` for {operation}")]
1013
MissingField {
1114
field: &'static str,

crates/sncast/src/accounts/model.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::collections::BTreeMap;
33
use std::fmt::{Display, Formatter};
44
use std::str::FromStr;
55

6-
use anyhow::anyhow;
76
use clap::ValueEnum;
87
use serde::{Deserialize, Serialize};
98
use starknet_types_core::felt::Felt;
@@ -16,20 +15,23 @@ use crate::signers::SignerSpec;
1615
pub enum AccountType {
1716
#[serde(rename = "open_zeppelin")]
1817
OpenZeppelin,
18+
// Backwards compatibility with pre-rebranding account files.
1919
#[serde(alias = "argent")]
2020
Ready,
2121
Braavos,
2222
}
2323

2424
impl FromStr for AccountType {
25-
type Err = anyhow::Error;
25+
type Err = AccountsError;
2626

2727
fn from_str(value: &str) -> Result<Self, Self::Err> {
2828
match value {
2929
"open_zeppelin" | "open-zeppelin" | "oz" => Ok(Self::OpenZeppelin),
3030
"ready" => Ok(Self::Ready),
3131
"braavos" => Ok(Self::Braavos),
32-
account_type => Err(anyhow!("Invalid account type = {account_type}")),
32+
account_type => Err(AccountsError::InvalidAccountType {
33+
account_type: account_type.to_owned(),
34+
}),
3335
}
3436
}
3537
}
@@ -48,7 +50,7 @@ macro_rules! identifier {
4850
impl $name {
4951
pub fn new(value: impl Into<String>) -> Result<Self, AccountsError> {
5052
let value = value.into();
51-
if value.is_empty() {
53+
if value.trim().is_empty() {
5254
return Err(AccountsError::EmptyIdentifier { kind: $kind });
5355
}
5456
Ok(Self(value))
@@ -208,7 +210,7 @@ impl<'a> DeployableAccountRecord<'a> {
208210
}
209211
}
210212

211-
fn required<T: Copy>(
213+
fn required<T>(
212214
value: Option<T>,
213215
field: &'static str,
214216
operation: &'static str,
@@ -240,6 +242,8 @@ mod tests {
240242
fn identifiers_reject_empty_values() {
241243
assert!(AccountName::new("").is_err());
242244
assert!(NetworkName::new("").is_err());
245+
assert!(AccountName::new(" \t").is_err());
246+
assert!(NetworkName::new("\n").is_err());
243247
}
244248

245249
#[test]
@@ -252,6 +256,7 @@ mod tests {
252256

253257
let registry = AccountRegistry::new(networks);
254258
assert!(registry.account("alpha-sepolia", "alice").is_some());
259+
assert!(registry.account("alpha-sepolia", "bob").is_none());
255260
}
256261

257262
#[test]

crates/sncast/src/signers/spec.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use camino::Utf8PathBuf;
1+
use camino::{Utf8Path, Utf8PathBuf};
22
use starknet_rust::signers::DerivationPath;
33
use starknet_types_core::felt::Felt;
44

@@ -57,8 +57,8 @@ impl KeystoreSpec {
5757
}
5858

5959
#[must_use]
60-
pub fn path(&self) -> &Utf8PathBuf {
61-
&self.path
60+
pub fn path(&self) -> &Utf8Path {
61+
self.path.as_path()
6262
}
6363

6464
#[must_use]

0 commit comments

Comments
 (0)