namada_core/
lib.rs

1//! The core Namada types, helpers and re-exported dependencies.
2
3#![doc(html_favicon_url = "https://dev.namada.net/master/favicon.png")]
4#![doc(html_logo_url = "https://dev.namada.net/master/rustdoc-logo.png")]
5#![deny(rustdoc::broken_intra_doc_links)]
6#![deny(rustdoc::private_intra_doc_links)]
7#![warn(
8    missing_docs,
9    rust_2018_idioms,
10    clippy::cast_sign_loss,
11    clippy::cast_possible_truncation,
12    clippy::cast_possible_wrap,
13    clippy::cast_lossless,
14    clippy::arithmetic_side_effects,
15    clippy::dbg_macro,
16    clippy::print_stdout,
17    clippy::print_stderr
18)]
19#![cfg_attr(feature = "arbitrary", allow(clippy::disallowed_methods))]
20
21pub mod arith;
22pub mod borsh;
23pub mod bytes;
24#[cfg(any(test, feature = "control_flow"))]
25pub mod control_flow;
26pub mod hints;
27
28pub use masp_primitives;
29/// Re-export of tendermint v0.37
30pub mod tendermint {
31    /// Re-export of tendermint v0.37 ABCI
32    pub mod abci {
33        pub use tendermint::abci::response::ApplySnapshotChunkResult;
34        pub use tendermint::abci::{
35            types, Code, Event, EventAttribute, MethodKind,
36        };
37        pub use tendermint::v0_37::abci::*;
38    }
39    pub use tendermint::*;
40}
41/// Re-export of tendermint-proto v0.37
42pub mod tendermint_proto {
43    pub use tendermint_proto::google; // 💩
44    pub use tendermint_proto::v0_37::*;
45}
46
47#[allow(missing_docs)]
48pub mod collections {
49    //! Re-exports of collection types.
50
51    pub mod hash_map {
52        pub use indexmap::map::{IndexMap as HashMap, *};
53    }
54
55    pub mod hash_set {
56        pub use indexmap::set::{IndexSet as HashSet, *};
57    }
58
59    pub use hash_map::HashMap;
60    pub use hash_set::HashSet;
61}
62
63pub mod address;
64pub mod booleans;
65pub mod chain;
66pub mod dec;
67pub mod eth_abi;
68pub mod eth_bridge_pool;
69pub mod ethereum_events;
70pub mod ethereum_structs;
71pub mod hash;
72pub mod ibc;
73pub mod internal;
74pub mod keccak;
75pub mod key;
76pub mod masp;
77pub mod parameters;
78pub mod storage;
79pub mod string_encoding;
80#[cfg(any(test, feature = "task_env"))]
81pub mod task_env;
82pub mod time;
83pub mod token;
84pub mod uint;
85pub mod validity_predicate;
86pub mod voting_power;
87
88use thiserror::Error;
89
90use crate::borsh::{BorshDeserialize, BorshSerialize, BorshSerializeExt};
91
92#[allow(missing_docs)]
93#[derive(Error, Debug)]
94pub enum DecodeError {
95    #[error("Deserialization error: {0}")]
96    DeserializationError(std::io::Error),
97}
98
99/// Encode a value with borsh
100pub fn encode<T>(value: &T) -> Vec<u8>
101where
102    T: BorshSerialize,
103{
104    value.serialize_to_vec()
105}
106
107/// Decode a value with borsh
108pub fn decode<T>(bytes: impl AsRef<[u8]>) -> Result<T, DecodeError>
109where
110    T: BorshDeserialize,
111{
112    T::try_from_slice(bytes.as_ref()).map_err(DecodeError::DeserializationError)
113}