Skip to content

Commit

Permalink
slash_fund: replace hard-coded nam with native_token
Browse files Browse the repository at this point in the history
  • Loading branch information
tzemanovic committed Oct 25, 2022
1 parent 4c9e727 commit 3880c61
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions shared/src/ledger/slash_fund/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ use thiserror::Error;

use self::storage as slash_fund_storage;
use super::governance::vp::is_proposal_accepted;
use super::storage_api::StorageRead;
use crate::ledger::native_vp::{self, Ctx, NativeVp};
use crate::ledger::storage::{self as ledger_storage, StorageHasher};
use crate::types::address::{nam, Address, InternalAddress};
use crate::types::address::{Address, InternalAddress};
use crate::types::storage::Key;
use crate::types::token;
use crate::vm::WasmCacheAccess;
Expand All @@ -24,7 +25,7 @@ pub const ADDRESS: Address = Address::Internal(InternalAddress::SlashFund);
#[derive(Error, Debug)]
pub enum Error {
#[error("Native VP error: {0}")]
NativeVpError(native_vp::Error),
NativeVpError(#[from] native_vp::Error),
}

/// SlashFund functions result
Expand Down Expand Up @@ -57,8 +58,9 @@ where
keys_changed: &BTreeSet<Key>,
_verifiers: &BTreeSet<Address>,
) -> Result<bool> {
let native_token = self.ctx.pre().get_native_token()?;
let result = keys_changed.iter().all(|key| {
let key_type: KeyType = key.into();
let key_type: KeyType = get_key_type(key, &native_token);
match key_type {
KeyType::BALANCE(addr) => {
if addr.ne(&ADDRESS) {
Expand Down Expand Up @@ -90,17 +92,15 @@ enum KeyType {
UNKNOWN,
}

impl From<&Key> for KeyType {
fn from(value: &Key) -> Self {
if slash_fund_storage::is_slash_fund_key(value) {
KeyType::UNKNOWN_SLASH_FUND
} else if token::is_any_token_balance_key(value).is_some() {
match token::is_balance_key(&nam(), value) {
Some(addr) => KeyType::BALANCE(addr.clone()),
None => KeyType::UNKNOWN,
}
} else {
KeyType::UNKNOWN
fn get_key_type(value: &Key, native_token: &Address) -> KeyType {
if slash_fund_storage::is_slash_fund_key(value) {
KeyType::UNKNOWN_SLASH_FUND
} else if token::is_any_token_balance_key(value).is_some() {
match token::is_balance_key(native_token, value) {
Some(addr) => KeyType::BALANCE(addr.clone()),
None => KeyType::UNKNOWN,
}
} else {
KeyType::UNKNOWN
}
}

0 comments on commit 3880c61

Please sign in to comment.