Created
January 29, 2024 16:51
-
-
Save Mc01/8f5c9106cfea0f64d6254d60f1240353 to your computer and use it in GitHub Desktop.
[Substrate] Convert string to AccountId
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use bs58; | |
#[inline] | |
pub fn convert_string_to_accountid(account_str: &str) -> AccountId { | |
let mut output = vec![0xFF; 35]; | |
bs58::decode(account_str).onto(&mut output).unwrap(); | |
let cut_address_vec: Vec<_> = output.drain(1..33).collect(); | |
let mut array = [0; 32]; | |
let bytes = &cut_address_vec[..array.len()]; | |
array.copy_from_slice(bytes); | |
let accountId: AccountId = array.into(); | |
accountId | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment