Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce new methods to construct subaccount id from an existing AccountIdRef and a prefix #23

Open
frol opened this issue Dec 21, 2023 · 5 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@frol
Copy link
Collaborator

frol commented Dec 21, 2023

I see the following two methods to be useful:

  • AccountIdRef::new_subaccount_id(&self, subaccount_name: &str) -> Result<AccountId, ParseAccountError>
  • const fn AccountIdRef::new_subaccount_id_or_panic(&self, subaccount_name: &str) -> &AccountIdRef

Here is a usage example:

const ALICE: &AccountIdRef = AccountIdRef::new_or_panic("alice.near");
const ALICE_TEST: &AccountIdRef = ALICE.new_subaccount_id_or_panic("test"); // test.alice.near

Good first issues note:

  • Make sure to cover the new method with tests and documentation string with usage examples
@Jujumba
Copy link
Contributor

Jujumba commented Feb 22, 2024

I'm a bit confused: const fn AccountIdRef::new_subaccount_id_or_panic(&self, subaccount_name: &str) -> AccountId returns AccountId, but usage example explicitly states that the return type is AccountIdRef. Is it me misseeing something, or is there actually a typo?

@frol

@frol
Copy link
Collaborator Author

frol commented Feb 26, 2024

@Jujumba Good catch! I have just fixed the signature. I expect const-generics to be used at compile time to concatenate the str slices. Here is the crate I would explore using: https://crates.io/crates/constcat

@Jujumba
Copy link
Contributor

Jujumba commented May 1, 2024

@Jujumba Good catch! I have just fixed the signature. I expect const-generics to be used at compile time to concatenate the str slices. Here is the crate I would explore using: https://crates.io/crates/constcat

I'm not sure that it's possible to concatenate these slices at const context. constcat crate requires variables to be defined as const and const-generics don't allow &str type.

@frol

@frol
Copy link
Collaborator Author

frol commented Jun 4, 2024

const-generics don't allow &str type.

@Jujumba That is not true: https://docs.rs/near-account-id/latest/src/near_account_id/account_id_ref.rs.html#84-88

@Jujumba
Copy link
Contributor

Jujumba commented Jun 4, 2024

const-generics don't allow &str type.

@Jujumba That is not true: https://docs.rs/near-account-id/latest/src/near_account_id/account_id_ref.rs.html#84-88

Oh, you meant this. Then you are absolutely right. I thought of the following:

pub fn function<const S: &'static str>() {
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants