Skip to content

Commit c6f1eca

Browse files
authored
Merge pull request #3472 from anoma/tomas/systems-crate
systems crate
2 parents ee68f85 + c64c7aa commit c6f1eca

File tree

44 files changed

+369
-362
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+369
-362
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- Added a new namada_systems crate to contain abstract systems interfaces,
2+
previously added to core crate. Also switched to use the concrete
3+
storage error and result type instead of the generic associated
4+
type which reduces the amount of typing needed one the caller side.
5+
([\#3472](https://github.com/anoma/namada/pull/3472))

Cargo.lock

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ members = [
2626
"crates/shielded_token",
2727
"crates/state",
2828
"crates/storage",
29+
"crates/systems",
2930
"crates/test_utils",
3031
"crates/tests",
3132
"crates/token",

crates/core/src/ibc.rs

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,18 @@
11
//! IBC-related data types
22
3-
use std::collections::{BTreeMap, BTreeSet};
43
use std::fmt::Display;
54
use std::str::FromStr;
65

76
use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
87
use data_encoding::{DecodePartial, HEXLOWER, HEXLOWER_PERMISSIVE};
98
pub use ibc::*;
10-
use masp_primitives::transaction::components::ValueSum;
11-
use masp_primitives::transaction::TransparentAddress;
129
use namada_macros::BorshDeserializer;
1310
#[cfg(feature = "migrations")]
1411
use namada_migrations::*;
1512
use serde::{Deserialize, Serialize};
1613

1714
use super::address::HASH_LEN;
18-
use crate::address::Address;
1915
use crate::hash::Hash;
20-
use crate::masp::TAddrData;
21-
use crate::{storage, token};
22-
23-
/// Abstract IBC storage read interface
24-
pub trait Read<S> {
25-
/// Storage error
26-
type Err;
27-
28-
/// Extract MASP transaction from IBC envelope
29-
fn try_extract_masp_tx_from_envelope(
30-
tx_data: &[u8],
31-
) -> Result<Option<masp_primitives::transaction::Transaction>, Self::Err>;
32-
33-
/// Apply relevant IBC packets to the changed balances structure
34-
fn apply_ibc_packet(
35-
storage: &S,
36-
tx_data: &[u8],
37-
acc: ChangedBalances,
38-
keys_changed: &BTreeSet<storage::Key>,
39-
) -> Result<ChangedBalances, Self::Err>;
40-
}
41-
42-
/// Balances changed by a transaction
43-
#[derive(Default, Debug, Clone)]
44-
pub struct ChangedBalances {
45-
/// Map between MASP transparent address and namada types
46-
pub decoder: BTreeMap<TransparentAddress, TAddrData>,
47-
/// Balances before the tx
48-
pub pre: BTreeMap<TransparentAddress, ValueSum<Address, token::Amount>>,
49-
/// Balances after the tx
50-
pub post: BTreeMap<TransparentAddress, ValueSum<Address, token::Amount>>,
51-
}
5216

5317
/// IBC token hash derived from a denomination.
5418
#[derive(
@@ -69,7 +33,7 @@ pub struct ChangedBalances {
6933
#[repr(transparent)]
7034
pub struct IbcTokenHash(pub [u8; HASH_LEN]);
7135

72-
impl std::fmt::Display for IbcTokenHash {
36+
impl Display for IbcTokenHash {
7337
#[inline(always)]
7438
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
7539
write!(f, "{}", HEXLOWER.encode(&self.0))

crates/core/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ pub mod arith;
2121
pub mod bytes;
2222
#[cfg(any(test, feature = "control_flow"))]
2323
pub mod control_flow;
24-
pub mod governance;
2524
pub mod hints;
26-
pub mod proof_of_stake;
2725

2826
// TODO(namada#3248): only re-export v037 `tendermint-rs`
2927
pub use {masp_primitives, tendermint, tendermint_proto};

crates/core/src/parameters.rs

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,41 +12,6 @@ use super::hash::Hash;
1212
use super::time::DurationSecs;
1313
use super::token;
1414
use crate::borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
15-
use crate::storage;
16-
17-
/// Abstract parameters storage keys interface
18-
pub trait Keys {
19-
/// Key for implicit VP
20-
fn implicit_vp_key() -> storage::Key;
21-
}
22-
23-
/// Abstract parameters storage read interface
24-
pub trait Read<S> {
25-
/// Storage error
26-
type Err;
27-
28-
/// Read all parameters
29-
fn read(storage: &S) -> Result<Parameters, Self::Err>;
30-
31-
/// Read MASP epoch multiplier
32-
fn masp_epoch_multiplier(storage: &S) -> Result<u64, Self::Err>;
33-
34-
/// Read the the epoch duration parameter from store
35-
fn epoch_duration_parameter(
36-
storage: &S,
37-
) -> Result<EpochDuration, Self::Err>;
38-
39-
/// Helper function to retrieve the `is_native_token_transferable` protocol
40-
/// parameter from storage
41-
fn is_native_token_transferable(storage: &S) -> Result<bool, Self::Err>;
42-
}
43-
44-
/// Abstract parameters storage write interface
45-
pub trait Write<S>: Read<S> {
46-
/// Write all parameters
47-
fn write(storage: &mut S, parameters: &Parameters)
48-
-> Result<(), Self::Err>;
49-
}
5015

5116
/// Protocol parameters
5217
#[derive(

crates/core/src/token.rs

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -14,73 +14,12 @@ use namada_migrations::*;
1414
use serde::{Deserialize, Serialize};
1515
use thiserror::Error;
1616

17-
use crate::address::Address;
1817
use crate::arith::{self, checked, CheckedAdd, CheckedSub};
1918
use crate::dec::{Dec, POS_DECIMAL_PRECISION};
2019
use crate::storage;
2120
use crate::storage::{DbKeySeg, KeySeg};
2221
use crate::uint::{self, Uint, I256};
2322

24-
/// Abstract token keys interface
25-
pub trait Keys {
26-
/// Key for transparent token balance
27-
fn balance_key(token: &Address, owner: &Address) -> storage::Key;
28-
29-
/// Returns the owner address if the given storage key is a balance key for
30-
/// the given token.
31-
fn is_balance_key<'a>(
32-
token_addr: &Address,
33-
key: &'a storage::Key,
34-
) -> Option<&'a Address>;
35-
36-
/// Check if the given storage key is a balance key for an unspecified
37-
/// token. If it is, return the token and owner address.
38-
fn is_any_token_balance_key(key: &storage::Key) -> Option<[&Address; 2]>;
39-
40-
/// Obtain a storage key for the multitoken minter.
41-
fn minter_key(token_addr: &Address) -> storage::Key;
42-
}
43-
44-
/// Abstract token storage read interface
45-
pub trait Read<S> {
46-
/// Storage error
47-
type Err;
48-
}
49-
50-
/// Abstract token storage write interface
51-
pub trait Write<S>: Read<S> {
52-
/// Transfer `token` from `src` to `dest`. Returns an `Err` if `src` has
53-
/// insufficient balance or if the transfer the `dest` would overflow (This
54-
/// can only happen if the total supply doesn't fit in `token::Amount`).
55-
fn transfer(
56-
storage: &mut S,
57-
token: &Address,
58-
src: &Address,
59-
dest: &Address,
60-
amount: Amount,
61-
) -> Result<(), Self::Err>;
62-
63-
/// Burn a specified amount of tokens from some address. If the burn amount
64-
/// is larger than the total balance of the given address, then the
65-
/// remaining balance is burned. The total supply of the token is
66-
/// properly adjusted.
67-
fn burn_tokens(
68-
storage: &mut S,
69-
token: &Address,
70-
source: &Address,
71-
amount: Amount,
72-
) -> Result<(), Self::Err>;
73-
74-
/// Credit tokens to an account, to be used only by protocol. In
75-
/// transactions, this would get rejected by the default `vp_token`.
76-
fn credit_tokens(
77-
storage: &mut S,
78-
token: &Address,
79-
dest: &Address,
80-
amount: Amount,
81-
) -> Result<(), Self::Err>;
82-
}
83-
8423
/// Amount in micro units. For different granularity another representation
8524
/// might be more appropriate.
8625
#[derive(

crates/ethereum_bridge/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ namada_parameters = {path = "../parameters"}
3535
namada_proof_of_stake = {path = "../proof_of_stake", default-features = false}
3636
namada_state = {path = "../state"}
3737
namada_storage = {path = "../storage"}
38+
namada_systems = { path = "../systems" }
3839
namada_trans_token = {path = "../trans_token"}
3940
namada_tx = {path = "../tx"}
4041
namada_vote_ext = {path = "../vote_ext"}

crates/ethereum_bridge/src/vp/bridge_pool_vp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ use namada_core::eth_bridge_pool::{
2626
use namada_core::ethereum_events::EthAddress;
2727
use namada_core::hints;
2828
use namada_core::storage::Key;
29-
use namada_core::token::{self, Amount};
3029
use namada_core::uint::I320;
3130
use namada_state::{ResultExt, StateRead};
31+
use namada_systems::trans_token::{self as token, Amount};
3232
use namada_tx::BatchedTxRef;
3333
use namada_vp::native_vp::{self, Ctx, NativeVp, StorageReader, VpEvaluator};
3434

crates/ethereum_bridge/src/vp/eth_bridge_vp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use namada_core::address::Address;
77
use namada_core::booleans::BoolResultUnitExt;
88
use namada_core::collections::HashSet;
99
use namada_core::storage::Key;
10-
use namada_core::token::{self, Amount};
1110
use namada_state::StateRead;
11+
use namada_systems::trans_token::{self as token, Amount};
1212
use namada_tx::BatchedTxRef;
1313
use namada_vp::native_vp::{self, Ctx, NativeVp, StorageReader, VpEvaluator};
1414

0 commit comments

Comments
 (0)