astar_primitives/
genesis.rs1use scale_info::prelude::format;
20use sp_core::{Pair, Public};
21use sp_runtime::traits::{IdentifyAccount, Verify};
22
23use super::{AccountId, Signature};
24
25type AccountPublic = <Signature as Verify>::Signer;
26
27pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
29 TPublic::Pair::from_string(&format!("//{}", seed), None)
30 .expect("static values are valid; qed")
31 .public()
32}
33
34pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId
36where
37 AccountPublic: From<<TPublic::Pair as Pair>::Public>,
38{
39 AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()
40}
41
42#[derive(Clone, PartialEq, Eq)]
44pub struct GenesisAccount<TPublic: Public> {
45 pub account_id: AccountId,
47 pub pub_key: <TPublic::Pair as Pair>::Public,
49}
50
51impl<TPublic: Public> GenesisAccount<TPublic>
52where
53 AccountPublic: From<<TPublic::Pair as Pair>::Public>,
54{
55 pub fn from_seed(seed: &str) -> Self {
57 let pub_key = get_from_seed::<TPublic>(seed);
58 let account_id = AccountPublic::from(pub_key.clone()).into_account();
59
60 Self {
61 account_id,
62 pub_key,
63 }
64 }
65
66 pub fn account_id(&self) -> AccountId {
68 self.account_id.clone()
69 }
70
71 pub fn pub_key(&self) -> <TPublic::Pair as Pair>::Public {
73 self.pub_key.clone()
74 }
75}