Skip to content

Commit

Permalink
add new crate "namada_core" for core types, storage_api, tx_env, vp_env
Browse files Browse the repository at this point in the history
  • Loading branch information
tzemanovic committed Nov 4, 2022
1 parent 69c0fa7 commit 08a162e
Show file tree
Hide file tree
Showing 38 changed files with 377 additions and 315 deletions.
38 changes: 34 additions & 4 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 @@ -3,6 +3,7 @@ resolver = "2"

members = [
"apps",
"core",
"proof_of_stake",
"shared",
"tests",
Expand Down
48 changes: 48 additions & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[package]
authors = ["Heliax AG <[email protected]>"]
edition = "2021"
license = "GPL-3.0"
name = "namada_core"
resolver = "2"
version = "0.9.0"

[features]
default = []
# for integration tests and test utilies
testing = [
"rand",
"rand_core",
]

[dependencies]
# We switch off "blake2b" because it cannot be compiled to wasm
# branch = "bat/arse-merkle-tree"
arse-merkle-tree = {package = "sparse-merkle-tree", git = "https://github.com/heliaxdev/sparse-merkle-tree", rev = "04ad1eeb28901b57a7599bbe433b3822965dabe8", default-features = false, features = ["std", "borsh"]}
bech32 = "0.8.0"
borsh = "0.9.0"
chrono = {version = "0.4.22", default-features = false, features = ["clock", "std"]}
data-encoding = "2.3.2"
derivative = "2.2.0"
ed25519-consensus = "1.2.0"
itertools = "0.10.0"
libsecp256k1 = {git = "https://github.com/heliaxdev/libsecp256k1", rev = "bbb3bd44a49db361f21d9db80f9a087c194c0ae9", default-features = false, features = ["std", "static-context"]}
rand = {version = "0.8", optional = true}
rand_core = {version = "0.6", optional = true}
rust_decimal = "1.26.1"
serde = {version = "1.0.125", features = ["derive"]}
serde_json = "1.0.62"
sha2 = "0.9.3"
thiserror = "1.0.30"
tracing = "0.1.30"
zeroize = {version = "1.5.5", features = ["zeroize_derive"]}

[dev-dependencies]
assert_matches = "1.5.0"
libsecp256k1 = {git = "https://github.com/heliaxdev/libsecp256k1", rev = "bbb3bd44a49db361f21d9db80f9a087c194c0ae9"}
pretty_assertions = "0.7.2"
# A fork with state machine testing
proptest = {git = "https://github.com/heliaxdev/proptest", branch = "tomas/sm"}
rand = {version = "0.8"}
rand_core = {version = "0.6"}
test-log = {version = "0.2.7", default-features = false, features = ["trace"]}
tracing-subscriber = {version = "0.3.7", default-features = false, features = ["env-filter", "fmt"]}
File renamed without changes.
5 changes: 5 additions & 0 deletions core/src/ledger/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//! The ledger modules
pub mod storage_api;
pub mod tx_env;
pub mod vp_env;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//! TODO
#![doc(html_favicon_url = "https://dev.anoma.net/master/favicon.png")]
#![doc(html_logo_url = "https://dev.anoma.net/master/rustdoc-logo.png")]
#![warn(missing_docs)]
#![deny(rustdoc::broken_intra_doc_links)]
#![deny(rustdoc::private_intra_doc_links)]

pub mod bytes;
pub mod ledger;
pub mod types;

#[cfg(test)]
#[macro_use]
extern crate assert_matches;
File renamed without changes.
File renamed without changes.
File renamed without changes.
45 changes: 25 additions & 20 deletions shared/src/types/hash.rs → core/src/types/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
use std::fmt::{self, Display};
use std::ops::Deref;

use arse_merkle_tree::traits::Value;
use arse_merkle_tree::Hash as TreeHash;
// use arse_merkle_tree::traits::Value;
// use arse_merkle_tree::Hash as TreeHash;
use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
use thiserror::Error;

use crate::tendermint::abci::transaction;
use crate::tendermint::Hash as TmHash;
// use crate::tendermint::abci::transaction;
// use crate::tendermint::Hash as TmHash;

/// The length of the transaction hash string
pub const HASH_LENGTH: usize = 32;
Expand Down Expand Up @@ -86,11 +86,12 @@ impl TryFrom<&[u8]> for Hash {
}
}

impl From<Hash> for transaction::Hash {
fn from(hash: Hash) -> Self {
Self::new(hash.0)
}
}
// TODO move
// impl From<Hash> for transaction::Hash {
// fn from(hash: Hash) -> Self {
// Self::new(hash.0)
// }
// }

impl Hash {
/// Compute sha256 of some bytes
Expand All @@ -99,20 +100,24 @@ impl Hash {
Self(*digest.as_ref())
}

fn zero() -> Self {
Self([0u8; 32])
}

/// Check if the hash is all zeros
pub fn is_zero(&self) -> bool {
self == &Self::zero()
}
}

impl From<Hash> for TmHash {
fn from(hash: Hash) -> Self {
TmHash::Sha256(hash.0)
}
}

impl From<Hash> for TreeHash {
fn from(hash: Hash) -> Self {
Self::from(hash.0)
}
}
// impl From<Hash> for TmHash {
// fn from(hash: Hash) -> Self {
// TmHash::Sha256(hash.0)
// }
// }

// impl From<Hash> for TreeHash {
// fn from(hash: Hash) -> Self {
// Self::from(hash.0)
// }
// }
13 changes: 7 additions & 6 deletions shared/src/types/key/common.rs → core/src/types/key/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::str::FromStr;

use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
use data_encoding::HEXLOWER;
use namada_proof_of_stake::types::PublicKeyTmRawHash;
// use namada_proof_of_stake::types::PublicKeyTmRawHash;
#[cfg(feature = "rand")]
use rand::{CryptoRng, RngCore};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -325,8 +325,9 @@ impl super::SigScheme for SigScheme {
}
}

impl PublicKeyTmRawHash for PublicKey {
fn tm_raw_hash(&self) -> String {
tm_consensus_key_raw_hash(self)
}
}
// TODO
// impl PublicKeyTmRawHash for PublicKey {
// fn tm_raw_hash(&self) -> String {
// tm_consensus_key_raw_hash(self)
// }
// }
File renamed without changes.
2 changes: 0 additions & 2 deletions shared/src/types/key/mod.rs → core/src/types/key/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
//! Cryptographic keys
/// Elliptic curve keys for the DKG
pub mod dkg_session_keys;
use std::fmt::{Debug, Display};
use std::hash::Hash;
Expand Down
File renamed without changes.
11 changes: 11 additions & 0 deletions core/src/types/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//! Types definitions.
pub mod address;
pub mod chain;
pub mod governance;
pub mod hash;
pub mod key;
pub mod storage;
pub mod time;
pub mod token;
pub mod validity_predicate;
File renamed without changes.
Loading

0 comments on commit 08a162e

Please sign in to comment.