difftreelog
feat support evm accounts in chainspec
in: master
2 files changed
node/src/chain_spec.rsdiffbeforeafterboth1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56use nft_runtime::*;7use sp_core::{Pair, Public, sr25519};8use nft_runtime::{9 AccountId, AuraConfig, BalancesConfig, EVMConfig, EthereumConfig, GenesisConfig, GrandpaConfig,10 SudoConfig, SystemConfig, WASM_BINARY, Signature11};12use sp_consensus_aura::sr25519::AuthorityId as AuraId;13use sp_finality_grandpa::AuthorityId as GrandpaId;14use sp_runtime::traits::{Verify, IdentifyAccount};15use sc_service::ChainType;16use serde_json::map::Map;17use std::collections::BTreeMap;1819// Note this is the URL for the telemetry server20//const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";2122/// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type.23pub type ChainSpec = sc_service::GenericChainSpec<GenesisConfig>;2425/// Helper function to generate a crypto pair from seed26pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {27 TPublic::Pair::from_string(&format!("//{}", seed), None)28 .expect("static values are valid; qed")29 .public()30}3132type AccountPublic = <Signature as Verify>::Signer;3334/// Helper function to generate an account ID from seed35pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId36where37 AccountPublic: From<<TPublic::Pair as Pair>::Public>,38{39 AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()40}4142/// Helper function to generate an authority key for Aura43pub fn authority_keys_from_seed(s: &str) -> (AuraId, GrandpaId) {44 (get_from_seed::<AuraId>(s), get_from_seed::<GrandpaId>(s))45}4647pub fn development_config() -> Result<ChainSpec, String> {48 let wasm_binary = WASM_BINARY.ok_or("Development wasm binary not available".to_string())?;4950 let mut properties = Map::new();51 properties.insert("tokenSymbol".into(), "UniqueTest".into());52 properties.insert("tokenDecimals".into(), 15.into());53 properties.insert("ss58Format".into(), 42.into()); // Generic Substrate wildcard (SS58 checksum preimage)5455 Ok(ChainSpec::from_genesis(56 // Name57 "Development",58 // ID59 "dev",60 ChainType::Development,61 move || testnet_genesis(62 wasm_binary,63 // Initial PoA authorities64 vec![65 authority_keys_from_seed("Alice"),66 ],67 // Sudo account68 get_account_id_from_seed::<sr25519::Public>("Alice"),69 // Pre-funded accounts70 vec![71 get_account_id_from_seed::<sr25519::Public>("Alice"),72 get_account_id_from_seed::<sr25519::Public>("Bob"),73 get_account_id_from_seed::<sr25519::Public>("Alice//stash"),74 get_account_id_from_seed::<sr25519::Public>("Bob//stash"),75 ],76 true,77 ),78 // Bootnodes79 vec![],80 // Telemetry81 None,82 // Protocol ID83 None,84 // Properties85 Some(properties),86 // Extensions87 None,88 ))89}9091pub fn local_testnet_config() -> Result<ChainSpec, String> {92 let wasm_binary = WASM_BINARY.ok_or("Development wasm binary not available".to_string())?;9394 Ok(ChainSpec::from_genesis(95 // Name96 "Local Testnet",97 // ID98 "local_testnet",99 ChainType::Local,100 move || testnet_genesis(101 wasm_binary,102 // Initial PoA authorities103 vec![104 authority_keys_from_seed("Alice"),105 authority_keys_from_seed("Bob"),106 ],107 // Sudo account108 get_account_id_from_seed::<sr25519::Public>("Alice"),109 // Pre-funded accounts110 vec![111 get_account_id_from_seed::<sr25519::Public>("Alice"),112 get_account_id_from_seed::<sr25519::Public>("Bob"),113 get_account_id_from_seed::<sr25519::Public>("Charlie"),114 get_account_id_from_seed::<sr25519::Public>("Dave"),115 get_account_id_from_seed::<sr25519::Public>("Eve"),116 get_account_id_from_seed::<sr25519::Public>("Ferdie"),117 get_account_id_from_seed::<sr25519::Public>("Alice//stash"),118 get_account_id_from_seed::<sr25519::Public>("Bob//stash"),119 get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),120 get_account_id_from_seed::<sr25519::Public>("Dave//stash"),121 get_account_id_from_seed::<sr25519::Public>("Eve//stash"),122 get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),123 ],124 true,125 ),126 // Bootnodes127 vec![],128 // Telemetry129 None,130 // Protocol ID131 None,132 // Properties133 None,134 // Extensions135 None,136 ))137}138139fn testnet_genesis(140 wasm_binary: &[u8],141 initial_authorities: Vec<(AuraId, GrandpaId)>,142 root_key: AccountId,143 endowed_accounts: Vec<AccountId>,144 enable_println: bool,145) -> GenesisConfig {146147 let vested_accounts = vec![148 get_account_id_from_seed::<sr25519::Public>("Bob"),149 ];150151 GenesisConfig {152 system: SystemConfig {153 code: wasm_binary.to_vec(),154 changes_trie_config: Default::default(),155 },156 pallet_balances: BalancesConfig {157 balances: endowed_accounts158 .iter()159 .cloned()160 .map(|k| (k, 1 << 100))161 .collect(),162 },163 pallet_aura: AuraConfig {164 authorities: initial_authorities.iter().map(|x| (x.0.clone())).collect(),165 },166 pallet_grandpa: GrandpaConfig {167 authorities: initial_authorities168 .iter()169 .map(|x| (x.1.clone(), 1))170 .collect(),171 },172 pallet_treasury: Default::default(),173 pallet_sudo: SudoConfig { key: root_key },174 pallet_vesting: VestingConfig {175 vesting: vested_accounts176 .iter()177 .cloned()178 .map(|k| (k, 1000, 100, 1 << 98))179 .collect(),180 },181 pallet_nft: NftConfig {182 collection_id: vec![(183 1,184 Collection {185 owner: get_account_id_from_seed::<sr25519::Public>("Alice"),186 mode: CollectionMode::NFT,187 access: AccessMode::Normal,188 decimal_points: 0,189 name: vec![],190 description: vec![],191 token_prefix: vec![],192 mint_mode: false,193 offchain_schema: vec![],194 schema_version: SchemaVersion::default(),195 sponsorship: SponsorshipState::Confirmed(get_account_id_from_seed::<sr25519::Public>("Alice")),196 const_on_chain_schema: vec![],197 variable_on_chain_schema: vec![],198 limits: CollectionLimits::default()199 },200 )],201 nft_item_id: vec![],202 fungible_item_id: vec![],203 refungible_item_id: vec![],204 chain_limit: ChainLimits {205 collection_numbers_limit: 100000,206 account_token_ownership_limit: 1000000,207 collections_admins_limit: 5,208 custom_data_limit: 2048,209 nft_sponsor_transfer_timeout: 15,210 fungible_sponsor_transfer_timeout: 15,211 refungible_sponsor_transfer_timeout: 15,212 offchain_schema_limit: 1024,213 variable_on_chain_schema_limit: 1024,214 const_on_chain_schema_limit: 1024,215 },216 },217 pallet_contracts: ContractsConfig {218 current_schedule: ContractsSchedule {219 enable_println,220 ..Default::default()221 },222 },223 pallet_evm: EVMConfig {224 accounts: BTreeMap::new(),225 },226 pallet_ethereum: EthereumConfig {},227 }228}1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56use nft_runtime::*;7use sp_core::{Pair, Public, sr25519};8use nft_runtime::{9 AccountId, AuraConfig, BalancesConfig, EVMConfig, EthereumConfig, GenesisConfig, GrandpaConfig,10 SudoConfig, SystemConfig, WASM_BINARY, Signature11};12use sp_consensus_aura::sr25519::AuthorityId as AuraId;13use sp_finality_grandpa::AuthorityId as GrandpaId;14use sp_runtime::traits::{Verify, IdentifyAccount};15use sc_service::ChainType;16use serde_json::map::Map;17use std::collections::BTreeMap;1819// Note this is the URL for the telemetry server20//const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";2122/// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type.23pub type ChainSpec = sc_service::GenericChainSpec<GenesisConfig>;2425/// Helper function to generate a crypto pair from seed26pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {27 TPublic::Pair::from_string(&format!("//{}", seed), None)28 .expect("static values are valid; qed")29 .public()30}3132type AccountPublic = <Signature as Verify>::Signer;3334/// Helper function to generate an account ID from seed35pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId36where37 AccountPublic: From<<TPublic::Pair as Pair>::Public>,38{39 AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()40}4142/// Helper function to generate an authority key for Aura43pub fn authority_keys_from_seed(s: &str) -> (AuraId, GrandpaId) {44 (get_from_seed::<AuraId>(s), get_from_seed::<GrandpaId>(s))45}4647pub fn development_config() -> Result<ChainSpec, String> {48 let wasm_binary = WASM_BINARY.ok_or("Development wasm binary not available".to_string())?;4950 let mut properties = Map::new();51 properties.insert("tokenSymbol".into(), "UniqueTest".into());52 properties.insert("tokenDecimals".into(), 15.into());53 properties.insert("ss58Format".into(), 42.into()); // Generic Substrate wildcard (SS58 checksum preimage)5455 Ok(ChainSpec::from_genesis(56 // Name57 "Development",58 // ID59 "dev",60 ChainType::Development,61 move || testnet_genesis(62 wasm_binary,63 // Initial PoA authorities64 vec![65 authority_keys_from_seed("Alice"),66 ],67 // Sudo account68 get_account_id_from_seed::<sr25519::Public>("Alice"),69 // Pre-funded accounts70 vec![71 get_account_id_from_seed::<sr25519::Public>("Alice"),72 get_account_id_from_seed::<sr25519::Public>("Bob"),73 get_account_id_from_seed::<sr25519::Public>("Alice//stash"),74 get_account_id_from_seed::<sr25519::Public>("Bob//stash"),75 ],76 true,77 ),78 // Bootnodes79 vec![],80 // Telemetry81 None,82 // Protocol ID83 None,84 // Properties85 Some(properties),86 // Extensions87 None,88 ))89}9091pub fn local_testnet_config() -> Result<ChainSpec, String> {92 let wasm_binary = WASM_BINARY.ok_or("Development wasm binary not available".to_string())?;9394 Ok(ChainSpec::from_genesis(95 // Name96 "Local Testnet",97 // ID98 "local_testnet",99 ChainType::Local,100 move || testnet_genesis(101 wasm_binary,102 // Initial PoA authorities103 vec![104 authority_keys_from_seed("Alice"),105 authority_keys_from_seed("Bob"),106 ],107 // Sudo account108 get_account_id_from_seed::<sr25519::Public>("Alice"),109 // Pre-funded accounts110 vec![111 get_account_id_from_seed::<sr25519::Public>("Alice"),112 get_account_id_from_seed::<sr25519::Public>("Bob"),113 get_account_id_from_seed::<sr25519::Public>("Charlie"),114 get_account_id_from_seed::<sr25519::Public>("Dave"),115 get_account_id_from_seed::<sr25519::Public>("Eve"),116 get_account_id_from_seed::<sr25519::Public>("Ferdie"),117 get_account_id_from_seed::<sr25519::Public>("Alice//stash"),118 get_account_id_from_seed::<sr25519::Public>("Bob//stash"),119 get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),120 get_account_id_from_seed::<sr25519::Public>("Dave//stash"),121 get_account_id_from_seed::<sr25519::Public>("Eve//stash"),122 get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),123 ],124 true,125 ),126 // Bootnodes127 vec![],128 // Telemetry129 None,130 // Protocol ID131 None,132 // Properties133 None,134 // Extensions135 None,136 ))137}138139fn testnet_genesis(140 wasm_binary: &[u8],141 initial_authorities: Vec<(AuraId, GrandpaId)>,142 root_key: AccountId,143 endowed_accounts: Vec<AccountId>,144 enable_println: bool,145) -> GenesisConfig {146147 let vested_accounts = vec![148 get_account_id_from_seed::<sr25519::Public>("Bob"),149 ];150151 GenesisConfig {152 system: SystemConfig {153 code: wasm_binary.to_vec(),154 changes_trie_config: Default::default(),155 },156 pallet_balances: BalancesConfig {157 balances: endowed_accounts158 .iter()159 .cloned()160 .map(|k| (k, 1 << 100))161 .collect(),162 },163 pallet_aura: AuraConfig {164 authorities: initial_authorities.iter().map(|x| (x.0.clone())).collect(),165 },166 pallet_grandpa: GrandpaConfig {167 authorities: initial_authorities168 .iter()169 .map(|x| (x.1.clone(), 1))170 .collect(),171 },172 pallet_treasury: Default::default(),173 pallet_sudo: SudoConfig { key: root_key },174 pallet_vesting: VestingConfig {175 vesting: vested_accounts176 .iter()177 .cloned()178 .map(|k| (k, 1000, 100, 1 << 98))179 .collect(),180 },181 pallet_nft: NftConfig {182 collection_id: vec![],183 nft_item_id: vec![],184 fungible_item_id: vec![],185 refungible_item_id: vec![],186 chain_limit: ChainLimits {187 collection_numbers_limit: 100000,188 account_token_ownership_limit: 1000000,189 collections_admins_limit: 5,190 custom_data_limit: 2048,191 nft_sponsor_transfer_timeout: 15,192 fungible_sponsor_transfer_timeout: 15,193 refungible_sponsor_transfer_timeout: 15,194 offchain_schema_limit: 1024,195 variable_on_chain_schema_limit: 1024,196 const_on_chain_schema_limit: 1024,197 },198 },199 pallet_contracts: ContractsConfig {200 current_schedule: ContractsSchedule {201 enable_println,202 ..Default::default()203 },204 },205 pallet_evm: EVMConfig {206 accounts: BTreeMap::new(),207 },208 pallet_ethereum: EthereumConfig {},209 }210}pallets/nft/src/lib.rsdiffbeforeafterboth--- a/pallets/nft/src/lib.rs
+++ b/pallets/nft/src/lib.rs
@@ -604,7 +604,7 @@
}
for (collection_id, account_id, fungible_item) in &config.fungible_item_id {
- <Module<T>>::init_fungible_token(*collection_id, account_id, fungible_item);
+ <Module<T>>::init_fungible_token(*collection_id, &T::CrossAccountId::from_sub(account_id.clone()), fungible_item);
}
for (_num, _c, _i) in &config.refungible_item_id {
@@ -2412,24 +2412,23 @@
CreatedCollectionCount::put(next_id);
}
- fn init_nft_token(collection_id: CollectionId, item: &NftItemType<T::AccountId>) {
+ fn init_nft_token(collection_id: CollectionId, item: &NftItemType<T::CrossAccountId>) {
let current_index = <ItemListIndex>::get(collection_id)
.checked_add(1)
.unwrap();
- let item_owner = item.owner.clone();
Self::add_token_index(collection_id, current_index, &item.owner).unwrap();
<ItemListIndex>::insert(collection_id, current_index);
// Update balance
- let new_balance = <Balance<T>>::get(collection_id, &item_owner)
+ let new_balance = <Balance<T>>::get(collection_id, item.owner.as_sub())
.checked_add(1)
.unwrap();
- <Balance<T>>::insert(collection_id, item_owner.clone(), new_balance);
+ <Balance<T>>::insert(collection_id, item.owner.as_sub(), new_balance);
}
- fn init_fungible_token(collection_id: CollectionId, owner: &T::AccountId, item: &FungibleItemType) {
+ fn init_fungible_token(collection_id: CollectionId, owner: &T::CrossAccountId, item: &FungibleItemType) {
let current_index = <ItemListIndex>::get(collection_id)
.checked_add(1)
.unwrap();
@@ -2439,13 +2438,13 @@
<ItemListIndex>::insert(collection_id, current_index);
// Update balance
- let new_balance = <Balance<T>>::get(collection_id, owner)
+ let new_balance = <Balance<T>>::get(collection_id, owner.as_sub())
.checked_add(item.value)
.unwrap();
- <Balance<T>>::insert(collection_id, (*owner).clone(), new_balance);
+ <Balance<T>>::insert(collection_id, owner.as_sub(), new_balance);
}
- fn init_refungible_token(collection_id: CollectionId, item: &ReFungibleItemType<T::AccountId>) {
+ fn init_refungible_token(collection_id: CollectionId, item: &ReFungibleItemType<T::CrossAccountId>) {
let current_index = <ItemListIndex>::get(collection_id)
.checked_add(1)
.unwrap();
@@ -2458,42 +2457,42 @@
<ItemListIndex>::insert(collection_id, current_index);
// Update balance
- let new_balance = <Balance<T>>::get(collection_id, &owner)
+ let new_balance = <Balance<T>>::get(collection_id, &owner.as_sub())
.checked_add(value)
.unwrap();
- <Balance<T>>::insert(collection_id, owner.clone(), new_balance);
+ <Balance<T>>::insert(collection_id, owner.as_sub(), new_balance);
}
- fn add_token_index(collection_id: CollectionId, item_index: TokenId, owner: &T::AccountId) -> DispatchResult {
+ fn add_token_index(collection_id: CollectionId, item_index: TokenId, owner: &T::CrossAccountId) -> DispatchResult {
// add to account limit
- if <AccountItemCount<T>>::contains_key(owner) {
+ if <AccountItemCount<T>>::contains_key(owner.as_sub()) {
// bound Owned tokens by a single address
- let count = <AccountItemCount<T>>::get(owner);
+ let count = <AccountItemCount<T>>::get(owner.as_sub());
ensure!(count < ChainLimit::get().account_token_ownership_limit, Error::<T>::AddressOwnershipLimitExceeded);
- <AccountItemCount<T>>::insert(owner.clone(), count
+ <AccountItemCount<T>>::insert(owner.as_sub(), count
.checked_add(1)
.ok_or(Error::<T>::NumOverflow)?);
}
else {
- <AccountItemCount<T>>::insert(owner.clone(), 1);
+ <AccountItemCount<T>>::insert(owner.as_sub(), 1);
}
- let list_exists = <AddressTokens<T>>::contains_key(collection_id, owner);
+ let list_exists = <AddressTokens<T>>::contains_key(collection_id, owner.as_sub());
if list_exists {
- let mut list = <AddressTokens<T>>::get(collection_id, owner);
+ let mut list = <AddressTokens<T>>::get(collection_id, owner.as_sub());
let item_contains = list.contains(&item_index.clone());
if !item_contains {
list.push(item_index.clone());
}
- <AddressTokens<T>>::insert(collection_id, owner.clone(), list);
+ <AddressTokens<T>>::insert(collection_id, owner.as_sub(), list);
} else {
let mut itm = Vec::new();
itm.push(item_index.clone());
- <AddressTokens<T>>::insert(collection_id, owner.clone(), itm);
+ <AddressTokens<T>>::insert(collection_id, owner.as_sub(), itm);
}
Ok(())
@@ -2502,24 +2501,24 @@
fn remove_token_index(
collection_id: CollectionId,
item_index: TokenId,
- owner: &T::AccountId,
+ owner: &T::CrossAccountId,
) -> DispatchResult {
// update counter
- <AccountItemCount<T>>::insert(owner.clone(),
- <AccountItemCount<T>>::get(owner)
+ <AccountItemCount<T>>::insert(owner.as_sub(),
+ <AccountItemCount<T>>::get(owner.as_sub())
.checked_sub(1)
.ok_or(Error::<T>::NumOverflow)?);
- let list_exists = <AddressTokens<T>>::contains_key(collection_id, owner);
+ let list_exists = <AddressTokens<T>>::contains_key(collection_id, owner.as_sub());
if list_exists {
- let mut list = <AddressTokens<T>>::get(collection_id, owner);
+ let mut list = <AddressTokens<T>>::get(collection_id, owner.as_sub());
let item_contains = list.contains(&item_index.clone());
if item_contains {
list.retain(|&item| item != item_index);
- <AddressTokens<T>>::insert(collection_id, owner.clone(), list);
+ <AddressTokens<T>>::insert(collection_id, owner.as_sub(), list);
}
}
@@ -2529,8 +2528,8 @@
fn move_token_index(
collection_id: CollectionId,
item_index: TokenId,
- old_owner: &T::AccountId,
- new_owner: &T::AccountId,
+ old_owner: &T::CrossAccountId,
+ new_owner: &T::CrossAccountId,
) -> DispatchResult {
Self::remove_token_index(collection_id, item_index, old_owner)?;
Self::add_token_index(collection_id, item_index, new_owner)?;