Skip to content

Commit

Permalink
chore: move subaccount_prefix validation to trait methods
Browse files Browse the repository at this point in the history
  • Loading branch information
dj8yf0μl committed Dec 26, 2024
1 parent 66e424a commit 1388747
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
8 changes: 8 additions & 0 deletions workspaces/src/network/sandbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ impl RootAccountSubaccountCreator for Sandbox {
subaccount_prefix: AccountId,
sk: SecretKey,
) -> Result<Execution<Account>> {
if subaccount_prefix.as_str().contains('.') {
return Err(crate::error::ErrorKind::Io
.custom("Subaccount prefix for subaccount created cannot contain '.'"));
}
let root_id = self.root_account_id()?;
let id = AccountId::from_str(format!("{}.{}", subaccount_prefix, root_id).as_str())
.map_err(|e| ErrorKind::DataConversion.custom(e))?;
Expand All @@ -203,6 +207,10 @@ impl RootAccountSubaccountCreator for Sandbox {
sk: SecretKey,
wasm: &[u8],
) -> Result<Execution<Contract>> {
if subaccount_prefix.as_str().contains('.') {
return Err(crate::error::ErrorKind::Io
.custom("Subaccount prefix for subaccount created cannot contain '.'"));
}
let root_id = self.root_account_id()?;
let id = AccountId::from_str(format!("{}.{}", subaccount_prefix, root_id).as_str())
.map_err(|e| ErrorKind::DataConversion.custom(e))?;
Expand Down
4 changes: 4 additions & 0 deletions workspaces/src/network/testnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ impl RootAccountSubaccountCreator for Testnet {
sk: SecretKey,
// TODO: return Account only, but then you don't get metadata info for it...
) -> Result<Execution<Account>> {
if subaccount_prefix.as_str().contains('.') {
return Err(crate::error::ErrorKind::Io
.custom("Subaccount prefix for subaccount created cannot contain '.'"));
}
let url = Url::parse(HELPER_URL).unwrap();
let root_id = self
.root_account_id()
Expand Down
10 changes: 1 addition & 9 deletions workspaces/src/network/variants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub trait NetworkInfo {
/// For example, if this parameter is `"subaccount"` then
/// the full ID for testnet will be `"subaccount.testnet"`.
///
/// It is expected that the `subaccount_prefix` does not contain a `.`.
/// Currently all implementations validate that `subaccount_prefix` does not contain a `.`.
#[async_trait]
pub trait RootAccountSubaccountCreator {
/// for sandbox value of [`Worker::<Sandbox>::root_account`]
Expand Down Expand Up @@ -136,10 +136,6 @@ where
subaccount_prefix: AccountId,
sk: SecretKey,
) -> Result<Execution<Account>> {
if subaccount_prefix.as_str().contains('.') {
return Err(crate::error::ErrorKind::Io
.custom("Subaccount prefix for subaccount created cannot contain '.'"));
}
let res = self
.workspace
.create_root_account_subaccount(self.clone().coerce(), subaccount_prefix, sk)
Expand All @@ -158,10 +154,6 @@ where
sk: SecretKey,
wasm: &[u8],
) -> Result<Execution<Contract>> {
if subaccount_prefix.as_str().contains('.') {
return Err(crate::error::ErrorKind::Io
.custom("Subaccount prefix for subaccount created cannot contain '.'"));
}
let res = self
.workspace
.create_root_account_subaccount_and_deploy(
Expand Down

0 comments on commit 1388747

Please sign in to comment.