From 2780e6cdaa2afdc7e190e78ef7822bb1d364f6b2 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Tue, 29 Nov 2022 09:45:28 +1100 Subject: [PATCH] Move base58 module to crate root In preparation for removing the `util` module move the `base58` module to the crate root. This is likely not the final resting place for this module but it is a step in the right direction. Includes addition of rustfmt attribute to skip formatting the digits array. No other changes to the `base58` module. --- bitcoin/src/address.rs | 2 +- bitcoin/src/{util => }/base58.rs | 1 + bitcoin/src/bip32.rs | 2 +- bitcoin/src/crypto/key.rs | 3 +-- bitcoin/src/lib.rs | 1 + bitcoin/src/util/mod.rs | 2 -- 6 files changed, 5 insertions(+), 6 deletions(-) rename bitcoin/src/{util => }/base58.rs (99%) diff --git a/bitcoin/src/address.rs b/bitcoin/src/address.rs index c0ea619c..7772702a 100644 --- a/bitcoin/src/address.rs +++ b/bitcoin/src/address.rs @@ -36,6 +36,7 @@ use bech32; use bitcoin_internals::write_err; use secp256k1::{Secp256k1, Verification, XOnlyPublicKey}; +use crate::base58; use crate::blockdata::constants::{ MAX_SCRIPT_ELEMENT_SIZE, PUBKEY_ADDRESS_PREFIX_MAIN, PUBKEY_ADDRESS_PREFIX_TEST, SCRIPT_ADDRESS_PREFIX_MAIN, SCRIPT_ADDRESS_PREFIX_TEST, @@ -51,7 +52,6 @@ use crate::hashes::{sha256, Hash, HashEngine}; use crate::network::constants::Network; use crate::prelude::*; use crate::taproot::TapBranchHash; -use crate::util::base58; /// Address error. #[derive(Debug, PartialEq, Eq, Clone)] diff --git a/bitcoin/src/util/base58.rs b/bitcoin/src/base58.rs similarity index 99% rename from bitcoin/src/util/base58.rs rename to bitcoin/src/base58.rs index e6c86e7b..a69d84bf 100644 --- a/bitcoin/src/util/base58.rs +++ b/bitcoin/src/base58.rs @@ -16,6 +16,7 @@ use crate::hashes::{sha256d, Hash}; static BASE58_CHARS: &[u8] = b"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; +#[rustfmt::skip] static BASE58_DIGITS: [Option; 128] = [ None, None, None, None, None, None, None, None, // 0-7 None, None, None, None, None, None, None, None, // 8-15 diff --git a/bitcoin/src/bip32.rs b/bitcoin/src/bip32.rs index 038b7177..f5f5f59d 100644 --- a/bitcoin/src/bip32.rs +++ b/bitcoin/src/bip32.rs @@ -18,6 +18,7 @@ use secp256k1::{self, Secp256k1, XOnlyPublicKey}; #[cfg(feature = "serde")] use serde; +use crate::base58; use crate::crypto::key::{self, KeyPair, PrivateKey, PublicKey}; use crate::hash_types::XpubIdentifier; use crate::hashes::{hex, sha512, Hash, HashEngine, Hmac, HmacEngine}; @@ -25,7 +26,6 @@ use crate::internal_macros::impl_bytes_newtype; use crate::io::Write; use crate::network::constants::Network; use crate::prelude::*; -use crate::util::base58; /// A chain code #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] diff --git a/bitcoin/src/crypto/key.rs b/bitcoin/src/crypto/key.rs index b8f06ff1..6c91efa4 100644 --- a/bitcoin/src/crypto/key.rs +++ b/bitcoin/src/crypto/key.rs @@ -14,11 +14,10 @@ use core::fmt::{self, Write}; use bitcoin_internals::write_err; pub use secp256k1::{self, Secp256k1, XOnlyPublicKey, KeyPair}; -use crate::io; +use crate::{base58, io}; use crate::network::constants::Network; use crate::hashes::{Hash, hash160, hex, hex::FromHex}; use crate::hash_types::{PubkeyHash, WPubkeyHash}; -use crate::util::base58; /// A key-related error. #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] diff --git a/bitcoin/src/lib.rs b/bitcoin/src/lib.rs index 2fe89bcd..f6337af5 100644 --- a/bitcoin/src/lib.rs +++ b/bitcoin/src/lib.rs @@ -92,6 +92,7 @@ mod serde_utils; pub mod network; pub mod address; pub mod amount; +pub mod base58; pub mod bip152; pub mod bip158; pub mod bip32; diff --git a/bitcoin/src/util/mod.rs b/bitcoin/src/util/mod.rs index 8d5e538c..95e01c4b 100644 --- a/bitcoin/src/util/mod.rs +++ b/bitcoin/src/util/mod.rs @@ -6,8 +6,6 @@ //! Functions needed by all parts of the Bitcoin library. //! -pub mod base58; - /// The `misc` module was moved and re-named to `sign_message`. pub mod misc { use crate::prelude::*;