Skip to content

Commit bb495a2

Browse files
committed
Merge rust-bitcoin/rust-bitcoin#983: Edition 2018
9f0c687 Enable edition 2018 (Tobin C. Harding) dca0d67 Fix in preparation for next edition (Tobin C. Harding) Pull request description: This PR supersedes #635 at the permission of @Kixunil in the thread of that PR. Do a minimal set of changes to enable edition 2018. Patch 1 is the biggest change set, it is done with `cargo`, no other manual changes are included in patch 1. It can verified by running `cargo fix --edition` on master and checking the diffs are the same. Patch 2 enables 2018 and includes all the manual changes required to get the code to build (with _all_ the feature combinations :) ACKs for top commit: dunxen: re-ACK 9f0c687 apoelstra: re-ACK 9f0c687 RCasatta: ACK 9f0c687, Tree-SHA512: 7c23554adb4c1dd932af1e80f04397bad0418b4fdae2d0fe243c3f19ba1169686a386bffd38a3c02871c7544b5a7bc8af525b50617a2695726408c091700f081
2 parents 588e837 + decd9df commit bb495a2

Some content is hidden

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

46 files changed

+552
-549
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ description = "General purpose library for using and interoperating with Bitcoin
1010
keywords = [ "crypto", "bitcoin" ]
1111
readme = "README.md"
1212
exclude = ["./test_data"]
13+
edition = "2018"
1314

1415
# Please don't forget to add relevant features to docs.rs below
1516
[features]

src/blockdata/block.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,22 @@
2020
//! these blocks and the blockchain.
2121
//!
2222
23-
use prelude::*;
23+
use crate::prelude::*;
2424

2525
use core::fmt;
2626

27-
use util;
28-
use util::Error::{BlockBadTarget, BlockBadProofOfWork};
29-
use util::hash::bitcoin_merkle_root;
30-
use hashes::{Hash, HashEngine};
31-
use hash_types::{Wtxid, BlockHash, TxMerkleNode, WitnessMerkleNode, WitnessCommitment};
32-
use util::uint::Uint256;
33-
use consensus::encode::Encodable;
34-
use network::constants::Network;
35-
use blockdata::transaction::Transaction;
36-
use blockdata::constants::{max_target, WITNESS_SCALE_FACTOR};
37-
use blockdata::script;
38-
use VarInt;
27+
use crate::util;
28+
use crate::util::Error::{BlockBadTarget, BlockBadProofOfWork};
29+
use crate::util::hash::bitcoin_merkle_root;
30+
use crate::hashes::{Hash, HashEngine};
31+
use crate::hash_types::{Wtxid, BlockHash, TxMerkleNode, WitnessMerkleNode, WitnessCommitment};
32+
use crate::util::uint::Uint256;
33+
use crate::consensus::encode::Encodable;
34+
use crate::network::constants::Network;
35+
use crate::blockdata::transaction::Transaction;
36+
use crate::blockdata::constants::{max_target, WITNESS_SCALE_FACTOR};
37+
use crate::blockdata::script;
38+
use crate::VarInt;
3939

4040
/// A block header, which contains all the block's information except
4141
/// the actual transactions
@@ -359,13 +359,13 @@ impl ::std::error::Error for Bip34Error {}
359359

360360
#[cfg(test)]
361361
mod tests {
362-
use hashes::hex::FromHex;
362+
use crate::hashes::hex::FromHex;
363363

364-
use blockdata::block::{Block, BlockHeader};
365-
use consensus::encode::{deserialize, serialize};
366-
use util::uint::Uint256;
367-
use util::Error::{BlockBadTarget, BlockBadProofOfWork};
368-
use network::constants::Network;
364+
use crate::blockdata::block::{Block, BlockHeader};
365+
use crate::consensus::encode::{deserialize, serialize};
366+
use crate::util::uint::Uint256;
367+
use crate::util::Error::{BlockBadTarget, BlockBadProofOfWork};
368+
use crate::network::constants::Network;
369369

370370
#[test]
371371
fn test_coinbase_and_bip34() {
@@ -508,10 +508,10 @@ mod tests {
508508
#[cfg(all(test, feature = "unstable"))]
509509
mod benches {
510510
use super::Block;
511-
use EmptyWrite;
512-
use consensus::{deserialize, Encodable};
511+
use crate::EmptyWrite;
512+
use crate::consensus::{deserialize, Encodable};
513513
use test::{black_box, Bencher};
514-
use network::stream_reader::StreamReader;
514+
use crate::network::stream_reader::StreamReader;
515515

516516
#[bench]
517517
#[allow(deprecated)]

src/blockdata/constants.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@
1919
//! single transaction.
2020
//!
2121
22-
use prelude::*;
22+
use crate::prelude::*;
2323

2424
use core::default::Default;
2525

26-
use hashes::hex::{self, HexIterator};
27-
use hashes::sha256d;
28-
use blockdata::opcodes;
29-
use blockdata::script;
30-
use blockdata::transaction::{OutPoint, Transaction, TxOut, TxIn};
31-
use blockdata::block::{Block, BlockHeader};
32-
use blockdata::witness::Witness;
33-
use network::constants::Network;
34-
use util::uint::Uint256;
26+
use crate::hashes::hex::{self, HexIterator};
27+
use crate::hashes::sha256d;
28+
use crate::blockdata::opcodes;
29+
use crate::blockdata::script;
30+
use crate::blockdata::transaction::{OutPoint, Transaction, TxOut, TxIn};
31+
use crate::blockdata::block::{Block, BlockHeader};
32+
use crate::blockdata::witness::Witness;
33+
use crate::network::constants::Network;
34+
use crate::util::uint::Uint256;
3535

3636
/// The maximum allowable sequence number
3737
pub const MAX_SEQUENCE: u32 = 0xFFFFFFFF;
@@ -179,12 +179,12 @@ pub fn genesis_block(network: Network) -> Block {
179179
#[cfg(test)]
180180
mod test {
181181
use core::default::Default;
182-
use hashes::hex::FromHex;
182+
use crate::hashes::hex::FromHex;
183183

184-
use network::constants::Network;
185-
use consensus::encode::serialize;
186-
use blockdata::constants::{genesis_block, bitcoin_genesis_tx};
187-
use blockdata::constants::{MAX_SEQUENCE, COIN_VALUE};
184+
use crate::network::constants::Network;
185+
use crate::consensus::encode::serialize;
186+
use crate::blockdata::constants::{genesis_block, bitcoin_genesis_tx};
187+
use crate::blockdata::constants::{MAX_SEQUENCE, COIN_VALUE};
188188

189189
#[test]
190190
fn bitcoin_genesis_first_transaction() {

src/blockdata/opcodes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

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

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

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

src/blockdata/script.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,28 @@
2323
//! This module provides the structures and functions needed to support scripts.
2424
//!
2525
26-
use prelude::*;
26+
use crate::prelude::*;
2727

28-
use io;
28+
use crate::io;
2929
use core::{fmt, default::Default};
3030
use core::ops::Index;
3131

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

34-
use hash_types::{PubkeyHash, WPubkeyHash, ScriptHash, WScriptHash};
35-
use blockdata::opcodes;
36-
use consensus::{encode, Decodable, Encodable};
37-
use hashes::{Hash, hex};
38-
use policy::DUST_RELAY_TX_FEE;
34+
use crate::hash_types::{PubkeyHash, WPubkeyHash, ScriptHash, WScriptHash};
35+
use crate::blockdata::opcodes;
36+
use crate::consensus::{encode, Decodable, Encodable};
37+
use crate::hashes::{Hash, hex};
38+
use crate::policy::DUST_RELAY_TX_FEE;
3939
#[cfg(feature="bitcoinconsensus")] use bitcoinconsensus;
4040
#[cfg(feature="bitcoinconsensus")] use core::convert::From;
41-
use OutPoint;
41+
use crate::OutPoint;
4242

43-
use util::key::PublicKey;
44-
use util::address::WitnessVersion;
45-
use util::taproot::{LeafVersion, TapBranchHash, TapLeafHash};
43+
use crate::util::key::PublicKey;
44+
use crate::util::address::WitnessVersion;
45+
use crate::util::taproot::{LeafVersion, TapBranchHash, TapLeafHash};
4646
use secp256k1::{Secp256k1, Verification, XOnlyPublicKey};
47-
use schnorr::{TapTweak, TweakedPublicKey, UntweakedPublicKey};
47+
use crate::schnorr::{TapTweak, TweakedPublicKey, UntweakedPublicKey};
4848

4949
/// A Bitcoin script.
5050
#[derive(Clone, Default, PartialOrd, Ord, PartialEq, Eq, Hash)]
@@ -557,7 +557,7 @@ impl Script {
557557

558558
/// Checks whether a script can be proven to have no satisfying input.
559559
pub fn is_provably_unspendable(&self) -> bool {
560-
use blockdata::opcodes::Class::{ReturnOp, IllegalOp};
560+
use crate::blockdata::opcodes::Class::{ReturnOp, IllegalOp};
561561

562562
match self.0.first() {
563563
Some(b) => {
@@ -572,7 +572,7 @@ impl Script {
572572

573573
/// Returns the minimum value an output with this script should have in order to be
574574
/// broadcastable on today's Bitcoin network.
575-
pub fn dust_value(&self) -> ::Amount {
575+
pub fn dust_value(&self) -> crate::Amount {
576576
// This must never be lower than Bitcoin Core's GetDustThreshold() (as of v0.21) as it may
577577
// otherwise allow users to create transactions which likely can never be broadcast/confirmed.
578578
let sats = DUST_RELAY_TX_FEE as u64 / 1000 * // The default dust relay fee is 3000 satoshi/kB (i.e. 3 sat/vByte)
@@ -588,7 +588,7 @@ impl Script {
588588
self.consensus_encode(&mut sink()).expect("sinks don't error") as u64 // The serialized size of this script_pubkey
589589
};
590590

591-
::Amount::from_sat(sats)
591+
crate::Amount::from_sat(sats)
592592
}
593593

594594
/// Iterates over the script in the form of `Instruction`s, which are an enum covering opcodes,
@@ -617,7 +617,7 @@ impl Script {
617617
/// Shorthand for [`Self::verify_with_flags`] with flag [bitcoinconsensus::VERIFY_ALL].
618618
#[cfg(feature="bitcoinconsensus")]
619619
#[cfg_attr(docsrs, doc(cfg(feature = "bitcoinconsensus")))]
620-
pub fn verify (&self, index: usize, amount: ::Amount, spending: &[u8]) -> Result<(), Error> {
620+
pub fn verify (&self, index: usize, amount: crate::Amount, spending: &[u8]) -> Result<(), Error> {
621621
self.verify_with_flags(index, amount, spending, ::bitcoinconsensus::VERIFY_ALL)
622622
}
623623

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

@@ -1075,11 +1075,11 @@ mod test {
10751075
use super::*;
10761076
use super::build_scriptint;
10771077

1078-
use hashes::hex::{FromHex, ToHex};
1079-
use consensus::encode::{deserialize, serialize};
1080-
use blockdata::opcodes;
1081-
use util::key::PublicKey;
1082-
use util::psbt::serialize::Serialize;
1078+
use crate::hashes::hex::{FromHex, ToHex};
1079+
use crate::consensus::encode::{deserialize, serialize};
1080+
use crate::blockdata::opcodes;
1081+
use crate::util::key::PublicKey;
1082+
use crate::util::psbt::serialize::Serialize;
10831083

10841084
#[test]
10851085
fn script() {
@@ -1440,7 +1440,7 @@ mod test {
14401440
// a random segwit transaction from the blockchain using native segwit
14411441
let spent = Builder::from(Vec::from_hex("0020701a8d401c84fb13e6baf169d59684e17abd9fa216c8cc5b9fc63d622ff8c58d").unwrap()).into_script();
14421442
let spending = Vec::from_hex("010000000001011f97548fbbe7a0db7588a66e18d803d0089315aa7d4cc28360b6ec50ef36718a0100000000ffffffff02df1776000000000017a9146c002a686959067f4866b8fb493ad7970290ab728757d29f0000000000220020701a8d401c84fb13e6baf169d59684e17abd9fa216c8cc5b9fc63d622ff8c58d04004730440220565d170eed95ff95027a69b313758450ba84a01224e1f7f130dda46e94d13f8602207bdd20e307f062594022f12ed5017bbf4a055a06aea91c10110a0e3bb23117fc014730440220647d2dc5b15f60bc37dc42618a370b2a1490293f9e5c8464f53ec4fe1dfe067302203598773895b4b16d37485cbe21b337f4e4b650739880098c592553add7dd4355016952210375e00eb72e29da82b89367947f29ef34afb75e8654f6ea368e0acdfd92976b7c2103a1b26313f430c4b15bb1fdce663207659d8cac749a0e53d70eff01874496feff2103c96d495bfdd5ba4145e3e046fee45e84a8a48ad05bd8dbb395c011a32cf9f88053ae00000000").unwrap();
1443-
spent.verify(0, ::Amount::from_sat(18393430), spending.as_slice()).unwrap();
1443+
spent.verify(0, crate::Amount::from_sat(18393430), spending.as_slice()).unwrap();
14441444
}
14451445

14461446
#[test]
@@ -1449,7 +1449,7 @@ mod test {
14491449
// well-known scriptPubKey types.
14501450
let script_p2wpkh = Builder::new().push_int(0).push_slice(&[42; 20]).into_script();
14511451
assert!(script_p2wpkh.is_v0_p2wpkh());
1452-
assert_eq!(script_p2wpkh.dust_value(), ::Amount::from_sat(294));
1452+
assert_eq!(script_p2wpkh.dust_value(), crate::Amount::from_sat(294));
14531453

14541454
let script_p2pkh = Builder::new()
14551455
.push_opcode(opcodes::all::OP_DUP)
@@ -1459,7 +1459,7 @@ mod test {
14591459
.push_opcode(opcodes::all::OP_CHECKSIG)
14601460
.into_script();
14611461
assert!(script_p2pkh.is_p2pkh());
1462-
assert_eq!(script_p2pkh.dust_value(), ::Amount::from_sat(546));
1462+
assert_eq!(script_p2pkh.dust_value(), crate::Amount::from_sat(546));
14631463
}
14641464

14651465
#[test]

src/blockdata/transaction.rs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,27 @@
2323
//! This module provides the structures and functions needed to support transactions.
2424
//!
2525
26-
use prelude::*;
26+
use crate::prelude::*;
2727

28-
use io;
28+
use crate::io;
2929
use core::{fmt, str, default::Default};
3030
#[cfg(feature = "std")] use std::error;
3131

32-
use hashes::{self, Hash, sha256d};
33-
use hashes::hex::FromHex;
32+
use crate::hashes::{self, Hash, sha256d};
33+
use crate::hashes::hex::FromHex;
3434

35-
use util::endian;
36-
use blockdata::constants::WITNESS_SCALE_FACTOR;
37-
#[cfg(feature="bitcoinconsensus")] use blockdata::script;
38-
use blockdata::script::Script;
39-
use blockdata::witness::Witness;
40-
use consensus::{encode, Decodable, Encodable};
41-
use consensus::encode::MAX_VEC_SIZE;
42-
use hash_types::{Sighash, Txid, Wtxid};
43-
use VarInt;
35+
use crate::util::endian;
36+
use crate::blockdata::constants::WITNESS_SCALE_FACTOR;
37+
#[cfg(feature="bitcoinconsensus")] use crate::blockdata::script;
38+
use crate::blockdata::script::Script;
39+
use crate::blockdata::witness::Witness;
40+
use crate::consensus::{encode, Decodable, Encodable};
41+
use crate::consensus::encode::MAX_VEC_SIZE;
42+
use crate::hash_types::{Sighash, Txid, Wtxid};
43+
use crate::VarInt;
4444

4545
#[cfg(doc)]
46-
use util::sighash::SchnorrSighashType;
46+
use crate::util::sighash::SchnorrSighashType;
4747

4848
/// Used for signature hash for invalid use of SIGHASH_SINGLE.
4949
const UINT256_ONE: [u8; 32] = [
@@ -590,7 +590,7 @@ impl Transaction {
590590
let flags: u32 = flags.into();
591591
for (idx, input) in self.input.iter().enumerate() {
592592
if let Some(output) = spent(&input.previous_output) {
593-
output.script_pubkey.verify_with_flags(idx, ::Amount::from_sat(output.value), tx.as_slice(), flags)?;
593+
output.script_pubkey.verify_with_flags(idx, crate::Amount::from_sat(output.value), tx.as_slice(), flags)?;
594594
} else {
595595
return Err(script::Error::UnknownSpentOutput(input.previous_output.clone()));
596596
}
@@ -895,17 +895,17 @@ mod tests {
895895
use super::*;
896896

897897
use core::str::FromStr;
898-
use blockdata::constants::WITNESS_SCALE_FACTOR;
899-
use blockdata::script::Script;
900-
use consensus::encode::serialize;
901-
use consensus::encode::deserialize;
898+
use crate::blockdata::constants::WITNESS_SCALE_FACTOR;
899+
use crate::blockdata::script::Script;
900+
use crate::consensus::encode::serialize;
901+
use crate::consensus::encode::deserialize;
902902

903-
use hashes::Hash;
904-
use hashes::hex::FromHex;
903+
use crate::hashes::Hash;
904+
use crate::hashes::hex::FromHex;
905905

906-
use hash_types::*;
906+
use crate::hash_types::*;
907907
use super::EcdsaSighashType;
908-
use util::sighash::SighashCache;
908+
use crate::util::sighash::SighashCache;
909909

910910
#[test]
911911
fn test_outpoint() {
@@ -958,8 +958,8 @@ mod tests {
958958

959959
#[test]
960960
fn test_is_coinbase () {
961-
use network::constants::Network;
962-
use blockdata::constants;
961+
use crate::network::constants::Network;
962+
use crate::blockdata::constants;
963963

964964
let genesis = constants::genesis_block(Network::Bitcoin);
965965
assert! (genesis.txdata[0].is_coin_base());
@@ -1541,10 +1541,10 @@ mod tests {
15411541
#[test]
15421542
#[cfg(feature="bitcoinconsensus")]
15431543
fn test_transaction_verify () {
1544-
use hashes::hex::FromHex;
15451544
use std::collections::HashMap;
1546-
use blockdata::script;
1547-
use blockdata::witness::Witness;
1545+
use crate::hashes::hex::FromHex;
1546+
use crate::blockdata::script;
1547+
use crate::blockdata::witness::Witness;
15481548

15491549
// a random recent segwit transaction from blockchain using both old and segwit inputs
15501550
let mut spending: Transaction = deserialize(Vec::from_hex("020000000001031cfbc8f54fbfa4a33a30068841371f80dbfe166211242213188428f437445c91000000006a47304402206fbcec8d2d2e740d824d3d36cc345b37d9f65d665a99f5bd5c9e8d42270a03a8022013959632492332200c2908459547bf8dbf97c65ab1a28dec377d6f1d41d3d63e012103d7279dfb90ce17fe139ba60a7c41ddf605b25e1c07a4ddcb9dfef4e7d6710f48feffffff476222484f5e35b3f0e43f65fc76e21d8be7818dd6a989c160b1e5039b7835fc00000000171600140914414d3c94af70ac7e25407b0689e0baa10c77feffffffa83d954a62568bbc99cc644c62eb7383d7c2a2563041a0aeb891a6a4055895570000000017160014795d04cc2d4f31480d9a3710993fbd80d04301dffeffffff06fef72f000000000017a91476fd7035cd26f1a32a5ab979e056713aac25796887a5000f00000000001976a914b8332d502a529571c6af4be66399cd33379071c588ac3fda0500000000001976a914fc1d692f8de10ae33295f090bea5fe49527d975c88ac522e1b00000000001976a914808406b54d1044c429ac54c0e189b0d8061667e088ac6eb68501000000001976a914dfab6085f3a8fb3e6710206a5a959313c5618f4d88acbba20000000000001976a914eb3026552d7e3f3073457d0bee5d4757de48160d88ac0002483045022100bee24b63212939d33d513e767bc79300051f7a0d433c3fcf1e0e3bf03b9eb1d70220588dc45a9ce3a939103b4459ce47500b64e23ab118dfc03c9caa7d6bfc32b9c601210354fd80328da0f9ae6eef2b3a81f74f9a6f66761fadf96f1d1d22b1fd6845876402483045022100e29c7e3a5efc10da6269e5fc20b6a1cb8beb92130cc52c67e46ef40aaa5cac5f0220644dd1b049727d991aece98a105563416e10a5ac4221abac7d16931842d5c322012103960b87412d6e169f30e12106bdf70122aabb9eb61f455518322a18b920a4dfa887d30700")
@@ -1601,9 +1601,9 @@ mod tests {
16011601
#[cfg(all(test, feature = "unstable"))]
16021602
mod benches {
16031603
use super::Transaction;
1604-
use EmptyWrite;
1605-
use consensus::{deserialize, Encodable};
1606-
use hashes::hex::FromHex;
1604+
use crate::EmptyWrite;
1605+
use crate::consensus::{deserialize, Encodable};
1606+
use crate::hashes::hex::FromHex;
16071607
use test::{black_box, Bencher};
16081608

16091609
const SOME_TX: &'static str = "0100000001a15d57094aa7a21a28cb20b59aab8fc7d1149a3bdbcddba9c622e4f5f6a99ece010000006c493046022100f93bb0e7d8db7bd46e40132d1f8242026e045f03a0efe71bbb8e3f475e970d790221009337cd7f1f929f00cc6ff01f03729b069a7c21b59b1736ddfee5db5946c5da8c0121033b9b137ee87d5a812d6f506efdd37f0affa7ffc310711c06c7f3e097c9447c52ffffffff0100e1f505000000001976a9140389035a9225b3839e2bbf32d826a1e222031fd888ac00000000";

0 commit comments

Comments
 (0)