diff --git a/core/src/ledger/masp_conversions.rs b/core/src/ledger/masp_conversions.rs index b1427ea873..df59ff926d 100644 --- a/core/src/ledger/masp_conversions.rs +++ b/core/src/ledger/masp_conversions.rs @@ -5,8 +5,6 @@ use std::collections::BTreeMap; use borsh::{BorshDeserialize, BorshSerialize}; use borsh_ext::BorshSerializeExt; use masp_primitives::asset_type::AssetType; -#[cfg(feature = "wasm-runtime")] -use masp_primitives::bls12_381; use masp_primitives::convert::AllowedConversion; use masp_primitives::merkle_tree::FrozenCommitmentTree; use masp_primitives::sapling::Node; @@ -19,8 +17,6 @@ use crate::ledger::storage_api::{StorageRead, StorageWrite}; use crate::types::address::{Address, MASP}; use crate::types::dec::Dec; use crate::types::storage::Epoch; -#[cfg(feature = "wasm-runtime")] -use crate::types::storage::{Key, KeySeg}; use crate::types::token::{self, DenominatedAmount, MaspDenom}; use crate::types::uint::Uint; @@ -208,6 +204,7 @@ where { use std::cmp::Ordering; + use masp_primitives::bls12_381; use masp_primitives::ff::PrimeField; use masp_primitives::transaction::components::I128Sum as MaspAmount; use rayon::iter::{ @@ -216,6 +213,7 @@ where use rayon::prelude::ParallelSlice; use crate::types::address; + use crate::types::storage::{Key, KeySeg}; use crate::types::token::MASP_CONVERT_ANCHOR_KEY; // The derived conversions will be placed in MASP address space diff --git a/core/src/types/token.rs b/core/src/types/token.rs index c4601b44bc..1648fef9db 100644 --- a/core/src/types/token.rs +++ b/core/src/types/token.rs @@ -1160,10 +1160,14 @@ pub fn is_balance_key<'a>( key: &'a Key, ) -> Option<&'a Address> { match &key.segments[..] { - [DbKeySeg::AddressSeg(addr), DbKeySeg::AddressSeg(token), DbKeySeg::StringSeg(balance), DbKeySeg::AddressSeg(owner)] - if *addr == Address::Internal(InternalAddress::Multitoken) - && token == token_addr - && balance == BALANCE_STORAGE_KEY => + [ + DbKeySeg::AddressSeg(addr), + DbKeySeg::AddressSeg(token), + DbKeySeg::StringSeg(balance), + DbKeySeg::AddressSeg(owner), + ] if *addr == Address::Internal(InternalAddress::Multitoken) + && token == token_addr + && balance == BALANCE_STORAGE_KEY => { Some(owner) } @@ -1175,9 +1179,13 @@ pub fn is_balance_key<'a>( /// is, returns the token and owner address. pub fn is_any_token_balance_key(key: &Key) -> Option<[&Address; 2]> { match &key.segments[..] { - [DbKeySeg::AddressSeg(addr), DbKeySeg::AddressSeg(token), DbKeySeg::StringSeg(balance), DbKeySeg::AddressSeg(owner)] - if *addr == Address::Internal(InternalAddress::Multitoken) - && balance == BALANCE_STORAGE_KEY => + [ + DbKeySeg::AddressSeg(addr), + DbKeySeg::AddressSeg(token), + DbKeySeg::StringSeg(balance), + DbKeySeg::AddressSeg(owner), + ] if *addr == Address::Internal(InternalAddress::Multitoken) + && balance == BALANCE_STORAGE_KEY => { Some([token, owner]) } @@ -1222,11 +1230,11 @@ pub fn is_masp_allowed_key(key: &Key) -> bool { true } - [DbKeySeg::AddressSeg(addr), DbKeySeg::StringSeg(key), DbKeySeg::StringSeg(_nullifier)] - if *addr == MASP && key == MASP_NULLIFIERS_KEY => - { - true - } + [ + DbKeySeg::AddressSeg(addr), + DbKeySeg::StringSeg(key), + DbKeySeg::StringSeg(_nullifier), + ] if *addr == MASP && key == MASP_NULLIFIERS_KEY => true, _ => false, } } @@ -1278,9 +1286,12 @@ pub fn masp_last_inflation_key(token_address: &Address) -> Key { /// If it is, returns the token. pub fn is_any_minter_key(key: &Key) -> Option<&Address> { match &key.segments[..] { - [DbKeySeg::AddressSeg(addr), DbKeySeg::AddressSeg(token), DbKeySeg::StringSeg(minter)] - if *addr == Address::Internal(InternalAddress::Multitoken) - && minter == MINTER_STORAGE_KEY => + [ + DbKeySeg::AddressSeg(addr), + DbKeySeg::AddressSeg(token), + DbKeySeg::StringSeg(minter), + ] if *addr == Address::Internal(InternalAddress::Multitoken) + && minter == MINTER_STORAGE_KEY => { Some(token) } @@ -1292,10 +1303,14 @@ pub fn is_any_minter_key(key: &Key) -> Option<&Address> { /// If it is, returns the token. pub fn is_any_minted_balance_key(key: &Key) -> Option<&Address> { match &key.segments[..] { - [DbKeySeg::AddressSeg(addr), DbKeySeg::AddressSeg(token), DbKeySeg::StringSeg(balance), DbKeySeg::StringSeg(owner)] - if *addr == Address::Internal(InternalAddress::Multitoken) - && balance == BALANCE_STORAGE_KEY - && owner == MINTED_STORAGE_KEY => + [ + DbKeySeg::AddressSeg(addr), + DbKeySeg::AddressSeg(token), + DbKeySeg::StringSeg(balance), + DbKeySeg::StringSeg(owner), + ] if *addr == Address::Internal(InternalAddress::Multitoken) + && balance == BALANCE_STORAGE_KEY + && owner == MINTED_STORAGE_KEY => { Some(token) }