Skip to content

Commit

Permalink
Merge branch 'tomas/core-refactor' (#2503)
Browse files Browse the repository at this point in the history
* tomas/core-refactor:
  changelog: add #2503
  update all core types usages
  core: flatten types mod
  update replay_protection usage
  core: factor out the ledger::replay_protection mod into a new crate
  core: refactor out ledger::eth_bridge mod
  • Loading branch information
tzemanovic committed Feb 27, 2024
2 parents 0f5f2d4 + 94d1a0b commit 84b922c
Show file tree
Hide file tree
Showing 326 changed files with 1,831 additions and 1,912 deletions.
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))
12 changes: 10 additions & 2 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
24 changes: 12 additions & 12 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 borsh_ext::BorshSerializeExt;
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::core::host::types::path::{
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::tendermint_rpc::{self};
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 @@ -1051,7 +1051,7 @@ impl BenchShieldedCtx {

let mut hasher = Sha256::new();
let shielded_section_hash = shielded.clone().map(|transaction| {
namada::types::hash::Hash(
namada::core::hash::Hash(
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 @@ -2932,19 +2932,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,6 +1,6 @@
use color_eyre::eyre::Result;
use masp_primitives::zip32::ExtendedFullViewingKey;
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
2 changes: 1 addition & 1 deletion crates/apps/src/lib/client/masp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use namada_sdk::masp::{
ShieldedUtils,
};
use namada_sdk::queries::Client;
use namada_sdk::types::storage::BlockHeight;
use namada_sdk::storage::BlockHeight;
use namada_sdk::{display, display_line, MaybeSend, MaybeSync};

pub async fn syncing<
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::merkle_tree::MerklePath;
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::storage::proposal::{
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::types::{CommissionPair, Slash};
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 @@ -380,7 +380,7 @@ pub async fn query_transparent_balance(
args: args::QueryBalance,
) {
let prefix = Key::from(
Address::Internal(namada::types::address::InternalAddress::Multitoken)
Address::Internal(namada::core::address::InternalAddress::Multitoken)
.to_db_key(),
);
match (args.token, args.owner) {
Expand Down
8 changes: 4 additions & 4 deletions crates/apps/src/lib/client/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ use borsh_ext::BorshSerializeExt;
use ledger_namada_rs::{BIP44Path, NamadaApp};
use ledger_transport_hid::hidapi::HidApi;
use ledger_transport_hid::TransportNativeHID;
use namada::core::address::{Address, ImplicitAddress};
use namada::core::dec::Dec;
use namada::core::key::{self, *};
use namada::governance::cli::offline::{
OfflineProposal, OfflineSignedProposal, OfflineVote,
};
Expand All @@ -15,13 +18,10 @@ use namada::governance::cli::onchain::{
};
use namada::governance::ProposalVote;
use namada::ibc::apps::transfer::types::Memo;
use namada::io::Io;
use namada::state::EPOCH_SWITCH_BLOCKS_DELAY;
use namada::tx::data::pos::{BecomeValidator, ConsensusKeyChange};
use namada::tx::{CompressedSignature, Section, Signer, Tx};
use namada::types::address::{Address, ImplicitAddress};
use namada::types::dec::Dec;
use namada::types::io::Io;
use namada::types::key::{self, *};
use namada_sdk::rpc::{InnerTxResult, TxBroadcastData, TxResponse};
use namada_sdk::signing::validate_fee_and_gen_unshield;
use namada_sdk::wallet::alias::validator_consensus_key;
Expand Down
12 changes: 6 additions & 6 deletions crates/apps/src/lib/client/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ use flate2::read::GzDecoder;
use flate2::write::GzEncoder;
use flate2::Compression;
use itertools::Either;
use namada::types::chain::ChainId;
use namada::types::dec::Dec;
use namada::types::key::*;
use namada::types::string_encoding::StringEncoded;
use namada::types::token;
use namada::types::uint::Uint;
use namada::core::chain::ChainId;
use namada::core::dec::Dec;
use namada::core::key::*;
use namada::core::string_encoding::StringEncoded;
use namada::core::token;
use namada::core::uint::Uint;
use namada::vm::validate_untrusted_wasm;
use namada_sdk::wallet::{alias, Wallet};
use prost::bytes::Bytes;
Expand Down
Loading

0 comments on commit 84b922c

Please sign in to comment.