Skip to content

Commit

Permalink
fixup! Merge branch 'grarco/spend-description-validation' (#2244)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gianmarco Fraccaroli committed Dec 13, 2023
1 parent 2a17b0e commit f608c5d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
4 changes: 2 additions & 2 deletions apps/src/lib/node/ledger/shell/init_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ use std::hash::Hash;
use masp_primitives::merkle_tree::CommitmentTree;
use masp_primitives::sapling::Node;
use masp_proofs::bls12_381;
use namada::core::types::storage::KeySeg;
use namada::ledger::parameters::Parameters;
use namada::ledger::storage::traits::StorageHasher;
use namada::ledger::storage::{DBIter, DB};
use namada::ledger::storage_api::token::{credit_tokens, write_denom};
use namada::ledger::storage_api::StorageWrite;
use namada::ledger::{ibc, pos};
use namada::proof_of_stake::BecomeValidator;
use namada::types::address::Address;
use namada::types::address::MASP;
use namada::types::address::{Address, MASP};
use namada::types::hash::Hash as CodeHash;
use namada::types::key::*;
use namada::types::time::{DateTimeUtc, TimeZone, Utc};
Expand Down
43 changes: 29 additions & 14 deletions core/src/types/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1155,10 +1155,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 @@ -1170,9 +1174,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 @@ -1254,9 +1262,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 @@ -1268,10 +1279,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 f608c5d

Please sign in to comment.