From da851e77ed01263742bd1cfe9134ade448197b8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Thu, 25 Jan 2024 16:48:14 +0000 Subject: [PATCH] fixup! Merge branch 'yuji/fix-multitoken-vp' (#2443) --- .../namada/src/ledger/native_vp/slash_fund.rs | 103 ------------------ 1 file changed, 103 deletions(-) delete mode 100644 crates/namada/src/ledger/native_vp/slash_fund.rs diff --git a/crates/namada/src/ledger/native_vp/slash_fund.rs b/crates/namada/src/ledger/native_vp/slash_fund.rs deleted file mode 100644 index 6cd463ea1c..0000000000 --- a/crates/namada/src/ledger/native_vp/slash_fund.rs +++ /dev/null @@ -1,103 +0,0 @@ -//! SlashFund VP - -use std::collections::BTreeSet; - -use namada_core::ledger::slash_fund; -/// SlashFund storage -pub use namada_core::ledger::slash_fund::storage; -use namada_state::StorageRead; -use namada_tx::Tx; -use thiserror::Error; - -use crate::ledger::native_vp::{self, governance, Ctx, NativeVp}; -use crate::state::{self as ledger_storage, StorageHasher}; -use crate::token; -use crate::types::address::Address; -use crate::types::storage::Key; -use crate::vm::WasmCacheAccess; - -#[allow(missing_docs)] -#[derive(Error, Debug)] -pub enum Error { - #[error("Native VP error: {0}")] - NativeVpError(#[from] native_vp::Error), -} - -/// SlashFund functions result -pub type Result = std::result::Result; - -/// SlashFund VP -pub struct SlashFundVp<'a, DB, H, CA> -where - DB: namada_state::DB + for<'iter> namada_state::DBIter<'iter>, - H: StorageHasher, - CA: WasmCacheAccess, -{ - /// Context to interact with the host structures. - pub ctx: Ctx<'a, DB, H, CA>, -} - -impl<'a, DB, H, CA> NativeVp for SlashFundVp<'a, DB, H, CA> -where - DB: 'static + namada_state::DB + for<'iter> namada_state::DBIter<'iter>, - H: 'static + StorageHasher, - CA: 'static + WasmCacheAccess, -{ - type Error = Error; - - fn validate_tx( - &self, - tx_data: &Tx, - keys_changed: &BTreeSet, - _verifiers: &BTreeSet
, - ) -> Result { - let native_token = self.ctx.pre().get_native_token()?; - let result = keys_changed.iter().all(|key| { - let key_type: KeyType = get_key_type(key, &native_token); - match key_type { - KeyType::BALANCE(addr) => { - if addr.ne(&slash_fund::ADDRESS) { - return true; - } - let data = if let Some(data) = tx_data.data() { - data - } else { - return false; - }; - governance::utils::is_proposal_accepted( - &self.ctx.pre(), - &data, - ) - .unwrap_or(false) - } - KeyType::UNKNOWN_SLASH_FUND => false, - KeyType::UNKNOWN => true, - } - }); - Ok(result) - } -} - -#[allow(clippy::upper_case_acronyms)] -enum KeyType { - #[allow(clippy::upper_case_acronyms)] - BALANCE(Address), - #[allow(clippy::upper_case_acronyms)] - #[allow(non_camel_case_types)] - UNKNOWN_SLASH_FUND, - #[allow(clippy::upper_case_acronyms)] - UNKNOWN, -} - -fn get_key_type(value: &Key, native_token: &Address) -> KeyType { - if 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 - } -}