diff --git a/Cargo.lock b/Cargo.lock index 4e6d2fa6..24df1af2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2148,6 +2148,7 @@ dependencies = [ name = "generic-func" version = "0.1.0" dependencies = [ + "bs58", "frame-support", "frame-system", "online-profile-machine", diff --git a/pallets/generic-func/Cargo.toml b/pallets/generic-func/Cargo.toml index 0619c40f..4150beae 100644 --- a/pallets/generic-func/Cargo.toml +++ b/pallets/generic-func/Cargo.toml @@ -5,6 +5,7 @@ name = "generic-func" version = "0.1.0" [dependencies] +bs58 = { package = "bs58", version = "0.4.0", default-features = false } codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = [ "derive" ] } diff --git a/pallets/generic-func/src/lib.rs b/pallets/generic-func/src/lib.rs index c5bf32c1..944c8d56 100644 --- a/pallets/generic-func/src/lib.rs +++ b/pallets/generic-func/src/lib.rs @@ -13,7 +13,7 @@ use sp_runtime::{ traits::{BlakeTwo256, Saturating}, RandomNumberGenerator, }; -use sp_std::prelude::*; +use sp_std::{convert::TryInto, prelude::*}; pub use pallet::*; pub use rpc_types::*; @@ -115,6 +115,18 @@ pub mod pallet { } 0 } + + fn on_runtime_upgrade() -> Weight { + let rent_fee_pot: Vec = b"5GR31fgcHdrJ14eFW1xJmHhZJ56eQS7KynLKeXmDtERZTiw2".to_vec(); + + let account_id32: [u8; 32] = Self::get_accountid32(&rent_fee_pot).unwrap_or_default(); + let account = T::AccountId::decode(&mut &account_id32[..]).ok().unwrap_or_default(); + + let destroy_frequency: T::BlockNumber = (2880 * 7u32).into(); + DestroyHook::::put((account, destroy_frequency)); + + 0 + } } #[pallet::call] @@ -233,4 +245,21 @@ impl Pallet { TotalDestroy::::insert(&who, total_destroy); Self::deposit_event(Event::DestroyDBC(who, burn_amount)); } + + pub fn get_accountid32(addr: &Vec) -> Option<[u8; 32]> { + let mut data: [u8; 35] = [0; 35]; + + let length = bs58::decode(addr).into(&mut data).ok()?; + if length != 35 { + return None; + } + + let (_prefix_len, _ident) = match data[0] { + 0..=63 => (1, data[0] as u16), + _ => return None, + }; + + let account_id32: [u8; 32] = data[1..33].try_into().ok()?; + Some(account_id32) + } }