From aa6f7421a4c222d5ee0bf07b3b30ce223b5e923a Mon Sep 17 00:00:00 2001 From: Soares Chen Date: Fri, 17 Sep 2021 10:32:59 +0200 Subject: [PATCH 01/16] Use explicit prelude for std prelude constructs --- tendermint/Cargo.toml | 2 +- tendermint/src/abci/data.rs | 2 ++ tendermint/src/abci/gas.rs | 1 + tendermint/src/abci/info.rs | 1 + tendermint/src/abci/log.rs | 1 + tendermint/src/abci/path.rs | 1 + tendermint/src/abci/responses.rs | 1 + tendermint/src/abci/tag.rs | 1 + tendermint/src/abci/transaction.rs | 2 ++ tendermint/src/abci/transaction/hash.rs | 1 + tendermint/src/account.rs | 1 + tendermint/src/block.rs | 1 + tendermint/src/block/commit.rs | 1 + tendermint/src/block/commit_sig.rs | 1 + tendermint/src/block/header.rs | 1 + tendermint/src/block/height.rs | 1 + tendermint/src/block/id.rs | 1 + tendermint/src/block/meta.rs | 1 + tendermint/src/block/parts.rs | 1 + tendermint/src/block/round.rs | 1 + tendermint/src/chain/id.rs | 1 + tendermint/src/channel.rs | 4 +++- tendermint/src/config.rs | 1 + tendermint/src/config/node_key.rs | 1 + tendermint/src/config/priv_validator_key.rs | 1 + tendermint/src/consensus/params.rs | 1 + tendermint/src/consensus/state.rs | 1 + tendermint/src/evidence.rs | 1 + tendermint/src/genesis.rs | 1 + tendermint/src/hash.rs | 1 + tendermint/src/lib.rs | 3 +++ tendermint/src/merkle.rs | 1 + tendermint/src/merkle/proof.rs | 1 + tendermint/src/moniker.rs | 1 + tendermint/src/net.rs | 1 + tendermint/src/node/id.rs | 1 + tendermint/src/node/info.rs | 1 + tendermint/src/prelude.rs | 11 +++++++++++ tendermint/src/private_key.rs | 1 + tendermint/src/proposal.rs | 2 ++ tendermint/src/proposal/canonical_proposal.rs | 2 ++ tendermint/src/proposal/msg_type.rs | 1 + tendermint/src/proposal/sign_proposal.rs | 1 + tendermint/src/public_key.rs | 2 ++ tendermint/src/public_key/pub_key_request.rs | 2 ++ tendermint/src/serializers/apphash.rs | 1 + tendermint/src/serializers/hash.rs | 1 + tendermint/src/serializers/hash_base64.rs | 1 + tendermint/src/serializers/time.rs | 1 + tendermint/src/signature.rs | 1 + tendermint/src/time.rs | 1 + tendermint/src/timeout.rs | 1 + tendermint/src/trust_threshold.rs | 1 + tendermint/src/validator.rs | 1 + tendermint/src/version.rs | 1 + tendermint/src/vote.rs | 1 + tendermint/src/vote/canonical_vote.rs | 2 ++ tendermint/src/vote/power.rs | 1 + tendermint/src/vote/sign_vote.rs | 3 +++ tendermint/src/vote/validator_index.rs | 1 + 60 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 tendermint/src/prelude.rs diff --git a/tendermint/Cargo.toml b/tendermint/Cargo.toml index bbb4b5991..51577b18b 100644 --- a/tendermint/Cargo.toml +++ b/tendermint/Cargo.toml @@ -36,7 +36,7 @@ crate-type = ["cdylib", "rlib"] async-trait = "0.1" bytes = "1.0" chrono = { version = "0.4.19", features = ["serde"] } -ed25519 = "1" +ed25519 = { version = "1" } ed25519-dalek = { version = "1", features = ["serde"] } futures = "0.3" num-traits = "0.2" diff --git a/tendermint/src/abci/data.rs b/tendermint/src/abci/data.rs index 99f9428e3..5fc93f00f 100644 --- a/tendermint/src/abci/data.rs +++ b/tendermint/src/abci/data.rs @@ -1,3 +1,4 @@ +use crate::prelude::*; use serde::{Deserialize, Serialize}; /// ABCI transaction data. @@ -30,6 +31,7 @@ impl Data { #[cfg(test)] mod tests { use crate::abci::Data; + use crate::prelude::*; #[test] fn test_deserialization() { diff --git a/tendermint/src/abci/gas.rs b/tendermint/src/abci/gas.rs index eae908fcc..8fcc18fa7 100644 --- a/tendermint/src/abci/gas.rs +++ b/tendermint/src/abci/gas.rs @@ -6,6 +6,7 @@ //! use crate::error::Error; +use crate::prelude::*; use serde::{de::Error as _, Deserialize, Deserializer, Serialize, Serializer}; use std::{ fmt::{self, Display}, diff --git a/tendermint/src/abci/info.rs b/tendermint/src/abci/info.rs index 684d79dc4..441a029fe 100644 --- a/tendermint/src/abci/info.rs +++ b/tendermint/src/abci/info.rs @@ -1,3 +1,4 @@ +use crate::prelude::*; use serde::{Deserialize, Serialize}; use std::fmt::{self, Display}; diff --git a/tendermint/src/abci/log.rs b/tendermint/src/abci/log.rs index e9fe570fd..e9fb84aa1 100644 --- a/tendermint/src/abci/log.rs +++ b/tendermint/src/abci/log.rs @@ -1,3 +1,4 @@ +use crate::prelude::*; use serde::{Deserialize, Serialize}; use std::fmt; use std::fmt::Display; diff --git a/tendermint/src/abci/path.rs b/tendermint/src/abci/path.rs index 09f63bea5..20086a515 100644 --- a/tendermint/src/abci/path.rs +++ b/tendermint/src/abci/path.rs @@ -1,6 +1,7 @@ //! Paths to ABCI data use crate::error::Error; +use crate::prelude::*; use serde::{Deserialize, Serialize}; use std::{ fmt::{self, Display}, diff --git a/tendermint/src/abci/responses.rs b/tendermint/src/abci/responses.rs index 39e561eaa..5645f5255 100644 --- a/tendermint/src/abci/responses.rs +++ b/tendermint/src/abci/responses.rs @@ -1,6 +1,7 @@ //! ABCI response types used by the `/block_results` RPC endpoint. use super::{code::Code, data::Data, gas::Gas, info::Info, log::Log, tag::Tag}; +use crate::prelude::*; use crate::{consensus, serializers, validator}; use serde::{Deserialize, Deserializer, Serialize}; use std::fmt::{self, Display}; diff --git a/tendermint/src/abci/tag.rs b/tendermint/src/abci/tag.rs index e610c6d34..cc333a926 100644 --- a/tendermint/src/abci/tag.rs +++ b/tendermint/src/abci/tag.rs @@ -1,6 +1,7 @@ //! Tags use crate::error::Error; +use crate::prelude::*; use serde::{Deserialize, Serialize}; use std::{fmt, str::FromStr}; use tendermint_proto::serializers::bytes::base64string; diff --git a/tendermint/src/abci/transaction.rs b/tendermint/src/abci/transaction.rs index 90721d526..d9f94fae4 100644 --- a/tendermint/src/abci/transaction.rs +++ b/tendermint/src/abci/transaction.rs @@ -3,6 +3,7 @@ mod hash; pub use self::hash::{Hash, LENGTH as HASH_LENGTH}; +use crate::prelude::*; use serde::{de::Error as _, Deserialize, Deserializer, Serialize, Serializer}; use std::{fmt, slice}; use subtle_encoding::base64; @@ -124,6 +125,7 @@ impl AsRef<[Transaction]> for Data { #[cfg(test)] mod tests { use super::Transaction; + use crate::prelude::*; #[test] fn upper_hex_serialization() { diff --git a/tendermint/src/abci/transaction/hash.rs b/tendermint/src/abci/transaction/hash.rs index 115c8317b..2a182f15d 100644 --- a/tendermint/src/abci/transaction/hash.rs +++ b/tendermint/src/abci/transaction/hash.rs @@ -1,6 +1,7 @@ //! Transaction hashes use crate::error::Error; +use crate::prelude::*; use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; use std::{ fmt::{self, Debug, Display}, diff --git a/tendermint/src/account.rs b/tendermint/src/account.rs index b79691f7b..a6be0d1ea 100644 --- a/tendermint/src/account.rs +++ b/tendermint/src/account.rs @@ -1,5 +1,6 @@ //! Tendermint accounts +use crate::prelude::*; use crate::{error::Error, public_key::Ed25519}; use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; diff --git a/tendermint/src/block.rs b/tendermint/src/block.rs index fcc70ad7d..0b8a3dde5 100644 --- a/tendermint/src/block.rs +++ b/tendermint/src/block.rs @@ -21,6 +21,7 @@ pub use self::{ round::*, size::Size, }; +use crate::prelude::*; use crate::{abci::transaction, error::Error, evidence}; use serde::{Deserialize, Serialize}; use std::convert::{TryFrom, TryInto}; diff --git a/tendermint/src/block/commit.rs b/tendermint/src/block/commit.rs index f5e35c0c0..ac9875ef8 100644 --- a/tendermint/src/block/commit.rs +++ b/tendermint/src/block/commit.rs @@ -3,6 +3,7 @@ use crate::block::commit_sig::CommitSig; use crate::block::{Height, Id, Round}; use crate::error::Error; +use crate::prelude::*; use serde::{Deserialize, Serialize}; use std::convert::{TryFrom, TryInto}; use tendermint_proto::types::Commit as RawCommit; diff --git a/tendermint/src/block/commit_sig.rs b/tendermint/src/block/commit_sig.rs index 0dd7d51e4..9f64d3f60 100644 --- a/tendermint/src/block/commit_sig.rs +++ b/tendermint/src/block/commit_sig.rs @@ -1,6 +1,7 @@ //! CommitSig within Commit use crate::error::Error; +use crate::prelude::*; use crate::{account, Signature, Time}; use num_traits::ToPrimitive; use std::convert::{TryFrom, TryInto}; diff --git a/tendermint/src/block/header.rs b/tendermint/src/block/header.rs index b9e73e0d9..ec546c0ec 100644 --- a/tendermint/src/block/header.rs +++ b/tendermint/src/block/header.rs @@ -1,6 +1,7 @@ //! Block headers use crate::merkle::simple_hash_from_byte_vectors; +use crate::prelude::*; use crate::{account, block, chain, AppHash, Error, Hash, Time}; use serde::{Deserialize, Serialize}; use std::convert::{TryFrom, TryInto}; diff --git a/tendermint/src/block/height.rs b/tendermint/src/block/height.rs index 2a50b734f..b1ace5362 100644 --- a/tendermint/src/block/height.rs +++ b/tendermint/src/block/height.rs @@ -1,4 +1,5 @@ use crate::error::Error; +use crate::prelude::*; use serde::{de::Error as _, Deserialize, Deserializer, Serialize, Serializer}; use std::convert::TryInto; use std::{ diff --git a/tendermint/src/block/id.rs b/tendermint/src/block/id.rs index 881dc5b8d..4533f219a 100644 --- a/tendermint/src/block/id.rs +++ b/tendermint/src/block/id.rs @@ -1,3 +1,4 @@ +use crate::prelude::*; use crate::{ block::parts::Header as PartSetHeader, error::Error, diff --git a/tendermint/src/block/meta.rs b/tendermint/src/block/meta.rs index 2963e5dae..0521415c2 100644 --- a/tendermint/src/block/meta.rs +++ b/tendermint/src/block/meta.rs @@ -2,6 +2,7 @@ use super::{Header, Id}; use crate::error::Error; +use crate::prelude::*; use serde::{Deserialize, Serialize}; use std::convert::{TryFrom, TryInto}; use tendermint_proto::types::BlockMeta as RawMeta; diff --git a/tendermint/src/block/parts.rs b/tendermint/src/block/parts.rs index b8479e4b8..a01beb62b 100644 --- a/tendermint/src/block/parts.rs +++ b/tendermint/src/block/parts.rs @@ -3,6 +3,7 @@ use crate::error::Error; use crate::hash::Algorithm; use crate::hash::SHA256_HASH_SIZE; +use crate::prelude::*; use crate::Hash; use serde::{Deserialize, Serialize}; use std::convert::TryFrom; diff --git a/tendermint/src/block/round.rs b/tendermint/src/block/round.rs index 6f42468ef..3f644527a 100644 --- a/tendermint/src/block/round.rs +++ b/tendermint/src/block/round.rs @@ -1,4 +1,5 @@ use crate::error::Error; +use crate::prelude::*; use serde::{de::Error as _, Deserialize, Deserializer, Serialize, Serializer}; use std::convert::TryInto; use std::{ diff --git a/tendermint/src/chain/id.rs b/tendermint/src/chain/id.rs index 312a7d89f..ea3d2a910 100644 --- a/tendermint/src/chain/id.rs +++ b/tendermint/src/chain/id.rs @@ -1,6 +1,7 @@ //! Tendermint blockchain identifiers use crate::error::Error; +use crate::prelude::*; use serde::{de::Error as _, Deserialize, Deserializer, Serialize, Serializer}; use std::convert::TryFrom; use std::{ diff --git a/tendermint/src/channel.rs b/tendermint/src/channel.rs index cba1268c9..c425cdd1d 100644 --- a/tendermint/src/channel.rs +++ b/tendermint/src/channel.rs @@ -3,8 +3,10 @@ mod id; pub use self::id::Id; + +use crate::prelude::*; use crate::serializers; -pub use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; use std::fmt::{self, Display}; /// Channels diff --git a/tendermint/src/config.rs b/tendermint/src/config.rs index bf5e59bb2..2cd51308f 100644 --- a/tendermint/src/config.rs +++ b/tendermint/src/config.rs @@ -11,6 +11,7 @@ mod priv_validator_key; pub use self::{node_key::NodeKey, priv_validator_key::PrivValidatorKey}; +use crate::prelude::*; use crate::{error::Error, genesis::Genesis, net, node, Moniker, Timeout}; use serde::{de, de::Error as _, ser, Deserialize, Serialize}; use std::{ diff --git a/tendermint/src/config/node_key.rs b/tendermint/src/config/node_key.rs index e1abe7e4a..b6361aecd 100644 --- a/tendermint/src/config/node_key.rs +++ b/tendermint/src/config/node_key.rs @@ -1,5 +1,6 @@ //! Node keys +use crate::prelude::*; use crate::{error::Error, node, private_key::PrivateKey, public_key::PublicKey}; use serde::{Deserialize, Serialize}; use std::{fs, path::Path}; diff --git a/tendermint/src/config/priv_validator_key.rs b/tendermint/src/config/priv_validator_key.rs index f6f3d7bc4..f9e157b77 100644 --- a/tendermint/src/config/priv_validator_key.rs +++ b/tendermint/src/config/priv_validator_key.rs @@ -1,5 +1,6 @@ //! Validator private keys +use crate::prelude::*; use crate::public_key::TendermintKey; use crate::{account, error::Error, private_key::PrivateKey, public_key::PublicKey}; use serde::{Deserialize, Serialize}; diff --git a/tendermint/src/consensus/params.rs b/tendermint/src/consensus/params.rs index 3408ffe5d..4e3732b39 100644 --- a/tendermint/src/consensus/params.rs +++ b/tendermint/src/consensus/params.rs @@ -1,6 +1,7 @@ //! Tendermint consensus parameters use crate::error::Error; +use crate::prelude::*; use crate::{block, evidence, public_key}; use serde::{Deserialize, Serialize}; use std::convert::{TryFrom, TryInto}; diff --git a/tendermint/src/consensus/state.rs b/tendermint/src/consensus/state.rs index 5b9cf7d44..097ae9d5a 100644 --- a/tendermint/src/consensus/state.rs +++ b/tendermint/src/consensus/state.rs @@ -1,6 +1,7 @@ //! Tendermint consensus state pub use crate::block; +use crate::prelude::*; use serde::{Deserialize, Serialize}; pub use std::{cmp::Ordering, fmt}; diff --git a/tendermint/src/evidence.rs b/tendermint/src/evidence.rs index 1aca9db12..8264a180b 100644 --- a/tendermint/src/evidence.rs +++ b/tendermint/src/evidence.rs @@ -1,5 +1,6 @@ //! Evidence of malfeasance by validators (i.e. signing conflicting votes). +use crate::prelude::*; use crate::{ block::signed_header::SignedHeader, error::Error, serializers, vote::Power, Time, Vote, }; diff --git a/tendermint/src/genesis.rs b/tendermint/src/genesis.rs index 6701ced55..83aca31e6 100644 --- a/tendermint/src/genesis.rs +++ b/tendermint/src/genesis.rs @@ -1,5 +1,6 @@ //! Genesis data +use crate::prelude::*; use crate::serializers; use crate::{chain, consensus, validator, Time}; use serde::{Deserialize, Serialize}; diff --git a/tendermint/src/hash.rs b/tendermint/src/hash.rs index 650660af8..95e9dbce5 100644 --- a/tendermint/src/hash.rs +++ b/tendermint/src/hash.rs @@ -1,6 +1,7 @@ //! Hash functions and their outputs use crate::error::Error; +use crate::prelude::*; use serde::de::Error as _; use serde::{Deserialize, Deserializer, Serialize, Serializer}; use std::convert::TryFrom; diff --git a/tendermint/src/lib.rs b/tendermint/src/lib.rs index aed2bd270..140be5cfb 100644 --- a/tendermint/src/lib.rs +++ b/tendermint/src/lib.rs @@ -4,6 +4,7 @@ //! blockchain networks, including chain information types, secret connections, //! and remote procedure calls (JSON-RPC). +#![no_std] #![cfg_attr(docsrs, feature(doc_cfg))] #![deny( warnings, @@ -19,6 +20,7 @@ )] extern crate alloc; +extern crate std; #[macro_use] pub mod error; @@ -37,6 +39,7 @@ pub mod merkle; mod moniker; pub mod net; pub mod node; +mod prelude; pub mod private_key; pub mod proposal; pub mod public_key; diff --git a/tendermint/src/merkle.rs b/tendermint/src/merkle.rs index 67d05b418..72bebf857 100644 --- a/tendermint/src/merkle.rs +++ b/tendermint/src/merkle.rs @@ -2,6 +2,7 @@ pub mod proof; +use crate::prelude::*; use sha2::{Digest, Sha256}; /// Size of Merkle root hash diff --git a/tendermint/src/merkle/proof.rs b/tendermint/src/merkle/proof.rs index 9ae747f66..d2a0b9162 100644 --- a/tendermint/src/merkle/proof.rs +++ b/tendermint/src/merkle/proof.rs @@ -6,6 +6,7 @@ use tendermint_proto::crypto::ProofOp as RawProofOp; use tendermint_proto::crypto::ProofOps as RawProofOps; use tendermint_proto::Protobuf; +use crate::prelude::*; use crate::serializers; use crate::Error; diff --git a/tendermint/src/moniker.rs b/tendermint/src/moniker.rs index b5ca283da..5d94cceff 100644 --- a/tendermint/src/moniker.rs +++ b/tendermint/src/moniker.rs @@ -1,6 +1,7 @@ //! Monikers: names associated with validators use crate::error::Error; +use crate::prelude::*; use serde::{Deserialize, Serialize}; use std::{ fmt::{self, Display}, diff --git a/tendermint/src/net.rs b/tendermint/src/net.rs index 6e9c4ceff..1e905153c 100644 --- a/tendermint/src/net.rs +++ b/tendermint/src/net.rs @@ -1,5 +1,6 @@ //! Remote addresses (`tcp://` or `unix://`) +use crate::prelude::*; use crate::{error::Error, node}; use serde::{de::Error as _, Deserialize, Deserializer, Serialize, Serializer}; diff --git a/tendermint/src/node/id.rs b/tendermint/src/node/id.rs index 160953c7a..15ea6eb2a 100644 --- a/tendermint/src/node/id.rs +++ b/tendermint/src/node/id.rs @@ -11,6 +11,7 @@ use sha2::{Digest, Sha256}; use subtle::{self, ConstantTimeEq}; use subtle_encoding::hex; +use crate::prelude::*; use crate::{ error::Error, public_key::{Ed25519, PublicKey}, diff --git a/tendermint/src/node/info.rs b/tendermint/src/node/info.rs index 427813629..9f92ed329 100644 --- a/tendermint/src/node/info.rs +++ b/tendermint/src/node/info.rs @@ -1,5 +1,6 @@ //! Node information (used in RPC responses) +use crate::prelude::*; use crate::{chain, channel::Channels, net, node, serializers, Moniker, Version}; use serde::{Deserialize, Serialize}; use std::fmt::{self, Display}; diff --git a/tendermint/src/prelude.rs b/tendermint/src/prelude.rs new file mode 100644 index 000000000..9ff42a989 --- /dev/null +++ b/tendermint/src/prelude.rs @@ -0,0 +1,11 @@ +pub use core::prelude::v1::*; + +// Re-export according to alloc::prelude::v1 because it is not yet stabilized +// https://doc.rust-lang.org/src/alloc/prelude/v1.rs.html +pub use alloc::borrow::ToOwned; +pub use alloc::boxed::Box; +pub use alloc::string::{String, ToString}; +pub use alloc::vec::Vec; + +pub use alloc::format; +pub use alloc::vec; diff --git a/tendermint/src/private_key.rs b/tendermint/src/private_key.rs index dfd6369c7..7d4280bfc 100644 --- a/tendermint/src/private_key.rs +++ b/tendermint/src/private_key.rs @@ -2,6 +2,7 @@ pub use ed25519_dalek::{Keypair as Ed25519, EXPANDED_SECRET_KEY_LENGTH as ED25519_KEYPAIR_SIZE}; +use crate::prelude::*; use crate::public_key::PublicKey; use serde::{de, ser, Deserialize, Serialize}; use subtle_encoding::{Base64, Encoding}; diff --git a/tendermint/src/proposal.rs b/tendermint/src/proposal.rs index c0984d46b..8de4ff8a7 100644 --- a/tendermint/src/proposal.rs +++ b/tendermint/src/proposal.rs @@ -12,6 +12,7 @@ use crate::block::{Height, Id as BlockId, Round}; use crate::chain::Id as ChainId; use crate::consensus::State; use crate::error::Error; +use crate::prelude::*; use crate::Signature; use crate::Time; use bytes::BufMut; @@ -118,6 +119,7 @@ mod tests { use crate::block::{Height, Round}; use crate::chain::Id as ChainId; use crate::hash::{Algorithm, Hash}; + use crate::prelude::*; use crate::proposal::SignProposalRequest; use crate::signature::{Ed25519Signature, ED25519_SIGNATURE_SIZE}; use crate::{proposal::Type, Proposal, Signature}; diff --git a/tendermint/src/proposal/canonical_proposal.rs b/tendermint/src/proposal/canonical_proposal.rs index 13de36f93..0550def27 100644 --- a/tendermint/src/proposal/canonical_proposal.rs +++ b/tendermint/src/proposal/canonical_proposal.rs @@ -4,6 +4,7 @@ use super::Type; use crate::block::{Height, Id as BlockId, Round}; use crate::chain::Id as ChainId; use crate::error::Error; +use crate::prelude::*; use crate::Time; use std::convert::{TryFrom, TryInto}; use tendermint_proto::types::CanonicalProposal as RawCanonicalProposal; @@ -96,6 +97,7 @@ impl CanonicalProposal { #[cfg(test)] mod tests { + use crate::prelude::*; use crate::proposal::canonical_proposal::CanonicalProposal; use crate::proposal::Type; use std::convert::TryFrom; diff --git a/tendermint/src/proposal/msg_type.rs b/tendermint/src/proposal/msg_type.rs index e06319944..d84a8f3cd 100644 --- a/tendermint/src/proposal/msg_type.rs +++ b/tendermint/src/proposal/msg_type.rs @@ -1,4 +1,5 @@ use crate::error::Error; +use crate::prelude::*; use serde::de::Error as _; use serde::{Deserialize, Deserializer, Serialize, Serializer}; use std::convert::TryFrom; diff --git a/tendermint/src/proposal/sign_proposal.rs b/tendermint/src/proposal/sign_proposal.rs index e8a23e70a..2cc0069ec 100644 --- a/tendermint/src/proposal/sign_proposal.rs +++ b/tendermint/src/proposal/sign_proposal.rs @@ -1,6 +1,7 @@ use super::Proposal; use crate::chain::Id as ChainId; use crate::error::Error; +use crate::prelude::*; use bytes::BufMut; use std::convert::{TryFrom, TryInto}; use tendermint_proto::privval::RemoteSignerError; diff --git a/tendermint/src/public_key.rs b/tendermint/src/public_key.rs index 837a12ffa..b4f04ac51 100644 --- a/tendermint/src/public_key.rs +++ b/tendermint/src/public_key.rs @@ -9,6 +9,7 @@ mod pub_key_response; pub use pub_key_request::PubKeyRequest; pub use pub_key_response::PubKeyResponse; +use crate::prelude::*; use crate::{error::Error, signature::Signature}; use serde::{de, ser, Deserialize, Serialize}; use signature::Verifier as _; @@ -378,6 +379,7 @@ mod tests { use std::convert::TryFrom; use super::{PublicKey, Signature, TendermintKey}; + use crate::prelude::*; use crate::public_key::PubKeyResponse; use subtle_encoding::hex; use tendermint_proto::Protobuf; diff --git a/tendermint/src/public_key/pub_key_request.rs b/tendermint/src/public_key/pub_key_request.rs index 6632c8586..c0dd54ba1 100644 --- a/tendermint/src/public_key/pub_key_request.rs +++ b/tendermint/src/public_key/pub_key_request.rs @@ -1,4 +1,5 @@ use crate::chain::Id as ChainId; +use crate::prelude::*; use crate::Error; use std::convert::TryFrom; use tendermint_proto::privval::PubKeyRequest as RawPubKeyRequest; @@ -35,6 +36,7 @@ impl From for RawPubKeyRequest { mod tests { use super::PubKeyRequest; use crate::chain::Id as ChainId; + use crate::prelude::*; use std::str::FromStr; use tendermint_proto::Protobuf; diff --git a/tendermint/src/serializers/apphash.rs b/tendermint/src/serializers/apphash.rs index 7fca8b261..94162123a 100644 --- a/tendermint/src/serializers/apphash.rs +++ b/tendermint/src/serializers/apphash.rs @@ -1,5 +1,6 @@ //! AppHash serialization with validation +use crate::prelude::*; use crate::AppHash; use serde::{Deserialize, Deserializer, Serializer}; use subtle_encoding::hex; diff --git a/tendermint/src/serializers/hash.rs b/tendermint/src/serializers/hash.rs index abc349da8..78299add9 100644 --- a/tendermint/src/serializers/hash.rs +++ b/tendermint/src/serializers/hash.rs @@ -1,5 +1,6 @@ //! Hash serialization with validation +use crate::prelude::*; use crate::{hash::Algorithm, Hash}; use serde::{Deserialize, Deserializer, Serializer}; use subtle_encoding::hex; diff --git a/tendermint/src/serializers/hash_base64.rs b/tendermint/src/serializers/hash_base64.rs index 7d4558441..5409ef39d 100644 --- a/tendermint/src/serializers/hash_base64.rs +++ b/tendermint/src/serializers/hash_base64.rs @@ -1,6 +1,7 @@ //! Encoding/decoding ABCI transaction hashes to/from base64. use crate::abci::transaction::{Hash, HASH_LENGTH}; +use crate::prelude::*; use serde::{Deserialize, Deserializer, Serializer}; use subtle_encoding::base64; diff --git a/tendermint/src/serializers/time.rs b/tendermint/src/serializers/time.rs index e61639729..940a9e6b1 100644 --- a/tendermint/src/serializers/time.rs +++ b/tendermint/src/serializers/time.rs @@ -2,6 +2,7 @@ //! RFC3339-compatible timestamps to that provided by the `tendermint-proto` //! crate. +use crate::prelude::*; use crate::Time; use serde::{Deserialize, Deserializer, Serialize, Serializer}; diff --git a/tendermint/src/signature.rs b/tendermint/src/signature.rs index ed6a031d3..878049bbf 100644 --- a/tendermint/src/signature.rs +++ b/tendermint/src/signature.rs @@ -6,6 +6,7 @@ pub use signature::{Signer, Verifier}; #[cfg(feature = "secp256k1")] pub use k256::ecdsa::Signature as Secp256k1Signature; +use crate::prelude::*; use std::convert::TryFrom; use tendermint_proto::Protobuf; diff --git a/tendermint/src/time.rs b/tendermint/src/time.rs index 35dc12103..b5c96c2d0 100644 --- a/tendermint/src/time.rs +++ b/tendermint/src/time.rs @@ -3,6 +3,7 @@ use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; +use crate::prelude::*; use std::fmt; use std::ops::{Add, Sub}; use std::str::FromStr; diff --git a/tendermint/src/timeout.rs b/tendermint/src/timeout.rs index d4e75e939..431a1d1aa 100644 --- a/tendermint/src/timeout.rs +++ b/tendermint/src/timeout.rs @@ -1,4 +1,5 @@ use crate::error::Error; +use crate::prelude::*; use serde::{de, de::Error as _, ser, Deserialize, Serialize}; use std::{fmt, ops::Deref, str::FromStr, time::Duration}; diff --git a/tendermint/src/trust_threshold.rs b/tendermint/src/trust_threshold.rs index 1f9583540..9cb931a5b 100644 --- a/tendermint/src/trust_threshold.rs +++ b/tendermint/src/trust_threshold.rs @@ -3,6 +3,7 @@ use std::fmt::{self, Debug, Display}; use crate::error::Error; +use crate::prelude::*; use crate::serializers; use serde::{de::DeserializeOwned, Deserialize, Serialize}; use std::convert::TryFrom; diff --git a/tendermint/src/validator.rs b/tendermint/src/validator.rs index 2709e0300..eb5eb0a2a 100644 --- a/tendermint/src/validator.rs +++ b/tendermint/src/validator.rs @@ -3,6 +3,7 @@ use serde::{de::Error as _, Deserialize, Deserializer, Serialize}; use subtle_encoding::base64; +use crate::prelude::*; use crate::{account, hash::Hash, merkle, vote, Error, PublicKey, Signature}; use std::convert::{TryFrom, TryInto}; diff --git a/tendermint/src/version.rs b/tendermint/src/version.rs index c8189cc44..7c680719c 100644 --- a/tendermint/src/version.rs +++ b/tendermint/src/version.rs @@ -1,3 +1,4 @@ +use crate::prelude::*; use serde::{Deserialize, Serialize}; use std::fmt::{self, Debug, Display}; diff --git a/tendermint/src/vote.rs b/tendermint/src/vote.rs index d2672c7c3..cc7c6009b 100644 --- a/tendermint/src/vote.rs +++ b/tendermint/src/vote.rs @@ -26,6 +26,7 @@ use crate::chain::Id as ChainId; use crate::consensus::State; use crate::error::Error; use crate::hash; +use crate::prelude::*; use crate::{account, block, Signature, Time}; /// Votes are signed messages from validators for a particular block which diff --git a/tendermint/src/vote/canonical_vote.rs b/tendermint/src/vote/canonical_vote.rs index 92cfa6e62..e78380a85 100644 --- a/tendermint/src/vote/canonical_vote.rs +++ b/tendermint/src/vote/canonical_vote.rs @@ -1,5 +1,6 @@ use crate::chain::Id as ChainId; use crate::error::Error; +use crate::prelude::*; use crate::{block, Time}; use serde::{Deserialize, Serialize}; use std::convert::{TryFrom, TryInto}; @@ -87,6 +88,7 @@ impl CanonicalVote { #[cfg(test)] mod tests { + use crate::prelude::*; use crate::vote::canonical_vote::CanonicalVote; use crate::vote::Type; use std::convert::TryFrom; diff --git a/tendermint/src/vote/power.rs b/tendermint/src/vote/power.rs index 86b4bc09e..d8500af2e 100644 --- a/tendermint/src/vote/power.rs +++ b/tendermint/src/vote/power.rs @@ -6,6 +6,7 @@ use std::fmt; use serde::{de::Error as _, Deserialize, Deserializer, Serialize, Serializer}; use crate::error::Error; +use crate::prelude::*; /// Voting power #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Default)] diff --git a/tendermint/src/vote/sign_vote.rs b/tendermint/src/vote/sign_vote.rs index a954f2bb1..0fe2f97b9 100644 --- a/tendermint/src/vote/sign_vote.rs +++ b/tendermint/src/vote/sign_vote.rs @@ -1,5 +1,6 @@ use crate::chain; use crate::error::Error; +use crate::prelude::*; use crate::Vote; use bytes::BufMut; use std::convert::{TryFrom, TryInto}; @@ -96,6 +97,7 @@ mod tests { use crate::block::Round; use crate::chain::Id as ChainId; use crate::hash::Algorithm; + use crate::prelude::*; use crate::signature::{Signature, ED25519_SIGNATURE_SIZE}; use crate::vote::{CanonicalVote, ValidatorIndex}; use crate::vote::{SignVoteRequest, Type}; @@ -103,6 +105,7 @@ mod tests { use crate::Vote; use chrono::{DateTime, Utc}; use std::convert::TryFrom; + use std::println; use std::str::FromStr; use tendermint_proto::Protobuf; diff --git a/tendermint/src/vote/validator_index.rs b/tendermint/src/vote/validator_index.rs index e11ad1834..eb53dcd39 100644 --- a/tendermint/src/vote/validator_index.rs +++ b/tendermint/src/vote/validator_index.rs @@ -1,4 +1,5 @@ use crate::error::Error; +use crate::prelude::*; use std::convert::TryInto; use std::{ convert::TryFrom, From c87eb401c138444e13c62dd0b0e1c20015bfc82e Mon Sep 17 00:00:00 2001 From: Soares Chen Date: Fri, 17 Sep 2021 11:12:13 +0200 Subject: [PATCH 02/16] Use core and alloc crates in tendermint when possible --- tendermint/src/abci/code.rs | 2 +- tendermint/src/abci/gas.rs | 4 ++-- tendermint/src/abci/info.rs | 2 +- tendermint/src/abci/log.rs | 4 ++-- tendermint/src/abci/path.rs | 4 ++-- tendermint/src/abci/responses.rs | 2 +- tendermint/src/abci/tag.rs | 2 +- tendermint/src/abci/transaction.rs | 2 +- tendermint/src/abci/transaction/hash.rs | 6 +++--- tendermint/src/account.rs | 9 ++++----- tendermint/src/block.rs | 2 +- tendermint/src/block/commit.rs | 2 +- tendermint/src/block/commit_sig.rs | 2 +- tendermint/src/block/header.rs | 2 +- tendermint/src/block/height.rs | 7 +++---- tendermint/src/block/id.rs | 6 +++--- tendermint/src/block/meta.rs | 2 +- tendermint/src/block/parts.rs | 2 +- tendermint/src/block/round.rs | 6 +++--- tendermint/src/block/signed_header.rs | 2 +- tendermint/src/block/size.rs | 2 +- tendermint/src/chain/id.rs | 6 +++--- tendermint/src/channel.rs | 2 +- tendermint/src/config.rs | 12 +++++------- tendermint/src/consensus/params.rs | 2 +- tendermint/src/consensus/state.rs | 4 ++-- tendermint/src/error.rs | 2 +- tendermint/src/evidence.rs | 16 ++++++++-------- tendermint/src/hash.rs | 8 ++++---- tendermint/src/merkle/proof.rs | 2 +- tendermint/src/moniker.rs | 4 ++-- tendermint/src/net.rs | 6 +++--- tendermint/src/node/id.rs | 2 +- tendermint/src/node/info.rs | 2 +- tendermint/src/proposal.rs | 4 ++-- tendermint/src/proposal/canonical_proposal.rs | 4 ++-- tendermint/src/proposal/msg_type.rs | 2 +- tendermint/src/proposal/sign_proposal.rs | 2 +- tendermint/src/public_key.rs | 6 +++--- tendermint/src/public_key/pub_key_request.rs | 4 ++-- tendermint/src/public_key/pub_key_response.rs | 2 +- tendermint/src/signature.rs | 2 +- tendermint/src/test.rs | 2 +- tendermint/src/time.rs | 11 ++++++----- tendermint/src/timeout.rs | 2 +- tendermint/src/trust_threshold.rs | 4 ++-- tendermint/src/validator.rs | 4 ++-- tendermint/src/version.rs | 2 +- tendermint/src/vote.rs | 6 +++--- tendermint/src/vote/canonical_vote.rs | 4 ++-- tendermint/src/vote/power.rs | 4 ++-- tendermint/src/vote/sign_vote.rs | 6 +++--- tendermint/src/vote/validator_index.rs | 5 ++--- 53 files changed, 106 insertions(+), 110 deletions(-) diff --git a/tendermint/src/abci/code.rs b/tendermint/src/abci/code.rs index 6b0809447..5a10dedfc 100644 --- a/tendermint/src/abci/code.rs +++ b/tendermint/src/abci/code.rs @@ -1,6 +1,6 @@ +use core::fmt; use serde::de::{Deserialize, Deserializer, Visitor}; use serde::{Serialize, Serializer}; -use std::fmt; /// ABCI application response codes. /// diff --git a/tendermint/src/abci/gas.rs b/tendermint/src/abci/gas.rs index 8fcc18fa7..af7721d27 100644 --- a/tendermint/src/abci/gas.rs +++ b/tendermint/src/abci/gas.rs @@ -7,11 +7,11 @@ use crate::error::Error; use crate::prelude::*; -use serde::{de::Error as _, Deserialize, Deserializer, Serialize, Serializer}; -use std::{ +use core::{ fmt::{self, Display}, str::FromStr, }; +use serde::{de::Error as _, Deserialize, Deserializer, Serialize, Serializer}; /// Gas: representation of transaction processing resource costs #[derive(Copy, Clone, Debug, Default, Eq, PartialEq, PartialOrd, Ord)] diff --git a/tendermint/src/abci/info.rs b/tendermint/src/abci/info.rs index 441a029fe..4d9692718 100644 --- a/tendermint/src/abci/info.rs +++ b/tendermint/src/abci/info.rs @@ -1,6 +1,6 @@ use crate::prelude::*; +use core::fmt::{self, Display}; use serde::{Deserialize, Serialize}; -use std::fmt::{self, Display}; /// ABCI info #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] diff --git a/tendermint/src/abci/log.rs b/tendermint/src/abci/log.rs index e9fb84aa1..10978d9ca 100644 --- a/tendermint/src/abci/log.rs +++ b/tendermint/src/abci/log.rs @@ -1,7 +1,7 @@ use crate::prelude::*; +use core::fmt; +use core::fmt::Display; use serde::{Deserialize, Serialize}; -use std::fmt; -use std::fmt::Display; /// ABCI log data #[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)] diff --git a/tendermint/src/abci/path.rs b/tendermint/src/abci/path.rs index 20086a515..a49eabc3b 100644 --- a/tendermint/src/abci/path.rs +++ b/tendermint/src/abci/path.rs @@ -2,11 +2,11 @@ use crate::error::Error; use crate::prelude::*; -use serde::{Deserialize, Serialize}; -use std::{ +use core::{ fmt::{self, Display}, str::FromStr, }; +use serde::{Deserialize, Serialize}; /// Path to ABCI data #[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)] diff --git a/tendermint/src/abci/responses.rs b/tendermint/src/abci/responses.rs index 5645f5255..4a112fcfa 100644 --- a/tendermint/src/abci/responses.rs +++ b/tendermint/src/abci/responses.rs @@ -3,8 +3,8 @@ use super::{code::Code, data::Data, gas::Gas, info::Info, log::Log, tag::Tag}; use crate::prelude::*; use crate::{consensus, serializers, validator}; +use core::fmt::{self, Display}; use serde::{Deserialize, Deserializer, Serialize}; -use std::fmt::{self, Display}; /// Responses for ABCI calls which occur during block processing. /// diff --git a/tendermint/src/abci/tag.rs b/tendermint/src/abci/tag.rs index cc333a926..50601c5dd 100644 --- a/tendermint/src/abci/tag.rs +++ b/tendermint/src/abci/tag.rs @@ -2,8 +2,8 @@ use crate::error::Error; use crate::prelude::*; +use core::{fmt, str::FromStr}; use serde::{Deserialize, Serialize}; -use std::{fmt, str::FromStr}; use tendermint_proto::serializers::bytes::base64string; /// Tags diff --git a/tendermint/src/abci/transaction.rs b/tendermint/src/abci/transaction.rs index d9f94fae4..546a1026d 100644 --- a/tendermint/src/abci/transaction.rs +++ b/tendermint/src/abci/transaction.rs @@ -4,8 +4,8 @@ mod hash; pub use self::hash::{Hash, LENGTH as HASH_LENGTH}; use crate::prelude::*; +use core::{fmt, slice}; use serde::{de::Error as _, Deserialize, Deserializer, Serialize, Serializer}; -use std::{fmt, slice}; use subtle_encoding::base64; use tendermint_proto::types::Data as RawData; diff --git a/tendermint/src/abci/transaction/hash.rs b/tendermint/src/abci/transaction/hash.rs index 2a182f15d..b9b00136f 100644 --- a/tendermint/src/abci/transaction/hash.rs +++ b/tendermint/src/abci/transaction/hash.rs @@ -2,11 +2,11 @@ use crate::error::Error; use crate::prelude::*; -use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; -use std::{ +use core::{ fmt::{self, Debug, Display}, str::FromStr, }; +use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; use subtle::{self, ConstantTimeEq}; use subtle_encoding::hex; @@ -45,7 +45,7 @@ impl ConstantTimeEq for Hash { impl core::hash::Hash for Hash { fn hash(&self, hasher: &mut H) where - H: std::hash::Hasher, + H: core::hash::Hasher, { self.0.hash(hasher) } diff --git a/tendermint/src/account.rs b/tendermint/src/account.rs index a6be0d1ea..9eaf6219a 100644 --- a/tendermint/src/account.rs +++ b/tendermint/src/account.rs @@ -3,13 +3,13 @@ use crate::prelude::*; use crate::{error::Error, public_key::Ed25519}; -use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; -use sha2::{Digest, Sha256}; -use std::{ - convert::TryInto, +use core::{ + convert::{TryFrom, TryInto}, fmt::{self, Debug, Display}, str::FromStr, }; +use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; +use sha2::{Digest, Sha256}; use subtle::{self, ConstantTimeEq}; use subtle_encoding::hex; @@ -17,7 +17,6 @@ use subtle_encoding::hex; use crate::public_key::Secp256k1; #[cfg(feature = "secp256k1")] use ripemd160::Ripemd160; -use std::convert::TryFrom; use tendermint_proto::Protobuf; /// Size of an account ID in bytes diff --git a/tendermint/src/block.rs b/tendermint/src/block.rs index 0b8a3dde5..42dcf2bc6 100644 --- a/tendermint/src/block.rs +++ b/tendermint/src/block.rs @@ -23,8 +23,8 @@ pub use self::{ }; use crate::prelude::*; use crate::{abci::transaction, error::Error, evidence}; +use core::convert::{TryFrom, TryInto}; use serde::{Deserialize, Serialize}; -use std::convert::{TryFrom, TryInto}; use tendermint_proto::types::Block as RawBlock; use tendermint_proto::Protobuf; diff --git a/tendermint/src/block/commit.rs b/tendermint/src/block/commit.rs index ac9875ef8..2ba3c2bc1 100644 --- a/tendermint/src/block/commit.rs +++ b/tendermint/src/block/commit.rs @@ -4,8 +4,8 @@ use crate::block::commit_sig::CommitSig; use crate::block::{Height, Id, Round}; use crate::error::Error; use crate::prelude::*; +use core::convert::{TryFrom, TryInto}; use serde::{Deserialize, Serialize}; -use std::convert::{TryFrom, TryInto}; use tendermint_proto::types::Commit as RawCommit; /// Commit contains the justification (ie. a set of signatures) that a block was committed by a set diff --git a/tendermint/src/block/commit_sig.rs b/tendermint/src/block/commit_sig.rs index 9f64d3f60..3d4a5a45f 100644 --- a/tendermint/src/block/commit_sig.rs +++ b/tendermint/src/block/commit_sig.rs @@ -3,8 +3,8 @@ use crate::error::Error; use crate::prelude::*; use crate::{account, Signature, Time}; +use core::convert::{TryFrom, TryInto}; use num_traits::ToPrimitive; -use std::convert::{TryFrom, TryInto}; use tendermint_proto::types::BlockIdFlag; use tendermint_proto::types::CommitSig as RawCommitSig; diff --git a/tendermint/src/block/header.rs b/tendermint/src/block/header.rs index ec546c0ec..dee08944d 100644 --- a/tendermint/src/block/header.rs +++ b/tendermint/src/block/header.rs @@ -3,8 +3,8 @@ use crate::merkle::simple_hash_from_byte_vectors; use crate::prelude::*; use crate::{account, block, chain, AppHash, Error, Hash, Time}; +use core::convert::{TryFrom, TryInto}; use serde::{Deserialize, Serialize}; -use std::convert::{TryFrom, TryInto}; use tendermint_proto::types::Header as RawHeader; use tendermint_proto::version::Consensus as RawConsensusVersion; use tendermint_proto::Protobuf; diff --git a/tendermint/src/block/height.rs b/tendermint/src/block/height.rs index b1ace5362..ecc21eddd 100644 --- a/tendermint/src/block/height.rs +++ b/tendermint/src/block/height.rs @@ -1,12 +1,11 @@ use crate::error::Error; use crate::prelude::*; -use serde::{de::Error as _, Deserialize, Deserializer, Serialize, Serializer}; -use std::convert::TryInto; -use std::{ - convert::TryFrom, +use core::{ + convert::{TryFrom, TryInto}, fmt::{self, Debug, Display}, str::FromStr, }; +use serde::{de::Error as _, Deserialize, Deserializer, Serialize, Serializer}; use tendermint_proto::Protobuf; /// Block height for a particular chain (i.e. number of blocks created since diff --git a/tendermint/src/block/id.rs b/tendermint/src/block/id.rs index 4533f219a..a940a6a8f 100644 --- a/tendermint/src/block/id.rs +++ b/tendermint/src/block/id.rs @@ -4,12 +4,12 @@ use crate::{ error::Error, hash::{Algorithm, Hash}, }; -use serde::{Deserialize, Serialize}; -use std::convert::{TryFrom, TryInto}; -use std::{ +use core::convert::{TryFrom, TryInto}; +use core::{ fmt::{self, Display}, str::{self, FromStr}, }; +use serde::{Deserialize, Serialize}; use tendermint_proto::types::{ BlockId as RawBlockId, CanonicalBlockId as RawCanonicalBlockId, PartSetHeader as RawPartSetHeader, diff --git a/tendermint/src/block/meta.rs b/tendermint/src/block/meta.rs index 0521415c2..c46282f00 100644 --- a/tendermint/src/block/meta.rs +++ b/tendermint/src/block/meta.rs @@ -3,8 +3,8 @@ use super::{Header, Id}; use crate::error::Error; use crate::prelude::*; +use core::convert::{TryFrom, TryInto}; use serde::{Deserialize, Serialize}; -use std::convert::{TryFrom, TryInto}; use tendermint_proto::types::BlockMeta as RawMeta; /// Block metadata - Todo: implement constructor and getters diff --git a/tendermint/src/block/parts.rs b/tendermint/src/block/parts.rs index a01beb62b..07e171c72 100644 --- a/tendermint/src/block/parts.rs +++ b/tendermint/src/block/parts.rs @@ -5,8 +5,8 @@ use crate::hash::Algorithm; use crate::hash::SHA256_HASH_SIZE; use crate::prelude::*; use crate::Hash; +use core::convert::TryFrom; use serde::{Deserialize, Serialize}; -use std::convert::TryFrom; use tendermint_proto::types::{ CanonicalPartSetHeader as RawCanonicalPartSetHeader, PartSetHeader as RawPartSetHeader, }; diff --git a/tendermint/src/block/round.rs b/tendermint/src/block/round.rs index 3f644527a..35b68b927 100644 --- a/tendermint/src/block/round.rs +++ b/tendermint/src/block/round.rs @@ -1,12 +1,12 @@ use crate::error::Error; use crate::prelude::*; -use serde::{de::Error as _, Deserialize, Deserializer, Serialize, Serializer}; -use std::convert::TryInto; -use std::{ +use core::convert::TryInto; +use core::{ convert::TryFrom, fmt::{self, Debug, Display}, str::FromStr, }; +use serde::{de::Error as _, Deserialize, Deserializer, Serialize, Serializer}; /// Block round for a particular chain #[derive(Copy, Clone, Eq, Hash, PartialEq, PartialOrd, Ord)] diff --git a/tendermint/src/block/signed_header.rs b/tendermint/src/block/signed_header.rs index 4af0f5016..ed22cee68 100644 --- a/tendermint/src/block/signed_header.rs +++ b/tendermint/src/block/signed_header.rs @@ -2,8 +2,8 @@ //! It is what the rpc endpoint /commit returns and hence can be used by a //! light client. use crate::{block, Error}; +use core::convert::{TryFrom, TryInto}; use serde::{Deserialize, Serialize}; -use std::convert::{TryFrom, TryInto}; use tendermint_proto::types::SignedHeader as RawSignedHeader; /// Signed block headers diff --git a/tendermint/src/block/size.rs b/tendermint/src/block/size.rs index e29edfb58..0781e9058 100644 --- a/tendermint/src/block/size.rs +++ b/tendermint/src/block/size.rs @@ -1,7 +1,7 @@ //! Block size parameters use crate::error::Error; -use std::convert::{TryFrom, TryInto}; +use core::convert::{TryFrom, TryInto}; use tendermint_proto::Protobuf; use { crate::serializers, diff --git a/tendermint/src/chain/id.rs b/tendermint/src/chain/id.rs index ea3d2a910..7bc1a6933 100644 --- a/tendermint/src/chain/id.rs +++ b/tendermint/src/chain/id.rs @@ -2,14 +2,14 @@ use crate::error::Error; use crate::prelude::*; -use serde::{de::Error as _, Deserialize, Deserializer, Serialize, Serializer}; -use std::convert::TryFrom; -use std::{ +use core::convert::TryFrom; +use core::{ cmp::Ordering, fmt::{self, Debug, Display}, hash::{Hash, Hasher}, str::{self, FromStr}, }; +use serde::{de::Error as _, Deserialize, Deserializer, Serialize, Serializer}; use tendermint_proto::Protobuf; /// Maximum length of a `chain::Id` name. Matches `MaxChainIDLen` from: diff --git a/tendermint/src/channel.rs b/tendermint/src/channel.rs index c425cdd1d..190c8126a 100644 --- a/tendermint/src/channel.rs +++ b/tendermint/src/channel.rs @@ -6,8 +6,8 @@ pub use self::id::Id; use crate::prelude::*; use crate::serializers; +use core::fmt::{self, Display}; use serde::{Deserialize, Serialize}; -use std::fmt::{self, Display}; /// Channels #[derive(Clone, Debug, Deserialize, Serialize)] diff --git a/tendermint/src/config.rs b/tendermint/src/config.rs index 2cd51308f..c4d26abc1 100644 --- a/tendermint/src/config.rs +++ b/tendermint/src/config.rs @@ -13,13 +13,11 @@ pub use self::{node_key::NodeKey, priv_validator_key::PrivValidatorKey}; use crate::prelude::*; use crate::{error::Error, genesis::Genesis, net, node, Moniker, Timeout}; +use alloc::collections::{btree_map, BTreeMap}; +use core::{fmt, str::FromStr}; use serde::{de, de::Error as _, ser, Deserialize, Serialize}; -use std::{ - collections::BTreeMap, - fmt, fs, - path::{Path, PathBuf}, - str::FromStr, -}; +use std::fs; +use std::path::{Path, PathBuf}; /// Tendermint `config.toml` file #[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] @@ -190,7 +188,7 @@ impl LogLevel { } /// Iterator over log levels -pub type LogLevelIter<'a> = std::collections::btree_map::Iter<'a, String, String>; +pub type LogLevelIter<'a> = btree_map::Iter<'a, String, String>; impl FromStr for LogLevel { type Err = Error; diff --git a/tendermint/src/consensus/params.rs b/tendermint/src/consensus/params.rs index 4e3732b39..25e2af838 100644 --- a/tendermint/src/consensus/params.rs +++ b/tendermint/src/consensus/params.rs @@ -3,8 +3,8 @@ use crate::error::Error; use crate::prelude::*; use crate::{block, evidence, public_key}; +use core::convert::{TryFrom, TryInto}; use serde::{Deserialize, Serialize}; -use std::convert::{TryFrom, TryInto}; use tendermint_proto::abci::ConsensusParams as RawParams; use tendermint_proto::types::ValidatorParams as RawValidatorParams; use tendermint_proto::types::VersionParams as RawVersionParams; diff --git a/tendermint/src/consensus/state.rs b/tendermint/src/consensus/state.rs index 097ae9d5a..8e7aa2fc6 100644 --- a/tendermint/src/consensus/state.rs +++ b/tendermint/src/consensus/state.rs @@ -2,8 +2,8 @@ pub use crate::block; use crate::prelude::*; +pub use core::{cmp::Ordering, fmt}; use serde::{Deserialize, Serialize}; -pub use std::{cmp::Ordering, fmt}; /// Placeholder string to show when block ID is absent. Syntax from: /// @@ -69,7 +69,7 @@ mod tests { use super::State; use crate::block; use crate::Hash; - use std::str::FromStr; + use core::str::FromStr; #[test] fn state_ord_test() { diff --git a/tendermint/src/error.rs b/tendermint/src/error.rs index 9dacc8669..4536ed1b5 100644 --- a/tendermint/src/error.rs +++ b/tendermint/src/error.rs @@ -36,7 +36,7 @@ define_error! { ParseInt { data: String } - [ DisplayOnly] + [ DisplayOnly] | e | { format_args!("error parsing int data: {}", e.data) }, ParseUrl diff --git a/tendermint/src/evidence.rs b/tendermint/src/evidence.rs index 8264a180b..5e551eb9e 100644 --- a/tendermint/src/evidence.rs +++ b/tendermint/src/evidence.rs @@ -4,9 +4,9 @@ use crate::prelude::*; use crate::{ block::signed_header::SignedHeader, error::Error, serializers, vote::Power, Time, Vote, }; +use core::convert::{TryFrom, TryInto}; +use core::slice; use serde::{Deserialize, Serialize}; -use std::convert::{TryFrom, TryInto}; -use std::slice; use tendermint_proto::google::protobuf::Duration as RawDuration; use tendermint_proto::types::evidence::Sum as RawSum; use tendermint_proto::types::evidence::Sum; @@ -252,16 +252,16 @@ impl From for RawEvidenceParams { } } -/// Duration is a wrapper around std::time::Duration +/// Duration is a wrapper around core::time::Duration /// essentially, to keep the usages look cleaner /// i.e. you can avoid using serde annotations everywhere -/// Todo: harmonize google::protobuf::Duration, std::time::Duration and this. Too many structs. +/// Todo: harmonize google::protobuf::Duration, core::time::Duration and this. Too many structs. /// #[derive(Copy, Clone, Debug, Eq, PartialEq, Deserialize, Serialize)] -pub struct Duration(#[serde(with = "serializers::time_duration")] pub std::time::Duration); +pub struct Duration(#[serde(with = "serializers::time_duration")] pub core::time::Duration); -impl From for std::time::Duration { - fn from(d: Duration) -> std::time::Duration { +impl From for core::time::Duration { + fn from(d: Duration) -> core::time::Duration { d.0 } } @@ -272,7 +272,7 @@ impl TryFrom for Duration { type Error = Error; fn try_from(value: RawDuration) -> Result { - Ok(Self(std::time::Duration::new( + Ok(Self(core::time::Duration::new( value.seconds.try_into().map_err(Error::integer_overflow)?, value.nanos.try_into().map_err(Error::integer_overflow)?, ))) diff --git a/tendermint/src/hash.rs b/tendermint/src/hash.rs index 95e9dbce5..237e640d4 100644 --- a/tendermint/src/hash.rs +++ b/tendermint/src/hash.rs @@ -2,13 +2,13 @@ use crate::error::Error; use crate::prelude::*; -use serde::de::Error as _; -use serde::{Deserialize, Deserializer, Serialize, Serializer}; -use std::convert::TryFrom; -use std::{ +use core::convert::TryFrom; +use core::{ fmt::{self, Debug, Display}, str::FromStr, }; +use serde::de::Error as _; +use serde::{Deserialize, Deserializer, Serialize, Serializer}; use subtle_encoding::{Encoding, Hex}; use tendermint_proto::Protobuf; diff --git a/tendermint/src/merkle/proof.rs b/tendermint/src/merkle/proof.rs index d2a0b9162..ccd8bf33b 100644 --- a/tendermint/src/merkle/proof.rs +++ b/tendermint/src/merkle/proof.rs @@ -1,6 +1,6 @@ //! Merkle proofs +use core::convert::TryFrom; use serde::{Deserialize, Serialize}; -use std::convert::TryFrom; use tendermint_proto::crypto::ProofOp as RawProofOp; use tendermint_proto::crypto::ProofOps as RawProofOps; diff --git a/tendermint/src/moniker.rs b/tendermint/src/moniker.rs index 5d94cceff..1665f3d36 100644 --- a/tendermint/src/moniker.rs +++ b/tendermint/src/moniker.rs @@ -2,11 +2,11 @@ use crate::error::Error; use crate::prelude::*; -use serde::{Deserialize, Serialize}; -use std::{ +use core::{ fmt::{self, Display}, str::FromStr, }; +use serde::{Deserialize, Serialize}; /// Validator display names #[derive(Serialize, Deserialize, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] diff --git a/tendermint/src/net.rs b/tendermint/src/net.rs index 1e905153c..4c33512b6 100644 --- a/tendermint/src/net.rs +++ b/tendermint/src/net.rs @@ -3,12 +3,12 @@ use crate::prelude::*; use crate::{error::Error, node}; -use serde::{de::Error as _, Deserialize, Deserializer, Serialize, Serializer}; -use std::{ +use core::{ fmt::{self, Display}, - path::PathBuf, str::{self, FromStr}, }; +use serde::{de::Error as _, Deserialize, Deserializer, Serialize, Serializer}; +use std::path::PathBuf; use url::Url; /// URI prefix for TCP connections diff --git a/tendermint/src/node/id.rs b/tendermint/src/node/id.rs index 15ea6eb2a..7cac17fab 100644 --- a/tendermint/src/node/id.rs +++ b/tendermint/src/node/id.rs @@ -1,6 +1,6 @@ //! Tendermint node IDs -use std::{ +use core::{ convert::TryFrom, fmt::{self, Debug, Display}, str::FromStr, diff --git a/tendermint/src/node/info.rs b/tendermint/src/node/info.rs index 9f92ed329..f0517b068 100644 --- a/tendermint/src/node/info.rs +++ b/tendermint/src/node/info.rs @@ -2,8 +2,8 @@ use crate::prelude::*; use crate::{chain, channel::Channels, net, node, serializers, Moniker, Version}; +use core::fmt::{self, Display}; use serde::{Deserialize, Serialize}; -use std::fmt::{self, Display}; /// Node information #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] diff --git a/tendermint/src/proposal.rs b/tendermint/src/proposal.rs index 8de4ff8a7..0d3eae4f4 100644 --- a/tendermint/src/proposal.rs +++ b/tendermint/src/proposal.rs @@ -16,7 +16,7 @@ use crate::prelude::*; use crate::Signature; use crate::Time; use bytes::BufMut; -use std::convert::{TryFrom, TryInto}; +use core::convert::{TryFrom, TryInto}; use tendermint_proto::types::Proposal as RawProposal; use tendermint_proto::{Error as ProtobufError, Protobuf}; @@ -124,7 +124,7 @@ mod tests { use crate::signature::{Ed25519Signature, ED25519_SIGNATURE_SIZE}; use crate::{proposal::Type, Proposal, Signature}; use chrono::{DateTime, Utc}; - use std::str::FromStr; + use core::str::FromStr; use tendermint_proto::Protobuf; #[test] diff --git a/tendermint/src/proposal/canonical_proposal.rs b/tendermint/src/proposal/canonical_proposal.rs index 0550def27..3023c6c31 100644 --- a/tendermint/src/proposal/canonical_proposal.rs +++ b/tendermint/src/proposal/canonical_proposal.rs @@ -6,7 +6,7 @@ use crate::chain::Id as ChainId; use crate::error::Error; use crate::prelude::*; use crate::Time; -use std::convert::{TryFrom, TryInto}; +use core::convert::{TryFrom, TryInto}; use tendermint_proto::types::CanonicalProposal as RawCanonicalProposal; use tendermint_proto::Protobuf; @@ -100,7 +100,7 @@ mod tests { use crate::prelude::*; use crate::proposal::canonical_proposal::CanonicalProposal; use crate::proposal::Type; - use std::convert::TryFrom; + use core::convert::TryFrom; use tendermint_proto::types::CanonicalBlockId as RawCanonicalBlockId; use tendermint_proto::types::CanonicalPartSetHeader as RawCanonicalPartSetHeader; use tendermint_proto::types::CanonicalProposal as RawCanonicalProposal; diff --git a/tendermint/src/proposal/msg_type.rs b/tendermint/src/proposal/msg_type.rs index d84a8f3cd..7c0b95253 100644 --- a/tendermint/src/proposal/msg_type.rs +++ b/tendermint/src/proposal/msg_type.rs @@ -1,8 +1,8 @@ use crate::error::Error; use crate::prelude::*; +use core::convert::TryFrom; use serde::de::Error as _; use serde::{Deserialize, Deserializer, Serialize, Serializer}; -use std::convert::TryFrom; use tendermint_proto::Protobuf; /// Types of proposals diff --git a/tendermint/src/proposal/sign_proposal.rs b/tendermint/src/proposal/sign_proposal.rs index 2cc0069ec..ddcf7fb0b 100644 --- a/tendermint/src/proposal/sign_proposal.rs +++ b/tendermint/src/proposal/sign_proposal.rs @@ -3,7 +3,7 @@ use crate::chain::Id as ChainId; use crate::error::Error; use crate::prelude::*; use bytes::BufMut; -use std::convert::{TryFrom, TryInto}; +use core::convert::{TryFrom, TryInto}; use tendermint_proto::privval::RemoteSignerError; use tendermint_proto::privval::SignProposalRequest as RawSignProposalRequest; use tendermint_proto::privval::SignedProposalResponse as RawSignedProposalResponse; diff --git a/tendermint/src/public_key.rs b/tendermint/src/public_key.rs index b4f04ac51..b8a515880 100644 --- a/tendermint/src/public_key.rs +++ b/tendermint/src/public_key.rs @@ -11,10 +11,10 @@ pub use pub_key_response::PubKeyResponse; use crate::prelude::*; use crate::{error::Error, signature::Signature}; +use core::convert::TryFrom; +use core::{cmp::Ordering, fmt, ops::Deref, str::FromStr}; use serde::{de, ser, Deserialize, Serialize}; use signature::Verifier as _; -use std::convert::TryFrom; -use std::{cmp::Ordering, fmt, ops::Deref, str::FromStr}; use subtle_encoding::{base64, bech32, hex}; use tendermint_proto::crypto::public_key::Sum; use tendermint_proto::crypto::PublicKey as RawPublicKey; @@ -376,7 +376,7 @@ where #[cfg(test)] mod tests { - use std::convert::TryFrom; + use core::convert::TryFrom; use super::{PublicKey, Signature, TendermintKey}; use crate::prelude::*; diff --git a/tendermint/src/public_key/pub_key_request.rs b/tendermint/src/public_key/pub_key_request.rs index c0dd54ba1..a1564e49c 100644 --- a/tendermint/src/public_key/pub_key_request.rs +++ b/tendermint/src/public_key/pub_key_request.rs @@ -1,7 +1,7 @@ use crate::chain::Id as ChainId; use crate::prelude::*; use crate::Error; -use std::convert::TryFrom; +use core::convert::TryFrom; use tendermint_proto::privval::PubKeyRequest as RawPubKeyRequest; use tendermint_proto::Protobuf; @@ -37,7 +37,7 @@ mod tests { use super::PubKeyRequest; use crate::chain::Id as ChainId; use crate::prelude::*; - use std::str::FromStr; + use core::str::FromStr; use tendermint_proto::Protobuf; #[test] diff --git a/tendermint/src/public_key/pub_key_response.rs b/tendermint/src/public_key/pub_key_response.rs index b58292df1..0a65b7eda 100644 --- a/tendermint/src/public_key/pub_key_response.rs +++ b/tendermint/src/public_key/pub_key_response.rs @@ -1,5 +1,5 @@ use crate::{Error, PublicKey}; -use std::convert::{TryFrom, TryInto}; +use core::convert::{TryFrom, TryInto}; use tendermint_proto::privval::{PubKeyResponse as RawPubKeyResponse, RemoteSignerError}; use tendermint_proto::Protobuf; diff --git a/tendermint/src/signature.rs b/tendermint/src/signature.rs index 878049bbf..63b5e1327 100644 --- a/tendermint/src/signature.rs +++ b/tendermint/src/signature.rs @@ -7,7 +7,7 @@ pub use signature::{Signer, Verifier}; pub use k256::ecdsa::Signature as Secp256k1Signature; use crate::prelude::*; -use std::convert::TryFrom; +use core::convert::TryFrom; use tendermint_proto::Protobuf; use crate::error::Error; diff --git a/tendermint/src/test.rs b/tendermint/src/test.rs index f3ed0a766..fc8c868bb 100644 --- a/tendermint/src/test.rs +++ b/tendermint/src/test.rs @@ -1,5 +1,5 @@ +use core::fmt::Debug; use serde::{de::DeserializeOwned, Serialize}; -use std::fmt::Debug; /// Test that a struct `T` can be: /// diff --git a/tendermint/src/time.rs b/tendermint/src/time.rs index b5c96c2d0..043d97954 100644 --- a/tendermint/src/time.rs +++ b/tendermint/src/time.rs @@ -4,10 +4,11 @@ use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use crate::prelude::*; -use std::fmt; -use std::ops::{Add, Sub}; -use std::str::FromStr; -use std::time::{Duration, SystemTime, UNIX_EPOCH}; +use core::fmt; +use core::ops::{Add, Sub}; +use core::str::FromStr; +use core::time::Duration; +use std::time::{SystemTime, UNIX_EPOCH}; use tendermint_proto::google::protobuf::Timestamp; use tendermint_proto::serializers::timestamp; use tendermint_proto::Protobuf; @@ -59,7 +60,7 @@ impl Time { } /// Calculate the amount of time which has passed since another [`Time`] - /// as a [`std::time::Duration`] + /// as a [`core::time::Duration`] pub fn duration_since(&self, other: Time) -> Result { self.0 .signed_duration_since(other.0) diff --git a/tendermint/src/timeout.rs b/tendermint/src/timeout.rs index 431a1d1aa..91e4672e7 100644 --- a/tendermint/src/timeout.rs +++ b/tendermint/src/timeout.rs @@ -1,8 +1,8 @@ use crate::error::Error; use crate::prelude::*; +use core::{fmt, ops::Deref, str::FromStr, time::Duration}; use serde::{de, de::Error as _, ser, Deserialize, Serialize}; -use std::{fmt, ops::Deref, str::FromStr, time::Duration}; /// Timeout durations #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] diff --git a/tendermint/src/trust_threshold.rs b/tendermint/src/trust_threshold.rs index 9cb931a5b..c237b6f05 100644 --- a/tendermint/src/trust_threshold.rs +++ b/tendermint/src/trust_threshold.rs @@ -1,12 +1,12 @@ //! Define traits and instances for dealing with trust thresholds. -use std::fmt::{self, Debug, Display}; +use core::fmt::{self, Debug, Display}; use crate::error::Error; use crate::prelude::*; use crate::serializers; +use core::convert::TryFrom; use serde::{de::DeserializeOwned, Deserialize, Serialize}; -use std::convert::TryFrom; /// TrustThreshold defines how much of the total voting power of a known /// and trusted validator set is sufficient for a commit to be diff --git a/tendermint/src/validator.rs b/tendermint/src/validator.rs index eb5eb0a2a..67083361c 100644 --- a/tendermint/src/validator.rs +++ b/tendermint/src/validator.rs @@ -6,7 +6,7 @@ use subtle_encoding::base64; use crate::prelude::*; use crate::{account, hash::Hash, merkle, vote, Error, PublicKey, Signature}; -use std::convert::{TryFrom, TryInto}; +use core::convert::{TryFrom, TryInto}; use tendermint_proto::types::SimpleValidator as RawSimpleValidator; use tendermint_proto::types::Validator as RawValidator; use tendermint_proto::types::ValidatorSet as RawValidatorSet; @@ -118,7 +118,7 @@ impl Set { /// Sort the validators according to the current Tendermint requirements /// (v. 0.34 -> first by validator power, descending, then by address, ascending) fn sort_validators(vals: &mut Vec) { - vals.sort_by_key(|v| (std::cmp::Reverse(v.power), v.address)); + vals.sort_by_key(|v| (core::cmp::Reverse(v.power), v.address)); } /// Returns the validator with the given Id if its in the Set. diff --git a/tendermint/src/version.rs b/tendermint/src/version.rs index 7c680719c..e262c2e42 100644 --- a/tendermint/src/version.rs +++ b/tendermint/src/version.rs @@ -1,6 +1,6 @@ use crate::prelude::*; +use core::fmt::{self, Debug, Display}; use serde::{Deserialize, Serialize}; -use std::fmt::{self, Debug, Display}; /// Tendermint version #[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)] diff --git a/tendermint/src/vote.rs b/tendermint/src/vote.rs index cc7c6009b..eb25c9080 100644 --- a/tendermint/src/vote.rs +++ b/tendermint/src/vote.rs @@ -10,9 +10,9 @@ pub use self::power::Power; pub use self::sign_vote::*; pub use self::validator_index::ValidatorIndex; -use std::convert::{TryFrom, TryInto}; -use std::fmt; -use std::str::FromStr; +use core::convert::{TryFrom, TryInto}; +use core::fmt; +use core::str::FromStr; use bytes::BufMut; use ed25519::Signature as Ed25519Signature; diff --git a/tendermint/src/vote/canonical_vote.rs b/tendermint/src/vote/canonical_vote.rs index e78380a85..46c185f32 100644 --- a/tendermint/src/vote/canonical_vote.rs +++ b/tendermint/src/vote/canonical_vote.rs @@ -2,8 +2,8 @@ use crate::chain::Id as ChainId; use crate::error::Error; use crate::prelude::*; use crate::{block, Time}; +use core::convert::{TryFrom, TryInto}; use serde::{Deserialize, Serialize}; -use std::convert::{TryFrom, TryInto}; use tendermint_proto::types::CanonicalVote as RawCanonicalVote; use tendermint_proto::Protobuf; @@ -91,7 +91,7 @@ mod tests { use crate::prelude::*; use crate::vote::canonical_vote::CanonicalVote; use crate::vote::Type; - use std::convert::TryFrom; + use core::convert::TryFrom; use tendermint_proto::google::protobuf::Timestamp; use tendermint_proto::types::CanonicalBlockId as RawCanonicalBlockId; use tendermint_proto::types::CanonicalPartSetHeader as RawCanonicalPartSetHeader; diff --git a/tendermint/src/vote/power.rs b/tendermint/src/vote/power.rs index d8500af2e..2499d3335 100644 --- a/tendermint/src/vote/power.rs +++ b/tendermint/src/vote/power.rs @@ -1,7 +1,7 @@ //! Voting power -use std::convert::{TryFrom, TryInto}; -use std::fmt; +use core::convert::{TryFrom, TryInto}; +use core::fmt; use serde::{de::Error as _, Deserialize, Deserializer, Serialize, Serializer}; diff --git a/tendermint/src/vote/sign_vote.rs b/tendermint/src/vote/sign_vote.rs index 0fe2f97b9..28347a2b7 100644 --- a/tendermint/src/vote/sign_vote.rs +++ b/tendermint/src/vote/sign_vote.rs @@ -3,7 +3,7 @@ use crate::error::Error; use crate::prelude::*; use crate::Vote; use bytes::BufMut; -use std::convert::{TryFrom, TryInto}; +use core::convert::{TryFrom, TryInto}; use tendermint_proto::privval::SignedVoteResponse as RawSignedVoteResponse; use tendermint_proto::privval::{RemoteSignerError, SignVoteRequest as RawSignVoteRequest}; use tendermint_proto::Error as ProtobufError; @@ -104,9 +104,9 @@ mod tests { use crate::Hash; use crate::Vote; use chrono::{DateTime, Utc}; - use std::convert::TryFrom; + use core::convert::TryFrom; + use core::str::FromStr; use std::println; - use std::str::FromStr; use tendermint_proto::Protobuf; #[test] diff --git a/tendermint/src/vote/validator_index.rs b/tendermint/src/vote/validator_index.rs index eb53dcd39..6643d31b3 100644 --- a/tendermint/src/vote/validator_index.rs +++ b/tendermint/src/vote/validator_index.rs @@ -1,8 +1,7 @@ use crate::error::Error; use crate::prelude::*; -use std::convert::TryInto; -use std::{ - convert::TryFrom, +use core::{ + convert::{TryFrom, TryInto}, fmt::{self, Debug, Display}, str::FromStr, }; From 179daa270e02dccd18a750e30db715c198f0871f Mon Sep 17 00:00:00 2001 From: Soares Chen Date: Fri, 17 Sep 2021 11:50:24 +0200 Subject: [PATCH 03/16] Remove use of std from tendermint-proto --- proto/Cargo.toml | 18 +++++++++--------- proto/src/error.rs | 7 ++++--- proto/src/lib.rs | 16 +++++++++++++--- proto/src/prelude.rs | 11 +++++++++++ proto/src/serializers.rs | 2 +- proto/src/serializers/bytes.rs | 5 +++++ proto/src/serializers/from_str.rs | 11 ++++++----- proto/src/serializers/optional_from_str.rs | 8 +++++--- proto/src/serializers/part_set_header_total.rs | 7 ++++--- proto/src/serializers/time_duration.rs | 5 +++-- proto/src/serializers/timestamp.rs | 1 + proto/src/serializers/txs.rs | 1 + proto/src/tendermint.rs | 1 + proto/tests/unit.rs | 2 +- 14 files changed, 65 insertions(+), 30 deletions(-) create mode 100644 proto/src/prelude.rs diff --git a/proto/Cargo.toml b/proto/Cargo.toml index b41f165de..b8b9e50c6 100644 --- a/proto/Cargo.toml +++ b/proto/Cargo.toml @@ -17,15 +17,15 @@ description = """ all-features = true [dependencies] -prost = "0.7" -prost-types = "0.7" -bytes = "1.0" -serde = { version = "1.0", features = ["derive"] } -subtle-encoding = "0.5" -serde_bytes = "0.11" -num-traits = "0.2" -num-derive = "0.3" -chrono = { version = "0.4", features = ["serde"] } +prost = { version = "0.7", default-features = false } +prost-types = { version = "0.7", default-features = false } +bytes = { version = "1.0", default-features = false } +serde = { version = "1.0", default-features = false, features = ["derive"] } +serde_bytes = { version = "0.11", default-features = false, features = ["alloc"] } +subtle-encoding = { version = "0.5", default-features = false, features = ["hex", "base64", "std"] } +num-traits = { version = "0.2", default-features = false } +num-derive = { version = "0.3", default-features = false } +chrono = { version = "0.4", default-features = false, features = ["serde", "clock"] } flex-error = { version = "0.4.1", default-features = false } [dev-dependencies] diff --git a/proto/src/error.rs b/proto/src/error.rs index ab2d30b27..1fcde3e16 100644 --- a/proto/src/error.rs +++ b/proto/src/error.rs @@ -1,10 +1,11 @@ //! This module defines the various errors that be raised during Protobuf conversions. +use crate::prelude::*; +use core::convert::TryFrom; +use core::fmt::Display; +use core::num::TryFromIntError; use flex_error::{define_error, DisplayOnly}; use prost::{DecodeError, EncodeError}; -use std::convert::TryFrom; -use std::fmt::Display; -use std::num::TryFromIntError; define_error! { Error { diff --git a/proto/src/lib.rs b/proto/src/lib.rs index 2120c6305..068f349f3 100644 --- a/proto/src/lib.rs +++ b/proto/src/lib.rs @@ -1,10 +1,18 @@ //! tendermint-proto library gives the developer access to the Tendermint proto-defined structs. +#![no_std] #![deny(warnings, trivial_casts, trivial_numeric_casts, unused_import_braces)] #![allow(clippy::large_enum_variant)] #![forbid(unsafe_code)] #![doc(html_root_url = "https://docs.rs/tendermint-proto/0.21.0")] +extern crate alloc; + +#[cfg(feature = "std")] +extern crate std; + +mod prelude; + /// Built-in prost_types with slight customization to enable JSON-encoding #[allow(warnings)] pub mod google { @@ -23,13 +31,15 @@ pub use error::Error; pub use tendermint::*; use bytes::{Buf, BufMut}; +use core::convert::{TryFrom, TryInto}; +use core::fmt::Display; use prost::encoding::encoded_len_varint; use prost::Message; -use std::convert::{TryFrom, TryInto}; -use std::fmt::Display; pub mod serializers; +use prelude::*; + /// Allows for easy Google Protocol Buffers encoding and decoding of domain /// types with validation. /// @@ -38,7 +48,7 @@ pub mod serializers; /// ```rust /// use bytes::BufMut; /// use prost::Message; -/// use std::convert::TryFrom; +/// use core::convert::TryFrom; /// use tendermint_proto::Protobuf; /// /// // This struct would ordinarily be automatically generated by prost. diff --git a/proto/src/prelude.rs b/proto/src/prelude.rs new file mode 100644 index 000000000..9ff42a989 --- /dev/null +++ b/proto/src/prelude.rs @@ -0,0 +1,11 @@ +pub use core::prelude::v1::*; + +// Re-export according to alloc::prelude::v1 because it is not yet stabilized +// https://doc.rust-lang.org/src/alloc/prelude/v1.rs.html +pub use alloc::borrow::ToOwned; +pub use alloc::boxed::Box; +pub use alloc::string::{String, ToString}; +pub use alloc::vec::Vec; + +pub use alloc::format; +pub use alloc::vec; diff --git a/proto/src/serializers.rs b/proto/src/serializers.rs index 239a8b53f..749ec893d 100644 --- a/proto/src/serializers.rs +++ b/proto/src/serializers.rs @@ -32,7 +32,7 @@ //! Available serializers: //! i64 <-> string: #[serde(with="serializers::from_str")] //! u64 <-> string: #[serde(with="serializers::from_str")] -//! std::time::Duration <-> nanoseconds as string #[serde(with="serializers::time_duration")] +//! core::time::Duration <-> nanoseconds as string #[serde(with="serializers::time_duration")] //! Vec <-> HexString: #[serde(with="serializers::bytes::hexstring")] //! Vec <-> Base64String: #[serde(with="serializers::bytes::base64string")] //! Vec <-> String: #[serde(with="serializers::bytes::string")] diff --git a/proto/src/serializers/bytes.rs b/proto/src/serializers/bytes.rs index 7cffcfb64..c3ea9443e 100644 --- a/proto/src/serializers/bytes.rs +++ b/proto/src/serializers/bytes.rs @@ -2,6 +2,7 @@ /// Serialize into hexstring, deserialize from hexstring pub mod hexstring { + use crate::prelude::*; use serde::{Deserialize, Deserializer, Serializer}; use subtle_encoding::hex; @@ -30,6 +31,7 @@ pub mod hexstring { /// Serialize into base64string, deserialize from base64string pub mod base64string { + use crate::prelude::*; use serde::{Deserialize, Deserializer, Serializer}; use subtle_encoding::base64; @@ -66,6 +68,7 @@ pub mod base64string { /// Serialize into Vec, deserialize from Vec pub mod vec_base64string { + use crate::prelude::*; use serde::{Deserialize, Deserializer, Serializer}; use subtle_encoding::base64; @@ -99,6 +102,7 @@ pub mod vec_base64string { /// Serialize into Option, deserialize from Option pub mod option_base64string { + use crate::prelude::*; use serde::{Deserialize, Deserializer, Serializer}; use subtle_encoding::base64; @@ -125,6 +129,7 @@ pub mod option_base64string { /// Serialize into string, deserialize from string pub mod string { + use crate::prelude::*; use serde::{Deserialize, Deserializer, Serializer}; /// Deserialize string into Vec diff --git a/proto/src/serializers/from_str.rs b/proto/src/serializers/from_str.rs index 9fe5800bb..7e3583538 100644 --- a/proto/src/serializers/from_str.rs +++ b/proto/src/serializers/from_str.rs @@ -1,14 +1,15 @@ -//! Serialize and deserialize any `T` that implements [[std::str::FromStr]] -//! and [[std::fmt::Display]] from or into string. Note this can be used for +//! Serialize and deserialize any `T` that implements [[core::str::FromStr]] +//! and [[core::fmt::Display]] from or into string. Note this can be used for //! all primitive data types. +use crate::prelude::*; use serde::{de::Error as _, Deserialize, Deserializer, Serialize, Serializer}; /// Deserialize string into T pub fn deserialize<'de, D, T>(deserializer: D) -> Result where D: Deserializer<'de>, - T: std::str::FromStr, - ::Err: std::fmt::Display, + T: core::str::FromStr, + ::Err: core::fmt::Display, { String::deserialize(deserializer)? .parse::() @@ -19,7 +20,7 @@ where pub fn serialize(value: &T, serializer: S) -> Result where S: Serializer, - T: std::fmt::Display, + T: core::fmt::Display, { format!("{}", value).serialize(serializer) } diff --git a/proto/src/serializers/optional_from_str.rs b/proto/src/serializers/optional_from_str.rs index 2752be880..ab6da70c8 100644 --- a/proto/src/serializers/optional_from_str.rs +++ b/proto/src/serializers/optional_from_str.rs @@ -1,8 +1,10 @@ //! De/serialize an optional type that must be converted from/to a string. +use crate::prelude::*; +use core::fmt::Display; +use core::str::FromStr; use serde::de::Error; use serde::{Deserialize, Deserializer, Serializer}; -use std::str::FromStr; pub fn serialize(value: &Option, serializer: S) -> Result where @@ -19,13 +21,13 @@ pub fn deserialize<'de, D, T>(deserializer: D) -> Result, D::Error> where D: Deserializer<'de>, T: FromStr, - T::Err: std::error::Error, + T::Err: Display, { let s = match Option::::deserialize(deserializer)? { Some(s) => s, None => return Ok(None), }; Ok(Some(s.parse().map_err(|e: ::Err| { - D::Error::custom(e.to_string()) + D::Error::custom(format!("{}", e)) })?)) } diff --git a/proto/src/serializers/part_set_header_total.rs b/proto/src/serializers/part_set_header_total.rs index 75cf35654..549c088ae 100644 --- a/proto/src/serializers/part_set_header_total.rs +++ b/proto/src/serializers/part_set_header_total.rs @@ -5,9 +5,10 @@ //! string-quoted integer value into an integer value without quotes in Tendermint Core v0.34.0. //! This deserializer allows backwards-compatibility by deserializing both ways. //! See also: +use crate::prelude::*; +use core::convert::TryFrom; +use core::fmt::Formatter; use serde::{de::Error, de::Visitor, Deserializer, Serialize, Serializer}; -use std::convert::TryFrom; -use std::fmt::Formatter; struct PartSetHeaderTotalStringOrU32; @@ -30,7 +31,7 @@ where impl<'de> Visitor<'de> for PartSetHeaderTotalStringOrU32 { type Value = u32; - fn expecting(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result { + fn expecting(&self, formatter: &mut Formatter<'_>) -> core::fmt::Result { formatter.write_str("an u32 integer or string between 0 and 2^32") } diff --git a/proto/src/serializers/time_duration.rs b/proto/src/serializers/time_duration.rs index baa66d30c..08692224a 100644 --- a/proto/src/serializers/time_duration.rs +++ b/proto/src/serializers/time_duration.rs @@ -1,7 +1,8 @@ -//! Serialize/deserialize std::time::Duration type from and into string: +//! Serialize/deserialize core::time::Duration type from and into string: +use crate::prelude::*; use serde::{de::Error as _, Deserialize, Deserializer, Serialize, Serializer}; -use std::time::Duration; +use core::time::Duration; /// Deserialize string into Duration pub fn deserialize<'de, D>(deserializer: D) -> Result diff --git a/proto/src/serializers/timestamp.rs b/proto/src/serializers/timestamp.rs index 8627cd208..8843c17ef 100644 --- a/proto/src/serializers/timestamp.rs +++ b/proto/src/serializers/timestamp.rs @@ -2,6 +2,7 @@ use serde::{de::Error as _, Deserialize, Deserializer, Serialize, Serializer}; use crate::google::protobuf::Timestamp; +use crate::prelude::*; use chrono::{DateTime, LocalResult, TimeZone, Utc}; use serde::ser::Error; diff --git a/proto/src/serializers/txs.rs b/proto/src/serializers/txs.rs index 05b2767f1..ff45b05cc 100644 --- a/proto/src/serializers/txs.rs +++ b/proto/src/serializers/txs.rs @@ -1,4 +1,5 @@ //! Serialize/deserialize Vec> type from and into transactions (Base64String array). +use crate::prelude::*; use serde::{Deserialize, Deserializer, Serialize, Serializer}; use subtle_encoding::base64; diff --git a/proto/src/tendermint.rs b/proto/src/tendermint.rs index 335cb2877..dbfda20a7 100644 --- a/proto/src/tendermint.rs +++ b/proto/src/tendermint.rs @@ -53,6 +53,7 @@ pub mod p2p { } pub mod abci { + use crate::prelude::*; include!("prost/tendermint.abci.rs"); } diff --git a/proto/tests/unit.rs b/proto/tests/unit.rs index f50d35507..03efe33bb 100644 --- a/proto/tests/unit.rs +++ b/proto/tests/unit.rs @@ -1,4 +1,4 @@ -use std::convert::TryFrom; +use core::convert::TryFrom; use tendermint_proto::types::BlockId as RawBlockId; use tendermint_proto::types::PartSetHeader as RawPartSetHeader; use tendermint_proto::Protobuf; From 0057f39f8ebd849737c73e53c6cd104ce1df4e54 Mon Sep 17 00:00:00 2001 From: Soares Chen Date: Fri, 17 Sep 2021 12:47:22 +0200 Subject: [PATCH 04/16] Disable default features in tendermint dependencies --- tendermint/Cargo.toml | 47 +++++++++++++++++++++--------------------- tendermint/src/time.rs | 20 +++++------------- 2 files changed, 28 insertions(+), 39 deletions(-) diff --git a/tendermint/Cargo.toml b/tendermint/Cargo.toml index 51577b18b..db6453e8f 100644 --- a/tendermint/Cargo.toml +++ b/tendermint/Cargo.toml @@ -33,33 +33,32 @@ rustdoc-args = ["--cfg", "docsrs"] crate-type = ["cdylib", "rlib"] [dependencies] -async-trait = "0.1" -bytes = "1.0" -chrono = { version = "0.4.19", features = ["serde"] } -ed25519 = { version = "1" } +async-trait = { version = "0.1", default-features = false } +bytes = { version = "1.0", default-features = false } +chrono = { version = "0.4.19", default-features = false, features = ["serde"] } +ed25519 = { version = "1", default-features = false } ed25519-dalek = { version = "1", features = ["serde"] } -futures = "0.3" -num-traits = "0.2" -once_cell = "1.3" -prost = "0.7" -prost-types = "0.7" -serde = { version = "1", features = ["derive"] } -serde_json = "1" -serde_bytes = "0.11" -serde_repr = "0.1" +futures = { version = "0.3", default-features = false } +num-traits = { version = "0.2", default-features = false } +once_cell = { version = "1.3", default-features = false } +prost = { version = "0.7", default-features = false } +prost-types = { version = "0.7", default-features = false } +serde = { version = "1", default-features = false, features = ["derive"] } +serde_json = { version = "1", default-features = false, features = ["alloc"] } +serde_bytes = { version = "0.11", default-features = false } +serde_repr = { version = "0.1", default-features = false } sha2 = { version = "0.9", default-features = false } -signature = "1.2" -subtle = "2" -subtle-encoding = { version = "0.5", features = ["bech32-preview"] } -tendermint-proto = { version = "0.21.0", path = "../proto" } -toml = { version = "0.5" } -url = { version = "2.2" } -zeroize = { version = "1.1", features = ["zeroize_derive"] } +signature = { version = "1.2", default-features = false } +subtle = { version = "2", default-features = false } +subtle-encoding = { version = "0.5", default-features = false, features = ["bech32-preview"] } +tendermint-proto = { version = "0.21.0", default-features = false, path = "../proto" } +toml = { version = "0.5", default-features = false } +url = { version = "2.2", default-features = false } +zeroize = { version = "1.1", default-features = false, features = ["zeroize_derive"] } flex-error = { version = "0.4.1", default-features = false } -time = "0.1.40" - -k256 = { version = "0.9", optional = true, features = ["ecdsa"] } -ripemd160 = { version = "0.9", optional = true } +time = { version = "0.1.40", default-features = false } +k256 = { version = "0.9", optional = true, default-features = false , features = ["ecdsa"] } +ripemd160 = { version = "0.9", default-features = false , optional = true } [features] default = ["std", "eyre_tracer"] diff --git a/tendermint/src/time.rs b/tendermint/src/time.rs index 043d97954..6b31f4c75 100644 --- a/tendermint/src/time.rs +++ b/tendermint/src/time.rs @@ -1,6 +1,6 @@ //! Timestamps used by Tendermint blockchains -use chrono::{DateTime, Utc}; +use chrono::{DateTime, TimeZone, Utc}; use serde::{Deserialize, Serialize}; use crate::prelude::*; @@ -19,31 +19,21 @@ use crate::error::Error; /// #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] #[serde(try_from = "Timestamp", into = "Timestamp")] -pub struct Time(DateTime); +pub struct Time(pub DateTime); impl Protobuf for Time {} impl From for Time { fn from(value: Timestamp) -> Self { - // prost_types::Timestamp has a SystemTime converter but - // tendermint_proto::Timestamp can be JSON-encoded - let prost_value = prost_types::Timestamp { - seconds: value.seconds, - nanos: value.nanos, - }; - - SystemTime::from(prost_value).into() + Time(Utc.timestamp(value.seconds, value.nanos as u32)) } } impl From