Skip to content

Commit edc86b1

Browse files
committed
match on results instead
1 parent ddb5184 commit edc86b1

File tree

1 file changed

+33
-18
lines changed

1 file changed

+33
-18
lines changed

pallets/subtensor/src/migrations/migrate_fix_pending_emission.rs

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ use frame_support::{traits::Get, weights::Weight};
44
use sp_core::crypto::Ss58Codec;
55
use sp_runtime::AccountId32;
66

7-
fn get_account_id_from_ss58<T: Config>(ss58_str: &str) -> T::AccountId {
8-
let account = AccountId32::from_ss58check(ss58_str).unwrap();
9-
let onchain_account = T::AccountId::decode(&mut account.as_ref()).unwrap();
7+
fn get_account_id_from_ss58<T: Config>(ss58_str: &str) -> Result<T::AccountId, codec::Error> {
8+
let account =
9+
AccountId32::from_ss58check(ss58_str).map_err(|_| codec::Error::from("Invalid SS58"))?;
10+
let onchain_account = T::AccountId::decode(&mut account.as_ref())?;
1011

11-
onchain_account
12+
Ok(onchain_account)
1213
}
1314

1415
/**
@@ -77,24 +78,38 @@ pub fn do_migrate_fix_pending_emission<T: Config>() -> Weight {
7778
let taostats_old_hotkey = "5Hddm3iBFD2GLT5ik7LZnT3XJUnRnN8PoeCFgGQgawUVKNm8";
7879
let taostats_new_hotkey = "5GKH9FPPnWSUoeeTJp19wVtd84XqFW4pyK2ijV2GsFbhTrP1";
7980

80-
let taostats_old_hk_account: T::AccountId = get_account_id_from_ss58::<T>(taostats_old_hotkey);
81-
let taostats_new_hk_account: T::AccountId = get_account_id_from_ss58::<T>(taostats_new_hotkey);
82-
83-
weight.saturating_accrue(migrate_pending_emissions_including_null_stake::<T>(
84-
&taostats_old_hk_account,
85-
&taostats_new_hk_account,
86-
));
81+
let taostats_old_hk_account = get_account_id_from_ss58::<T>(taostats_old_hotkey);
82+
let taostats_new_hk_account = get_account_id_from_ss58::<T>(taostats_new_hotkey);
83+
84+
match (taostats_old_hk_account, taostats_new_hk_account) {
85+
(Ok(taostats_old_hk_acct), Ok(taostats_new_hk_acct)) => {
86+
weight.saturating_accrue(migrate_pending_emissions_including_null_stake::<T>(
87+
&taostats_old_hk_acct,
88+
&taostats_new_hk_acct,
89+
));
90+
}
91+
_ => {
92+
log::warn!("Failed to get account id from ss58 for taostats hotkeys");
93+
}
94+
}
8795

8896
let datura_old_hotkey = "5FKstHjZkh4v3qAMSBa1oJcHCLjxYZ8SNTSz1opTv4hR7gVB";
8997
let datura_new_hotkey = "5GP7c3fFazW9GXK8Up3qgu2DJBk8inu4aK9TZy3RuoSWVCMi";
9098

91-
let datura_old_hk_account: T::AccountId = get_account_id_from_ss58::<T>(datura_old_hotkey);
92-
let datura_new_hk_account: T::AccountId = get_account_id_from_ss58::<T>(datura_new_hotkey);
93-
94-
weight.saturating_accrue(migrate_pending_emissions_including_null_stake::<T>(
95-
&datura_old_hk_account,
96-
&datura_new_hk_account,
97-
));
99+
let datura_old_hk_account = get_account_id_from_ss58::<T>(datura_old_hotkey);
100+
let datura_new_hk_account = get_account_id_from_ss58::<T>(datura_new_hotkey);
101+
102+
match (datura_old_hk_account, datura_new_hk_account) {
103+
(Ok(datura_old_hk_acct), Ok(datura_new_hk_acct)) => {
104+
weight.saturating_accrue(migrate_pending_emissions_including_null_stake::<T>(
105+
&datura_old_hk_acct,
106+
&datura_new_hk_acct,
107+
));
108+
}
109+
_ => {
110+
log::warn!("Failed to get account id from ss58 for datura hotkeys");
111+
}
112+
}
98113

99114
weight
100115
}

0 commit comments

Comments
 (0)