Skip to content

Commit

Permalink
Merge pull request #405 from liberland/BLOCKCHAIN-478/on-chain-identi…
Browse files Browse the repository at this point in the history
…ties-for-tech-accounts

 BLOCKCHAIN-478 - Add identities for gov/technical/external accounts
  • Loading branch information
DorianSternVukotic authored Sep 20, 2024
2 parents d8f61aa + 6f6baad commit a29d0a8
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 79 deletions.
3 changes: 2 additions & 1 deletion substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1853,7 +1853,8 @@ pub type Executive = frame_executive::Executive<
// All migrations executed on runtime upgrade as a nested tuple of types implementing
// `OnRuntimeUpgrade`.
type Migrations = (
crate::migrations::add_senate_account_pallet::Migration<Runtime>,
// Migrations for spec version 26 - delete when bumping to v27
crate::migrations::add_onchain_identities::Migration<Runtime>,
);

type EventRecord = frame_system::EventRecord<
Expand Down
126 changes: 48 additions & 78 deletions substrate/bin/node/runtime/src/migrations.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::*;
use frame_support::{pallet_prelude::*, traits::OnRuntimeUpgrade};
use frame_support::traits::OnRuntimeUpgrade;

#[cfg(feature = "try-runtime")]
use sp_std::vec::Vec;
Expand All @@ -9,8 +9,11 @@ use sp_runtime::TryRuntimeError;

type DbWeight = <Runtime as frame_system::Config>::DbWeight;

pub mod add_contracts_registry_pallet {
pub mod add_onchain_identities {
use super::*;
use crate::Identity;
use pallet_identity::{Data, IdentityInfo, Judgement};
use sp_core::crypto::Ss58Codec;

pub struct Migration<T>(sp_std::marker::PhantomData<T>);

Expand All @@ -21,14 +24,49 @@ pub mod add_contracts_registry_pallet {
}

fn on_runtime_upgrade() -> Weight {
let mut weight = DbWeight::get().reads(1);

if StorageVersion::get::<ContractsRegistry>() == 0 {
StorageVersion::new(1).put::<ContractsRegistry>();
weight = weight.saturating_add(DbWeight::get().reads_writes(1, 1));
}

weight
let identities = vec![
("5EYCAe5hvejUE1BUTDSnxDfCqVkADRicSKqbcJrduV1KCDmk", b"Vault".to_vec()),
("5EYCAe5hveooUENA5d7dwq3caqM4LLBzktNumMKmhNRXu4JE", b"Senate".to_vec()),
(
"5EYCAe5iXF2YZuVZv1vig4xvf1CcDVocZCWYrv3TVSXpMTYA",
b"Citizenship Office".to_vec(),
),
//("5EYCAe5ijiYfyeZ2JJCGq56LmPyNRAKzpG4QkoQkkQNB5e6Z", b"Treasury"), - skipping this as Polkadot.js Apps have it builtin
("5EYCAe5g8CDuMsTief7QBxfvzDFEfws6ueXTUhsbx5V81nGH", b"Congress".to_vec()),
("5GmkwXZ94cuLMMbtE5VtBaLpFDehoEpy6MZnJhkCSicxePs2", b"SORA Bridge".to_vec()),
("5DSfG3S7qSZzrDMj3F3qYybXAy1BLsVpRG5CNwRdwwNPjgVm", b"MEXC".to_vec()),
("5HEX1wk33NHAeEJV3B6goDHMJTqhy411znCUmfEAxKkQeqds", b"Coinstore".to_vec()),
("5EYCAe5iXF2YZiuxDWAcwtPMDaG7ihsYzPxajcNKRpNyD1Zi", b"Company Registry Office".to_vec()),
("5EYCAe5iXF2YZzoQHqGhj9dtcsUNB4puM5GqR1BwVHZyaWxM", b"Land Registry Office".to_vec()),
("5EYCAe5iXF2Ya2c2iKjeFWUAXAEcMyoKCBPvhRy8YprHTLNd", b"Metaverse Land Registry Office".to_vec()),
("5EYCAe5iXF2YZfPZ4arKGSYZvQruDacGHkuw4qAsQSQsKpMK", b"Asset Registry Office".to_vec()),
("5EYCAe5iXF2YZpCZr7ALYUUYaNpMXde3NUXxYn1Sc1YRM4gV", b"Ministry of Finance Office".to_vec()),
("5FBQRNJfzsttYvw1XnSwxwSUmb7A3EYm4q8aiscADREqvzYz", b"Wrapped LLD Token Contract".to_vec()),
("5EYCAe5ijGqt3WEM9aKUBdth51NEBNz9P84NaUMWZazzWt7c", b"LLM Politipool Technical Account".to_vec()),
("5GsBCWqN6mnrq4arSMBuT4uQ8GJKwgeBsa5UyCvTN6DyVj3S", b"Emirex".to_vec()),
("5FhqVhuxGtcUBYXhyjtyvjh9jLucmoWzejcomA4HcqW9tBbP", b"LLM/LLD DEX Pool".to_vec()),
];
let mut weight = DbWeight::get().reads(0);
for (addr, display) in identities {
let account = AccountId::from_ss58check(addr).unwrap();
let id = IdentityInfo {
twitter: Data::None,
additional: vec![].try_into().unwrap(),
display: Data::Raw(display.try_into().unwrap()),
legal: Data::None,
web: Data::None,
riot: Data::None,
email: Data::None,
pgp_fingerprint: None,
image: Data::None,
};
let judgements = vec![(0, Judgement::KnownGood)].try_into().unwrap();
let set_identity_weight =
Identity::set_identity_no_deposit(&account, judgements, id);
weight = weight.saturating_add(set_identity_weight);
}

weight
}

#[cfg(feature = "try-runtime")]
Expand All @@ -37,71 +75,3 @@ pub mod add_contracts_registry_pallet {
}
}
}

pub mod add_sora_bridge {
use super::*;

pub struct Migration<T>(sp_std::marker::PhantomData<T>);

impl OnRuntimeUpgrade for Migration<Runtime> {
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, TryRuntimeError> {
Ok(().encode())
}

fn on_runtime_upgrade() -> Weight {
let mut weight = DbWeight::get().reads(1);

if StorageVersion::get::<SubstrateBridgeInboundChannel>() == 0 {
StorageVersion::new(1).put::<SubstrateBridgeInboundChannel>();
weight = weight.saturating_add(DbWeight::get().reads_writes(1, 1));
}

if StorageVersion::get::<SubstrateBridgeOutboundChannel>() == 0 {
StorageVersion::new(1).put::<SubstrateBridgeOutboundChannel>();
weight = weight.saturating_add(DbWeight::get().reads_writes(1, 1));
}

if StorageVersion::get::<SubstrateDispatch>() == 0 {
StorageVersion::new(1).put::<SubstrateDispatch>();
weight = weight.saturating_add(DbWeight::get().reads_writes(1, 1));
}

weight
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(_state: Vec<u8>) -> Result<(), TryRuntimeError> {
Ok(())
}
}
}

pub mod add_senate_account_pallet {
use super::*;

pub struct Migration<T>(sp_std::marker::PhantomData<T>);

impl OnRuntimeUpgrade for Migration<Runtime> {
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, TryRuntimeError> {
Ok(().encode())
}

fn on_runtime_upgrade() -> Weight {
let mut weight = DbWeight::get().reads(1);

if StorageVersion::get::<SenateAccount>() == 0 {
StorageVersion::new(1).put::<SenateAccount>();
weight = weight.saturating_add(DbWeight::get().reads_writes(1, 1));
}

weight
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(_state: Vec<u8>) -> Result<(), TryRuntimeError> {
Ok(())
}
}
}
19 changes: 19 additions & 0 deletions substrate/frame/identity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -998,4 +998,23 @@ impl<T: Config> Pallet<T> {
IdentityOf::<T>::get(who)
.map_or(false, |registration| (registration.info.fields().0.bits() & fields) == fields)
}

/// Set identity for some account
pub fn set_identity_no_deposit(
target: &T::AccountId,
judgements: sp_runtime::BoundedVec<(u32, Judgement<BalanceOf<T>>), T::MaxRegistrars>,
info: IdentityInfo<T::MaxAdditionalFields>
) -> frame_support::pallet_prelude::Weight {
let id = Registration {
judgements,
deposit: 0u8.into(),
info,
};
let weight = T::WeightInfo::set_identity(
id.judgements.len() as u32,
id.info.additional.len() as u32,
);
IdentityOf::<T>::insert(target, id);
weight
}
}

0 comments on commit a29d0a8

Please sign in to comment.