1
// Copyright (C) Moondance Labs Ltd.
2
// This file is part of Tanssi.
3

            
4
// Tanssi is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8

            
9
// Tanssi is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13

            
14
// You should have received a copy of the GNU General Public License
15
// along with Tanssi.  If not, see <http://www.gnu.org/licenses/>.
16

            
17
pub use node_common::chain_spec::Extensions;
18
pub use sp_core::crypto::get_public_from_string_or_panic;
19
use {dancebox_runtime::AccountId, nimbus_primitives::NimbusId, sp_core::sr25519};
20

            
21
pub mod dancebox;
22
pub mod flashbox;
23

            
24
/// Generate collator keys from seed.
25
///
26
/// This function's return type must always match the session keys of the chain in tuple format.
27
120
pub fn get_collator_keys_from_seed(seed: &str) -> NimbusId {
28
120
    get_public_from_string_or_panic::<NimbusId>(seed)
29
120
}
30

            
31
/// Helper function to turn a list of names into a list of `(AccountId, NimbusId)`
32
30
pub fn invulnerables_from_seeds<S: AsRef<str>, I: Iterator<Item = S>>(
33
30
    names: I,
34
30
) -> Vec<(AccountId, NimbusId)> {
35
30
    names
36
120
        .map(|name| {
37
120
            let name = name.as_ref();
38
120
            (
39
120
                get_public_from_string_or_panic::<sr25519::Public>(name).into(),
40
120
                get_collator_keys_from_seed(name),
41
120
            )
42
120
        })
43
30
        .collect()
44
30
}
45

            
46
/// Helper function to turn a list of names into a list of `AccountId`
47
30
pub fn account_ids(names: &[&str]) -> Vec<AccountId> {
48
30
    names
49
30
        .iter()
50
360
        .map(|name| get_public_from_string_or_panic::<sr25519::Public>(name).into())
51
30
        .collect()
52
30
}