From 3ad5f5b38191c4c098631f145ad19dcba8b08449 Mon Sep 17 00:00:00 2001 From: azuchi Date: Thu, 25 Dec 2025 15:05:33 +0900 Subject: [PATCH 1/7] Apply cargo fix --- src/blockdata/block.rs | 34 ++++++++++++------------ src/blockdata/constants.rs | 2 +- src/blockdata/script.rs | 30 +++++++++++----------- src/blockdata/transaction.rs | 32 +++++++++++------------ src/consensus/encode.rs | 30 +++++++++++----------- src/consensus/params.rs | 2 +- src/hash_types.rs | 6 ++--- src/lib.rs | 44 ++++++++++++++++---------------- src/network/address.rs | 8 +++--- src/network/constants.rs | 4 +-- src/network/message.rs | 38 +++++++++++++-------------- src/network/message_blockdata.rs | 12 ++++----- src/network/message_filter.rs | 2 +- src/network/message_network.rs | 18 ++++++------- src/network/stream_reader.rs | 12 ++++----- src/test_helpers.rs | 4 +-- src/util/address.rs | 24 ++++++++--------- src/util/base58.rs | 10 ++++---- src/util/bip143.rs | 26 +++++++++---------- src/util/bip158.rs | 26 +++++++++---------- src/util/bip32.rs | 20 +++++++-------- src/util/contracthash.rs | 22 ++++++++-------- src/util/hash.rs | 4 +-- src/util/key.rs | 14 +++++----- src/util/merkleblock.rs | 28 ++++++++++---------- src/util/misc.rs | 8 +++--- src/util/mod.rs | 4 +-- src/util/prime.rs | 2 +- src/util/psbt/error.rs | 4 +-- src/util/psbt/map/global.rs | 14 +++++----- src/util/psbt/map/input.rs | 18 ++++++------- src/util/psbt/map/mod.rs | 6 ++--- src/util/psbt/map/output.rs | 16 ++++++------ src/util/psbt/mod.rs | 42 +++++++++++++++--------------- src/util/psbt/raw.rs | 6 ++--- src/util/psbt/serialize.rs | 12 ++++----- src/util/rfc6979.rs | 8 +++--- src/util/signature.rs | 20 +++++++-------- src/util/uint.rs | 6 ++--- 39 files changed, 309 insertions(+), 309 deletions(-) diff --git a/src/blockdata/block.rs b/src/blockdata/block.rs index 4e82c885..4bb1654a 100644 --- a/src/blockdata/block.rs +++ b/src/blockdata/block.rs @@ -28,18 +28,18 @@ use std::io; use std::str::FromStr; -use hashes::{Hash, HashEngine}; -use hashes::hex::FromHex; -use hash_types::{Wtxid, BlockHash, BlockSigHash, TxMerkleNode, WitnessMerkleNode, WitnessCommitment, XFieldHash}; -use consensus::{serialize, encode, Decodable, Encodable}; -use consensus::encode::Error; -use consensus::encode::serialize_hex; -use blockdata::constants::WITNESS_SCALE_FACTOR; -use blockdata::transaction::Transaction; -use util::hash::bitcoin_merkle_root; -use util::key::PublicKey; -use util::signature::Signature; -use VarInt; +use crate::hashes::{Hash, HashEngine}; +use crate::hashes::hex::FromHex; +use crate::hash_types::{Wtxid, BlockHash, BlockSigHash, TxMerkleNode, WitnessMerkleNode, WitnessCommitment, XFieldHash}; +use crate::consensus::{serialize, encode, Decodable, Encodable}; +use crate::consensus::encode::Error; +use crate::consensus::encode::serialize_hex; +use crate::blockdata::constants::WITNESS_SCALE_FACTOR; +use crate::blockdata::transaction::Transaction; +use crate::util::hash::bitcoin_merkle_root; +use crate::util::key::PublicKey; +use crate::util::signature::Signature; +use crate::VarInt; /// A block header, which contains all the block's information except @@ -399,11 +399,11 @@ impl_consensus_encoding!( mod tests { use std::str::FromStr; - use blockdata::block::{Block, XField}; - use consensus::encode::{deserialize, serialize, Error}; - use util::key::PublicKey; - use hash_types::{BlockSigHash, XFieldHash}; - use hashes::hex::FromHex; + use crate::blockdata::block::{Block, XField}; + use crate::consensus::encode::{deserialize, serialize, Error}; + use crate::util::key::PublicKey; + use crate::hash_types::{BlockSigHash, XFieldHash}; + use crate::hashes::hex::FromHex; #[test] fn block_test() { diff --git a/src/blockdata/constants.rs b/src/blockdata/constants.rs index f301805a..2eb1e9b7 100644 --- a/src/blockdata/constants.rs +++ b/src/blockdata/constants.rs @@ -24,7 +24,7 @@ //! single transaction //! -use network::constants::Network; +use crate::network::constants::Network; /// The maximum allowable sequence number pub const MAX_SEQUENCE: u32 = 0xFFFFFFFF; diff --git a/src/blockdata/script.rs b/src/blockdata/script.rs index 641771b5..02fc982e 100644 --- a/src/blockdata/script.rs +++ b/src/blockdata/script.rs @@ -30,18 +30,18 @@ use std::str::FromStr; #[cfg(feature = "serde")] use serde; -use hash_types::{ScriptHash, WScriptHash}; -use blockdata::opcodes; -use blockdata::transaction::OutPoint; -use consensus::{deserialize, encode, Decodable, Encodable}; -use consensus::encode::serialize_hex; -use hashes::hex::FromHex; -use hashes::{sha256, Hash}; +use crate::hash_types::{ScriptHash, WScriptHash}; +use crate::blockdata::opcodes; +use crate::blockdata::transaction::OutPoint; +use crate::consensus::{deserialize, encode, Decodable, Encodable}; +use crate::consensus::encode::serialize_hex; +use crate::hashes::hex::FromHex; +use crate::hashes::{sha256, Hash}; #[cfg(feature="bitcoinconsensus")] use bitcoinconsensus; #[cfg(feature="bitcoinconsensus")] use std::convert; -use util::key::PublicKey; +use crate::util::key::PublicKey; #[derive(Clone, Default, PartialOrd, Ord, PartialEq, Eq, Hash)] /// A Bitcoin script @@ -510,7 +510,7 @@ impl Script { /// it as a slice using `script[..]` or convert it to a vector using `into_bytes()`. /// /// To force minimal pushes, use [instructions_minimal]. - pub fn instructions(&self) -> Instructions { + pub fn instructions(&self) -> Instructions<'_> { Instructions { data: &self.0[..], enforce_minimal: false, @@ -519,7 +519,7 @@ impl Script { /// Iterate over the script in the form of `Instruction`s while enforcing /// minimal pushes. - pub fn instructions_minimal(&self) -> Instructions { + pub fn instructions_minimal(&self) -> Instructions<'_> { Instructions { data: &self.0[..], enforce_minimal: true, @@ -1178,11 +1178,11 @@ mod test { use super::*; use super::build_scriptint; - use consensus::encode::{deserialize, serialize}; - use blockdata::opcodes; - use util::key::PublicKey; - use hash_types::Txid; - use hashes::hex::FromHex; + use crate::consensus::encode::{deserialize, serialize}; + use crate::blockdata::opcodes; + use crate::util::key::PublicKey; + use crate::hash_types::Txid; + use crate::hashes::hex::FromHex; #[test] fn script() { diff --git a/src/blockdata/transaction.rs b/src/blockdata/transaction.rs index 25e9a0e4..232d74cd 100644 --- a/src/blockdata/transaction.rs +++ b/src/blockdata/transaction.rs @@ -31,16 +31,16 @@ use std::default::Default; use std::{fmt, io}; -use hashes::{self, Hash, sha256d}; -use hashes::hex::FromHex; +use crate::hashes::{self, Hash, sha256d}; +use crate::hashes::hex::FromHex; -use util::endian; -use blockdata::constants::WITNESS_SCALE_FACTOR; +use crate::util::endian; +use crate::blockdata::constants::WITNESS_SCALE_FACTOR; #[cfg(feature="bitcoinconsensus")] use blockdata::script; -use blockdata::script::Script; -use consensus::{encode, Decodable, Encodable}; -use hash_types::*; -use VarInt; +use crate::blockdata::script::Script; +use crate::consensus::{encode, Decodable, Encodable}; +use crate::hash_types::*; +use crate::VarInt; /// A reference to a transaction output #[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] @@ -641,15 +641,15 @@ mod tests { use super::{OutPoint, ParseOutPointError, Transaction, TxIn}; use std::str::FromStr; - use blockdata::constants::WITNESS_SCALE_FACTOR; - use blockdata::script::Script; - use consensus::encode::serialize; - use consensus::encode::deserialize; + use crate::blockdata::constants::WITNESS_SCALE_FACTOR; + use crate::blockdata::script::Script; + use crate::consensus::encode::serialize; + use crate::consensus::encode::deserialize; - use hashes::Hash; - use hashes::hex::FromHex; + use crate::hashes::Hash; + use crate::hashes::hex::FromHex; - use hash_types::*; + use crate::hash_types::*; #[test] fn test_outpoint() { @@ -702,7 +702,7 @@ mod tests { #[test] fn test_is_coinbase () { - use blockdata::block::Block; + use crate::blockdata::block::Block; let hex_block = Vec::from_hex("010000000000000000000000000000000000000000000000000000000000000000000000c0d6961ad2819f74eb6d085f04f9cceb0a9a6d5c153fd3c39fc47c3ca0bb548f85fbd09a5f7d8ac4c9552e52931ef6672984f64e52ad6d05d1cdb18907da8527db317c5e012103addb2555f37abf8f28f11f498bec7bd1460e7243c1813847c49a7ae326a97d1c40e2d9e39bfb25f5534cf3fa235697e18efa81ce02e161946a73b9b20b3641576a9636f19747447ab8b02a97a9d96ecdaf0aa3a56b93f9e8f81d55252854270617010100000001000000000000000000000000000000000000000000000000000000000000000000000000222103addb2555f37abf8f28f11f498bec7bd1460e7243c1813847c49a7ae326a97d1cffffffff0100f2052a010000001976a914a15f16ea2ba840d178e4c19781abca5f4fb1b4c288ac00000000").unwrap(); let block: Block = deserialize(&hex_block).unwrap(); assert! (block.txdata[0].is_coin_base()); diff --git a/src/consensus/encode.rs b/src/consensus/encode.rs index 522402a7..45262e53 100644 --- a/src/consensus/encode.rs +++ b/src/consensus/encode.rs @@ -32,19 +32,19 @@ use std::{fmt, error, io, mem, u32}; use std::borrow::Cow; use std::io::{Cursor, Read, Write}; -use hashes::hex::ToHex; +use crate::hashes::hex::ToHex; -use hashes::{sha256d, Hash}; -use hash_types::{BlockHash, FilterHash, TxMerkleNode}; +use crate::hashes::{sha256d, Hash}; +use crate::hash_types::{BlockHash, FilterHash, TxMerkleNode}; -use util::endian; -use util::psbt; -use util::key; -use util::signature::Signature; +use crate::util::endian; +use crate::util::psbt; +use crate::util::key; +use crate::util::signature::Signature; -use blockdata::transaction::{TxOut, Transaction, TxIn}; -use network::message_blockdata::Inventory; -use network::address::Address; +use crate::blockdata::transaction::{TxOut, Transaction, TxIn}; +use crate::network::message_blockdata::Inventory; +use crate::network::address::Address; /// Encoding error #[derive(Debug)] @@ -799,12 +799,12 @@ mod tests { use std::mem::discriminant; use super::{deserialize, serialize, Error, CheckedData, VarInt}; use super::{Transaction, BlockHash, FilterHash, TxMerkleNode, TxOut, TxIn}; - use consensus::{Encodable, deserialize_partial, Decodable}; - use util::endian::{u64_to_array_le, u32_to_array_le, u16_to_array_le}; + use crate::consensus::{Encodable, deserialize_partial, Decodable}; + use crate::util::endian::{u64_to_array_le, u32_to_array_le, u16_to_array_le}; use secp256k1::rand::{thread_rng, Rng}; - use network::message_blockdata::Inventory; - use network::Address; - use util::signature::Signature; + use crate::network::message_blockdata::Inventory; + use crate::network::Address; + use crate::util::signature::Signature; #[test] fn serialize_int_test() { diff --git a/src/consensus/params.rs b/src/consensus/params.rs index b6c674e5..6deb41ae 100644 --- a/src/consensus/params.rs +++ b/src/consensus/params.rs @@ -22,7 +22,7 @@ //! This module provides predefined set of parameters for different chains. //! -use network::constants::Network; +use crate::network::constants::Network; #[derive(Debug, Clone)] /// Parameters that influence chain consensus. diff --git a/src/hash_types.rs b/src/hash_types.rs index b2db9b01..878d6510 100644 --- a/src/hash_types.rs +++ b/src/hash_types.rs @@ -16,9 +16,9 @@ //! to avoid mixing data of the same hash format (like SHA256d) but of different meaning //! (transaction id, block hash etc). -use consensus::encode::{Encodable, Decodable, Error}; -use hashes::{Hash, sha256, sha256d, ripemd160, hash160}; -use hashes::hex::{FromHex, ToHex}; +use crate::consensus::encode::{Encodable, Decodable, Error}; +use crate::hashes::{Hash, sha256, sha256d, ripemd160, hash160}; +use crate::hashes::hex::{FromHex, ToHex}; macro_rules! impl_hashencode { ($hashtype:ident) => { diff --git a/src/lib.rs b/src/lib.rs index 627ba069..703d7911 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -81,25 +81,25 @@ pub mod consensus; #[allow(unused_imports)] pub mod hash_types; -pub use hash_types::*; -pub use blockdata::block::Block; -pub use blockdata::block::BlockHeader; -pub use blockdata::script::Script; -pub use blockdata::script::ColorIdentifier; -pub use blockdata::transaction::Transaction; -pub use blockdata::transaction::TxIn; -pub use blockdata::transaction::TxOut; -pub use blockdata::transaction::OutPoint; -pub use blockdata::transaction::SigHashType; -pub use consensus::encode::VarInt; -pub use network::constants::Network; -pub use util::Error; -pub use util::address::Address; -pub use util::address::AddressType; -pub use util::amount::Amount; -pub use util::amount::Denomination; -pub use util::amount::SignedAmount; -pub use util::key::PrivateKey; -pub use util::key::PublicKey; -pub use util::merkleblock::MerkleBlock; -pub use util::signature::Signature; +pub use crate::hash_types::*; +pub use crate::blockdata::block::Block; +pub use crate::blockdata::block::BlockHeader; +pub use crate::blockdata::script::Script; +pub use crate::blockdata::script::ColorIdentifier; +pub use crate::blockdata::transaction::Transaction; +pub use crate::blockdata::transaction::TxIn; +pub use crate::blockdata::transaction::TxOut; +pub use crate::blockdata::transaction::OutPoint; +pub use crate::blockdata::transaction::SigHashType; +pub use crate::consensus::encode::VarInt; +pub use crate::network::constants::Network; +pub use crate::util::Error; +pub use crate::util::address::Address; +pub use crate::util::address::AddressType; +pub use crate::util::amount::Amount; +pub use crate::util::amount::Denomination; +pub use crate::util::amount::SignedAmount; +pub use crate::util::key::PrivateKey; +pub use crate::util::key::PublicKey; +pub use crate::util::merkleblock::MerkleBlock; +pub use crate::util::signature::Signature; diff --git a/src/network/address.rs b/src/network/address.rs index 6edc5bb5..ef118d0f 100644 --- a/src/network/address.rs +++ b/src/network/address.rs @@ -22,8 +22,8 @@ use std::io; use std::fmt; use std::net::{SocketAddr, Ipv6Addr, SocketAddrV4, SocketAddrV6}; -use network::constants::ServiceFlags; -use consensus::encode::{self, Decodable, Encodable}; +use crate::network::constants::ServiceFlags; +use crate::consensus::encode::{self, Decodable, Encodable}; /// A message which can be sent on the Bitcoin network #[derive(Clone, PartialEq, Eq, Hash)] @@ -114,10 +114,10 @@ impl fmt::Debug for Address { mod test { use std::str::FromStr; use super::Address; - use network::constants::ServiceFlags; + use crate::network::constants::ServiceFlags; use std::net::{SocketAddr, IpAddr, Ipv4Addr, Ipv6Addr}; - use consensus::encode::{deserialize, serialize}; + use crate::consensus::encode::{deserialize, serialize}; #[test] fn serialize_address_test() { diff --git a/src/network/constants.rs b/src/network/constants.rs index edb6eeca..1d290fed 100644 --- a/src/network/constants.rs +++ b/src/network/constants.rs @@ -44,7 +44,7 @@ use std::{fmt, io, ops}; use std::str::FromStr; -use consensus::encode::{self, Encodable, Decodable}; +use crate::consensus::encode::{self, Encodable, Decodable}; /// Version of the protocol as appearing in network message headers pub const PROTOCOL_VERSION: u32 = 10000; @@ -317,7 +317,7 @@ impl Decodable for ServiceFlags { mod tests { use std::str::FromStr; use super::{NetworkId, Network, ServiceFlags}; - use consensus::encode::{deserialize, serialize}; + use crate::consensus::encode::{deserialize, serialize}; #[test] fn serialize_test() { diff --git a/src/network/message.rs b/src/network/message.rs index 56b7d12e..ddf96483 100644 --- a/src/network/message.rs +++ b/src/network/message.rs @@ -23,15 +23,15 @@ use std::{io, iter, mem, fmt}; use std::borrow::Cow; use std::io::Cursor; -use blockdata::block; -use blockdata::transaction; -use network::address::Address; -use network::message_network; -use network::message_blockdata; -use network::message_filter; -use consensus::encode::{CheckedData, Decodable, Encodable, VarInt}; -use consensus::{encode, serialize}; -use consensus::encode::MAX_VEC_SIZE; +use crate::blockdata::block; +use crate::blockdata::transaction; +use crate::network::address::Address; +use crate::network::message_network; +use crate::network::message_blockdata; +use crate::network::message_filter; +use crate::consensus::encode::{CheckedData, Decodable, Encodable, VarInt}; +use crate::consensus::{encode, serialize}; +use crate::consensus::encode::MAX_VEC_SIZE; /// Serializer for command string #[derive(PartialEq, Eq, Clone, Debug)] @@ -337,17 +337,17 @@ impl Decodable for RawNetworkMessage { mod test { use std::io; use super::{RawNetworkMessage, NetworkMessage, CommandString}; - use network::constants::ServiceFlags; - use consensus::encode::{Encodable, deserialize, deserialize_partial, serialize}; - use hashes::hex::FromHex; - use hashes::sha256d::Hash; - use hashes::Hash as HashTrait; - use network::address::Address; + use crate::network::constants::ServiceFlags; + use crate::consensus::encode::{Encodable, deserialize, deserialize_partial, serialize}; + use crate::hashes::hex::FromHex; + use crate::hashes::sha256d::Hash; + use crate::hashes::Hash as HashTrait; + use crate::network::address::Address; use super::message_network::{Reject, RejectReason, VersionMessage}; - use network::message_blockdata::{Inventory, GetBlocksMessage, GetHeadersMessage}; - use blockdata::block::{Block, BlockHeader}; - use network::message_filter::{GetCFilters, CFilter, GetCFHeaders, CFHeaders, GetCFCheckpt, CFCheckpt}; - use blockdata::transaction::Transaction; + use crate::network::message_blockdata::{Inventory, GetBlocksMessage, GetHeadersMessage}; + use crate::blockdata::block::{Block, BlockHeader}; + use crate::network::message_filter::{GetCFilters, CFilter, GetCFHeaders, CFHeaders, GetCFCheckpt, CFCheckpt}; + use crate::blockdata::transaction::Transaction; fn hash(slice: [u8;32]) -> Hash { Hash::from_slice(&slice).unwrap() diff --git a/src/network/message_blockdata.rs b/src/network/message_blockdata.rs index 60320749..dbb15b6c 100644 --- a/src/network/message_blockdata.rs +++ b/src/network/message_blockdata.rs @@ -20,11 +20,11 @@ use std::io; -use hashes::sha256d; +use crate::hashes::sha256d; -use network::constants; -use consensus::encode::{self, Decodable, Encodable}; -use hash_types::{BlockHash, Txid}; +use crate::network::constants; +use crate::consensus::encode::{self, Decodable, Encodable}; +use crate::hash_types::{BlockHash, Txid}; /// An inventory item. #[derive(PartialEq, Eq, Clone, Debug, Copy, Hash)] @@ -136,9 +136,9 @@ impl_consensus_encoding!(GetHeadersMessage, version, locator_hashes, stop_hash); mod tests { use super::{GetHeadersMessage, GetBlocksMessage}; - use hashes::hex::FromHex; + use crate::hashes::hex::FromHex; - use consensus::encode::{deserialize, serialize}; + use crate::consensus::encode::{deserialize, serialize}; use std::default::Default; #[test] diff --git a/src/network/message_filter.rs b/src/network/message_filter.rs index 4aaca151..4046f6eb 100644 --- a/src/network/message_filter.rs +++ b/src/network/message_filter.rs @@ -2,7 +2,7 @@ //! BIP157 Client Side Block Filtering network messages //! -use hash_types::{BlockHash, FilterHash}; +use crate::hash_types::{BlockHash, FilterHash}; #[derive(PartialEq, Eq, Clone, Debug)] /// getcfilters message diff --git a/src/network/message_network.rs b/src/network/message_network.rs index c3d90940..471fcd1b 100644 --- a/src/network/message_network.rs +++ b/src/network/message_network.rs @@ -21,12 +21,12 @@ use std::io; use std::borrow::Cow; -use network::address::Address; -use network::constants::{self, ServiceFlags}; -use consensus::{Encodable, Decodable, ReadExt}; -use consensus::encode; -use network::message::CommandString; -use hashes::sha256d; +use crate::network::address::Address; +use crate::network::constants::{self, ServiceFlags}; +use crate::consensus::{Encodable, Decodable, ReadExt}; +use crate::consensus::encode; +use crate::network::message::CommandString; +use crate::hashes::sha256d; /// Some simple messages @@ -147,10 +147,10 @@ impl_consensus_encoding!(Reject, message, ccode, reason, hash); mod tests { use super::VersionMessage; - use hashes::hex::FromHex; - use network::constants::ServiceFlags; + use crate::hashes::hex::FromHex; + use crate::network::constants::ServiceFlags; - use consensus::encode::{deserialize, serialize}; + use crate::consensus::encode::{deserialize, serialize}; #[test] fn version_message_test() { diff --git a/src/network/stream_reader.rs b/src/network/stream_reader.rs index fabab8d3..766358f7 100644 --- a/src/network/stream_reader.rs +++ b/src/network/stream_reader.rs @@ -23,7 +23,7 @@ use std::fmt; use std::io::{self, Read}; -use consensus::{encode, Decodable}; +use crate::consensus::{encode, Decodable}; /// Struct used to configure stream reader function pub struct StreamReader { @@ -86,10 +86,10 @@ mod test { use std::io::{self, BufReader, Write}; use std::net::{TcpListener, TcpStream, Shutdown}; use std::thread::JoinHandle; - use network::constants::ServiceFlags; + use crate::network::constants::ServiceFlags; use super::StreamReader; - use network::message::{NetworkMessage, RawNetworkMessage}; + use crate::network::message::{NetworkMessage, RawNetworkMessage}; // First, let's define some byte arrays for sample messages - dumps are taken from live // Bitcoin Core node v0.17.1 with Wireshark @@ -314,9 +314,9 @@ mod test { #[test] fn read_block_from_file_test() { use std::io; - use consensus::serialize; - use hashes::hex::FromHex; - use Block; + use crate::consensus::serialize; + use crate::hashes::hex::FromHex; + use crate::Block; let normal_data = Vec::from_hex("010000004ddccd549d28f385ab457e98d1b11ce80bfea2c5ab93015ade4973e400000000bf4473e53794beae34e64fccc471dace6ae544180816f89591894e0f417a914c364243a74762685f916378ce87c5384ad39b594aca206426d9d244ef51d644d2d74d6e490121032e58afe51f9ed8ad3cc7897f634d881fdbe49a81564629ded8156bebd2ffd1af000201000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0804ffff001d026e04ffffffff0100f2052a0100000043410446ef0102d1ec5240f0d061a4246c1bdef63fc3dbab7733052fbbf0ecd8f41fc26bf049ebb4f9527f374280259e7cfa99c48b0e3f39c51347a19a5819651503a5ac00000000010000000321f75f3139a013f50f315b23b0c9a2b6eac31e2bec98e5891c924664889942260000000049483045022100cb2c6b346a978ab8c61b18b5e9397755cbd17d6eb2fe0083ef32e067fa6c785a02206ce44e613f31d9a6b0517e46f3db1576e9812cc98d159bfdaf759a5014081b5c01ffffffff79cda0945903627c3da1f85fc95d0b8ee3e76ae0cfdc9a65d09744b1f8fc85430000000049483045022047957cdd957cfd0becd642f6b84d82f49b6cb4c51a91f49246908af7c3cfdf4a022100e96b46621f1bffcf5ea5982f88cef651e9354f5791602369bf5a82a6cd61a62501fffffffffe09f5fe3ffbf5ee97a54eb5e5069e9da6b4856ee86fc52938c2f979b0f38e82000000004847304402204165be9a4cbab8049e1af9723b96199bfd3e85f44c6b4c0177e3962686b26073022028f638da23fc003760861ad481ead4099312c60030d4cb57820ce4d33812a5ce01ffffffff01009d966b01000000434104ea1feff861b51fe3f5f8a3b12d0f4712db80e919548a80839fc47c6a21e66d957e9c5d8cd108c7a2d2324bad71f9904ac0ae7336507d785b17a2c115e427a32fac00000000").unwrap(); let cutoff_data = Vec::from_hex("010000004ddccd549d28f385ab457e98d1b11ce80bfea2c5ab93015ade4973e400000000bf4473e53794beae34e64fccc471dace6ae544180816f89591894e0f417a914c364243a74762685f916378ce87c5384ad39b594aca206426d9d244ef51d644d2d74d6e490121032e58afe51f9ed8ad3cc7897f634d881fdbe49a81564629ded8156bebd2ffd1af000201000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0804ffff001d026e04ffffffff0100f2052a0100000043410446ef0102d1ec5240f0d061a4246c1bdef63fc3dbab7733052fbbf0ecd8f41fc26bf049ebb4f9527f374280259e7cfa99c48b0e3f39c51347a19a5819651503a5ac00000000010000000321f75f3139a013f50f315b23b0c9a2b6eac31e2bec98e5891c924664889942260000000049483045022100cb2c6b346a978ab8c61b18b5e9397755cbd17d6eb2fe0083ef32e067fa6c785a02206ce44e613f31d9a6b0517e46f3db1576e9812cc98d159bfdaf759a5014081b5c01ffffffff79cda0945903627c3da1f85fc95d0b8ee3e76ae0cfdc9a65d09744b1f8fc85430000000049483045022047957cdd957cfd0becd642f6b84d82f49b6cb4c51a91f49246908af7c3cfdf4a022100e96b46621f1bffcf5ea5982f88cef651e9354f5791602369bf5a82a6cd61a62501fffffffffe09f5fe3ffbf5ee97a54eb5e5069e9da6b4856ee86fc52938c2f979b0f38e82000000004847304402204165be9a4cbab8049e1af9723b96199bfd3e85f44c6b4c0177e3962686b26073022028f638da23fc003760861ad481ead4099312c60030d4cb57820ce4d33812a5ce01ffffffff01009d966b01000000434104ea1feff861b51fe3f5f8a3b12d0f4712db80e919548a80839fc47c6a21e66d957e9c5d8cd108c7a2d2324bad71f9904ac0ae7336507d785b17a2c115e427a32fac").unwrap(); diff --git a/src/test_helpers.rs b/src/test_helpers.rs index e7fe5387..ee4f99df 100644 --- a/src/test_helpers.rs +++ b/src/test_helpers.rs @@ -7,8 +7,8 @@ //! use secp256k1::SecretKey; -use util::signature::Signature; -use consensus::deserialize; +use crate::util::signature::Signature; +use crate::consensus::deserialize; pub fn decode_sk(sk_hex: &str) -> SecretKey { let sk = hex::decode(sk_hex).unwrap(); diff --git a/src/util/address.rs b/src/util/address.rs index 8ed01c3d..4e0693d2 100644 --- a/src/util/address.rs +++ b/src/util/address.rs @@ -44,15 +44,15 @@ use std::fmt::{self, Display, Formatter}; use std::str::FromStr; -use hashes::Hash; -use hashes::hex::FromHex; +use crate::hashes::Hash; +use crate::hashes::hex::FromHex; -use hash_types::{PubkeyHash, ScriptHash}; -use blockdata::opcodes; -use blockdata::script::{Builder, ColorIdentifier, Script}; -use network::constants::Network; -use util::base58; -use util::key; +use crate::hash_types::{PubkeyHash, ScriptHash}; +use crate::blockdata::opcodes; +use crate::blockdata::script::{Builder, ColorIdentifier, Script}; +use crate::network::constants::Network; +use crate::util::base58; +use crate::util::key; /// Address error. #[derive(Debug, PartialEq)] @@ -404,11 +404,11 @@ mod tests { use std::str::FromStr; use std::string::ToString; - use hashes::hex::FromHex; + use crate::hashes::hex::FromHex; - use blockdata::script::Script; - use network::constants::Network::{Prod, Dev}; - use util::key::PublicKey; + use crate::blockdata::script::Script; + use crate::network::constants::Network::{Prod, Dev}; + use crate::util::key::PublicKey; use super::*; diff --git a/src/util/base58.rs b/src/util/base58.rs index 9b8dfb2e..718c1c68 100644 --- a/src/util/base58.rs +++ b/src/util/base58.rs @@ -16,9 +16,9 @@ use std::{error, fmt, iter, slice, str}; -use hashes::{sha256d, Hash}; +use crate::hashes::{sha256d, Hash}; -use util::endian; +use crate::util::endian; /// An error that might occur during base58 decoding #[derive(Debug, PartialEq, Eq, Clone)] @@ -91,12 +91,12 @@ impl SmallVec { } } - pub fn iter(&self) -> iter::Chain, slice::Iter> { + pub fn iter(&self) -> iter::Chain, slice::Iter<'_, T>> { // If len<100 then we just append an empty vec self.stack[0..self.len].iter().chain(self.heap.iter()) } - pub fn iter_mut(&mut self) -> iter::Chain, slice::IterMut> { + pub fn iter_mut(&mut self) -> iter::Chain, slice::IterMut<'_, T>> { // If len<100 then we just append an empty vec self.stack[0..self.len] .iter_mut() @@ -362,7 +362,7 @@ pub fn check_encode_slice_to_fmt(fmt: &mut fmt::Formatter, data: &[u8]) -> fmt:: #[cfg(test)] mod tests { use super::*; - use hashes::hex::FromHex; + use crate::hashes::hex::FromHex; #[test] fn test_base58_encode() { diff --git a/src/util/bip143.rs b/src/util/bip143.rs index db64ec82..caaa76d8 100644 --- a/src/util/bip143.rs +++ b/src/util/bip143.rs @@ -19,11 +19,11 @@ //! signatures, which are placed in the scriptSig. //! -use hashes::{Hash, sha256d}; -use hash_types::SigHash; -use blockdata::script::Script; -use blockdata::transaction::{Transaction, TxIn, SigHashType}; -use consensus::encode::Encodable; +use crate::hashes::{Hash, sha256d}; +use crate::hash_types::SigHash; +use crate::blockdata::script::Script; +use crate::blockdata::transaction::{Transaction, TxIn, SigHashType}; +use crate::consensus::encode::Encodable; use std::ops::{Deref, DerefMut}; @@ -248,14 +248,14 @@ impl> SigHashCache { #[cfg(test)] #[allow(deprecated)] mod tests { - use hash_types::SigHash; - use blockdata::script::Script; - use blockdata::transaction::Transaction; - use consensus::encode::deserialize; - use network::constants::Network; - use util::address::Address; - use util::key::PublicKey; - use hashes::hex::FromHex; + use crate::hash_types::SigHash; + use crate::blockdata::script::Script; + use crate::blockdata::transaction::Transaction; + use crate::consensus::encode::deserialize; + use crate::network::constants::Network; + use crate::util::address::Address; + use crate::util::key::PublicKey; + use crate::hashes::hex::FromHex; use super::*; diff --git a/src/util/bip158.rs b/src/util/bip158.rs index 81ee9651..04d595cc 100644 --- a/src/util/bip158.rs +++ b/src/util/bip158.rs @@ -56,15 +56,15 @@ use std::fmt::{Display, Formatter}; use std::io::Cursor; use std::cmp::Ordering; -use hashes::{Hash, siphash24}; -use hash_types::{BlockHash, FilterHash}; +use crate::hashes::{Hash, siphash24}; +use crate::hash_types::{BlockHash, FilterHash}; -use blockdata::block::Block; -use blockdata::script::Script; -use blockdata::transaction::OutPoint; -use consensus::{Decodable, Encodable}; -use consensus::encode::VarInt; -use util::endian; +use crate::blockdata::block::Block; +use crate::blockdata::script::Script; +use crate::blockdata::transaction::OutPoint; +use crate::consensus::{Decodable, Encodable}; +use crate::consensus::encode::VarInt; +use crate::util::endian; /// Golomb encoding parameter as in BIP-158, see also https://gist.github.com/sipa/576d5f09c3b86c3b1b75598d799fc845 const P: u8 = 19; @@ -445,7 +445,7 @@ pub struct BitStreamReader<'a> { impl<'a> BitStreamReader<'a> { /// Create a new BitStreamReader that reads bitwise from a given reader - pub fn new(reader: &'a mut io::Read) -> BitStreamReader { + pub fn new(reader: &'a mut io::Read) -> BitStreamReader<'a> { BitStreamReader { buffer: [0u8], reader: reader, @@ -483,7 +483,7 @@ pub struct BitStreamWriter<'a> { impl<'a> BitStreamWriter<'a> { /// Create a new BitStreamWriter that writes bitwise to a given writer - pub fn new(writer: &'a mut io::Write) -> BitStreamWriter { + pub fn new(writer: &'a mut io::Write) -> BitStreamWriter<'a> { BitStreamWriter { buffer: [0u8], writer: writer, @@ -527,8 +527,8 @@ mod test { use std::collections::{HashSet, HashMap}; use std::io::Cursor; - use hash_types::BlockHash; - use hashes::hex::FromHex; + use crate::hash_types::BlockHash; + use crate::hashes::hex::FromHex; use super::*; @@ -536,7 +536,7 @@ mod test { extern crate serde_json; use self::serde_json::{Value}; - use consensus::encode::deserialize; + use crate::consensus::encode::deserialize; #[test] #[ignore] diff --git a/src/util/bip32.rs b/src/util/bip32.rs index 1ea13c88..66b96364 100644 --- a/src/util/bip32.rs +++ b/src/util/bip32.rs @@ -27,13 +27,13 @@ use std::default::Default; use std::str::FromStr; use std::{error, fmt}; -use hash_types::XpubIdentifier; -use hashes::{sha512, Hash, HashEngine, Hmac, HmacEngine}; +use crate::hash_types::XpubIdentifier; +use crate::hashes::{sha512, Hash, HashEngine, Hmac, HmacEngine}; use secp256k1::{self, Secp256k1}; -use network::constants::Network; -use util::{base58, endian}; -use util::key::{PublicKey, PrivateKey}; +use crate::network::constants::Network; +use crate::util::{base58, endian}; +use crate::util::key::{PublicKey, PrivateKey}; /// A chain code pub struct ChainCode([u8; 32]); @@ -318,17 +318,17 @@ impl DerivationPath { /// Get an [Iterator] over the children of this [DerivationPath] /// starting with the given [ChildNumber]. - pub fn children_from(&self, cn: ChildNumber) -> DerivationPathIterator { + pub fn children_from(&self, cn: ChildNumber) -> DerivationPathIterator<'_> { DerivationPathIterator::start_from(&self, cn) } /// Get an [Iterator] over the unhardened children of this [DerivationPath]. - pub fn normal_children(&self) -> DerivationPathIterator { + pub fn normal_children(&self) -> DerivationPathIterator<'_> { DerivationPathIterator::start_from(&self, ChildNumber::Normal{ index: 0 }) } /// Get an [Iterator] over the hardened children of this [DerivationPath]. - pub fn hardened_children(&self) -> DerivationPathIterator { + pub fn hardened_children(&self) -> DerivationPathIterator<'_> { DerivationPathIterator::start_from(&self, ChildNumber::Hardened{ index: 0 }) } } @@ -717,9 +717,9 @@ mod tests { use std::string::ToString; use secp256k1::{self, Secp256k1}; - use hashes::hex::FromHex; + use crate::hashes::hex::FromHex; - use network::constants::Network::{self, Prod}; + use crate::network::constants::Network::{self, Prod}; #[test] fn test_parse_derivation_path() { diff --git a/src/util/contracthash.rs b/src/util/contracthash.rs index fa5c35f2..90b300d2 100644 --- a/src/util/contracthash.rs +++ b/src/util/contracthash.rs @@ -21,16 +21,16 @@ #![cfg_attr(not(test), deprecated)] use secp256k1::{self, Secp256k1}; -use PrivateKey; -use PublicKey; -use hashes::{sha256, Hash, HashEngine, Hmac, HmacEngine}; -use blockdata::{opcodes, script}; +use crate::PrivateKey; +use crate::PublicKey; +use crate::hashes::{sha256, Hash, HashEngine, Hmac, HmacEngine}; +use crate::blockdata::{opcodes, script}; use std::{error, fmt}; -use hash_types::ScriptHash; -use network::constants::Network; -use util::address; +use crate::hash_types::ScriptHash; +use crate::network::constants::Network; +use crate::util::address; /// Encoding of "pubkey here" in script; from Bitcoin Core `src/script/script.h` static PUBKEY: u8 = 0xFE; @@ -281,15 +281,15 @@ pub fn untemplate(script: &script::Script) -> Result<(Template, Vec), #[cfg(test)] mod tests { use secp256k1::Secp256k1; - use hashes::hex::FromHex; + use crate::hashes::hex::FromHex; use secp256k1::rand::thread_rng; use std::str::FromStr; - use blockdata::script::Script; - use network::constants::Network; + use crate::blockdata::script::Script; + use crate::network::constants::Network; use super::*; - use PublicKey; + use crate::PublicKey; macro_rules! hex (($hex:expr) => (Vec::from_hex($hex).unwrap())); macro_rules! hex_key (($hex:expr) => (PublicKey::from_slice(&hex!($hex)).unwrap())); diff --git a/src/util/hash.rs b/src/util/hash.rs index af2a9b5c..440e3e22 100644 --- a/src/util/hash.rs +++ b/src/util/hash.rs @@ -23,8 +23,8 @@ use std::cmp::min; use std::io; -use hashes::Hash; -use consensus::encode::Encodable; +use crate::hashes::Hash; +use crate::consensus::encode::Encodable; /// Calculates the merkle root of a list of hashes inline /// into the allocated slice. diff --git a/src/util/key.rs b/src/util/key.rs index d470dff6..46f578d5 100644 --- a/src/util/key.rs +++ b/src/util/key.rs @@ -25,10 +25,10 @@ use std::fmt::{self, Write}; use std::{io, ops, error}; use std::str::FromStr; -use consensus::{encode, Decodable, Encodable}; -use network::constants::Network; +use crate::consensus::{encode, Decodable, Encodable}; +use crate::network::constants::Network; use secp256k1::{self, Secp256k1}; -use util::base58; +use crate::util::base58; /// A key-related error. #[derive(Debug)] @@ -395,9 +395,9 @@ mod tests { use super::{PrivateKey, PublicKey}; use secp256k1::Secp256k1; use std::str::FromStr; - use network::constants::Network::Dev; - use network::constants::Network::Prod; - use util::address::Address; + use crate::network::constants::Network::Dev; + use crate::network::constants::Network::Prod; + use crate::util::address::Address; #[test] fn test_key_derivation() { @@ -483,7 +483,7 @@ mod tests { #[test] fn test_encode() { - use consensus::encode::{Decodable, Encodable}; + use crate::consensus::encode::{Decodable, Encodable}; let pk = PublicKey::from_str( "032e58afe51f9ed8ad3cc7897f634d881fdbe49a81564629ded8156bebd2ffd1af", diff --git a/src/util/merkleblock.rs b/src/util/merkleblock.rs index d6cae93a..c89d3ccd 100644 --- a/src/util/merkleblock.rs +++ b/src/util/merkleblock.rs @@ -63,14 +63,14 @@ use std::collections::HashSet; use std::io; -use hashes::Hash; -use hash_types::{Txid, TxMerkleNode}; +use crate::hashes::Hash; +use crate::hash_types::{Txid, TxMerkleNode}; -use blockdata::transaction::Transaction; -use blockdata::constants::{MAX_BLOCK_WEIGHT, MIN_TRANSACTION_WEIGHT}; -use consensus::encode::{self, Decodable, Encodable}; -use util::merkleblock::MerkleBlockError::*; -use {Block, BlockHeader}; +use crate::blockdata::transaction::Transaction; +use crate::blockdata::constants::{MAX_BLOCK_WEIGHT, MIN_TRANSACTION_WEIGHT}; +use crate::consensus::encode::{self, Decodable, Encodable}; +use crate::util::merkleblock::MerkleBlockError::*; +use crate::{Block, BlockHeader}; /// An error when verifying the merkle block #[derive(Clone, PartialEq, Eq, Debug)] @@ -507,15 +507,15 @@ impl Decodable for MerkleBlock { mod tests { use std::cmp::min; - use hashes::Hash; - use hashes::hex::{FromHex, ToHex}; - use hash_types::{Txid, TxMerkleNode}; + use crate::hashes::Hash; + use crate::hashes::hex::{FromHex, ToHex}; + use crate::hash_types::{Txid, TxMerkleNode}; use secp256k1::rand::prelude::*; - use consensus::encode::{deserialize, serialize}; - use util::hash::bitcoin_merkle_root; - use util::merkleblock::{MerkleBlock, PartialMerkleTree}; - use Block; + use crate::consensus::encode::{deserialize, serialize}; + use crate::util::hash::bitcoin_merkle_root; + use crate::util::merkleblock::{MerkleBlock, PartialMerkleTree}; + use crate::Block; #[test] fn pmt_tests() { diff --git a/src/util/misc.rs b/src/util/misc.rs index 87bbb8cb..2df9ce91 100644 --- a/src/util/misc.rs +++ b/src/util/misc.rs @@ -16,9 +16,9 @@ //! //! Various utility functions -use hashes::{sha256d, Hash, HashEngine}; -use blockdata::opcodes; -use consensus::{encode, Encodable}; +use crate::hashes::{sha256d, Hash, HashEngine}; +use crate::blockdata::opcodes; +use crate::consensus::{encode, Encodable}; static MSG_SIGN_PREFIX: &[u8] = b"\x18Bitcoin Signed Message:\n"; @@ -70,7 +70,7 @@ pub fn signed_msg_hash(msg: &str) -> sha256d::Hash { #[cfg(test)] mod tests { - use hashes::hex::ToHex; + use crate::hashes::hex::ToHex; use super::script_find_and_remove; use super::signed_msg_hash; diff --git a/src/util/mod.rs b/src/util/mod.rs index 655cadad..47801314 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -42,8 +42,8 @@ pub(crate) mod endian; use std::{error, fmt}; -use consensus::encode; -use network; +use crate::consensus::encode; +use crate::network; /// A trait which allows numbers to act as fixed-size bit arrays pub trait BitArray { diff --git a/src/util/prime.rs b/src/util/prime.rs index 703dbffd..ebe5f79c 100644 --- a/src/util/prime.rs +++ b/src/util/prime.rs @@ -66,7 +66,7 @@ fn jacobi_inner(a: &Integer, n: &Integer) -> i8 { #[cfg(test)] mod tests { - use util::prime::{jacobi, jacobi_inner}; + use crate::util::prime::{jacobi, jacobi_inner}; use rug::Integer; #[test] diff --git a/src/util/psbt/error.rs b/src/util/psbt/error.rs index 15ab268d..114b609a 100644 --- a/src/util/psbt/error.rs +++ b/src/util/psbt/error.rs @@ -15,8 +15,8 @@ use std::error; use std::fmt; -use blockdata::transaction::Transaction; -use util::psbt::raw; +use crate::blockdata::transaction::Transaction; +use crate::util::psbt::raw; /// Ways that a Partially Signed Transaction might fail. #[derive(Debug)] diff --git a/src/util/psbt/map/global.rs b/src/util/psbt/map/global.rs index 24ccbd70..ad04c229 100644 --- a/src/util/psbt/map/global.rs +++ b/src/util/psbt/map/global.rs @@ -16,12 +16,12 @@ use std::collections::BTreeMap; use std::collections::btree_map::Entry; use std::io::{self, Cursor}; -use blockdata::transaction::Transaction; -use consensus::{encode, Decodable, Encodable}; -use util::psbt; -use util::psbt::map::Map; -use util::psbt::raw; -use util::psbt::Error; +use crate::blockdata::transaction::Transaction; +use crate::consensus::{encode, Decodable, Encodable}; +use crate::util::psbt; +use crate::util::psbt::map::Map; +use crate::util::psbt::raw; +use crate::util::psbt::Error; /// A key-value map for global data. #[derive(Clone, Debug, PartialEq)] @@ -159,7 +159,7 @@ impl Decodable for Global { } } } - Err(::consensus::encode::Error::Psbt(::util::psbt::Error::NoMorePairs)) => break, + Err(crate::consensus::encode::Error::Psbt(crate::util::psbt::Error::NoMorePairs)) => break, Err(e) => return Err(e), } } diff --git a/src/util/psbt/map/input.rs b/src/util/psbt/map/input.rs index 05a24432..ff2ee434 100644 --- a/src/util/psbt/map/input.rs +++ b/src/util/psbt/map/input.rs @@ -14,15 +14,15 @@ use std::collections::BTreeMap; -use blockdata::script::Script; -use blockdata::transaction::{SigHashType, Transaction, TxOut}; -use consensus::encode; -use util::bip32::{DerivationPath, Fingerprint}; -use util::key::PublicKey; -use util::psbt; -use util::psbt::map::Map; -use util::psbt::raw; -use util::psbt::Error; +use crate::blockdata::script::Script; +use crate::blockdata::transaction::{SigHashType, Transaction, TxOut}; +use crate::consensus::encode; +use crate::util::bip32::{DerivationPath, Fingerprint}; +use crate::util::key::PublicKey; +use crate::util::psbt; +use crate::util::psbt::map::Map; +use crate::util::psbt::raw; +use crate::util::psbt::Error; /// A key-value map for an input of the corresponding index in the unsigned /// transaction. diff --git a/src/util/psbt/map/mod.rs b/src/util/psbt/map/mod.rs index a84cf8a3..ce83699d 100644 --- a/src/util/psbt/map/mod.rs +++ b/src/util/psbt/map/mod.rs @@ -12,9 +12,9 @@ // If not, see . // -use consensus::encode; -use util::psbt; -use util::psbt::raw; +use crate::consensus::encode; +use crate::util::psbt; +use crate::util::psbt::raw; /// A trait that describes a PSBT key-value map. pub trait Map { diff --git a/src/util/psbt/map/output.rs b/src/util/psbt/map/output.rs index 24736974..f593da2c 100644 --- a/src/util/psbt/map/output.rs +++ b/src/util/psbt/map/output.rs @@ -15,14 +15,14 @@ use std::collections::BTreeMap; use std::collections::btree_map::Entry; -use blockdata::script::Script; -use consensus::encode; -use util::bip32::{DerivationPath, Fingerprint}; -use util::key::PublicKey; -use util::psbt; -use util::psbt::map::Map; -use util::psbt::raw; -use util::psbt::Error; +use crate::blockdata::script::Script; +use crate::consensus::encode; +use crate::util::bip32::{DerivationPath, Fingerprint}; +use crate::util::key::PublicKey; +use crate::util::psbt; +use crate::util::psbt::map::Map; +use crate::util::psbt::raw; +use crate::util::psbt::Error; /// A key-value map for an output of the corresponding index in the unsigned /// transaction. diff --git a/src/util/psbt/mod.rs b/src/util/psbt/mod.rs index c4f402f6..deabb80e 100644 --- a/src/util/psbt/mod.rs +++ b/src/util/psbt/mod.rs @@ -18,9 +18,9 @@ //! defined at https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki //! except we define PSBTs containing non-standard SigHash types as invalid. -use blockdata::script::Script; -use blockdata::transaction::Transaction; -use consensus::{encode, Decodable, Encodable}; +use crate::blockdata::script::Script; +use crate::blockdata::transaction::Transaction; +use crate::consensus::{encode, Decodable, Encodable}; use std::io; @@ -159,21 +159,21 @@ impl Decodable for PartiallySignedTransaction { #[cfg(test)] mod tests { - use hashes::hex::FromHex; - use hash_types::Txid; + use crate::hashes::hex::FromHex; + use crate::hash_types::Txid; use std::collections::BTreeMap; use secp256k1::Secp256k1; - use blockdata::script::Script; - use blockdata::transaction::{OutPoint, Transaction, TxIn, TxOut}; - use consensus::encode::{deserialize, serialize, serialize_hex}; - use network::constants::Network::Prod; - use util::bip32::{ChildNumber, DerivationPath, ExtendedPrivKey, ExtendedPubKey, Fingerprint}; - use util::key::PublicKey; - use util::psbt::map::{Global, Output}; - use util::psbt::raw; + use crate::blockdata::script::Script; + use crate::blockdata::transaction::{OutPoint, Transaction, TxIn, TxOut}; + use crate::consensus::encode::{deserialize, serialize, serialize_hex}; + use crate::network::constants::Network::Prod; + use crate::util::bip32::{ChildNumber, DerivationPath, ExtendedPrivKey, ExtendedPubKey, Fingerprint}; + use crate::util::key::PublicKey; + use crate::util::psbt::map::{Global, Output}; + use crate::util::psbt::raw; use super::PartiallySignedTransaction; @@ -308,15 +308,15 @@ mod tests { mod bip_vectors { use std::collections::BTreeMap; - use hashes::hex::FromHex; - use hash_types::Txid; + use crate::hashes::hex::FromHex; + use crate::hash_types::Txid; - use blockdata::script::Script; - use blockdata::transaction::{OutPoint, SigHashType, Transaction, TxIn, TxOut}; - use consensus::encode::serialize_hex; - use util::psbt::map::{Global, Input, Map, Output}; - use util::psbt::raw; - use util::psbt::PartiallySignedTransaction; + use crate::blockdata::script::Script; + use crate::blockdata::transaction::{OutPoint, SigHashType, Transaction, TxIn, TxOut}; + use crate::consensus::encode::serialize_hex; + use crate::util::psbt::map::{Global, Input, Map, Output}; + use crate::util::psbt::raw; + use crate::util::psbt::PartiallySignedTransaction; #[test] fn invalid_vector_1() { diff --git a/src/util/psbt/raw.rs b/src/util/psbt/raw.rs index 53fc1be1..b7844d48 100644 --- a/src/util/psbt/raw.rs +++ b/src/util/psbt/raw.rs @@ -19,9 +19,9 @@ use std::{fmt, io}; -use consensus::encode::{self, Decodable, Encodable, VarInt, MAX_VEC_SIZE}; -use hashes::hex::ToHex; -use util::psbt::Error; +use crate::consensus::encode::{self, Decodable, Encodable, VarInt, MAX_VEC_SIZE}; +use crate::hashes::hex::ToHex; +use crate::util::psbt::Error; /// A PSBT key in its raw byte form. #[derive(Debug, PartialEq, Hash, Eq, Clone, Ord, PartialOrd)] diff --git a/src/util/psbt/serialize.rs b/src/util/psbt/serialize.rs index f0d3e745..907f8f70 100644 --- a/src/util/psbt/serialize.rs +++ b/src/util/psbt/serialize.rs @@ -19,12 +19,12 @@ use std::io; -use blockdata::script::Script; -use blockdata::transaction::{SigHashType, Transaction, TxOut}; -use consensus::encode::{self, serialize, Decodable}; -use util::bip32::{ChildNumber, DerivationPath, Fingerprint}; -use util::key::PublicKey; -use util::psbt; +use crate::blockdata::script::Script; +use crate::blockdata::transaction::{SigHashType, Transaction, TxOut}; +use crate::consensus::encode::{self, serialize, Decodable}; +use crate::util::bip32::{ChildNumber, DerivationPath, Fingerprint}; +use crate::util::key::PublicKey; +use crate::util::psbt; /// A trait for serializing a value as raw data for insertion into PSBT /// key-value pairs. diff --git a/src/util/rfc6979.rs b/src/util/rfc6979.rs index ad144ec2..ae706f4e 100644 --- a/src/util/rfc6979.rs +++ b/src/util/rfc6979.rs @@ -5,8 +5,8 @@ //! RFC6979 //! -use hashes::{HmacEngine, HashEngine, Hmac, Hash}; -use hashes::sha256::Hash as SHA256; +use crate::hashes::{HmacEngine, HashEngine, Hmac, Hash}; +use crate::hashes::sha256::Hash as SHA256; use secp256k1::SecretKey; /// Generate nonce @@ -100,8 +100,8 @@ impl RFC6979 { #[cfg(test)] mod tests { - use test_helpers::{decode_message, decode_sk}; - use util::rfc6979::nonce_rfc6979; + use crate::test_helpers::{decode_message, decode_sk}; + use crate::util::rfc6979::nonce_rfc6979; #[test] fn test() { diff --git a/src/util/signature.rs b/src/util/signature.rs index fe8d5df1..c0c51e3a 100644 --- a/src/util/signature.rs +++ b/src/util/signature.rs @@ -12,11 +12,11 @@ use std::fmt; use std::borrow::Borrow; use secp256k1::SecretKey; -use hashes::{sha256, HashEngine, Hash}; +use crate::hashes::{sha256, HashEngine, Hash}; -use util::key::{PublicKey, PrivateKey}; -use util::prime::jacobi; -use util::rfc6979::nonce_rfc6979; +use crate::util::key::{PublicKey, PrivateKey}; +use crate::util::prime::jacobi; +use crate::util::rfc6979::nonce_rfc6979; /// The size of scalar value on secp256k1 curve pub const SECP256K1_SCALAR_SIZE: usize = 32; @@ -209,13 +209,13 @@ impl error::Error for Error { #[cfg(test)] mod tests { - use hashes::hex::FromHex; + use crate::hashes::hex::FromHex; - use hashes::Hash; - use consensus::encode::{deserialize, serialize}; - use util::signature::Signature; - use util::key::PrivateKey; - use test_helpers::*; + use crate::hashes::Hash; + use crate::consensus::encode::{deserialize, serialize}; + use crate::util::signature::Signature; + use crate::util::key::PrivateKey; + use crate::test_helpers::*; #[test] fn test_p2p_sign_and_verify() { diff --git a/src/util/uint.rs b/src/util/uint.rs index adfff962..554417ad 100644 --- a/src/util/uint.rs +++ b/src/util/uint.rs @@ -436,9 +436,9 @@ impl Uint256 { #[cfg(test)] mod tests { - use consensus::{deserialize, serialize}; - use util::uint::{Uint256, Uint128}; - use util::BitArray; + use crate::consensus::{deserialize, serialize}; + use crate::util::uint::{Uint256, Uint128}; + use crate::util::BitArray; #[test] pub fn uint256_bits_test() { From e9344695abd218195d8d8c6c408dab2812d4ba68 Mon Sep 17 00:00:00 2001 From: azuchi Date: Thu, 25 Dec 2025 15:25:28 +0900 Subject: [PATCH 2/7] Update editoin to 2024 --- Cargo.toml | 1 + examples/handshake.rs | 8 ++++---- src/blockdata/opcodes.rs | 2 +- src/blockdata/script.rs | 2 +- src/blockdata/transaction.rs | 2 +- src/consensus/encode.rs | 22 +++++++++++----------- src/internal_macros.rs | 15 +++++++-------- src/lib.rs | 4 ---- src/network/message_blockdata.rs | 2 +- src/network/mod.rs | 2 +- src/util/address.rs | 12 ++++++------ src/util/amount.rs | 8 ++++---- src/util/bip158.rs | 26 +++++++++++++------------- src/util/bip32.rs | 2 +- src/util/contracthash.rs | 6 +++--- src/util/endian.rs | 4 ++-- src/util/key.rs | 4 ++-- src/util/merkleblock.rs | 4 ++-- src/util/mod.rs | 2 +- src/util/psbt/macros.rs | 6 +++--- src/util/signature.rs | 2 +- src/util/uint.rs | 4 ++-- 22 files changed, 68 insertions(+), 72 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d09b0e50..3009d1cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "tapyrus" version = "0.4.8" +edition = "2024" authors = ["Kohei Taniguchi ", "Hajime Yamaguchi "] license = "MIT" homepage = "https://github.com/chaintope/rust-tapyrus/" diff --git a/examples/handshake.rs b/examples/handshake.rs index a6e0e1ba..e664b7bc 100644 --- a/examples/handshake.rs +++ b/examples/handshake.rs @@ -34,7 +34,7 @@ fn main() { payload: version_message, }; - if let Ok(mut stream) = TcpStream::connect(address) { + match TcpStream::connect(address) { Ok(mut stream) => { // Send the message let _ = stream.write_all(encode::serialize(&first_message).as_slice()); println!("Sent version message"); @@ -68,9 +68,9 @@ fn main() { } } let _ = stream.shutdown(Shutdown::Both); - } else { + } _ => { eprintln!("Failed to open connection"); - } + }} } fn build_version_message(address: SocketAddr) -> message::NetworkMessage { @@ -93,7 +93,7 @@ fn build_version_message(address: SocketAddr) -> message::NetworkMessage { let addr_from = address::Address::new(&my_address, constants::ServiceFlags::NONE); // "Node random nonce, randomly generated every time a version packet is sent. This nonce is used to detect connections to self." - let nonce: u64 = secp256k1::rand::thread_rng().gen(); + let nonce: u64 = secp256k1::rand::thread_rng().r#gen(); // "User Agent (0x00 if string is 0 bytes long)" let user_agent = String::from("rust-example"); diff --git a/src/blockdata/opcodes.rs b/src/blockdata/opcodes.rs index 79b4b1f0..360f5a14 100644 --- a/src/blockdata/opcodes.rs +++ b/src/blockdata/opcodes.rs @@ -825,7 +825,7 @@ mod tests { use super::*; macro_rules! roundtrip { - ($unique:expr, $op:ident) => { + ($unique:expr_2021, $op:ident) => { assert_eq!(all::$op, All::from(all::$op.into_u8())); let s1 = format!("{}", all::$op); diff --git a/src/blockdata/script.rs b/src/blockdata/script.rs index 02fc982e..c7ccf438 100644 --- a/src/blockdata/script.rs +++ b/src/blockdata/script.rs @@ -537,7 +537,7 @@ impl Script { } /// Write the assembly decoding of the script to the formatter. - pub fn fmt_asm(&self, f: &mut fmt::Write) -> fmt::Result { + pub fn fmt_asm(&self, f: &mut dyn fmt::Write) -> fmt::Result { let mut index = 0; while index < self.0.len() { let opcode = opcodes::All::from(self.0[index]); diff --git a/src/blockdata/transaction.rs b/src/blockdata/transaction.rs index 232d74cd..b7dfea38 100644 --- a/src/blockdata/transaction.rs +++ b/src/blockdata/transaction.rs @@ -123,7 +123,7 @@ impl ::std::error::Error for ParseOutPointError { "description() is deprecated; use Display" } - fn cause(&self) -> Option<&::std::error::Error> { + fn cause(&self) -> Option<&dyn ::std::error::Error> { match *self { ParseOutPointError::Txid(ref e) => Some(e), ParseOutPointError::Vout(ref e) => Some(e), diff --git a/src/consensus/encode.rs b/src/consensus/encode.rs index 45262e53..09d51177 100644 --- a/src/consensus/encode.rs +++ b/src/consensus/encode.rs @@ -122,7 +122,7 @@ impl fmt::Display for Error { #[allow(deprecated)] impl error::Error for Error { - fn cause(&self) -> Option<&error::Error> { + fn cause(&self) -> Option<&dyn error::Error> { match *self { Error::Io(ref e) => Some(e), Error::Psbt(ref e) => Some(e), @@ -272,7 +272,7 @@ macro_rules! encoder_fn { } macro_rules! decoder_fn { - ($name:ident, $val_type:ty, $readfn:ident, $byte_len: expr) => { + ($name:ident, $val_type:ty, $readfn:ident, $byte_len: expr_2021) => { #[inline] fn $name(&mut self) -> Result<$val_type, Error> { assert_eq!(::std::mem::size_of::<$val_type>(), $byte_len); // size_of isn't a constfn in 1.22 @@ -402,9 +402,9 @@ impl VarInt { #[inline] pub fn len(&self) -> usize { match self.0 { - 0...0xFC => { 1 } - 0xFD...0xFFFF => { 3 } - 0x10000...0xFFFFFFFF => { 5 } + 0..=0xFC => { 1 } + 0xFD..=0xFFFF => { 3 } + 0x10000..=0xFFFFFFFF => { 5 } _ => { 9 } } } @@ -414,16 +414,16 @@ impl Encodable for VarInt { #[inline] fn consensus_encode(&self, mut s: S) -> Result { match self.0 { - 0...0xFC => { + 0..=0xFC => { (self.0 as u8).consensus_encode(s)?; Ok(1) }, - 0xFD...0xFFFF => { + 0xFD..=0xFFFF => { s.emit_u8(0xFD)?; (self.0 as u16).consensus_encode(s)?; Ok(3) }, - 0x10000...0xFFFFFFFF => { + 0x10000..=0xFFFFFFFF => { s.emit_u8(0xFE)?; (self.0 as u32).consensus_encode(s)?; Ok(5) @@ -530,7 +530,7 @@ impl Decodable for Cow<'static, str> { // Arrays macro_rules! impl_array { - ( $size:expr ) => ( + ( $size:expr_2021 ) => ( impl Encodable for [u8; $size] { #[inline] fn consensus_encode( @@ -1042,13 +1042,13 @@ mod tests { macro_rules! round_trip { ($($val_type:ty),*) => { $( - let r: $val_type = thread_rng().gen(); + let r: $val_type = thread_rng().r#gen(); assert_eq!(deserialize::<$val_type>(&serialize(&r)).unwrap(), r); )* }; } macro_rules! round_trip_bytes { - ($(($val_type:ty, $data:expr)),*) => { + ($(($val_type:ty, $data:expr_2021)),*) => { $( thread_rng().fill(&mut $data[..]); assert_eq!(deserialize::<$val_type>(&serialize(&$data)).unwrap()[..], $data[..]); diff --git a/src/internal_macros.rs b/src/internal_macros.rs index f81ecb72..9e3348b7 100644 --- a/src/internal_macros.rs +++ b/src/internal_macros.rs @@ -45,7 +45,7 @@ macro_rules! impl_consensus_encoding { /// Implements standard array methods for a given wrapper type macro_rules! impl_array_newtype { - ($thing:ident, $ty:ty, $len:expr) => { + ($thing:ident, $ty:ty, $len:expr_2021) => { impl $thing { #[inline] /// Converts the object to a raw pointer @@ -134,7 +134,6 @@ macro_rules! impl_array_newtype { } } - #[cfg_attr(feature = "clippy", allow(expl_impl_clone_on_copy))] // we don't define the `struct`, we have to explicitly impl impl ::std::clone::Clone for $thing { #[inline] fn clone(&self) -> $thing { @@ -227,13 +226,13 @@ macro_rules! display_from_debug { } #[cfg(test)] -macro_rules! hex_script (($s:expr) => ($crate::blockdata::script::Script::from( as $crate::hashes::hex::FromHex>::from_hex($s).unwrap()))); +macro_rules! hex_script (($s:expr_2021) => ($crate::blockdata::script::Script::from( as $crate::hashes::hex::FromHex>::from_hex($s).unwrap()))); #[cfg(test)] -macro_rules! hex_hash (($h:ident, $s:expr) => ($h::from_slice(& as $crate::hashes::hex::FromHex>::from_hex($s).unwrap()).unwrap())); +macro_rules! hex_hash (($h:ident, $s:expr_2021) => ($h::from_slice(& as $crate::hashes::hex::FromHex>::from_hex($s).unwrap()).unwrap())); macro_rules! serde_string_impl { - ($name:ident, $expecting:expr) => { + ($name:ident, $expecting:expr_2021) => { #[cfg(feature = "serde")] impl<'de> $crate::serde::Deserialize<'de> for $name { fn deserialize(deserializer: D) -> Result<$name, D::Error> @@ -292,7 +291,7 @@ macro_rules! serde_string_impl { /// A combination macro where the human-readable serialization is done like /// serde_string_impl and the non-human-readable impl is done as a struct. macro_rules! serde_struct_human_string_impl { - ($name:ident, $expecting:expr, $($fe:ident),*) => ( + ($name:ident, $expecting:expr_2021, $($fe:ident),*) => ( #[cfg(feature = "serde")] impl<'de> $crate::serde::Deserialize<'de> for $name { fn deserialize(deserializer: D) -> Result<$name, D::Error> @@ -481,7 +480,7 @@ macro_rules! serde_struct_human_string_impl { /// - std::str::FromStr /// - hashes::hex::FromHex macro_rules! impl_bytes_newtype { - ($t:ident, $len:expr) => ( + ($t:ident, $len:expr_2021) => ( impl ::std::fmt::LowerHex for $t { fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { @@ -603,7 +602,7 @@ macro_rules! user_enum { $(#[$attr:meta])* pub enum $name:ident { $(#[$doc:meta] - $elem:ident <-> $txt:expr),* + $elem:ident <-> $txt:expr_2021),* } ) => ( $(#[$attr])* diff --git a/src/lib.rs b/src/lib.rs index 703d7911..14393c98 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,10 +30,6 @@ // Experimental features we need #![cfg_attr(all(test, feature = "unstable"), feature(test))] -// Clippy whitelist -#![cfg_attr(feature = "clippy", allow(needless_range_loop))] // suggests making a big mess of array newtypes -#![cfg_attr(feature = "clippy", allow(extend_from_slice))] // `extend_from_slice` only available since 1.6 - // Coding conventions #![forbid(unsafe_code)] #![deny(non_upper_case_globals)] diff --git a/src/network/message_blockdata.rs b/src/network/message_blockdata.rs index dbb15b6c..279af0a9 100644 --- a/src/network/message_blockdata.rs +++ b/src/network/message_blockdata.rs @@ -48,7 +48,7 @@ impl Encodable for Inventory { mut s: S, ) -> Result { macro_rules! encode_inv { - ($code:expr, $item:expr) => { + ($code:expr_2021, $item:expr_2021) => { u32::consensus_encode(&$code, &mut s)? + $item.consensus_encode(&mut s)? } diff --git a/src/network/mod.rs b/src/network/mod.rs index b737894e..a1635b95 100644 --- a/src/network/mod.rs +++ b/src/network/mod.rs @@ -66,7 +66,7 @@ impl error::Error for Error { "description() is deprecated; use Display" } - fn cause(&self) -> Option<&error::Error> { + fn cause(&self) -> Option<&dyn error::Error> { match *self { Error::Io(ref e) => Some(e), Error::SocketMutexPoisoned | Error::SocketNotConnectedToPeer => None, diff --git a/src/util/address.rs b/src/util/address.rs index 4e0693d2..7d7046a7 100644 --- a/src/util/address.rs +++ b/src/util/address.rs @@ -76,7 +76,7 @@ impl fmt::Display for Error { #[allow(deprecated)] impl ::std::error::Error for Error { - fn cause(&self) -> Option<&::std::error::Error> { + fn cause(&self) -> Option<&dyn ::std::error::Error> { match *self { Error::Base58(ref e) => Some(e), _ => None, @@ -412,11 +412,11 @@ mod tests { use super::*; - macro_rules! hex (($hex:expr) => (Vec::from_hex($hex).unwrap())); - macro_rules! hex_key (($hex:expr) => (PublicKey::from_slice(&hex!($hex)).unwrap())); - macro_rules! hex_script (($hex:expr) => (Script::from(hex!($hex)))); - macro_rules! hex_pubkeyhash (($hex:expr) => (PubkeyHash::from_hex(&$hex).unwrap())); - macro_rules! hex_scripthash (($hex:expr) => (ScriptHash::from_hex(&$hex).unwrap())); + macro_rules! hex (($hex:expr_2021) => (Vec::from_hex($hex).unwrap())); + macro_rules! hex_key (($hex:expr_2021) => (PublicKey::from_slice(&hex!($hex)).unwrap())); + macro_rules! hex_script (($hex:expr_2021) => (Script::from(hex!($hex)))); + macro_rules! hex_pubkeyhash (($hex:expr_2021) => (PubkeyHash::from_hex(&$hex).unwrap())); + macro_rules! hex_scripthash (($hex:expr_2021) => (ScriptHash::from_hex(&$hex).unwrap())); fn roundtrips(addr: &Address) { assert_eq!( diff --git a/src/util/amount.rs b/src/util/amount.rs index 8963703e..db5db31f 100644 --- a/src/util/amount.rs +++ b/src/util/amount.rs @@ -167,7 +167,7 @@ fn parse_signed_to_tapyrus( let mut value: u64 = 0; // as tapyruses for c in s.chars() { match c { - '0'...'9' => { + '0'..='9' => { // Do `value = 10 * value + digit`, catching overflows. match 10_u64.checked_mul(value) { None => return Err(ParseAmountError::TooBig), @@ -210,7 +210,7 @@ fn parse_signed_to_tapyrus( fn fmt_tapyrus_in( tapyrus: u64, negative: bool, - f: &mut fmt::Write, + f: &mut dyn fmt::Write, denom: Denomination, ) -> fmt::Result { if negative { @@ -360,7 +360,7 @@ impl Amount { /// Format the value of this [Amount] in the given denomination. /// /// Does not include the denomination. - pub fn fmt_value_in(self, f: &mut fmt::Write, denom: Denomination) -> fmt::Result { + pub fn fmt_value_in(self, f: &mut dyn fmt::Write, denom: Denomination) -> fmt::Result { fmt_tapyrus_in(self.as_tap(), false, f, denom) } @@ -638,7 +638,7 @@ impl SignedAmount { /// Format the value of this [SignedAmount] in the given denomination. /// /// Does not include the denomination. - pub fn fmt_value_in(self, f: &mut fmt::Write, denom: Denomination) -> fmt::Result { + pub fn fmt_value_in(self, f: &mut dyn fmt::Write, denom: Denomination) -> fmt::Result { let taps = self.as_tap().checked_abs().map(|a: i64| a as u64).unwrap_or_else(|| { // We could also hard code this into `9223372036854775808` u64::max_value() - self.as_tap() as u64 +1 diff --git a/src/util/bip158.rs b/src/util/bip158.rs index 04d595cc..16c006b9 100644 --- a/src/util/bip158.rs +++ b/src/util/bip158.rs @@ -137,13 +137,13 @@ impl BlockFilter { } /// match any query pattern - pub fn match_any(&self, block_hash: &BlockHash, query: &mut Iterator) -> Result { + pub fn match_any(&self, block_hash: &BlockHash, query: &mut dyn Iterator) -> Result { let filter_reader = BlockFilterReader::new(block_hash); filter_reader.match_any(&mut Cursor::new(self.content.as_slice()), query) } /// match all query pattern - pub fn match_all(&self, block_hash: &BlockHash, query: &mut Iterator) -> Result { + pub fn match_all(&self, block_hash: &BlockHash, query: &mut dyn Iterator) -> Result { let filter_reader = BlockFilterReader::new(block_hash); filter_reader.match_all(&mut Cursor::new(self.content.as_slice()), query) } @@ -157,7 +157,7 @@ pub struct BlockFilterWriter<'a> { impl<'a> BlockFilterWriter<'a> { /// Create a block filter writer - pub fn new(writer: &'a mut io::Write, block: &'a Block) -> BlockFilterWriter<'a> { + pub fn new(writer: &'a mut dyn io::Write, block: &'a Block) -> BlockFilterWriter<'a> { let block_hash_as_int = block.block_hash().into_inner(); let k0 = endian::slice_to_u64_le(&block_hash_as_int[0..8]); let k1 = endian::slice_to_u64_le(&block_hash_as_int[8..16]); @@ -218,12 +218,12 @@ impl BlockFilterReader { } /// match any query pattern - pub fn match_any(&self, reader: &mut io::Read, query: &mut Iterator) -> Result { + pub fn match_any(&self, reader: &mut dyn io::Read, query: &mut dyn Iterator) -> Result { self.reader.match_any(reader, query) } /// match all query pattern - pub fn match_all(&self, reader: &mut io::Read, query: &mut Iterator) -> Result { + pub fn match_all(&self, reader: &mut dyn io::Read, query: &mut dyn Iterator) -> Result { self.reader.match_all(reader, query) } } @@ -242,7 +242,7 @@ impl GCSFilterReader { } /// match any query pattern - pub fn match_any(&self, reader: &mut io::Read, query: &mut Iterator) -> Result { + pub fn match_any(&self, reader: &mut dyn io::Read, query: &mut dyn Iterator) -> Result { let mut decoder = reader; let n_elements: VarInt = Decodable::consensus_decode(&mut decoder).unwrap_or(VarInt(0)); let reader = &mut decoder; @@ -282,7 +282,7 @@ impl GCSFilterReader { } /// match all query pattern - pub fn match_all(&self, reader: &mut io::Read, query: &mut Iterator) -> Result { + pub fn match_all(&self, reader: &mut dyn io::Read, query: &mut dyn Iterator) -> Result { let mut decoder = reader; let n_elements: VarInt = Decodable::consensus_decode(&mut decoder).unwrap_or(VarInt(0)); let reader = &mut decoder; @@ -344,14 +344,14 @@ fn map_to_range(hash: u64, nm: u64) -> u64 { /// Colomb-Rice encoded filter writer pub struct GCSFilterWriter<'a> { filter: GCSFilter, - writer: &'a mut io::Write, + writer: &'a mut dyn io::Write, elements: HashSet>, m: u64 } impl<'a> GCSFilterWriter<'a> { /// Create a new GCS writer wrapping a generic writer, with specific seed to siphash - pub fn new(writer: &'a mut io::Write, k0: u64, k1: u64, m: u64, p: u8) -> GCSFilterWriter<'a> { + pub fn new(writer: &'a mut dyn io::Write, k0: u64, k1: u64, m: u64, p: u8) -> GCSFilterWriter<'a> { GCSFilterWriter { filter: GCSFilter::new(k0, k1, p), writer, @@ -440,12 +440,12 @@ impl GCSFilter { pub struct BitStreamReader<'a> { buffer: [u8; 1], offset: u8, - reader: &'a mut io::Read, + reader: &'a mut dyn io::Read, } impl<'a> BitStreamReader<'a> { /// Create a new BitStreamReader that reads bitwise from a given reader - pub fn new(reader: &'a mut io::Read) -> BitStreamReader<'a> { + pub fn new(reader: &'a mut dyn io::Read) -> BitStreamReader<'a> { BitStreamReader { buffer: [0u8], reader: reader, @@ -478,12 +478,12 @@ impl<'a> BitStreamReader<'a> { pub struct BitStreamWriter<'a> { buffer: [u8; 1], offset: u8, - writer: &'a mut io::Write, + writer: &'a mut dyn io::Write, } impl<'a> BitStreamWriter<'a> { /// Create a new BitStreamWriter that writes bitwise to a given writer - pub fn new(writer: &'a mut io::Write) -> BitStreamWriter<'a> { + pub fn new(writer: &'a mut dyn io::Write) -> BitStreamWriter<'a> { BitStreamWriter { buffer: [0u8], writer: writer, diff --git a/src/util/bip32.rs b/src/util/bip32.rs index 66b96364..bcff085d 100644 --- a/src/util/bip32.rs +++ b/src/util/bip32.rs @@ -418,7 +418,7 @@ impl fmt::Display for Error { } impl error::Error for Error { - fn cause(&self) -> Option<&error::Error> { + fn cause(&self) -> Option<&dyn error::Error> { if let Error::Ecdsa(ref e) = *self { Some(e) } else { diff --git a/src/util/contracthash.rs b/src/util/contracthash.rs index 90b300d2..1e417a9e 100644 --- a/src/util/contracthash.rs +++ b/src/util/contracthash.rs @@ -73,7 +73,7 @@ impl fmt::Display for Error { #[allow(deprecated)] impl error::Error for Error { - fn cause(&self) -> Option<&error::Error> { + fn cause(&self) -> Option<&dyn error::Error> { match *self { Error::Secp(ref e) => Some(e), Error::Script(ref e) => Some(e), @@ -291,8 +291,8 @@ mod tests { use super::*; use crate::PublicKey; - macro_rules! hex (($hex:expr) => (Vec::from_hex($hex).unwrap())); - macro_rules! hex_key (($hex:expr) => (PublicKey::from_slice(&hex!($hex)).unwrap())); + macro_rules! hex (($hex:expr_2021) => (Vec::from_hex($hex).unwrap())); + macro_rules! hex_key (($hex:expr_2021) => (PublicKey::from_slice(&hex!($hex)).unwrap())); macro_rules! alpha_template(() => (Template::from(&hex!("55fefefefefefefe57AE")[..]))); macro_rules! alpha_keys(() => ( &[hex_key!("0269992fb441ae56968e5b77d46a3e53b69f136444ae65a94041fc937bdb28d933"), diff --git a/src/util/endian.rs b/src/util/endian.rs index 07b9bbf0..85f24579 100644 --- a/src/util/endian.rs +++ b/src/util/endian.rs @@ -25,7 +25,7 @@ macro_rules! define_slice_to_le { } } macro_rules! define_be_to_array { - ($name: ident, $type: ty, $byte_len: expr) => { + ($name: ident, $type: ty, $byte_len: expr_2021) => { #[inline] pub fn $name(val: $type) -> [u8; $byte_len] { assert_eq!(::std::mem::size_of::<$type>(), $byte_len); // size_of isn't a constfn in 1.22 @@ -38,7 +38,7 @@ macro_rules! define_be_to_array { } } macro_rules! define_le_to_array { - ($name: ident, $type: ty, $byte_len: expr) => { + ($name: ident, $type: ty, $byte_len: expr_2021) => { #[inline] pub fn $name(val: $type) -> [u8; $byte_len] { assert_eq!(::std::mem::size_of::<$type>(), $byte_len); // size_of isn't a constfn in 1.22 diff --git a/src/util/key.rs b/src/util/key.rs index 46f578d5..dd0fd6aa 100644 --- a/src/util/key.rs +++ b/src/util/key.rs @@ -50,7 +50,7 @@ impl fmt::Display for Error { } impl error::Error for Error { - fn cause(&self) -> Option<&error::Error> { + fn cause(&self) -> Option<&dyn error::Error> { match *self { Error::Base58(ref e) => Some(e), Error::Secp256k1(ref e) => Some(e), @@ -189,7 +189,7 @@ impl PrivateKey { } /// Format the private key to WIF format. - pub fn fmt_wif(&self, fmt: &mut fmt::Write) -> fmt::Result { + pub fn fmt_wif(&self, fmt: &mut dyn fmt::Write) -> fmt::Result { let mut ret = [0; 34]; ret[0] = match self.network { Network::Prod => 128, diff --git a/src/util/merkleblock.rs b/src/util/merkleblock.rs index c89d3ccd..82b4adfa 100644 --- a/src/util/merkleblock.rs +++ b/src/util/merkleblock.rs @@ -546,7 +546,7 @@ mod tests { // Generate `att / 2` random bits let rand_bits = match att / 2 { 0 => 0, - bits => rng.gen::() >> (64 - bits), + bits => rng.r#gen::() >> (64 - bits), }; let include = rand_bits == 0; matches[j] = include; @@ -710,7 +710,7 @@ mod tests { /// Flip one bit in one of the hashes - this should break the authentication fn damage(&mut self, rng: &mut ThreadRng) { let n = rng.gen_range(0, self.hashes.len()); - let bit = rng.gen::(); + let bit = rng.r#gen::(); let hashes = &mut self.hashes; let mut hash = hashes[n].into_inner(); hash[(bit >> 3) as usize] ^= 1 << (bit & 7); diff --git a/src/util/mod.rs b/src/util/mod.rs index 47801314..b8cad450 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -90,7 +90,7 @@ impl fmt::Display for Error { #[allow(deprecated)] impl error::Error for Error { - fn cause(&self) -> Option<&error::Error> { + fn cause(&self) -> Option<&dyn error::Error> { match *self { Error::Encode(ref e) => Some(e), Error::Network(ref e) => Some(e), diff --git a/src/util/psbt/macros.rs b/src/util/psbt/macros.rs index 9c3bcab0..4e9a2d2a 100644 --- a/src/util/psbt/macros.rs +++ b/src/util/psbt/macros.rs @@ -14,7 +14,7 @@ #[allow(unused_macros)] macro_rules! hex_psbt { - ($s:expr) => { $crate::consensus::deserialize(& as $crate::hashes::hex::FromHex>::from_hex($s).unwrap()) }; + ($s:expr_2021) => { $crate::consensus::deserialize(& as $crate::hashes::hex::FromHex>::from_hex($s).unwrap()) }; } macro_rules! merge { @@ -132,7 +132,7 @@ macro_rules! impl_psbt_insert_pair { #[cfg_attr(rustfmt, rustfmt_skip)] macro_rules! impl_psbt_get_pair { - ($rv:ident.push($slf:ident.$unkeyed_name:ident as <$unkeyed_typeval:expr, _>|<$unkeyed_value_type:ty>)) => { + ($rv:ident.push($slf:ident.$unkeyed_name:ident as <$unkeyed_typeval:expr_2021, _>|<$unkeyed_value_type:ty>)) => { if let Some(ref $unkeyed_name) = $slf.$unkeyed_name { $rv.push($crate::util::psbt::raw::Pair { key: $crate::util::psbt::raw::Key { @@ -143,7 +143,7 @@ macro_rules! impl_psbt_get_pair { }); } }; - ($rv:ident.push($slf:ident.$keyed_name:ident as <$keyed_typeval:expr, $keyed_key_type:ty>|<$keyed_value_type:ty>)) => { + ($rv:ident.push($slf:ident.$keyed_name:ident as <$keyed_typeval:expr_2021, $keyed_key_type:ty>|<$keyed_value_type:ty>)) => { for (key, val) in &$slf.$keyed_name { $rv.push($crate::util::psbt::raw::Pair { key: $crate::util::psbt::raw::Key { diff --git a/src/util/signature.rs b/src/util/signature.rs index c0c51e3a..222a5c1e 100644 --- a/src/util/signature.rs +++ b/src/util/signature.rs @@ -199,7 +199,7 @@ impl error::Error for Error { "description() is deprecated; use Display" } - fn cause(&self) -> Option<&error::Error> { + fn cause(&self) -> Option<&dyn error::Error> { match *self { Error::Secp256k1Error(ref e) => Some(e), Error::InvalidSignature => None, diff --git a/src/util/uint.rs b/src/util/uint.rs index 554417ad..f2cd9445 100644 --- a/src/util/uint.rs +++ b/src/util/uint.rs @@ -19,7 +19,7 @@ //! macro_rules! construct_uint { - ($name:ident, $n_words:expr) => { + ($name:ident, $n_words:expr_2021) => { /// Little-endian large integer type #[repr(C)] pub struct $name(pub [u64; $n_words]); @@ -372,7 +372,7 @@ macro_rules! construct_uint { impl ::std::fmt::Display for $name { fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { - <::std::fmt::Debug>::fmt(self, f) + ::fmt(self, f) } } From 548df05ee6ecaa555cd28083c4bc7dee9e9c312c Mon Sep 17 00:00:00 2001 From: azuchi Date: Thu, 25 Dec 2025 15:43:37 +0900 Subject: [PATCH 3/7] Fix clippy warnings --- src/blockdata/block.rs | 4 +-- src/blockdata/opcodes.rs | 4 +-- src/blockdata/script.rs | 25 ++++++++---------- src/blockdata/transaction.rs | 24 ++++++++--------- src/consensus/encode.rs | 19 +++++++++----- src/hash_types.rs | 6 ++--- src/internal_macros.rs | 2 +- src/network/address.rs | 2 +- src/network/constants.rs | 8 +++--- src/network/message.rs | 6 ++--- src/network/message_blockdata.rs | 8 +++--- src/network/message_network.rs | 16 +++++------- src/util/address.rs | 12 ++++----- src/util/amount.rs | 22 ++++++++-------- src/util/base58.rs | 4 +-- src/util/bip143.rs | 8 +++--- src/util/bip158.rs | 8 +++--- src/util/bip32.rs | 44 +++++++++++++++----------------- src/util/contracthash.rs | 15 +++++------ src/util/hash.rs | 4 +-- src/util/key.rs | 8 +++--- src/util/merkleblock.rs | 9 ++++--- src/util/prime.rs | 8 +++--- src/util/psbt/macros.rs | 4 +-- src/util/psbt/mod.rs | 10 ++++---- src/util/psbt/raw.rs | 4 +-- src/util/rfc6979.rs | 6 ++--- src/util/signature.rs | 8 +++--- 28 files changed, 147 insertions(+), 151 deletions(-) diff --git a/src/blockdata/block.rs b/src/blockdata/block.rs index 4bb1654a..5de0b992 100644 --- a/src/blockdata/block.rs +++ b/src/blockdata/block.rs @@ -100,7 +100,7 @@ impl BlockHeader { /// Tapyrus signer needs to sign this hash. The signature will be added to /// the block header as the proof field and submitted to the tapyrus node. pub fn signature_hash(&self) -> BlockSigHash { - let block = BlockHeaderWithoutProof::from(&self); + let block = BlockHeaderWithoutProof::from(self); BlockSigHash::hash(&serialize(&block)) } @@ -172,7 +172,7 @@ impl XField { impl FromStr for XField { type Err = encode::Error; fn from_str(s: &str) -> Result { - let bytes: Vec = Vec::from_hex(&s[..]).map_err(|_| encode::Error::ParseFailed("invalid hex string"))?; + let bytes: Vec = Vec::from_hex(s).map_err(|_| encode::Error::ParseFailed("invalid hex string"))?; XField::consensus_decode(&bytes[..]) } } diff --git a/src/blockdata/opcodes.rs b/src/blockdata/opcodes.rs index 360f5a14..5e610152 100644 --- a/src/blockdata/opcodes.rs +++ b/src/blockdata/opcodes.rs @@ -567,7 +567,7 @@ impl fmt::Debug for All { all::OP_PUSHDATA4 => write!(f, "PUSHDATA4"), all::OP_PUSHNUM_NEG1 => write!(f, "PUSHNUM_NEG1"), all::OP_RESERVED => write!(f, "RESERVED"), - All {code: x} if x >= all::OP_PUSHNUM_1.code && x <= all::OP_PUSHNUM_16.code => write!(f, "PUSHNUM_{}", x - all::OP_PUSHNUM_1.code + 1), + All {code: x} if (all::OP_PUSHNUM_1.code..=all::OP_PUSHNUM_16.code).contains(&x) => write!(f, "PUSHNUM_{}", x - all::OP_PUSHNUM_1.code + 1), all::OP_NOP => write!(f, "NOP"), all::OP_VER => write!(f, "VER"), all::OP_IF => write!(f, "IF"), @@ -650,7 +650,7 @@ impl fmt::Debug for All { all::OP_CLTV => write!(f, "CLTV"), all::OP_CSV => write!(f, "CSV"), all::OP_COLOR => write!(f, "COLOR"), - All {code: x} if x >= all::OP_NOP1.code && x <= all::OP_NOP10.code => write!(f, "NOP{}", x - all::OP_NOP1.code + 1), + All {code: x} if (all::OP_NOP1.code..=all::OP_NOP10.code).contains(&x) => write!(f, "NOP{}", x - all::OP_NOP1.code + 1), All {code: x} => write!(f, "RETURN_{}", x), } } diff --git a/src/blockdata/script.rs b/src/blockdata/script.rs index c7ccf438..d7d69494 100644 --- a/src/blockdata/script.rs +++ b/src/blockdata/script.rs @@ -308,7 +308,7 @@ impl Script { pub fn is_empty(&self) -> bool { self.0.is_empty() } /// Returns the script data - pub fn as_bytes(&self) -> &[u8] { &*self.0 } + pub fn as_bytes(&self) -> &[u8] { &self.0 } /// Returns a copy of the script data pub fn to_bytes(&self) -> Vec { self.0.clone().into_vec() } @@ -477,7 +477,7 @@ impl Script { } } Instruction::PushBytes(bytes) => { - match PublicKey::from_slice(&bytes) { + match PublicKey::from_slice(bytes) { Ok(key) => { pubkeys.push(key) }, _ => { return Err(MultisigError::IsNotMultisig) } } @@ -553,7 +553,7 @@ impl Script { break; } match read_uint(&self.0[index..], 1) { - Ok(n) => { index += 1; n as usize } + Ok(n) => { index += 1; n } Err(_) => { f.write_str("")?; break; } } } @@ -563,7 +563,7 @@ impl Script { break; } match read_uint(&self.0[index..], 2) { - Ok(n) => { index += 2; n as usize } + Ok(n) => { index += 2; n } Err(_) => { f.write_str("")?; break; } } } @@ -573,7 +573,7 @@ impl Script { break; } match read_uint(&self.0[index..], 4) { - Ok(n) => { index += 4; n as usize } + Ok(n) => { index += 4; n } Err(_) => { f.write_str("")?; break; } } } @@ -682,12 +682,11 @@ impl<'a> Iterator for Instructions<'a> { self.data = &[]; // Kill iterator so that it does not return an infinite stream of errors return Some(Err(Error::EarlyEndOfScript)); } - if self.enforce_minimal { - if n == 1 && (self.data[1] == 0x81 || (self.data[1] > 0 && self.data[1] <= 16)) { + if self.enforce_minimal + && n == 1 && (self.data[1] == 0x81 || (self.data[1] > 0 && self.data[1] <= 16)) { self.data = &[]; return Some(Err(Error::NonMinimalPush)); } - } let ret = Some(Ok(Instruction::PushBytes(&self.data[1..n+1]))); self.data = &self.data[n + 1..]; ret @@ -791,7 +790,7 @@ impl Builder { /// dedicated opcodes to push some small integers. pub fn push_int(self, data: i64) -> Builder { // We can special-case -1, 1-16 - if data == -1 || (data >= 1 && data <= 16) { + if data == -1 || (1..=16).contains(&data) { let opcode = opcodes::All::from( (data - 1 + opcodes::OP_TRUE.into_u8() as i64) as u8 ); @@ -1134,7 +1133,7 @@ impl Decodable for ColorIdentifier { let payload = sha256::Hash::from_slice(&bytes[1..]).map_err(|_| encode::Error::ParseFailed("invalid payload."))?; Ok(ColorIdentifier { - token_type: token_type, + token_type, payload: ColorIdentifierPayload(payload) }) } @@ -1162,12 +1161,10 @@ pub enum TokenTypes { impl TokenTypes { /// return true if token type is supported pub fn is_valid(token_type: &u8) -> bool { - vec![ - TokenTypes::None, + [TokenTypes::None, TokenTypes::Reissuable, TokenTypes::NonReissuable, - TokenTypes::Nft, - ].iter().any(|e| e.clone() as u8 == *token_type) + TokenTypes::Nft].iter().any(|e| e.clone() as u8 == *token_type) } } diff --git a/src/blockdata/transaction.rs b/src/blockdata/transaction.rs index b7dfea38..4c3bef30 100644 --- a/src/blockdata/transaction.rs +++ b/src/blockdata/transaction.rs @@ -57,8 +57,8 @@ impl OutPoint { #[inline] pub fn new(txid: Txid, vout: u32) -> OutPoint { OutPoint { - txid: txid, - vout: vout, + txid, + vout, } } @@ -67,7 +67,7 @@ impl OutPoint { pub fn null() -> OutPoint { OutPoint { txid: Default::default(), - vout: u32::max_value(), + vout: u32::MAX, } } @@ -136,12 +136,12 @@ impl ::std::error::Error for ParseOutPointError { /// It does not permit leading zeroes or non-digit characters. fn parse_vout(s: &str) -> Result { if s.len() > 1 { - let first = s.chars().nth(0).unwrap(); + let first = s.chars().next().unwrap(); if first == '0' || first == '+' { return Err(ParseOutPointError::VoutNotCanonical); } } - Ok(s.parse().map_err(ParseOutPointError::Vout)?) + s.parse().map_err(ParseOutPointError::Vout) } impl ::std::str::FromStr for OutPoint { @@ -152,7 +152,7 @@ impl ::std::str::FromStr for OutPoint { return Err(ParseOutPointError::TooLong); } let find = s.find(':'); - if find == None || find != s.rfind(':') { + if find.is_none() || find != s.rfind(':') { return Err(ParseOutPointError::Format); } let colon = find.unwrap(); @@ -193,7 +193,7 @@ impl Default for TxIn { TxIn { previous_output: OutPoint::default(), script_sig: Script::new(), - sequence: u32::max_value(), + sequence: u32::MAX, witness: Vec::new(), } } @@ -557,9 +557,9 @@ impl Decodable for Transaction { Err(encode::Error::ParseFailed("witness flag set but no witnesses present")) } else { Ok(Transaction { - version: version, - input: input, - output: output, + version, + input, + output, lock_time: Decodable::consensus_decode(d)?, }) } @@ -572,8 +572,8 @@ impl Decodable for Transaction { // non-segwit } else { Ok(Transaction { - version: version, - input: input, + version, + input, output: Decodable::consensus_decode(&mut d)?, lock_time: Decodable::consensus_decode(d)?, }) diff --git a/src/consensus/encode.rs b/src/consensus/encode.rs index 09d51177..be15e818 100644 --- a/src/consensus/encode.rs +++ b/src/consensus/encode.rs @@ -29,7 +29,7 @@ //! big-endian decimals, etc.) //! -use std::{fmt, error, io, mem, u32}; +use std::{fmt, error, io, mem}; use std::borrow::Cow; use std::io::{Cursor, Read, Write}; use crate::hashes::hex::ToHex; @@ -146,8 +146,6 @@ impl error::Error for Error { } } -#[doc(hidden)] - #[doc(hidden)] impl From for Error { fn from(error: io::Error) -> Self { @@ -408,6 +406,13 @@ impl VarInt { _ => { 9 } } } + + /// Returns whether this VarInt is empty. Always returns false since VarInt + /// always encodes to at least 1 byte. + #[inline] + pub fn is_empty(&self) -> bool { + false + } } impl Encodable for VarInt { @@ -430,7 +435,7 @@ impl Encodable for VarInt { }, _ => { s.emit_u8(0xFF)?; - (self.0 as u64).consensus_encode(s)?; + self.0.consensus_encode(s)?; Ok(9) }, } @@ -494,7 +499,7 @@ impl Encodable for String { fn consensus_encode(&self, mut s: S) -> Result { let b = self.as_bytes(); let vi_len = VarInt(b.len() as u64).consensus_encode(&mut s)?; - s.emit_slice(&b)?; + s.emit_slice(b)?; Ok(vi_len + b.len()) } } @@ -513,7 +518,7 @@ impl Encodable for Cow<'static, str> { fn consensus_encode(&self, mut s: S) -> Result { let b = self.as_bytes(); let vi_len = VarInt(b.len() as u64).consensus_encode(&mut s)?; - s.emit_slice(&b)?; + s.emit_slice(b)?; Ok(vi_len + b.len()) } } @@ -629,7 +634,7 @@ impl_vec!(u64); fn consensus_encode_with_size(data: &[u8], mut s: S) -> Result { let vi_len = VarInt(data.len() as u64).consensus_encode(&mut s)?; - s.emit_slice(&data)?; + s.emit_slice(data)?; Ok(vi_len + data.len()) } diff --git a/src/hash_types.rs b/src/hash_types.rs index 878d6510..71a653c2 100644 --- a/src/hash_types.rs +++ b/src/hash_types.rs @@ -16,9 +16,9 @@ //! to avoid mixing data of the same hash format (like SHA256d) but of different meaning //! (transaction id, block hash etc). -use crate::consensus::encode::{Encodable, Decodable, Error}; -use crate::hashes::{Hash, sha256, sha256d, ripemd160, hash160}; -use crate::hashes::hex::{FromHex, ToHex}; +use crate::consensus::encode::{Encodable, Decodable}; +use crate::hashes::{Hash, sha256, sha256d, hash160}; +use crate::hashes::hex::FromHex; macro_rules! impl_hashencode { ($hashtype:ident) => { diff --git a/src/internal_macros.rs b/src/internal_macros.rs index 9e3348b7..71aaa329 100644 --- a/src/internal_macros.rs +++ b/src/internal_macros.rs @@ -137,7 +137,7 @@ macro_rules! impl_array_newtype { impl ::std::clone::Clone for $thing { #[inline] fn clone(&self) -> $thing { - $thing::from(&self[..]) + *self } } diff --git a/src/network/address.rs b/src/network/address.rs index ef118d0f..af5bea7a 100644 --- a/src/network/address.rs +++ b/src/network/address.rs @@ -45,7 +45,7 @@ impl Address { SocketAddr::V4(addr) => (addr.ip().to_ipv6_mapped().segments(), addr.port()), SocketAddr::V6(addr) => (addr.ip().segments(), addr.port()) }; - Address { address: address, port: port, services: services } + Address { address, port, services } } /// extract socket address from an address message diff --git a/src/network/constants.rs b/src/network/constants.rs index 1d290fed..88c07ed5 100644 --- a/src/network/constants.rs +++ b/src/network/constants.rs @@ -51,7 +51,7 @@ pub const PROTOCOL_VERSION: u32 = 10000; /// Bitfield of services provided by this node pub const SERVICES: u64 = 0; /// User agent as it appears in the version message -pub const USER_AGENT: &'static str = "tapyrus-rust v0.1"; +pub const USER_AGENT: &str = "tapyrus-rust v0.1"; /// Network ID is identifier of the Tapyrus network #[derive(Clone, Debug, PartialEq)] @@ -262,9 +262,9 @@ impl From for ServiceFlags { } } -impl Into for ServiceFlags { - fn into(self) -> u64 { - self.0 +impl From for u64 { + fn from(val: ServiceFlags) -> Self { + val.0 } } diff --git a/src/network/message.rs b/src/network/message.rs index ddf96483..6a55f2a7 100644 --- a/src/network/message.rs +++ b/src/network/message.rs @@ -72,7 +72,7 @@ impl Encodable for CommandString { if strbytes.len() > 12 { return Err(encode::Error::UnrecognizedNetworkCommand(self.0.clone().into_owned())); } - rawbytes[..strbytes.len()].clone_from_slice(&strbytes[..]); + rawbytes[..strbytes.len()].clone_from_slice(strbytes); rawbytes.consensus_encode(s) } } @@ -327,8 +327,8 @@ impl Decodable for RawNetworkMessage { _ => return Err(encode::Error::UnrecognizedNetworkCommand(cmd.into_owned())), }; Ok(RawNetworkMessage { - magic: magic, - payload: payload + magic, + payload }) } } diff --git a/src/network/message_blockdata.rs b/src/network/message_blockdata.rs index 279af0a9..f9d96b79 100644 --- a/src/network/message_blockdata.rs +++ b/src/network/message_blockdata.rs @@ -111,8 +111,8 @@ impl GetBlocksMessage { pub fn new(locator_hashes: Vec, stop_hash: BlockHash) -> GetBlocksMessage { GetBlocksMessage { version: constants::PROTOCOL_VERSION, - locator_hashes: locator_hashes, - stop_hash: stop_hash + locator_hashes, + stop_hash } } } @@ -124,8 +124,8 @@ impl GetHeadersMessage { pub fn new(locator_hashes: Vec, stop_hash: BlockHash) -> GetHeadersMessage { GetHeadersMessage { version: constants::PROTOCOL_VERSION, - locator_hashes: locator_hashes, - stop_hash: stop_hash + locator_hashes, + stop_hash } } } diff --git a/src/network/message_network.rs b/src/network/message_network.rs index 471fcd1b..ec119dd4 100644 --- a/src/network/message_network.rs +++ b/src/network/message_network.rs @@ -28,8 +28,6 @@ use crate::consensus::encode; use crate::network::message::CommandString; use crate::hashes::sha256d; -/// Some simple messages - /// The `version` message #[derive(PartialEq, Eq, Clone, Debug)] pub struct VersionMessage { @@ -68,13 +66,13 @@ impl VersionMessage { ) -> VersionMessage { VersionMessage { version: constants::PROTOCOL_VERSION, - services: services, - timestamp: timestamp, - receiver: receiver, - sender: sender, - nonce: nonce, - user_agent: user_agent, - start_height: start_height, + services, + timestamp, + receiver, + sender, + nonce, + user_agent, + start_height, relay: false, } } diff --git a/src/util/address.rs b/src/util/address.rs index 7d7046a7..85cb005f 100644 --- a/src/util/address.rs +++ b/src/util/address.rs @@ -216,7 +216,7 @@ impl Address { pk.write_into(&mut hash_engine); Address { - network: network, + network, payload: Payload::PubkeyHash(PubkeyHash::from_engine(hash_engine)), } } @@ -226,7 +226,7 @@ impl Address { #[inline] pub fn p2sh(script: &Script, network: Network) -> Address { Address { - network: network, + network, payload: Payload::ScriptHash(ScriptHash::hash(&script[..])), } } @@ -239,7 +239,7 @@ impl Address { pk.write_into(&mut hash_engine); Address { - network: network, + network, payload: Payload::ColoredPubkeyHash(color_id.clone(), PubkeyHash::from_engine(hash_engine)), } } @@ -249,7 +249,7 @@ impl Address { #[inline] pub fn cp2sh(color_id: &ColorIdentifier, script: &Script, network: Network) -> Address { Address { - network: network, + network, payload: Payload::ColoredScriptHash(color_id.clone(), ScriptHash::hash(&script[..])), } } @@ -278,7 +278,7 @@ impl Address { pub fn from_script(script: &Script, network: Network) -> Option
{ Some(Address { payload: Payload::from_script(script)?, - network: network, + network, }) } @@ -395,7 +395,7 @@ impl FromStr for Address { impl ::std::fmt::Debug for Address { fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { - write!(f, "{}", self.to_string()) + write!(f, "{}", self) } } diff --git a/src/util/amount.rs b/src/util/amount.rs index db5db31f..6965e48e 100644 --- a/src/util/amount.rs +++ b/src/util/amount.rs @@ -152,7 +152,7 @@ fn parse_signed_to_tapyrus( // into a less precise amount. That is not allowed unless // there are no decimals and the last digits are zeroes as // many as the difference in precision. - let last_n = precision_diff.abs() as usize; + let last_n = precision_diff.unsigned_abs() as usize; if is_too_precise(s, last_n) { return Err(ParseAmountError::TooPrecise); } @@ -226,7 +226,7 @@ fn fmt_tapyrus_in( } Ordering::Less => { // need to inject a comma in the number - let nb_decimals = precision.abs() as usize; + let nb_decimals = precision.unsigned_abs() as usize; let real = format!("{:0width$}", tapyrus, width = nb_decimals); if real.len() == nb_decimals { write!(f, "0.{}", &real[real.len() - nb_decimals..])?; @@ -284,12 +284,12 @@ impl Amount { /// The maximum value of an [Amount]. pub fn max_value() -> Amount { - Amount(u64::max_value()) + Amount(u64::MAX) } /// The minimum value of an [Amount]. pub fn min_value() -> Amount { - Amount(u64::min_value()) + Amount(u64::MIN) } /// Convert from a value expressing tpcs to an [Amount]. @@ -306,7 +306,7 @@ impl Amount { if negative { return Err(ParseAmountError::Negative); } - if tapyrus > i64::max_value() as u64 { + if tapyrus > i64::MAX as u64 { return Err(ParseAmountError::TooBig); } Ok(Amount::from_tap(tapyrus)) @@ -324,7 +324,7 @@ impl Amount { return Err(ParseAmountError::InvalidFormat); } - Ok(Amount::from_str_in(amt_str, denom_str.parse()?)?) + Amount::from_str_in(amt_str, denom_str.parse()?) } /// Express this [Amount] as a floating-point value in the given denomination. @@ -562,12 +562,12 @@ impl SignedAmount { /// The maximum value of an [SignedAmount]. pub fn max_value() -> SignedAmount { - SignedAmount(i64::max_value()) + SignedAmount(i64::MAX) } /// The minimum value of an [SignedAmount]. pub fn min_value() -> SignedAmount { - SignedAmount(i64::min_value()) + SignedAmount(i64::MIN) } /// Convert from a value expressing tpcs to an [SignedAmount]. @@ -581,7 +581,7 @@ impl SignedAmount { /// with denomination, use [FromStr]. pub fn from_str_in(s: &str, denom: Denomination) -> Result { let (negative, tapyrus) = parse_signed_to_tapyrus(s, denom)?; - if tapyrus > i64::max_value() as u64 { + if tapyrus > i64::MAX as u64 { return Err(ParseAmountError::TooBig); } Ok(match negative { @@ -602,7 +602,7 @@ impl SignedAmount { return Err(ParseAmountError::InvalidFormat); } - Ok(SignedAmount::from_str_in(amt_str, denom_str.parse()?)?) + SignedAmount::from_str_in(amt_str, denom_str.parse()?) } /// Express this [SignedAmount] as a floating-point value in the given denomination. @@ -641,7 +641,7 @@ impl SignedAmount { pub fn fmt_value_in(self, f: &mut dyn fmt::Write, denom: Denomination) -> fmt::Result { let taps = self.as_tap().checked_abs().map(|a: i64| a as u64).unwrap_or_else(|| { // We could also hard code this into `9223372036854775808` - u64::max_value() - self.as_tap() as u64 +1 + u64::MAX - self.as_tap() as u64 +1 }); fmt_tapyrus_in(taps, self.is_negative(), f, denom) } diff --git a/src/util/base58.rs b/src/util/base58.rs index 718c1c68..c272f20f 100644 --- a/src/util/base58.rs +++ b/src/util/base58.rs @@ -347,14 +347,14 @@ pub fn encode_slice(data: &[u8]) -> String { /// Obtain a string with the base58check encoding of a slice /// (Tack the first 4 256-digits of the object's Bitcoin hash onto the end.) pub fn check_encode_slice(data: &[u8]) -> String { - let checksum = sha256d::Hash::hash(&data); + let checksum = sha256d::Hash::hash(data); encode_iter(data.iter().cloned().chain(checksum[0..4].iter().cloned())) } /// Obtain a string with the base58check encoding of a slice /// (Tack the first 4 256-digits of the object's Bitcoin hash onto the end.) pub fn check_encode_slice_to_fmt(fmt: &mut fmt::Formatter, data: &[u8]) -> fmt::Result { - let checksum = sha256d::Hash::hash(&data); + let checksum = sha256d::Hash::hash(data); let iter = data.iter().cloned().chain(checksum[0..4].iter().cloned()); format_iter(fmt, iter) } diff --git a/src/util/bip143.rs b/src/util/bip143.rs index caaa76d8..39481a1f 100644 --- a/src/util/bip143.rs +++ b/src/util/bip143.rs @@ -76,9 +76,9 @@ impl SighashComponents { SighashComponents { tx_version: tx.version, tx_locktime: tx.lock_time, - hash_prevouts: hash_prevouts, - hash_sequence: hash_sequence, - hash_outputs: hash_outputs, + hash_prevouts, + hash_sequence, + hash_outputs, } } @@ -122,7 +122,7 @@ impl> SigHashCache { /// script_sig and witnesses. pub fn new(tx: R) -> Self { SigHashCache { - tx: tx, + tx, hash_prevouts: None, hash_sequence: None, hash_outputs: None, diff --git a/src/util/bip158.rs b/src/util/bip158.rs index 16c006b9..9c5793ec 100644 --- a/src/util/bip158.rs +++ b/src/util/bip158.rs @@ -448,7 +448,7 @@ impl<'a> BitStreamReader<'a> { pub fn new(reader: &'a mut dyn io::Read) -> BitStreamReader<'a> { BitStreamReader { buffer: [0u8], - reader: reader, + reader, offset: 8, } } @@ -456,7 +456,7 @@ impl<'a> BitStreamReader<'a> { /// Read nbit bits pub fn read(&mut self, mut nbits: u8) -> Result { if nbits > 64 { - return Err(io::Error::new(io::ErrorKind::Other, "can not read more than 64 bits at once")); + return Err(io::Error::other("can not read more than 64 bits at once")); } let mut data = 0u64; while nbits > 0 { @@ -486,7 +486,7 @@ impl<'a> BitStreamWriter<'a> { pub fn new(writer: &'a mut dyn io::Write) -> BitStreamWriter<'a> { BitStreamWriter { buffer: [0u8], - writer: writer, + writer, offset: 0, } } @@ -494,7 +494,7 @@ impl<'a> BitStreamWriter<'a> { /// Write nbits bits from data pub fn write(&mut self, data: u64, mut nbits: u8) -> Result { if nbits > 64 { - return Err(io::Error::new(io::ErrorKind::Other, "can not write more than 64 bits at once")); + return Err(io::Error::other("can not write more than 64 bits at once")); } let mut wrote = 0; while nbits > 0 { diff --git a/src/util/bip32.rs b/src/util/bip32.rs index bcff085d..7f23744d 100644 --- a/src/util/bip32.rs +++ b/src/util/bip32.rs @@ -42,14 +42,12 @@ impl_array_newtype_show!(ChainCode); impl_bytes_newtype!(ChainCode, 32); /// A fingerprint +#[derive(Default)] pub struct Fingerprint([u8; 4]); impl_array_newtype!(Fingerprint, u8, 4); impl_array_newtype_show!(Fingerprint); impl_bytes_newtype!(Fingerprint, 4); -impl Default for Fingerprint { - fn default() -> Fingerprint { Fingerprint([0; 4]) } -} /// Extended private key #[derive(Copy, Clone, PartialEq, Eq, Debug)] @@ -109,7 +107,7 @@ impl ChildNumber { /// [`Normal`]: #variant.Normal pub fn from_normal_idx(index: u32) -> Result { if index & (1 << 31) == 0 { - Ok(ChildNumber::Normal { index: index }) + Ok(ChildNumber::Normal { index }) } else { Err(Error::InvalidChildNumber(index)) } @@ -121,7 +119,7 @@ impl ChildNumber { /// [`Hardened`]: #variant.Hardened pub fn from_hardened_idx(index: u32) -> Result { if index & (1 << 31) == 0 { - Ok(ChildNumber::Hardened { index: index }) + Ok(ChildNumber::Hardened { index }) } else { Err(Error::InvalidChildNumber(index)) } @@ -185,7 +183,7 @@ impl FromStr for ChildNumber { type Err = Error; fn from_str(inp: &str) -> Result { - let is_hardened = inp.chars().last().map_or(false, |l| l == '\'' || l == 'h'); + let is_hardened = inp.chars().last().is_some_and(|l| l == '\'' || l == 'h'); Ok(if is_hardened { ChildNumber::from_hardened_idx(inp[0..inp.len() - 1].parse().map_err(|_| Error::InvalidChildNumberFormat)?)? } else { @@ -225,9 +223,9 @@ impl From> for DerivationPath { } } -impl Into> for DerivationPath { - fn into(self) -> Vec { - self.0 +impl From for Vec { + fn from(val: DerivationPath) -> Self { + val.0 } } @@ -319,17 +317,17 @@ impl DerivationPath { /// Get an [Iterator] over the children of this [DerivationPath] /// starting with the given [ChildNumber]. pub fn children_from(&self, cn: ChildNumber) -> DerivationPathIterator<'_> { - DerivationPathIterator::start_from(&self, cn) + DerivationPathIterator::start_from(self, cn) } /// Get an [Iterator] over the unhardened children of this [DerivationPath]. pub fn normal_children(&self) -> DerivationPathIterator<'_> { - DerivationPathIterator::start_from(&self, ChildNumber::Normal{ index: 0 }) + DerivationPathIterator::start_from(self, ChildNumber::Normal{ index: 0 }) } /// Get an [Iterator] over the hardened children of this [DerivationPath]. pub fn hardened_children(&self) -> DerivationPathIterator<'_> { - DerivationPathIterator::start_from(&self, ChildNumber::Hardened{ index: 0 }) + DerivationPathIterator::start_from(self, ChildNumber::Hardened{ index: 0 }) } } @@ -443,13 +441,13 @@ impl ExtendedPrivKey { let hmac_result: Hmac = Hmac::from_engine(hmac_engine); Ok(ExtendedPrivKey { - network: network, + network, depth: 0, parent_fingerprint: Default::default(), child_number: ChildNumber::from_normal_idx(0)?, private_key: PrivateKey { compressed: true, - network: network, + network, key: secp256k1::SecretKey::from_slice( &hmac_result[..32] ).map_err(Error::Ecdsa)?, @@ -586,7 +584,7 @@ impl ExtendedPubKey { parent_fingerprint: self.fingerprint(), child_number: i, public_key: pk, - chain_code: chain_code + chain_code }) } @@ -610,7 +608,7 @@ impl fmt::Display for ExtendedPrivKey { Network::Prod => [0x04, 0x88, 0xAD, 0xE4], Network::Dev => [0x04, 0x35, 0x83, 0x94], }[..]); - ret[4] = self.depth as u8; + ret[4] = self.depth; ret[5..9].copy_from_slice(&self.parent_fingerprint[..]); ret[9..13].copy_from_slice(&endian::u32_to_array_be(u32::from(self.child_number))); ret[13..45].copy_from_slice(&self.chain_code[..]); @@ -638,18 +636,18 @@ impl FromStr for ExtendedPrivKey { } else if data[0..4] == [0x04u8, 0x35, 0x83, 0x94] { Network::Dev } else { - return Err(base58::Error::InvalidVersion((&data[0..4]).to_vec())); + return Err(base58::Error::InvalidVersion(data[0..4].to_vec())); }; Ok(ExtendedPrivKey { - network: network, + network, depth: data[4], parent_fingerprint: Fingerprint::from(&data[5..9]), - child_number: child_number, + child_number, chain_code: ChainCode::from(&data[13..45]), private_key: PrivateKey { compressed: true, - network: network, + network, key: secp256k1::SecretKey::from_slice( &data[46..78] ).map_err(|e| @@ -667,7 +665,7 @@ impl fmt::Display for ExtendedPubKey { Network::Prod => [0x04u8, 0x88, 0xB2, 0x1E], Network::Dev => [0x04u8, 0x35, 0x87, 0xCF], }[..]); - ret[4] = self.depth as u8; + ret[4] = self.depth; ret[5..9].copy_from_slice(&self.parent_fingerprint[..]); ret[9..13].copy_from_slice(&endian::u32_to_array_be(u32::from(self.child_number))); ret[13..45].copy_from_slice(&self.chain_code[..]); @@ -695,11 +693,11 @@ impl FromStr for ExtendedPubKey { } else if data[0..4] == [0x04u8, 0x35, 0x87, 0xCF] { Network::Dev } else { - return Err(base58::Error::InvalidVersion((&data[0..4]).to_vec())); + return Err(base58::Error::InvalidVersion(data[0..4].to_vec())); }, depth: data[4], parent_fingerprint: Fingerprint::from(&data[5..9]), - child_number: child_number, + child_number, chain_code: ChainCode::from(&data[13..45]), public_key: PublicKey::from_slice( &data[45..78]).map_err(|e| diff --git a/src/util/contracthash.rs b/src/util/contracthash.rs index 1e417a9e..82b10e22 100644 --- a/src/util/contracthash.rs +++ b/src/util/contracthash.rs @@ -131,15 +131,12 @@ impl Template { /// will represent the number of signatures that are required for the script /// to pass. pub fn first_push_as_number(&self) -> Option { - if !self.0.is_empty() { - if let TemplateElement::Op(op) = self.0[0] { - if let opcodes::Class::PushNum(n) = op.classify() { - if n >= 0 { + if !self.0.is_empty() + && let TemplateElement::Op(op) = self.0[0] + && let opcodes::Class::PushNum(n) = op.classify() + && n >= 0 { return Some(n as usize); } - } - } - } None } } @@ -182,7 +179,7 @@ pub fn compute_tweak(pk: &PublicKey, contract: &[u8]) -> Hmac { /// Tweak a secret key using some arbitrary data (calls `compute_tweak` internally) pub fn tweak_secret_key(secp: &Secp256k1, key: &PrivateKey, contract: &[u8]) -> Result { // Compute public key - let pk = PublicKey::from_private_key(secp, &key); + let pk = PublicKey::from_private_key(secp, key); // Compute tweak let hmac_sk = compute_tweak(&pk, contract); // Execute the tweak @@ -202,7 +199,7 @@ pub fn create_address(secp: &Secp256k1, let keys = tweak_keys(secp, keys, contract); let script = template.to_script(&keys)?; Ok(address::Address { - network: network, + network, payload: address::Payload::ScriptHash( ScriptHash::hash(&script[..]) ) diff --git a/src/util/hash.rs b/src/util/hash.rs index 440e3e22..5e127df7 100644 --- a/src/util/hash.rs +++ b/src/util/hash.rs @@ -42,7 +42,7 @@ pub fn bitcoin_merkle_root_inline(data: &mut [T]) -> T return T::from_inner(data[0].into_inner()); } // Recursion - for idx in 0..((data.len() + 1) / 2) { + for idx in 0..data.len().div_ceil(2) { let idx1 = 2 * idx; let idx2 = min(idx1 + 1, data.len() - 1); let mut encoder = T::engine(); @@ -65,7 +65,7 @@ pub fn bitcoin_merkle_root(mut iter: I) -> T return Default::default(); } if iter.len() == 1 { - return T::from_inner(iter.nth(0).unwrap().into_inner()); + return T::from_inner(iter.next().unwrap().into_inner()); } // Recursion let half_len = iter.len() / 2 + iter.len() % 2; diff --git a/src/util/key.rs b/src/util/key.rs index dd0fd6aa..980621cb 100644 --- a/src/util/key.rs +++ b/src/util/key.rs @@ -112,7 +112,7 @@ impl PublicKey { }; Ok(PublicKey { - compressed: compressed, + compressed, key: secp256k1::PublicKey::from_slice(data)?, }) } @@ -157,7 +157,7 @@ impl FromStr for PublicKey { fn from_str(s: &str) -> Result { let key = secp256k1::PublicKey::from_str(s)?; Ok(PublicKey { - key: key, + key, compressed: s.len() == 66 }) } @@ -230,8 +230,8 @@ impl PrivateKey { }; Ok(PrivateKey { - compressed: compressed, - network: network, + compressed, + network, key: secp256k1::SecretKey::from_slice(&data[1..33])?, }) } diff --git a/src/util/merkleblock.rs b/src/util/merkleblock.rs index 82b4adfa..9e5abd6e 100644 --- a/src/util/merkleblock.rs +++ b/src/util/merkleblock.rs @@ -117,6 +117,7 @@ pub enum MerkleBlockError { /// - uint256[] hashes in depth-first order (<= 32*N bytes) /// - varint number of bytes of flag bits (1-3 bytes) /// - byte[] flag bits, packed per 8 in a byte, least significant bit first (<= 2*N-1 bits) +/// /// The size constraints follow from this. #[derive(PartialEq, Eq, Clone, Debug)] pub struct PartialMerkleTree { @@ -216,7 +217,7 @@ impl PartialMerkleTree { self.traverse_and_extract(height, 0, &mut bits_used, &mut hash_used, matches, indexes)?; // Verify that all bits were consumed (except for the padding caused by // serializing it as a byte sequence) - if (bits_used + 7) / 8 != (self.bits.len() as u32 + 7) / 8 { + if bits_used.div_ceil(8) != (self.bits.len() as u32).div_ceil(8) { return Err(BadFormat("Not all bit were consumed".to_owned())); } // Verify that all hashes were consumed @@ -361,7 +362,7 @@ impl Encodable for PartialMerkleTree { ) -> Result { let ret = self.num_transactions.consensus_encode(&mut s)? + self.hashes.consensus_encode(&mut s)?; - let mut bytes: Vec = vec![0; (self.bits.len() + 7) / 8]; + let mut bytes: Vec = vec![0; self.bits.len().div_ceil(8)]; for p in 0..self.bits.len() { bytes[p / 8] |= (self.bits[p] as u8) << (p % 8) as u8; } @@ -453,12 +454,12 @@ impl MerkleBlock { match_txids: &HashSet, ) -> Self { let matches: Vec = block_txids - .into_iter() + .iter() .map(|txid| match_txids.contains(txid)) .collect(); - let pmt = PartialMerkleTree::from_txids(&block_txids, &matches); + let pmt = PartialMerkleTree::from_txids(block_txids, &matches); MerkleBlock { header: header.clone(), txn: pmt, diff --git a/src/util/prime.rs b/src/util/prime.rs index ebe5f79c..d7a6e072 100644 --- a/src/util/prime.rs +++ b/src/util/prime.rs @@ -25,12 +25,12 @@ pub fn jacobi(a: &[u8]) -> i8 { } fn jacobi_inner(a: &Integer, n: &Integer) -> i8 { - assert!(*n >= Integer::from(3)); + assert!(*n >= 3); let a = Integer::from(a % n); - if a == Integer::from(0) { + if a == 0 { return 0; } - if a == Integer::from(1) { + if a == 1 { return 1; } @@ -57,7 +57,7 @@ fn jacobi_inner(a: &Integer, n: &Integer) -> i8 { s = -s } - if a1 == Integer::from(1) { + if a1 == 1 { s } else { s * jacobi_inner(&(n % a1.clone()), &a1.clone()) diff --git a/src/util/psbt/macros.rs b/src/util/psbt/macros.rs index 4e9a2d2a..41bd5645 100644 --- a/src/util/psbt/macros.rs +++ b/src/util/psbt/macros.rs @@ -100,7 +100,7 @@ macro_rules! impl_psbtmap_consensus_enc_dec_oding { }; } -#[cfg_attr(rustfmt, rustfmt_skip)] +#[rustfmt::skip] macro_rules! impl_psbt_insert_pair { ($slf:ident.$unkeyed_name:ident <= <$raw_key:ident: _>|<$raw_value:ident: $unkeyed_value_type:ty>) => { if $raw_key.key.is_empty() { @@ -130,7 +130,7 @@ macro_rules! impl_psbt_insert_pair { }; } -#[cfg_attr(rustfmt, rustfmt_skip)] +#[rustfmt::skip] macro_rules! impl_psbt_get_pair { ($rv:ident.push($slf:ident.$unkeyed_name:ident as <$unkeyed_typeval:expr_2021, _>|<$unkeyed_value_type:ty>)) => { if let Some(ref $unkeyed_name) = $slf.$unkeyed_name { diff --git a/src/util/psbt/mod.rs b/src/util/psbt/mod.rs index deabb80e..20289b04 100644 --- a/src/util/psbt/mod.rs +++ b/src/util/psbt/mod.rs @@ -126,7 +126,7 @@ impl Decodable for PartiallySignedTransaction { let global: Global = Decodable::consensus_decode(&mut d)?; let inputs: Vec = { - let inputs_len: usize = (&global.unsigned_tx.input).len(); + let inputs_len: usize = global.unsigned_tx.input.len(); let mut inputs: Vec = Vec::with_capacity(inputs_len); @@ -138,7 +138,7 @@ impl Decodable for PartiallySignedTransaction { }; let outputs: Vec = { - let outputs_len: usize = (&global.unsigned_tx.output).len(); + let outputs_len: usize = global.unsigned_tx.output.len(); let mut outputs: Vec = Vec::with_capacity(outputs_len); @@ -150,9 +150,9 @@ impl Decodable for PartiallySignedTransaction { }; Ok(PartiallySignedTransaction { - global: global, - inputs: inputs, - outputs: outputs, + global, + inputs, + outputs, }) } } diff --git a/src/util/psbt/raw.rs b/src/util/psbt/raw.rs index b7844d48..d3c38a27 100644 --- a/src/util/psbt/raw.rs +++ b/src/util/psbt/raw.rs @@ -77,8 +77,8 @@ impl Decodable for Key { } Ok(Key { - type_value: type_value, - key: key, + type_value, + key, }) } } diff --git a/src/util/rfc6979.rs b/src/util/rfc6979.rs index ae706f4e..acfb3e73 100644 --- a/src/util/rfc6979.rs +++ b/src/util/rfc6979.rs @@ -56,7 +56,7 @@ impl RFC6979 { let mut hmac = HmacEngine::::new(&rng.k[..]); hmac.input(&rng.v[..]); hmac.input(&zero[..]); - hmac.input(&keydata[..]); + hmac.input(keydata); rng.k = Hmac::from_engine(hmac).into_inner(); let mut hmac = HmacEngine::::new(&rng.k[..]); hmac.input(&rng.v[..]); @@ -66,7 +66,7 @@ impl RFC6979 { let mut hmac = HmacEngine::::new(&rng.k[..]); hmac.input(&rng.v[..]); hmac.input(&one[..]); - hmac.input(&keydata[..]); + hmac.input(keydata); rng.k = Hmac::from_engine(hmac).into_inner(); let mut hmac = HmacEngine::::new(&rng.k[..]); hmac.input(&rng.v[..]); @@ -94,7 +94,7 @@ impl RFC6979 { self.retry = true; - self.v.clone() + self.v } } diff --git a/src/util/signature.rs b/src/util/signature.rs index 222a5c1e..947a855b 100644 --- a/src/util/signature.rs +++ b/src/util/signature.rs @@ -63,7 +63,7 @@ impl Signature { // Compute s = k + ep let sigma = { - let mut result = e.clone(); + let mut result = e; result.mul_assign(&sk[..])?; result.add_assign(&k[..])?; result @@ -93,7 +93,7 @@ impl Signature { let r = { e.negate_assign(); let minus_ep = { - let mut result = pk.clone(); + let mut result = *pk; result.mul_assign(&ctx, &e[..])?; result }; @@ -108,7 +108,7 @@ impl Signature { }; // Check that R.x is what we expect - if &r.serialize()[1..33] != self.r_x { + if r.serialize()[1..33] != self.r_x { return Err(Error::InvalidSignature); } @@ -128,7 +128,7 @@ impl Signature { engine.input(message); let hash = sha256::Hash::from_engine(engine); - Ok(SecretKey::from_slice(&hash[..])?) + SecretKey::from_slice(&hash[..]) } fn generate_k(sk: &SecretKey, message: &[u8; 32]) -> SecretKey { From 096bf6aab213e39793ed590c52531d79fb82e665 Mon Sep 17 00:00:00 2001 From: azuchi Date: Thu, 25 Dec 2025 15:48:56 +0900 Subject: [PATCH 4/7] Fix warnings --- Cargo.toml | 2 +- src/consensus/encode.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3009d1cb..b38952e1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tapyrus" -version = "0.4.8" +version = "0.5.0" edition = "2024" authors = ["Kohei Taniguchi ", "Hajime Yamaguchi "] license = "MIT" diff --git a/src/consensus/encode.rs b/src/consensus/encode.rs index be15e818..99d002e4 100644 --- a/src/consensus/encode.rs +++ b/src/consensus/encode.rs @@ -1066,7 +1066,7 @@ mod tests { for _ in 0..10 { round_trip!{bool, i8, u8, i16, u16, i32, u32, i64, u64, (bool, i8, u16, i32), (u64, i64, u32, i32, u16, i16), (i8, u8, i16, u16, i32, u32, i64, u64), - [u8; 2], [u8; 4], [u8; 8], [u8; 12], [u8; 16], [u8; 32]}; + [u8; 2], [u8; 4], [u8; 8], [u8; 12], [u8; 16], [u8; 32]} data.clear(); data64.clear(); @@ -1075,7 +1075,7 @@ mod tests { data64.resize(len, 0u64); let mut arr33 = [0u8; 33]; let mut arr16 = [0u16; 8]; - round_trip_bytes!{(Vec, data), ([u8; 33], arr33), ([u16; 8], arr16), (Vec, data64)}; + round_trip_bytes!{(Vec, data), ([u8; 33], arr33), ([u16; 8], arr16), (Vec, data64)} } From 7c501164def249f14eef183cfed94ea72a8ca880 Mon Sep 17 00:00:00 2001 From: azuchi Date: Thu, 25 Dec 2025 16:05:12 +0900 Subject: [PATCH 5/7] Update minimum Rust version to 1.85.0 for Edition 2024 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Edition 2024 requires Rust 1.85.0 or later. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .github/workflows/rust.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 8afee7e5..639aeea6 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -21,10 +21,9 @@ jobs: DO_FUZZ: true DO_BENCH: true AS_DEPENDENCY: true - - rust: 1.65.0 + - rust: 1.85.0 env: AS_DEPENDENCY: true - PIN_VERSIONS: true steps: - name: Install test dependencies run: sudo apt-get install -y binutils-dev libunwind8-dev libcurl4-openssl-dev libelf-dev libdw-dev cmake gcc libiberty-dev From 452c1881ed960c53e021e356c75a2a75e5d505d9 Mon Sep 17 00:00:00 2001 From: azuchi Date: Thu, 25 Dec 2025 16:38:01 +0900 Subject: [PATCH 6/7] Fix ci error --- src/blockdata/transaction.rs | 6 +++--- src/util/amount.rs | 22 +++++++++++----------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/blockdata/transaction.rs b/src/blockdata/transaction.rs index 4c3bef30..61dc9d61 100644 --- a/src/blockdata/transaction.rs +++ b/src/blockdata/transaction.rs @@ -36,7 +36,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::consensus::{encode, Decodable, Encodable}; use crate::hash_types::*; @@ -1200,9 +1200,9 @@ mod tests { #[test] #[cfg(feature="bitcoinconsensus")] fn test_transaction_verify () { - use hashes::hex::FromHex; + use crate::hashes::hex::FromHex; use std::collections::HashMap; - use blockdata::script; + use crate::blockdata::script; // a random recent segwit transaction from blockchain using both old and segwit inputs let mut spending: Transaction = deserialize(Vec::from_hex("020000000001031cfbc8f54fbfa4a33a30068841371f80dbfe166211242213188428f437445c91000000006a47304402206fbcec8d2d2e740d824d3d36cc345b37d9f65d665a99f5bd5c9e8d42270a03a8022013959632492332200c2908459547bf8dbf97c65ab1a28dec377d6f1d41d3d63e012103d7279dfb90ce17fe139ba60a7c41ddf605b25e1c07a4ddcb9dfef4e7d6710f48feffffff476222484f5e35b3f0e43f65fc76e21d8be7818dd6a989c160b1e5039b7835fc00000000171600140914414d3c94af70ac7e25407b0689e0baa10c77feffffffa83d954a62568bbc99cc644c62eb7383d7c2a2563041a0aeb891a6a4055895570000000017160014795d04cc2d4f31480d9a3710993fbd80d04301dffeffffff06fef72f000000000017a91476fd7035cd26f1a32a5ab979e056713aac25796887a5000f00000000001976a914b8332d502a529571c6af4be66399cd33379071c588ac3fda0500000000001976a914fc1d692f8de10ae33295f090bea5fe49527d975c88ac522e1b00000000001976a914808406b54d1044c429ac54c0e189b0d8061667e088ac6eb68501000000001976a914dfab6085f3a8fb3e6710206a5a959313c5618f4d88acbba20000000000001976a914eb3026552d7e3f3073457d0bee5d4757de48160d88ac0002483045022100bee24b63212939d33d513e767bc79300051f7a0d433c3fcf1e0e3bf03b9eb1d70220588dc45a9ce3a939103b4459ce47500b64e23ab118dfc03c9caa7d6bfc32b9c601210354fd80328da0f9ae6eef2b3a81f74f9a6f66761fadf96f1d1d22b1fd6845876402483045022100e29c7e3a5efc10da6269e5fc20b6a1cb8beb92130cc52c67e46ef40aaa5cac5f0220644dd1b049727d991aece98a105563416e10a5ac4221abac7d16931842d5c322012103960b87412d6e169f30e12106bdf70122aabb9eb61f455518322a18b920a4dfa887d30700") .unwrap().as_slice()).unwrap(); diff --git a/src/util/amount.rs b/src/util/amount.rs index 6965e48e..3dd570fd 100644 --- a/src/util/amount.rs +++ b/src/util/amount.rs @@ -874,7 +874,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. @@ -922,7 +922,7 @@ pub mod serde { //! Use with `#[serde(with = "amount::serde::as_tap")]`. use serde::{Deserializer, Serializer}; - use util::amount::serde::SerdeAmount; + use crate::util::amount::serde::SerdeAmount; pub fn serialize(a: &A, s: S) -> Result { a.ser_tap(s) @@ -937,7 +937,7 @@ pub mod serde { //! Use with `#[serde(default, with = "amount::serde::as_tap::opt")]`. use serde::{Deserializer, Serializer}; - use util::amount::serde::SerdeAmount; + use crate::util::amount::serde::SerdeAmount; pub fn serialize( a: &Option, @@ -962,7 +962,7 @@ pub mod serde { //! Use with `#[serde(with = "amount::serde::as_tpc")]`. use serde::{Deserializer, Serializer}; - use util::amount::serde::SerdeAmount; + use crate::util::amount::serde::SerdeAmount; pub fn serialize(a: &A, s: S) -> Result { a.ser_tpc(s) @@ -977,7 +977,7 @@ pub mod serde { //! Use with `#[serde(default, with = "amount::serde::as_tpc::opt")]`. use serde::{Deserializer, Serializer}; - use util::amount::serde::SerdeAmount; + use crate::util::amount::serde::SerdeAmount; pub fn serialize( a: &Option, @@ -1308,9 +1308,9 @@ mod tests { #[derive(Serialize, Deserialize, PartialEq, Debug)] struct T { - #[serde(with = "::util::amount::serde::as_tap")] + #[serde(with = "crate::util::amount::serde::as_tap")] pub amt: Amount, - #[serde(with = "::util::amount::serde::as_tap")] + #[serde(with = "crate::util::amount::serde::as_tap")] pub samt: SignedAmount, } @@ -1337,9 +1337,9 @@ mod tests { #[derive(Serialize, Deserialize, PartialEq, Debug)] struct T { - #[serde(with = "::util::amount::serde::as_tpc")] + #[serde(with = "crate::util::amount::serde::as_tpc")] pub amt: Amount, - #[serde(with = "::util::amount::serde::as_tpc")] + #[serde(with = "crate::util::amount::serde::as_tpc")] pub samt: SignedAmount, } @@ -1377,9 +1377,9 @@ mod tests { #[derive(Serialize, Deserialize, PartialEq, Debug)] struct T { - #[serde(default, with = "::util::amount::serde::as_tpc::opt")] + #[serde(default, with = "crate::util::amount::serde::as_tpc::opt")] pub amt: Option, - #[serde(default, with = "::util::amount::serde::as_tpc::opt")] + #[serde(default, with = "crate::util::amount::serde::as_tpc::opt")] pub samt: Option, } From ac83b6028e86b2084c249a132cc4db1b18960fec Mon Sep 17 00:00:00 2001 From: azuchi Date: Thu, 25 Dec 2025 16:46:49 +0900 Subject: [PATCH 7/7] Fix unstable let --- src/util/contracthash.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/util/contracthash.rs b/src/util/contracthash.rs index 82b10e22..c37dbd21 100644 --- a/src/util/contracthash.rs +++ b/src/util/contracthash.rs @@ -131,12 +131,15 @@ impl Template { /// will represent the number of signatures that are required for the script /// to pass. pub fn first_push_as_number(&self) -> Option { - if !self.0.is_empty() - && let TemplateElement::Op(op) = self.0[0] - && let opcodes::Class::PushNum(n) = op.classify() - && n >= 0 { + if !self.0.is_empty() { + if let TemplateElement::Op(op) = self.0[0] { + if let opcodes::Class::PushNum(n) = op.classify() { + if n >= 0 { return Some(n as usize); } + } + } + } None } }