git.delta.rocks / unique-network / refs/commits / ab6ae7620c9f

difftreelog

feat support evm accounts in chainspec

Yaroslav Bolyukin2021-04-30parent: #bbe9a34.patch.diff
in: master

2 files changed

modifiednode/src/chain_spec.rsdiffbeforeafterboth
179 .collect(),179 .collect(),
180 },180 },
181 pallet_nft: NftConfig {181 pallet_nft: NftConfig {
182 collection_id: vec![(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![],183 nft_item_id: vec![],
202 fungible_item_id: vec![],184 fungible_item_id: vec![],
203 refungible_item_id: vec![],185 refungible_item_id: vec![],
modifiedpallets/nft/src/lib.rsdiffbeforeafterboth
604 }604 }
605605
606 for (collection_id, account_id, fungible_item) in &config.fungible_item_id {606 for (collection_id, account_id, fungible_item) in &config.fungible_item_id {
607 <Module<T>>::init_fungible_token(*collection_id, account_id, fungible_item);607 <Module<T>>::init_fungible_token(*collection_id, &T::CrossAccountId::from_sub(account_id.clone()), fungible_item);
608 }608 }
609609
610 for (_num, _c, _i) in &config.refungible_item_id {610 for (_num, _c, _i) in &config.refungible_item_id {
2412 CreatedCollectionCount::put(next_id);2412 CreatedCollectionCount::put(next_id);
2413 }2413 }
24142414
2415 fn init_nft_token(collection_id: CollectionId, item: &NftItemType<T::AccountId>) {2415 fn init_nft_token(collection_id: CollectionId, item: &NftItemType<T::CrossAccountId>) {
2416 let current_index = <ItemListIndex>::get(collection_id)2416 let current_index = <ItemListIndex>::get(collection_id)
2417 .checked_add(1)2417 .checked_add(1)
2418 .unwrap();2418 .unwrap();
24192419
2420 let item_owner = item.owner.clone();
2421 Self::add_token_index(collection_id, current_index, &item.owner).unwrap();2420 Self::add_token_index(collection_id, current_index, &item.owner).unwrap();
24222421
2423 <ItemListIndex>::insert(collection_id, current_index);2422 <ItemListIndex>::insert(collection_id, current_index);
24242423
2425 // Update balance2424 // Update balance
2426 let new_balance = <Balance<T>>::get(collection_id, &item_owner)2425 let new_balance = <Balance<T>>::get(collection_id, item.owner.as_sub())
2427 .checked_add(1)2426 .checked_add(1)
2428 .unwrap();2427 .unwrap();
2429 <Balance<T>>::insert(collection_id, item_owner.clone(), new_balance);2428 <Balance<T>>::insert(collection_id, item.owner.as_sub(), new_balance);
2430 }2429 }
24312430
2432 fn init_fungible_token(collection_id: CollectionId, owner: &T::AccountId, item: &FungibleItemType) {2431 fn init_fungible_token(collection_id: CollectionId, owner: &T::CrossAccountId, item: &FungibleItemType) {
2433 let current_index = <ItemListIndex>::get(collection_id)2432 let current_index = <ItemListIndex>::get(collection_id)
2434 .checked_add(1)2433 .checked_add(1)
2435 .unwrap();2434 .unwrap();
2439 <ItemListIndex>::insert(collection_id, current_index);2438 <ItemListIndex>::insert(collection_id, current_index);
24402439
2441 // Update balance2440 // Update balance
2442 let new_balance = <Balance<T>>::get(collection_id, owner)2441 let new_balance = <Balance<T>>::get(collection_id, owner.as_sub())
2443 .checked_add(item.value)2442 .checked_add(item.value)
2444 .unwrap();2443 .unwrap();
2445 <Balance<T>>::insert(collection_id, (*owner).clone(), new_balance);2444 <Balance<T>>::insert(collection_id, owner.as_sub(), new_balance);
2446 }2445 }
24472446
2448 fn init_refungible_token(collection_id: CollectionId, item: &ReFungibleItemType<T::AccountId>) {2447 fn init_refungible_token(collection_id: CollectionId, item: &ReFungibleItemType<T::CrossAccountId>) {
2449 let current_index = <ItemListIndex>::get(collection_id)2448 let current_index = <ItemListIndex>::get(collection_id)
2450 .checked_add(1)2449 .checked_add(1)
2451 .unwrap();2450 .unwrap();
2458 <ItemListIndex>::insert(collection_id, current_index);2457 <ItemListIndex>::insert(collection_id, current_index);
24592458
2460 // Update balance2459 // Update balance
2461 let new_balance = <Balance<T>>::get(collection_id, &owner)2460 let new_balance = <Balance<T>>::get(collection_id, &owner.as_sub())
2462 .checked_add(value)2461 .checked_add(value)
2463 .unwrap();2462 .unwrap();
2464 <Balance<T>>::insert(collection_id, owner.clone(), new_balance);2463 <Balance<T>>::insert(collection_id, owner.as_sub(), new_balance);
2465 }2464 }
24662465
2467 fn add_token_index(collection_id: CollectionId, item_index: TokenId, owner: &T::AccountId) -> DispatchResult {2466 fn add_token_index(collection_id: CollectionId, item_index: TokenId, owner: &T::CrossAccountId) -> DispatchResult {
2468 // add to account limit2467 // add to account limit
2469 if <AccountItemCount<T>>::contains_key(owner) {2468 if <AccountItemCount<T>>::contains_key(owner.as_sub()) {
24702469
2471 // bound Owned tokens by a single address2470 // bound Owned tokens by a single address
2472 let count = <AccountItemCount<T>>::get(owner);2471 let count = <AccountItemCount<T>>::get(owner.as_sub());
2473 ensure!(count < ChainLimit::get().account_token_ownership_limit, Error::<T>::AddressOwnershipLimitExceeded);2472 ensure!(count < ChainLimit::get().account_token_ownership_limit, Error::<T>::AddressOwnershipLimitExceeded);
24742473
2475 <AccountItemCount<T>>::insert(owner.clone(), count2474 <AccountItemCount<T>>::insert(owner.as_sub(), count
2476 .checked_add(1)2475 .checked_add(1)
2477 .ok_or(Error::<T>::NumOverflow)?);2476 .ok_or(Error::<T>::NumOverflow)?);
2478 }2477 }
2479 else {2478 else {
2480 <AccountItemCount<T>>::insert(owner.clone(), 1);2479 <AccountItemCount<T>>::insert(owner.as_sub(), 1);
2481 }2480 }
24822481
2483 let list_exists = <AddressTokens<T>>::contains_key(collection_id, owner);2482 let list_exists = <AddressTokens<T>>::contains_key(collection_id, owner.as_sub());
2484 if list_exists {2483 if list_exists {
2485 let mut list = <AddressTokens<T>>::get(collection_id, owner);2484 let mut list = <AddressTokens<T>>::get(collection_id, owner.as_sub());
2486 let item_contains = list.contains(&item_index.clone());2485 let item_contains = list.contains(&item_index.clone());
24872486
2488 if !item_contains {2487 if !item_contains {
2489 list.push(item_index.clone());2488 list.push(item_index.clone());
2490 }2489 }
24912490
2492 <AddressTokens<T>>::insert(collection_id, owner.clone(), list);2491 <AddressTokens<T>>::insert(collection_id, owner.as_sub(), list);
2493 } else {2492 } else {
2494 let mut itm = Vec::new();2493 let mut itm = Vec::new();
2495 itm.push(item_index.clone());2494 itm.push(item_index.clone());
2496 <AddressTokens<T>>::insert(collection_id, owner.clone(), itm);2495 <AddressTokens<T>>::insert(collection_id, owner.as_sub(), itm);
2497 }2496 }
24982497
2499 Ok(())2498 Ok(())
2502 fn remove_token_index(2501 fn remove_token_index(
2503 collection_id: CollectionId,2502 collection_id: CollectionId,
2504 item_index: TokenId,2503 item_index: TokenId,
2505 owner: &T::AccountId,2504 owner: &T::CrossAccountId,
2506 ) -> DispatchResult {2505 ) -> DispatchResult {
25072506
2508 // update counter2507 // update counter
2509 <AccountItemCount<T>>::insert(owner.clone(), 2508 <AccountItemCount<T>>::insert(owner.as_sub(),
2510 <AccountItemCount<T>>::get(owner)2509 <AccountItemCount<T>>::get(owner.as_sub())
2511 .checked_sub(1)2510 .checked_sub(1)
2512 .ok_or(Error::<T>::NumOverflow)?);2511 .ok_or(Error::<T>::NumOverflow)?);
25132512
25142513
2515 let list_exists = <AddressTokens<T>>::contains_key(collection_id, owner);2514 let list_exists = <AddressTokens<T>>::contains_key(collection_id, owner.as_sub());
2516 if list_exists {2515 if list_exists {
2517 let mut list = <AddressTokens<T>>::get(collection_id, owner);2516 let mut list = <AddressTokens<T>>::get(collection_id, owner.as_sub());
2518 let item_contains = list.contains(&item_index.clone());2517 let item_contains = list.contains(&item_index.clone());
25192518
2520 if item_contains {2519 if item_contains {
2521 list.retain(|&item| item != item_index);2520 list.retain(|&item| item != item_index);
2522 <AddressTokens<T>>::insert(collection_id, owner.clone(), list);2521 <AddressTokens<T>>::insert(collection_id, owner.as_sub(), list);
2523 }2522 }
2524 }2523 }
25252524
2529 fn move_token_index(2528 fn move_token_index(
2530 collection_id: CollectionId,2529 collection_id: CollectionId,
2531 item_index: TokenId,2530 item_index: TokenId,
2532 old_owner: &T::AccountId,2531 old_owner: &T::CrossAccountId,
2533 new_owner: &T::AccountId,2532 new_owner: &T::CrossAccountId,
2534 ) -> DispatchResult {2533 ) -> DispatchResult {
2535 Self::remove_token_index(collection_id, item_index, old_owner)?;2534 Self::remove_token_index(collection_id, item_index, old_owner)?;
2536 Self::add_token_index(collection_id, item_index, new_owner)?;2535 Self::add_token_index(collection_id, item_index, new_owner)?;