1919use bifrost_polkadot_runtime:: {
2020 constants:: currency:: DOLLARS , AccountId , AuraId , Balance , BalancesConfig , BlockNumber ,
2121 CollatorSelectionConfig , GenesisConfig , IndicesConfig , ParachainInfoConfig , PolkadotXcmConfig ,
22- SessionConfig , SudoConfig , SystemConfig , VestingConfig , WASM_BINARY ,
22+ SS58Prefix , SessionConfig , SudoConfig , SystemConfig , VestingConfig , WASM_BINARY ,
2323} ;
24+ use bifrost_runtime_common:: dollar;
2425use cumulus_primitives_core:: ParaId ;
2526use frame_benchmarking:: { account, whitelisted_caller} ;
2627use hex_literal:: hex;
28+ use node_primitives:: { CurrencyId , TokenInfo , TokenSymbol } ;
29+ use sc_chain_spec:: Properties ;
2730use sc_service:: ChainType ;
2831use sc_telemetry:: TelemetryEndpoints ;
2932use sp_core:: { crypto:: UncheckedInto , sr25519} ;
@@ -37,7 +40,31 @@ const DEFAULT_PROTOCOL_ID: &str = "bifrost_polkadot";
3740/// Specialized `ChainSpec` for the bifrost-polkadot runtime.
3841pub type ChainSpec = sc_service:: GenericChainSpec < GenesisConfig , RelayExtensions > ;
3942
40- const ENDOWMENT : u128 = 1_000_000 * DOLLARS ;
43+ #[ allow( non_snake_case) ]
44+ pub fn ENDOWMENT ( ) -> u128 {
45+ 1_000_000 * dollar ( CurrencyId :: Native ( TokenSymbol :: BNC ) )
46+ }
47+
48+ fn bifrost_polkadot_properties ( ) -> Properties {
49+ let mut properties = sc_chain_spec:: Properties :: new ( ) ;
50+ let mut token_symbol: Vec < String > = vec ! [ ] ;
51+ let mut token_decimals: Vec < u32 > = vec ! [ ] ;
52+ [
53+ // native token
54+ CurrencyId :: Native ( TokenSymbol :: BNC ) ,
55+ ]
56+ . iter ( )
57+ . for_each ( |token| {
58+ token_symbol. push ( token. symbol ( ) . to_string ( ) ) ;
59+ token_decimals. push ( token. decimals ( ) as u32 ) ;
60+ } ) ;
61+
62+ properties. insert ( "tokenSymbol" . into ( ) , token_symbol. into ( ) ) ;
63+ properties. insert ( "tokenDecimals" . into ( ) , token_decimals. into ( ) ) ;
64+ properties. insert ( "ss58Format" . into ( ) , SS58Prefix :: get ( ) . into ( ) ) ;
65+
66+ properties
67+ }
4168
4269pub fn bifrost_polkadot_genesis (
4370 invulnerables : Vec < ( AccountId , AuraId ) > ,
@@ -87,11 +114,11 @@ fn development_config_genesis(id: ParaId) -> GenesisConfig {
87114 get_account_id_from_seed:: <sr25519:: Public >( "Alice" ) ,
88115 whitelisted_caller( ) , // Benchmarking whitelist_account
89116 ] ;
90- let balances = endowed_accounts. iter ( ) . cloned ( ) . map ( |x| ( x, ENDOWMENT ) ) . collect ( ) ;
117+ let balances = endowed_accounts. iter ( ) . cloned ( ) . map ( |x| ( x, ENDOWMENT ( ) ) ) . collect ( ) ;
91118 let vestings = endowed_accounts
92119 . iter ( )
93120 . cloned ( )
94- . map ( |x| ( x. clone ( ) , 0u32 , 100u32 , ENDOWMENT / 4 ) )
121+ . map ( |x| ( x. clone ( ) , 0u32 , 100u32 , ENDOWMENT ( ) / 4 ) )
95122 . collect ( ) ;
96123
97124 bifrost_polkadot_genesis (
@@ -115,7 +142,7 @@ pub fn development_config(id: ParaId) -> Result<ChainSpec, String> {
115142 vec ! [ ] ,
116143 None ,
117144 Some ( DEFAULT_PROTOCOL_ID ) ,
118- None ,
145+ Some ( bifrost_polkadot_properties ( ) ) ,
119146 RelayExtensions { relay_chain : "polkadot-dev" . into ( ) , para_id : id. into ( ) } ,
120147 ) )
121148}
@@ -138,11 +165,11 @@ fn local_config_genesis(id: ParaId) -> GenesisConfig {
138165 account( "bechmarking_account_1" , 0 , 0 ) , /* Benchmarking account_1, used for interacting
139166 * with whitelistted_caller */
140167 ] ;
141- let balances = endowed_accounts. iter ( ) . cloned ( ) . map ( |x| ( x, ENDOWMENT ) ) . collect ( ) ;
168+ let balances = endowed_accounts. iter ( ) . cloned ( ) . map ( |x| ( x, ENDOWMENT ( ) ) ) . collect ( ) ;
142169 let vestings = endowed_accounts
143170 . iter ( )
144171 . cloned ( )
145- . map ( |x| ( x. clone ( ) , 0u32 , 100u32 , ENDOWMENT / 4 ) )
172+ . map ( |x| ( x. clone ( ) , 0u32 , 100u32 , ENDOWMENT ( ) / 4 ) )
146173 . collect ( ) ;
147174
148175 bifrost_polkadot_genesis (
@@ -169,16 +196,12 @@ pub fn local_testnet_config(id: ParaId) -> Result<ChainSpec, String> {
169196 vec ! [ ] ,
170197 None ,
171198 Some ( DEFAULT_PROTOCOL_ID ) ,
172- None ,
199+ Some ( bifrost_polkadot_properties ( ) ) ,
173200 RelayExtensions { relay_chain : "polkadot-local" . into ( ) , para_id : id. into ( ) } ,
174201 ) )
175202}
176203
177204pub fn chainspec_config ( id : ParaId ) -> ChainSpec {
178- let mut properties = sc_chain_spec:: Properties :: new ( ) ;
179- properties. insert ( "tokenSymbol" . into ( ) , "BNC" . into ( ) ) ;
180- properties. insert ( "tokenDecimals" . into ( ) , 12 . into ( ) ) ;
181-
182205 ChainSpec :: from_genesis (
183206 "Bifrost Polkadot" ,
184207 "bifrost_polkadot" ,
@@ -187,7 +210,7 @@ pub fn chainspec_config(id: ParaId) -> ChainSpec {
187210 vec ! [ ] ,
188211 TelemetryEndpoints :: new ( vec ! [ ( TELEMETRY_URL . into( ) , 0 ) ] ) . ok ( ) ,
189212 Some ( DEFAULT_PROTOCOL_ID ) ,
190- Some ( properties ) ,
213+ Some ( bifrost_polkadot_properties ( ) ) ,
191214 RelayExtensions { relay_chain : "polkadot" . into ( ) , para_id : id. into ( ) } ,
192215 )
193216}
0 commit comments