Skip to content

Commit 3d3817c

Browse files
committed
use option for hotkeys
1 parent 5ceba80 commit 3d3817c

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

pallets/subtensor/runtime-api/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ sp_api::decl_runtime_apis! {
4646
fn get_stake_info_for_coldkey( coldkey_account: AccountId32 ) -> Vec<StakeInfo<AccountId32>>;
4747
fn get_stake_info_for_coldkeys( coldkey_accounts: Vec<AccountId32> ) -> Vec<(AccountId32, Vec<StakeInfo<AccountId32>>)>;
4848
fn get_stake_info_for_hotkey_coldkey_netuid( hotkey_account: AccountId32, coldkey_account: AccountId32, netuid: u16 ) -> Option<StakeInfo<AccountId32>>;
49-
fn get_stake_fee( origin_hotkey_account: AccountId32, origin_coldkey_account: AccountId32, destination_hotkey_account: AccountId32, destination_coldkey_account: AccountId32, origin_netuid: Option<u16>, destination_netuid: Option<u16>, amount: i64 ) -> u64;
49+
fn get_stake_fee( origin_hotkey_account: Option<AccountId32>, origin_coldkey_account: AccountId32, destination_hotkey_account: Option<AccountId32>, destination_coldkey_account: AccountId32, origin_netuid: Option<u16>, destination_netuid: Option<u16>, amount: i64 ) -> u64;
5050
}
5151

5252
pub trait SubnetRegistrationRuntimeApi {

pallets/subtensor/src/rpc_info/stake_info.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ impl<T: Config> Pallet<T> {
116116
}
117117

118118
pub fn get_stake_fee(
119-
origin_hotkey_account: T::AccountId,
119+
origin_hotkey_account: Option<T::AccountId>,
120120
_origin_coldkey_account: T::AccountId,
121-
_destination_hotkey_account: T::AccountId,
121+
_destination_hotkey_account: Option<T::AccountId>,
122122
_destination_coldkey_account: T::AccountId,
123123
origin_netuid: Option<u16>,
124124
_destination_netuid: Option<u16>,
@@ -128,12 +128,17 @@ impl<T: Config> Pallet<T> {
128128
// Adding stake
129129
DefaultStakingFee::<T>::get()
130130
} else {
131-
// Calculate fee for unstake (negative amount)
132-
Self::calculate_staking_fee(
133-
origin_netuid.unwrap_or(Self::get_root_netuid()),
134-
&origin_hotkey_account,
135-
I96F32::saturating_from_num(amount.neg()),
136-
)
131+
match (origin_netuid, origin_hotkey_account) {
132+
(Some(origin_netuid), Some(origin_hotkey_account)) => {
133+
// Calculate fee for unstake (negative amount)
134+
Self::calculate_staking_fee(
135+
origin_netuid,
136+
&origin_hotkey_account,
137+
I96F32::saturating_from_num(amount.neg()),
138+
)
139+
}
140+
_ => DefaultStakingFee::<T>::get(),
141+
}
137142
}
138143
}
139144
}

runtime/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2067,7 +2067,7 @@ impl_runtime_apis! {
20672067
SubtensorModule::get_stake_info_for_hotkey_coldkey_netuid( hotkey_account, coldkey_account, netuid )
20682068
}
20692069

2070-
fn get_stake_fee( origin_hotkey_account: AccountId32, origin_coldkey_account: AccountId32, destination_hotkey_account: AccountId32, destination_coldkey_account: AccountId32, origin_netuid: Option<u16>, destination_netuid: Option<u16>, amount: i64 ) -> u64 {
2070+
fn get_stake_fee( origin_hotkey_account: Option<AccountId32>, origin_coldkey_account: AccountId32, destination_hotkey_account: Option<AccountId32>, destination_coldkey_account: AccountId32, origin_netuid: Option<u16>, destination_netuid: Option<u16>, amount: i64 ) -> u64 {
20712071
SubtensorModule::get_stake_fee( origin_hotkey_account, origin_coldkey_account, destination_hotkey_account, destination_coldkey_account, origin_netuid, destination_netuid, amount )
20722072
}
20732073
}

0 commit comments

Comments
 (0)