Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core refactor #2503

Merged
merged 15 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Refactored sub-systems integration in the ABCI FinalizeBlock request handler.
([\#2482](https://github.com/anoma/namada/pull/2482))
1 change: 1 addition & 0 deletions .changelog/unreleased/improvements/2493-refactor-token.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Refactored token crates. ([\#2493](https://github.com/anoma/namada/pull/2493))
2 changes: 2 additions & 0 deletions .changelog/unreleased/improvements/2503-refactor-core.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Refactored core crate to flatten the modules structure.
([\#2503](https://github.com/anoma/namada/pull/2503))
15 changes: 12 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ members = [
"crates/merkle_tree",
"crates/parameters",
"crates/proof_of_stake",
"crates/replay_protection",
"crates/sdk",
"crates/namada",
"crates/shielded_token",
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ crates += namada_macros
crates += namada_merkle_tree
crates += namada_parameters
crates += namada_proof_of_stake
crates += namada_replay_protection
crates += namada_sdk
crates += namada_shielded_token
crates += namada_state
Expand Down
6 changes: 3 additions & 3 deletions crates/account/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ mod storage_key;
mod types;

use borsh::{BorshDeserialize, BorshSerialize};
pub use namada_core::types::account::AccountPublicKeysMap;
use namada_core::types::address::Address;
use namada_core::types::key::common;
pub use namada_core::account::AccountPublicKeysMap;
use namada_core::address::Address;
use namada_core::key::common;
use serde::{Deserialize, Serialize};
pub use storage::*;
pub use storage_key::*;
Expand Down
6 changes: 3 additions & 3 deletions crates/account/src/storage.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Cryptographic signature keys storage API

use namada_core::types::address::Address;
use namada_core::types::key::common;
use namada_core::types::storage;
use namada_core::address::Address;
use namada_core::key::common;
use namada_core::storage;
use namada_storage::{Result, StorageRead, StorageWrite};

use super::*;
Expand Down
6 changes: 3 additions & 3 deletions crates/account/src/storage_key.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use namada_core::types::address::Address;
use namada_core::types::key::common;
use namada_core::types::storage::{self, DbKeySeg};
use namada_core::address::Address;
use namada_core::key::common;
use namada_core::storage::{self, DbKeySeg};
use namada_macros::StorageKeys;
use namada_storage::collections::lazy_map::LazyMap;
use namada_storage::collections::{lazy_map, LazyCollection};
Expand Down
12 changes: 6 additions & 6 deletions crates/account/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use namada_core::address::Address;
use namada_core::borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
use namada_core::types::address::Address;
use namada_core::types::hash::Hash;
use namada_core::types::key::common;
use namada_core::hash::Hash;
use namada_core::key::common;
use serde::{Deserialize, Serialize};

/// A tx data type to initialize a new established account
Expand Down Expand Up @@ -53,9 +53,9 @@ pub struct UpdateAccount {
#[cfg(any(test, feature = "testing"))]
/// Tests and strategies for accounts
pub mod tests {
use namada_core::types::address::testing::arb_non_internal_address;
use namada_core::types::hash::testing::arb_hash;
use namada_core::types::key::testing::arb_common_pk;
use namada_core::address::testing::arb_non_internal_address;
use namada_core::hash::testing::arb_hash;
use namada_core::key::testing::arb_common_pk;
use proptest::prelude::Just;
use proptest::{collection, option, prop_compose};

Expand Down
2 changes: 1 addition & 1 deletion crates/apps/src/bin/namada-node/cli.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Namada node CLI.

use eyre::{Context, Result};
use namada::types::time::{DateTimeUtc, Utc};
use namada::core::time::{DateTimeUtc, Utc};
use namada_apps::cli::{self, cmds};
use namada_apps::config::ValidatorLocalConfig;
use namada_apps::node::ledger;
Expand Down
35 changes: 18 additions & 17 deletions crates/apps/src/lib/bench_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@
use masp_primitives::transaction::Transaction;
use masp_primitives::zip32::ExtendedFullViewingKey;
use masp_proofs::prover::LocalTxProver;
use namada::core::address::{self, Address, InternalAddress};
use namada::core::chain::ChainId;
use namada::core::hash::Hash;
use namada::core::key::common::SecretKey;
use namada::core::masp::{
ExtendedViewingKey, PaymentAddress, TransferSource, TransferTarget,
};
use namada::core::storage::{BlockHeight, Epoch, Key, KeySeg, TxIndex};
use namada::core::time::DateTimeUtc;
use namada::core::token::{Amount, DenominatedAmount, Transfer};
use namada::governance::storage::proposal::ProposalType;
use namada::governance::InitProposalData;
use namada::ibc::apps::transfer::types::msgs::transfer::MsgTransfer;
Expand Down Expand Up @@ -50,6 +60,7 @@
use namada::ibc::primitives::proto::{Any, Protobuf};
use namada::ibc::primitives::{Msg, Timestamp as IbcTimestamp};
use namada::ibc::storage::port_key;
use namada::io::StdIo;
use namada::ledger::dry_run_tx;
use namada::ledger::gas::TxGasMeter;
use namada::ledger::ibc::storage::{channel_key, connection_key};
Expand All @@ -62,17 +73,6 @@
use namada::tx::data::pos::Bond;
use namada::tx::data::{TxResult, VpsResult};
use namada::tx::{Code, Data, Section, Signature, Tx};
use namada::types::address::{self, Address, InternalAddress};
use namada::types::chain::ChainId;
use namada::types::hash::Hash;
use namada::types::io::StdIo;
use namada::types::key::common::SecretKey;
use namada::types::masp::{
ExtendedViewingKey, PaymentAddress, TransferSource, TransferTarget,
};
use namada::types::storage::{BlockHeight, Epoch, Key, KeySeg, TxIndex};
use namada::types::time::DateTimeUtc;
use namada::types::token::{Amount, DenominatedAmount, Transfer};
use namada::vm::wasm::run;
use namada::{proof_of_stake, tendermint};
use namada_sdk::masp::{
Expand Down Expand Up @@ -414,6 +414,11 @@
current_epoch + params.pipeline_len,
)
.unwrap();

namada::token::conversion::update_allowed_conversions(
&mut self.wl_storage,
)
.unwrap();

Check warning on line 421 in crates/apps/src/lib/bench_utils.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/bench_utils.rs#L417-L421

Added lines #L417 - L421 were not covered by tests
}

pub fn init_ibc_client_state(&mut self, addr_key: Key) -> ClientId {
Expand Down Expand Up @@ -887,7 +892,7 @@

impl Default for BenchShieldedCtx {
fn default() -> Self {
let mut shell = BenchShell::default();
let shell = BenchShell::default();

Check warning on line 895 in crates/apps/src/lib/bench_utils.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/bench_utils.rs#L895

Added line #L895 was not covered by tests
let base_dir = shell.tempdir.as_ref().canonicalize().unwrap();

// Create a global config and an empty wallet in the chain dir - this is
Expand Down Expand Up @@ -957,10 +962,6 @@
}

crate::wallet::save(&chain_ctx.wallet).unwrap();
namada::token::conversion::update_allowed_conversions(
&mut shell.wl_storage,
)
.unwrap();

Self {
shielded: ShieldedContext::default(),
Expand Down Expand Up @@ -1020,7 +1021,7 @@

let mut hasher = Sha256::new();
let shielded_section_hash = shielded.clone().map(|transaction| {
namada::types::hash::Hash(
namada::core::hash::Hash(

Check warning on line 1024 in crates/apps/src/lib/bench_utils.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/bench_utils.rs#L1024

Added line #L1024 was not covered by tests
Section::MaspTx(transaction)
.hash(&mut hasher)
.finalize_reset()
Expand Down
24 changes: 12 additions & 12 deletions crates/apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub mod wallet;

use clap::{ArgGroup, ArgMatches, ColorChoice};
use color_eyre::eyre::Result;
use namada::types::io::StdIo;
use namada::io::StdIo;
use utils::*;
pub use utils::{safe_exit, Cmd};

Expand Down Expand Up @@ -2849,19 +2849,19 @@ pub mod args {
use std::path::PathBuf;
use std::str::FromStr;

use namada::core::address::{Address, EstablishedAddress};
use namada::core::chain::{ChainId, ChainIdPrefix};
use namada::core::dec::Dec;
use namada::core::ethereum_events::EthAddress;
use namada::core::keccak::KeccakHash;
use namada::core::key::*;
use namada::core::masp::PaymentAddress;
use namada::core::storage::{self, BlockHeight, Epoch};
use namada::core::time::DateTimeUtc;
use namada::core::token;
use namada::core::token::NATIVE_MAX_DECIMAL_PLACES;
use namada::ibc::core::host::types::identifiers::{ChannelId, PortId};
use namada::tx::data::GasLimit;
use namada::types::address::{Address, EstablishedAddress};
use namada::types::chain::{ChainId, ChainIdPrefix};
use namada::types::dec::Dec;
use namada::types::ethereum_events::EthAddress;
use namada::types::keccak::KeccakHash;
use namada::types::key::*;
use namada::types::masp::PaymentAddress;
use namada::types::storage::{self, BlockHeight, Epoch};
use namada::types::time::DateTimeUtc;
use namada::types::token;
use namada::types::token::NATIVE_MAX_DECIMAL_PLACES;
pub use namada_sdk::args::*;
pub use namada_sdk::tx::{
TX_BECOME_VALIDATOR_WASM, TX_BOND_WASM, TX_BRIDGE_POOL_WASM,
Expand Down
2 changes: 1 addition & 1 deletion crates/apps/src/lib/cli/api.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use namada::io::Io;
use namada::tendermint_rpc::HttpClient;
use namada::types::io::Io;
use namada_sdk::error::Error;
use namada_sdk::queries::Client;
use namada_sdk::rpc::wait_until_node_is_synched;
Expand Down
2 changes: 1 addition & 1 deletion crates/apps/src/lib/cli/client.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use color_eyre::eyre::Result;
use namada::types::io::Io;
use namada::io::Io;
use namada_sdk::{Namada, NamadaImpl};

use crate::cli;
Expand Down
14 changes: 7 additions & 7 deletions crates/apps/src/lib/cli/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ use std::path::{Path, PathBuf};
use std::str::FromStr;

use color_eyre::eyre::Result;
use namada::core::address::{Address, InternalAddress};
use namada::core::chain::ChainId;
use namada::core::ethereum_events::EthAddress;
use namada::core::ibc::is_ibc_denom;
use namada::core::key::*;
use namada::core::masp::*;
use namada::io::Io;
use namada::ledger::ibc::storage::ibc_token;
use namada::types::address::{Address, InternalAddress};
use namada::types::chain::ChainId;
use namada::types::ethereum_events::EthAddress;
use namada::types::ibc::is_ibc_denom;
use namada::types::io::Io;
use namada::types::key::*;
use namada::types::masp::*;
use namada_sdk::masp::fs::FsShieldedUtils;
use namada_sdk::masp::ShieldedContext;
use namada_sdk::wallet::Wallet;
Expand Down
2 changes: 1 addition & 1 deletion crates/apps/src/lib/cli/relayer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use color_eyre::eyre::Result;
use namada::types::io::Io;
use namada::io::Io;
use namada_sdk::eth_bridge::{bridge_pool, validator_set};

use crate::cli;
Expand Down
8 changes: 4 additions & 4 deletions crates/apps/src/lib/cli/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ use ledger_namada_rs::{BIP44Path, NamadaApp};
use ledger_transport_hid::hidapi::HidApi;
use ledger_transport_hid::TransportNativeHID;
use masp_primitives::zip32::ExtendedFullViewingKey;
use namada::types::address::{Address, DecodeError};
use namada::types::io::Io;
use namada::types::key::*;
use namada::types::masp::{ExtendedSpendingKey, MaspValue, PaymentAddress};
use namada::core::address::{Address, DecodeError};
use namada::core::key::*;
use namada::core::masp::{ExtendedSpendingKey, MaspValue, PaymentAddress};
use namada::io::Io;
use namada_sdk::masp::find_valid_diversifier;
use namada_sdk::wallet::{
DecryptionError, DerivationPath, DerivationPathError, FindKeyError, Wallet,
Expand Down
22 changes: 11 additions & 11 deletions crates/apps/src/lib/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@
use masp_primitives::sapling::{Node, ViewingKey};
use masp_primitives::transaction::components::I128Sum;
use masp_primitives::zip32::ExtendedFullViewingKey;
use namada::core::address::{Address, InternalAddress, MASP};
use namada::core::hash::Hash;
use namada::core::ibc::{is_ibc_denom, IbcTokenHash};
use namada::core::key::*;
use namada::core::masp::{BalanceOwner, ExtendedViewingKey, PaymentAddress};
use namada::core::storage::{
BlockHeight, BlockResults, Epoch, IndexedTx, Key, KeySeg,
};
use namada::core::token::{Change, MaspDigitPos};
use namada::governance::cli::offline::{
find_offline_proposal, find_offline_votes, read_offline_files,
OfflineSignedProposal, OfflineVote,
Expand All @@ -29,6 +38,7 @@
use namada::governance::utils::{
compute_proposal_result, ProposalVotes, TallyType, TallyVote, VotePower,
};
use namada::io::Io;
use namada::ledger::events::Event;
use namada::ledger::ibc::storage::{
ibc_denom_key, ibc_denom_key_prefix, is_ibc_denom_key,
Expand All @@ -38,16 +48,6 @@
use namada::ledger::pos::PosParams;
use namada::ledger::queries::RPC;
use namada::proof_of_stake::types::{ValidatorState, WeightedValidator};
use namada::types::address::{Address, InternalAddress, MASP};
use namada::types::hash::Hash;
use namada::types::ibc::{is_ibc_denom, IbcTokenHash};
use namada::types::io::Io;
use namada::types::key::*;
use namada::types::masp::{BalanceOwner, ExtendedViewingKey, PaymentAddress};
use namada::types::storage::{
BlockHeight, BlockResults, Epoch, IndexedTx, Key, KeySeg,
};
use namada::types::token::{Change, MaspDigitPos};
use namada::{state as storage, token};
use namada_sdk::error::{
is_pinned_error, Error, PinnedBalanceError, QueryError,
Expand Down Expand Up @@ -348,7 +348,7 @@
args: args::QueryBalance,
) {
let prefix = Key::from(
Address::Internal(namada::types::address::InternalAddress::Multitoken)
Address::Internal(namada::core::address::InternalAddress::Multitoken)

Check warning on line 351 in crates/apps/src/lib/client/rpc.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/client/rpc.rs#L351

Added line #L351 was not covered by tests
.to_db_key(),
);
match (args.token, args.owner) {
Expand Down
Loading
Loading