Skip to content

Commit

Permalink
Enable edition 2018
Browse files Browse the repository at this point in the history
Add 'edition = "2018"' to the manifest and do a bunch of manual path
fixups (use statements and fully qualified paths).
  • Loading branch information
tcharding committed May 3, 2022
1 parent 060fb32 commit 715f510
Show file tree
Hide file tree
Showing 15 changed files with 90 additions and 87 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Expand Up @@ -10,6 +10,7 @@ description = "General purpose library for using and interoperating with Bitcoin
keywords = [ "crypto", "bitcoin" ]
readme = "README.md"
exclude = ["./test_data"]
edition = "2018"

# Please don't forget to add relevant features to docs.rs below
[features]
Expand Down
2 changes: 1 addition & 1 deletion src/blockdata/opcodes.rs
Expand Up @@ -22,7 +22,7 @@

#[cfg(feature = "serde")] use serde;

#[cfg(feature = "serde")] use prelude::*;
#[cfg(feature = "serde")] use crate::prelude::*;

use core::{fmt, convert::From};

Expand Down
6 changes: 3 additions & 3 deletions src/blockdata/script.rs
Expand Up @@ -617,7 +617,7 @@ impl Script {
/// Shorthand for [`Self::verify_with_flags`] with flag [bitcoinconsensus::VERIFY_ALL].
#[cfg(feature="bitcoinconsensus")]
#[cfg_attr(docsrs, doc(cfg(feature = "bitcoinconsensus")))]
pub fn verify (&self, index: usize, amount: ::Amount, spending: &[u8]) -> Result<(), Error> {
pub fn verify (&self, index: usize, amount: crate::Amount, spending: &[u8]) -> Result<(), Error> {
self.verify_with_flags(index, amount, spending, ::bitcoinconsensus::VERIFY_ALL)
}

Expand All @@ -630,7 +630,7 @@ impl Script {
/// * `flags` - Verification flags, see [`bitcoinconsensus::VERIFY_ALL`] and similar.
#[cfg(feature="bitcoinconsensus")]
#[cfg_attr(docsrs, doc(cfg(feature = "bitcoinconsensus")))]
pub fn verify_with_flags<F: Into<u32>>(&self, index: usize, amount: ::Amount, spending: &[u8], flags: F) -> Result<(), Error> {
pub fn verify_with_flags<F: Into<u32>>(&self, index: usize, amount: crate::Amount, spending: &[u8], flags: F) -> Result<(), Error> {
Ok(bitcoinconsensus::verify_with_flags (&self.0[..], amount.as_sat(), spending, index, flags.into())?)
}

Expand Down Expand Up @@ -1440,7 +1440,7 @@ mod test {
// a random segwit transaction from the blockchain using native segwit
let spent = Builder::from(Vec::from_hex("0020701a8d401c84fb13e6baf169d59684e17abd9fa216c8cc5b9fc63d622ff8c58d").unwrap()).into_script();
let spending = Vec::from_hex("010000000001011f97548fbbe7a0db7588a66e18d803d0089315aa7d4cc28360b6ec50ef36718a0100000000ffffffff02df1776000000000017a9146c002a686959067f4866b8fb493ad7970290ab728757d29f0000000000220020701a8d401c84fb13e6baf169d59684e17abd9fa216c8cc5b9fc63d622ff8c58d04004730440220565d170eed95ff95027a69b313758450ba84a01224e1f7f130dda46e94d13f8602207bdd20e307f062594022f12ed5017bbf4a055a06aea91c10110a0e3bb23117fc014730440220647d2dc5b15f60bc37dc42618a370b2a1490293f9e5c8464f53ec4fe1dfe067302203598773895b4b16d37485cbe21b337f4e4b650739880098c592553add7dd4355016952210375e00eb72e29da82b89367947f29ef34afb75e8654f6ea368e0acdfd92976b7c2103a1b26313f430c4b15bb1fdce663207659d8cac749a0e53d70eff01874496feff2103c96d495bfdd5ba4145e3e046fee45e84a8a48ad05bd8dbb395c011a32cf9f88053ae00000000").unwrap();
spent.verify(0, ::Amount::from_sat(18393430), spending.as_slice()).unwrap();
spent.verify(0, crate::Amount::from_sat(18393430), spending.as_slice()).unwrap();
}

#[test]
Expand Down
12 changes: 6 additions & 6 deletions src/blockdata/transaction.rs
Expand Up @@ -34,7 +34,7 @@ use crate::hashes::hex::FromHex;

use crate::util::endian;
use crate::blockdata::constants::WITNESS_SCALE_FACTOR;
#[cfg(feature="bitcoinconsensus")] use blockdata::script;
#[cfg(feature="bitcoinconsensus")] use crate::blockdata::script;
use crate::blockdata::script::Script;
use crate::blockdata::witness::Witness;
use crate::consensus::{encode, Decodable, Encodable};
Expand All @@ -43,7 +43,7 @@ use crate::hash_types::{Sighash, Txid, Wtxid};
use crate::VarInt;

#[cfg(doc)]
use util::sighash::SchnorrSighashType;
use crate::util::sighash::SchnorrSighashType;

/// Used for signature hash for invalid use of SIGHASH_SINGLE.
const UINT256_ONE: [u8; 32] = [
Expand Down Expand Up @@ -590,7 +590,7 @@ impl Transaction {
let flags: u32 = flags.into();
for (idx, input) in self.input.iter().enumerate() {
if let Some(output) = spent(&input.previous_output) {
output.script_pubkey.verify_with_flags(idx, ::Amount::from_sat(output.value), tx.as_slice(), flags)?;
output.script_pubkey.verify_with_flags(idx, crate::Amount::from_sat(output.value), tx.as_slice(), flags)?;
} else {
return Err(script::Error::UnknownSpentOutput(input.previous_output.clone()));
}
Expand Down Expand Up @@ -1541,10 +1541,10 @@ mod tests {
#[test]
#[cfg(feature="bitcoinconsensus")]
fn test_transaction_verify () {
use hashes::hex::FromHex;
use std::collections::HashMap;
use blockdata::script;
use blockdata::witness::Witness;
use crate::hashes::hex::FromHex;
use crate::blockdata::script;
use crate::blockdata::witness::Witness;

// a random recent segwit transaction from blockchain using both old and segwit inputs
let mut spending: Transaction = deserialize(Vec::from_hex("020000000001031cfbc8f54fbfa4a33a30068841371f80dbfe166211242213188428f437445c91000000006a47304402206fbcec8d2d2e740d824d3d36cc345b37d9f65d665a99f5bd5c9e8d42270a03a8022013959632492332200c2908459547bf8dbf97c65ab1a28dec377d6f1d41d3d63e012103d7279dfb90ce17fe139ba60a7c41ddf605b25e1c07a4ddcb9dfef4e7d6710f48feffffff476222484f5e35b3f0e43f65fc76e21d8be7818dd6a989c160b1e5039b7835fc00000000171600140914414d3c94af70ac7e25407b0689e0baa10c77feffffffa83d954a62568bbc99cc644c62eb7383d7c2a2563041a0aeb891a6a4055895570000000017160014795d04cc2d4f31480d9a3710993fbd80d04301dffeffffff06fef72f000000000017a91476fd7035cd26f1a32a5ab979e056713aac25796887a5000f00000000001976a914b8332d502a529571c6af4be66399cd33379071c588ac3fda0500000000001976a914fc1d692f8de10ae33295f090bea5fe49527d975c88ac522e1b00000000001976a914808406b54d1044c429ac54c0e189b0d8061667e088ac6eb68501000000001976a914dfab6085f3a8fb3e6710206a5a959313c5618f4d88acbba20000000000001976a914eb3026552d7e3f3073457d0bee5d4757de48160d88ac0002483045022100bee24b63212939d33d513e767bc79300051f7a0d433c3fcf1e0e3bf03b9eb1d70220588dc45a9ce3a939103b4459ce47500b64e23ab118dfc03c9caa7d6bfc32b9c601210354fd80328da0f9ae6eef2b3a81f74f9a6f66761fadf96f1d1d22b1fd6845876402483045022100e29c7e3a5efc10da6269e5fc20b6a1cb8beb92130cc52c67e46ef40aaa5cac5f0220644dd1b049727d991aece98a105563416e10a5ac4221abac7d16931842d5c322012103960b87412d6e169f30e12106bdf70122aabb9eb61f455518322a18b920a4dfa887d30700")
Expand Down
2 changes: 1 addition & 1 deletion src/hash_types.rs
Expand Up @@ -20,7 +20,7 @@
//! hash).
//!

use crate::hashes::{Hash, sha256, sha256d, hash160};
use crate::hashes::{Hash, sha256, sha256d, hash160, hash_newtype};

macro_rules! impl_hashencode {
($hashtype:ident) => {
Expand Down
6 changes: 3 additions & 3 deletions src/internal_macros.rs
Expand Up @@ -93,11 +93,11 @@ macro_rules! impl_array_newtype {
}
}

impl<I> $crate::core::ops::Index<I> for $thing
impl<I> core::ops::Index<I> for $thing
where
[$ty]: $crate::core::ops::Index<I>,
[$ty]: core::ops::Index<I>,
{
type Output = <[$ty] as $crate::core::ops::Index<I>>::Output;
type Output = <[$ty] as core::ops::Index<I>>::Output;

#[inline]
fn index(&self, index: I) -> &Self::Output {
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Expand Up @@ -190,7 +190,7 @@ mod prelude {
pub use std::io::sink;

#[cfg(not(feature = "std"))]
pub use io_extras::sink;
pub use crate::io_extras::sink;

#[cfg(feature = "hashbrown")]
pub use hashbrown::HashSet;
Expand Down
50 changes: 25 additions & 25 deletions src/serde_utils.rs
Expand Up @@ -9,14 +9,14 @@ pub mod btreemap_byte_values {

// NOTE: This module can be exactly copied to use with HashMap.

use prelude::*;
use hashes::hex::{FromHex, ToHex};
use crate::prelude::*;
use crate::hashes::hex::{FromHex, ToHex};
use serde;

pub fn serialize<S, T>(v: &BTreeMap<T, Vec<u8>>, s: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
T: serde::Serialize + ::core::hash::Hash + Eq + Ord,
T: serde::Serialize + core::hash::Hash + Eq + Ord,
{
use serde::ser::SerializeMap;

Expand All @@ -35,18 +35,18 @@ pub mod btreemap_byte_values {
pub fn deserialize<'de, D, T>(d: D) -> Result<BTreeMap<T, Vec<u8>>, D::Error>
where
D: serde::Deserializer<'de>,
T: serde::Deserialize<'de> + ::core::hash::Hash + Eq + Ord,
T: serde::Deserialize<'de> + core::hash::Hash + Eq + Ord,
{
use ::core::marker::PhantomData;
use core::marker::PhantomData;

struct Visitor<T>(PhantomData<T>);
impl<'de, T> serde::de::Visitor<'de> for Visitor<T>
where
T: serde::Deserialize<'de> + ::core::hash::Hash + Eq + Ord,
T: serde::Deserialize<'de> + core::hash::Hash + Eq + Ord,
{
type Value = BTreeMap<T, Vec<u8>>;

fn expecting(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
fn expecting(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
write!(f, "a map with hexadecimal values")
}

Expand Down Expand Up @@ -77,13 +77,13 @@ pub mod btreemap_as_seq {

// NOTE: This module can be exactly copied to use with HashMap.

use prelude::*;
use crate::prelude::*;
use serde;

pub fn serialize<S, T, U>(v: &BTreeMap<T, U>, s: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
T: serde::Serialize + ::core::hash::Hash + Eq + Ord,
T: serde::Serialize + core::hash::Hash + Eq + Ord,
U: serde::Serialize,
{
use serde::ser::SerializeSeq;
Expand All @@ -103,20 +103,20 @@ pub mod btreemap_as_seq {
pub fn deserialize<'de, D, T, U>(d: D) -> Result<BTreeMap<T, U>, D::Error>
where
D: serde::Deserializer<'de>,
T: serde::Deserialize<'de> + ::core::hash::Hash + Eq + Ord,
T: serde::Deserialize<'de> + core::hash::Hash + Eq + Ord,
U: serde::Deserialize<'de>,
{
use ::core::marker::PhantomData;
use core::marker::PhantomData;

struct Visitor<T, U>(PhantomData<(T, U)>);
impl<'de, T, U> serde::de::Visitor<'de> for Visitor<T, U>
where
T: serde::Deserialize<'de> + ::core::hash::Hash + Eq + Ord,
T: serde::Deserialize<'de> + core::hash::Hash + Eq + Ord,
U: serde::Deserialize<'de>,
{
type Value = BTreeMap<T, U>;

fn expecting(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
fn expecting(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
write!(f, "a sequence of pairs")
}

Expand Down Expand Up @@ -147,29 +147,29 @@ pub mod btreemap_as_seq_byte_values {

// NOTE: This module can be exactly copied to use with HashMap.

use prelude::*;
use crate::prelude::*;
use serde;

/// A custom key-value pair type that serialized the bytes as hex.
#[derive(Debug, Deserialize)]
struct OwnedPair<T>(
T,
#[serde(deserialize_with = "::serde_utils::hex_bytes::deserialize")]
#[serde(deserialize_with = "crate::serde_utils::hex_bytes::deserialize")]
Vec<u8>,
);

/// A custom key-value pair type that serialized the bytes as hex.
#[derive(Debug, Serialize)]
struct BorrowedPair<'a, T: 'static>(
&'a T,
#[serde(serialize_with = "::serde_utils::hex_bytes::serialize")]
#[serde(serialize_with = "crate::serde_utils::hex_bytes::serialize")]
&'a [u8],
);

pub fn serialize<S, T>(v: &BTreeMap<T, Vec<u8>>, s: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
T: serde::Serialize + ::core::hash::Hash + Eq + Ord + 'static,
T: serde::Serialize + core::hash::Hash + Eq + Ord + 'static,
{
use serde::ser::SerializeSeq;

Expand All @@ -188,18 +188,18 @@ pub mod btreemap_as_seq_byte_values {
pub fn deserialize<'de, D, T>(d: D) -> Result<BTreeMap<T, Vec<u8>>, D::Error>
where
D: serde::Deserializer<'de>,
T: serde::Deserialize<'de> + ::core::hash::Hash + Eq + Ord,
T: serde::Deserialize<'de> + core::hash::Hash + Eq + Ord,
{
use ::core::marker::PhantomData;
use core::marker::PhantomData;

struct Visitor<T>(PhantomData<T>);
impl<'de, T> serde::de::Visitor<'de> for Visitor<T>
where
T: serde::Deserialize<'de> + ::core::hash::Hash + Eq + Ord,
T: serde::Deserialize<'de> + core::hash::Hash + Eq + Ord,
{
type Value = BTreeMap<T, Vec<u8>>;

fn expecting(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
fn expecting(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
write!(f, "a sequence of pairs")
}

Expand Down Expand Up @@ -246,20 +246,20 @@ pub mod hex_bytes {
where
D: serde::Deserializer<'de>, B: serde::Deserialize<'de> + FromHex,
{
struct Visitor<B>(::core::marker::PhantomData<B>);
struct Visitor<B>(core::marker::PhantomData<B>);

impl<'de, B: FromHex> serde::de::Visitor<'de> for Visitor<B> {
type Value = B;

fn expecting(&self, formatter: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
fn expecting(&self, formatter: &mut core::fmt::Formatter) -> core::fmt::Result {
formatter.write_str("an ASCII hex string")
}

fn visit_bytes<E>(self, v: &[u8]) -> Result<Self::Value, E>
where
E: serde::de::Error,
{
if let Ok(hex) = ::core::str::from_utf8(v) {
if let Ok(hex) = core::str::from_utf8(v) {
FromHex::from_hex(hex).map_err(E::custom)
} else {
return Err(E::invalid_value(serde::de::Unexpected::Bytes(v), &self));
Expand All @@ -278,7 +278,7 @@ pub mod hex_bytes {
if !d.is_human_readable() {
serde::Deserialize::deserialize(d)
} else {
d.deserialize_str(Visitor(::core::marker::PhantomData))
d.deserialize_str(Visitor(core::marker::PhantomData))
}
}
}
26 changes: 13 additions & 13 deletions src/util/amount.rs
Expand Up @@ -1233,7 +1233,7 @@ pub mod serde {
//! ```

use serde::{Deserialize, Deserializer, Serialize, Serializer};
use util::amount::{Amount, Denomination, SignedAmount};
use crate::util::amount::{Amount, Denomination, SignedAmount};

/// This trait is used only to avoid code duplication and naming collisions
/// of the different serde serialization crates.
Expand Down Expand Up @@ -1322,7 +1322,7 @@ pub mod serde {
//! Use with `#[serde(with = "amount::serde::as_sat")]`.

use serde::{Deserializer, Serializer};
use util::amount::serde::SerdeAmount;
use crate::util::amount::serde::SerdeAmount;

pub fn serialize<A: SerdeAmount, S: Serializer>(a: &A, s: S) -> Result<S::Ok, S::Error> {
a.ser_sat(s)
Expand All @@ -1337,7 +1337,7 @@ pub mod serde {
//! Use with `#[serde(default, with = "amount::serde::as_sat::opt")]`.

use serde::{Deserializer, Serializer, de};
use util::amount::serde::SerdeAmountForOpt;
use crate::util::amount::serde::SerdeAmountForOpt;
use core::fmt;
use core::marker::PhantomData;

Expand Down Expand Up @@ -1386,7 +1386,7 @@ pub mod serde {
//! Use with `#[serde(with = "amount::serde::as_btc")]`.

use serde::{Deserializer, Serializer};
use util::amount::serde::SerdeAmount;
use crate::util::amount::serde::SerdeAmount;

pub fn serialize<A: SerdeAmount, S: Serializer>(a: &A, s: S) -> Result<S::Ok, S::Error> {
a.ser_btc(s)
Expand All @@ -1401,7 +1401,7 @@ pub mod serde {
//! Use with `#[serde(default, with = "amount::serde::as_btc::opt")]`.

use serde::{Deserializer, Serializer, de};
use util::amount::serde::SerdeAmountForOpt;
use crate::util::amount::serde::SerdeAmountForOpt;
use core::fmt;
use core::marker::PhantomData;

Expand Down Expand Up @@ -1941,9 +1941,9 @@ mod tests {

#[derive(Serialize, Deserialize, PartialEq, Debug)]
struct T {
#[serde(with = "::util::amount::serde::as_sat")]
#[serde(with = "crate::util::amount::serde::as_sat")]
pub amt: Amount,
#[serde(with = "::util::amount::serde::as_sat")]
#[serde(with = "crate::util::amount::serde::as_sat")]
pub samt: SignedAmount,
}

Expand All @@ -1970,9 +1970,9 @@ mod tests {

#[derive(Serialize, Deserialize, PartialEq, Debug)]
struct T {
#[serde(with = "::util::amount::serde::as_btc")]
#[serde(with = "crate::util::amount::serde::as_btc")]
pub amt: Amount,
#[serde(with = "::util::amount::serde::as_btc")]
#[serde(with = "crate::util::amount::serde::as_btc")]
pub samt: SignedAmount,
}

Expand Down Expand Up @@ -2004,9 +2004,9 @@ mod tests {

#[derive(Serialize, Deserialize, PartialEq, Debug, Eq)]
struct T {
#[serde(default, with = "::util::amount::serde::as_btc::opt")]
#[serde(default, with = "crate::util::amount::serde::as_btc::opt")]
pub amt: Option<Amount>,
#[serde(default, with = "::util::amount::serde::as_btc::opt")]
#[serde(default, with = "crate::util::amount::serde::as_btc::opt")]
pub samt: Option<SignedAmount>,
}

Expand Down Expand Up @@ -2047,9 +2047,9 @@ mod tests {

#[derive(Serialize, Deserialize, PartialEq, Debug, Eq)]
struct T {
#[serde(default, with = "::util::amount::serde::as_sat::opt")]
#[serde(default, with = "crate::util::amount::serde::as_sat::opt")]
pub amt: Option<Amount>,
#[serde(default, with = "::util::amount::serde::as_sat::opt")]
#[serde(default, with = "crate::util::amount::serde::as_sat::opt")]
pub samt: Option<SignedAmount>,
}

Expand Down

0 comments on commit 715f510

Please sign in to comment.