Skip to content

Commit

Permalink
evil: clippy + fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
grarco committed Dec 20, 2023
1 parent 0249de0 commit 2ee0ae1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 23 deletions.
6 changes: 2 additions & 4 deletions core/src/ledger/masp_conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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::{
Expand All @@ -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
Expand Down
53 changes: 34 additions & 19 deletions core/src/types/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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])
}
Expand Down Expand Up @@ -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,
}
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down

0 comments on commit 2ee0ae1

Please sign in to comment.